001package votorola.s.gwt.scene.diff; // Copyright 2010-2011. Michael Allan. Christian Weilbach.  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 votorola.a.voter.IDPair;
004import votorola.s.gwt.scene.feed.BiteJS;
005import votorola.s.gwt.scene.feed.PersonJS;
006
007import com.google.gwt.cell.client.*;
008import com.google.gwt.safehtml.shared.*;
009import com.google.gwt.core.client.JsArray;
010
011
012/** A view of a dummy tick rendered as a GWT cell.
013  */
014public final class DiffBiteVCell extends AbstractCell<BiteJS>
015{
016
017    public @Override void render(final Context contex, final BiteJS bite, final SafeHtmlBuilder b)
018    {
019        if(bite == null) return;   // GWT says null possible "if the data arrives out of order"
020
021        PersonJS author = bite.persons().get(0);
022        PersonJS addressee = bite.persons().get(1);
023        PersonJS left, right;
024        boolean authorIsLeft = true;
025        if( bite.relation() == 'v' ) {
026            left = author;
027            right = addressee;
028        } else if( bite.relation() == 'c' ) {
029            left = addressee;
030            right = author;
031            authorIsLeft = false;
032        } else {
033            if(author.username().compareTo(addressee.username()) < 0) {
034                left = author;
035                right = addressee;
036            } else {
037                left = addressee;
038                right = author;
039                authorIsLeft = false;
040            }
041        }
042
043        b.appendHtmlConstant("<div class=\"diff-DiffBite\">"
044                             + "<div class=\"diff-DiffBiteBubble\">"
045                             + "<div class=\"diff-DiffBiteSummary\">"
046                             + SafeHtmlUtils.htmlEscape(bite.message().content())
047                             + "</div>"
048
049                             + "</div>"  // end of bubble
050
051                             + "<div class=\"diff-DiffBiteAuthors\""
052                             + "style=\"text-align: " + (authorIsLeft ? "left" : "right") + ";\" "
053                             + ">"
054                             + "<a title=\"" + left.username() + "\">"
055                             + IDPair.buildUserMnemonic(left.username(), new StringBuilder()) + "</a>"
056                             + "<img class=\"diff-DiffBiteSeperator\" src=\"sep-"
057                             + (authorIsLeft ? "l" : "r")
058                             + ".png\"/>"
059                             + "<img class=\"diff-DiffBiteSeperator-Selected\" src=\"sep-sel-"
060                             + (authorIsLeft ? "l" : "r")
061                             + ".png\"/>"
062                             + "<a title=\"" + right.username() + "\">"
063                             + IDPair.buildUserMnemonic(right.username(), new StringBuilder()) + "</a>"
064                             + "</div>"
065                             + "</div>");
066    }
067}
068