001package 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.
002
003import com.google.gwt.core.client.JavaScriptObject;
004import votorola.a.count.gwt.*;
005import votorola.a.diff.*;
006import votorola.a.web.gwt.*;
007import votorola.g.web.gwt.*;
008import votorola.s.gwt.stage.*;
009import votorola.s.gwt.stage.vote.*;
010
011
012/** A difference between an {@linkplain DifferenceShadows#anchor() anchoring author}'s
013  * position draft and that of an immediate {@linkplain votorola.a.count.XCastRelation
014  * cast relation}.  The {@linkplain #selectand selectand} is always set to the ordinal of
015  * the anchoring author.
016  */
017public final class ShadowedDiff extends DiffLookJS implements LightableDifference
018{
019
020
021    protected ShadowedDiff() {} // "precisely one constructor... protected, empty, and no-argument"
022
023
024
025    /** Completes the construction of this ShadowedDiff.
026      *
027      *     @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER
028      *       REL_VOTER}.
029      *     @param sec the dart sector, which is used for {@linkplain #REL_VOTER
030      *       REL_VOTER} and {@linkplain #REL_CO REL_CO} relations.  It must
031      *       be -1 for any other relation or an assertion error is raised.
032      *
033      *     @see #node()
034      *     @see #selectand()
035      */
036    void init( final String key, final char rel, final int sec, final CountNodeJS node,
037      final String pollName, final boolean isSelectandB )
038    {
039        final StringBuilder b = new StringBuilder();
040        b.append( App.getServletContextLocation() ).append( "/w/D?" );
041        b.append(  "k=" ).append( key );
042        if( isSelectandB )
043        {
044            _set( "selectand", "b" );
045            _set( "bodyOrdClass", "voLiDi-ord-a" );
046            b.append( "&s" );
047        }
048        else _set( "bodyOrdClass", "voLiDi-ord-b" );
049        _set( "bridgeLoc", b.toString() );
050        _set( "key", key );
051        _set( "node", node );
052        _set( "pollName", pollName );
053        _setInt( "segmentCount", 0 ); // DifferenceShadowsV overwrites if diff has segs (not empty)
054        _setBoolean( "toPersist", false ); // else blocks shadow of *latest* diff after editing draft
055        init2_rel( rel, sec );
056    }
057
058
059
060    /** Initializes or re-initializes the cast-relational properties actorLinkVariant,
061      * bodyRelClass and stageRelClass.
062      *
063      *     @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER
064      *       REL_VOTER}.
065      *     @param sec the dart sector, which is used for {@linkplain #REL_VOTER
066      *       REL_VOTER} and {@linkplain #REL_CO REL_CO} relations.  It must
067      *       be -1 for any other relation or an assertion error is raised.
068      */
069    void init2_rel( final char rel, final int sec )
070    {
071        _set( "actorLinkVariant", LightableDifference1.actorLinkVariantFor( rel, selectand() ));
072        _set( "bodyRelClass", BODY_REL_PREFIX + rel );
073        if( rel == REL_VOTER || rel == REL_CO )
074        {
075            _set( "bodySecClass", BODY_SEC_PREFIX + Integer.toString(sec) );
076            _set( "stageRelClass", rel + Integer.toString(sec) );
077        }
078        else
079        {
080            assert sec == -1: "sec -1 for all but voter and co-voter relations";
081            _set( "bodySecClass", null );
082            _set( "stageRelClass", Character.toString(rel) );
083        }
084    }
085
086
087
088   // ------------------------------------------------------------------------------------
089
090
091    /** The URL to the {@linkplain votorola.s.wic.diff#WP_D diff view} of the difference
092      * bridge.
093      */
094    native String bridgeLoc() /*-{ return this.bridgeLoc; }-*/; // used by looksLikeShadowedDiff
095
096
097
098    /** Answers whether the specified object {@linkplain #_isDuckType(Object,String[])
099      * looks like} an instance of ShadowedDiff, returning true if it might be, false if
100      * it definitely is not.
101      */
102    static boolean looksLikeShadowedDiff( final Object o )
103    {
104        return _isDuckType( o, "bridgeLoc", "bodyOrdClass", "node" );
105    }
106
107
108
109    /** The count node of the other (non-anchor) author.
110      */
111    native CountNodeJS node() /*-{ return this.node; }-*/; // used by looksLikeShadowedDiff
112
113
114
115    /** The number of diff segments in this difference as initialized by {@linkplain
116      * DifferenceShadowsV DifferenceShadowsV}.
117      */
118    native int segmentCount() /*-{ return this.segmentCount; }-*/;
119
120
121
122    /** The text of the 'diff' output, as provided in the response from {@linkplain
123      * votorola.s.wap.DiffWAP DiffWAP}.
124      */
125    native String text() /*-{ return this.text; }-*/;
126
127
128
129   // - L i g h t a b l e - D i f f e r e n c e ------------------------------------------
130
131
132    public native String actorLinkVariant() /*-{ return this.actorLinkVariant; }-*/;
133
134
135
136    public native String bodyOrdClass() /*-{ return this.bodyOrdClass; }-*/;
137      // used by looksLikeShadowedDiff, LightableDifference.TYPIFIER
138
139
140
141    public native String bodyRelClass() /*-{ return this.bodyRelClass; }-*/;
142
143
144
145    public native String bodySecClass() /*-{ return this.bodySecClass; }-*/;
146
147
148
149    public String personName() { return node().name(); }
150
151
152
153    public native String pollName() /*-{ return this.pollName; }-*/;
154      // used by LightableDifference.TYPIFIER
155
156
157
158    public native String stageRelClass() /*-{ return this.stageRelClass; }-*/;
159
160
161}