package votorola.s.gwt.mediawiki; // Copyright 2012-2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import com.google.gwt.core.client.JavaScriptObject; import votorola.a.count.gwt.*; import votorola.a.diff.*; import votorola.a.web.gwt.*; import votorola.g.web.gwt.*; import votorola.s.gwt.stage.*; import votorola.s.gwt.stage.vote.*; /** A difference between an {@linkplain DifferenceShadows#anchor() anchoring author}'s * position draft and that of an immediate {@linkplain votorola.a.count.XCastRelation * cast relation}. The {@linkplain #selectand selectand} is always set to the ordinal of * the anchoring author. */ public final class ShadowedDiff extends DiffLookJS implements LightableDifference { protected ShadowedDiff() {} // "precisely one constructor... protected, empty, and no-argument" /** Completes the construction of this ShadowedDiff. * * @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER * REL_VOTER}. * @param sec the dart sector, which is used for {@linkplain #REL_VOTER * REL_VOTER} and {@linkplain #REL_CO REL_CO} relations. It must * be -1 for any other relation or an assertion error is raised. * * @see #node() * @see #selectand() */ void init( final String key, final char rel, final int sec, final CountNodeJS node, final String pollName, final boolean isSelectandB ) { final StringBuilder b = new StringBuilder(); b.append( App.getServletContextLocation() ).append( "/w/D?" ); b.append( "k=" ).append( key ); if( isSelectandB ) { _set( "selectand", "b" ); _set( "bodyOrdClass", "voLiDi-ord-a" ); b.append( "&s" ); } else _set( "bodyOrdClass", "voLiDi-ord-b" ); _set( "bridgeLoc", b.toString() ); _set( "key", key ); _set( "node", node ); _set( "pollName", pollName ); _setInt( "segmentCount", 0 ); // DifferenceShadowsV overwrites if diff has segs (not empty) _setBoolean( "toPersist", false ); // else blocks shadow of *latest* diff after editing draft init2_rel( rel, sec ); } /** Initializes or re-initializes the cast-relational properties actorLinkVariant, * bodyRelClass and stageRelClass. * * @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER * REL_VOTER}. * @param sec the dart sector, which is used for {@linkplain #REL_VOTER * REL_VOTER} and {@linkplain #REL_CO REL_CO} relations. It must * be -1 for any other relation or an assertion error is raised. */ void init2_rel( final char rel, final int sec ) { _set( "actorLinkVariant", LightableDifference1.actorLinkVariantFor( rel, selectand() )); _set( "bodyRelClass", BODY_REL_PREFIX + rel ); if( rel == REL_VOTER || rel == REL_CO ) { _set( "bodySecClass", BODY_SEC_PREFIX + Integer.toString(sec) ); _set( "stageRelClass", rel + Integer.toString(sec) ); } else { assert sec == -1: "sec -1 for all but voter and co-voter relations"; _set( "bodySecClass", null ); _set( "stageRelClass", Character.toString(rel) ); } } // ------------------------------------------------------------------------------------ /** The URL to the {@linkplain votorola.s.wic.diff#WP_D diff view} of the difference * bridge. */ native String bridgeLoc() /*-{ return this.bridgeLoc; }-*/; // used by looksLikeShadowedDiff /** Answers whether the specified object {@linkplain #_isDuckType(Object,String[]) * looks like} an instance of ShadowedDiff, returning true if it might be, false if * it definitely is not. */ static boolean looksLikeShadowedDiff( final Object o ) { return _isDuckType( o, "bridgeLoc", "bodyOrdClass", "node" ); } /** The count node of the other (non-anchor) author. */ native CountNodeJS node() /*-{ return this.node; }-*/; // used by looksLikeShadowedDiff /** The number of diff segments in this difference as initialized by {@linkplain * DifferenceShadowsV DifferenceShadowsV}. */ native int segmentCount() /*-{ return this.segmentCount; }-*/; /** The text of the 'diff' output, as provided in the response from {@linkplain * votorola.s.wap.DiffWAP DiffWAP}. */ native String text() /*-{ return this.text; }-*/; // - L i g h t a b l e - D i f f e r e n c e ------------------------------------------ public native String actorLinkVariant() /*-{ return this.actorLinkVariant; }-*/; public native String bodyOrdClass() /*-{ return this.bodyOrdClass; }-*/; // used by looksLikeShadowedDiff, LightableDifference.TYPIFIER public native String bodyRelClass() /*-{ return this.bodyRelClass; }-*/; public native String bodySecClass() /*-{ return this.bodySecClass; }-*/; public String personName() { return node().name(); } public native String pollName() /*-{ return this.pollName; }-*/; // used by LightableDifference.TYPIFIER public native String stageRelClass() /*-{ return this.stageRelClass; }-*/; }