Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString.

Prototype

public static SafeHtml fromTrustedString(String s) 

Source Link

Document

Returns a SafeHtml constructed from a trusted string, i.e., without escaping the string.

Usage

From source file:com.gwtmodel.table.view.ewidget.gwt.ImageButton.java

License:Apache License

@Override
public void setValObj(Object o) {
    value = (String) o;//ww w.  j av  a 2  s.c  o  m
    String[] ima = iList.getList(v);
    for (int i = 0; i < ima.length; i++) {
        HTML h = (HTML) hPanel.getWidget(i);
        if (IConsts.EMPTYIM.equals(ima[i]))
            h.setHTML("");
        else {
            String s = Utils.getImageHTML(ima[i]);
            SafeHtml html = SafeHtmlUtils.fromTrustedString(s);
            h.setHTML(html);
        }
    }
}

From source file:com.gwtmodel.table.view.table.edit.PresentationEditCellFactory.java

License:Apache License

@SuppressWarnings("incomplete-switch")
private SafeHtml createSafeForImage(PersistTypeEnum persist) {
    String imageName = null;//from w  w w. ja va 2 s  . c o  m
    String title = null;
    switch (persist) {
    case ADDBEFORE:
        imageName = pResources.getRes(IWebPanelResources.ADDBEFOREROW);
        title = MM.getL().AddRowAtTheBeginning();
        break;
    case ADD:
        imageName = pResources.getRes(IWebPanelResources.ADDROW);
        title = MM.getL().AddRowAfter();
        break;
    case REMOVE:
        imageName = pResources.getRes(IWebPanelResources.DELETEROW);
        title = MM.getL().RemoveRow();
        break;
    }
    String s = Utils.getImageHTML(imageName, IConsts.actionImageHeight, IConsts.actionImageWidth,
            persist.toString());
    // add div to have them vertically

    SafeHtml html = SafeHtmlUtils.fromTrustedString("<div title=\"" + title + "\" >" + s + "</div>");
    return html;
}

From source file:com.gwtplatform.samples.multimodule.module1.client.application.response.ResponseView.java

License:Apache License

@Override
public void setServerResponse(String serverResponse) {
    this.serverResponse.setHTML(SafeHtmlUtils.fromTrustedString(serverResponse));
}

From source file:com.laskysoftware.GXTPagingGrid.client.GridExampleLocking.java

License:sencha.com license

@Override
public Widget asWidget() {
    if (root == null) {
        final NumberFormat number = NumberFormat.getFormat("0.00");

        ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50,
                SafeHtmlUtils.fromTrustedString("<b>Company</b>"));

        ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
        ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

        ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
        changeCol.setCell(new AbstractCell<Double>() {

            @Override//from ww  w  .j av  a 2 s  . c om
            public void render(Context context, Double value, SafeHtmlBuilder sb) {
                String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
                String v = number.format(value);
                sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
            }
        });

        ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
                "Last Updated");
        lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

        List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
        //Remove name from main set of columns
        //l.add(nameCol);
        l.add(symbolCol);
        l.add(lastCol);
        l.add(changeCol);
        l.add(lastTransCol);

        //create two column models, one for the locked section
        ColumnModel<Stock> lockedCm = new ColumnModel<Stock>(
                Collections.<ColumnConfig<Stock, ?>>singletonList(nameCol));
        ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

        ListStore<Stock> store = new ListStore<Stock>(props.key());
        store.addAll(TestData.getStocks());

        root = new ContentPanel();
        root.setHeadingText("Locked Grid Sample");
        root.setPixelSize(600, 300);

        final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S);
        root.addExpandHandler(new ExpandHandler() {
            @Override
            public void onExpand(ExpandEvent event) {
                resizable.setEnabled(true);
            }
        });
        root.addCollapseHandler(new CollapseHandler() {
            @Override
            public void onCollapse(CollapseEvent event) {
                resizable.setEnabled(false);
            }
        });

        //locked grid
        final Grid<Stock> lockedGrid = new Grid<Stock>(store, lockedCm) {
            @Override
            protected Size adjustSize(Size size) {
                //this is a tricky part - convince the grid to draw just slightly too wide
                //and so push the scrollbar out of sight
                return new Size(size.getWidth() + XDOM.getScrollBarWidth() - 1, size.getHeight());
            }
        };
        lockedGrid.setView(new GridView<Stock>() {
            {
                this.scrollOffset = 0;
            }
        });
        //require columns to always fit, preventing scrollbar
        lockedGrid.getView().setForceFit(true);

        //main grid, with horiz scrollbar
        final Grid<Stock> grid = new Grid<Stock>(store, cm);
        //don't want this feature, want to encourage horizontal scrollbars
        //grid.getView().setAutoExpandColumn(nameCol);
        grid.getView().setStripeRows(true);
        grid.getView().setColumnLines(true);
        grid.setBorders(false);

        grid.setColumnReordering(true);
        grid.setStateful(true);
        grid.setStateId("gridExample");

        //link scrolling
        lockedGrid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                grid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });
        grid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                lockedGrid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });

        HorizontalLayoutContainer gridWrapper = new HorizontalLayoutContainer();
        root.setWidget(gridWrapper);

        //add locked column, only 300px wide (in this example, use layouts to change how this works
        HorizontalLayoutData lockedColumnLayoutData = new HorizontalLayoutData(300, 1.0);

        //this is optional - without this, you get a little offset issue at the very bottom of the non-locked grid
        lockedColumnLayoutData.setMargins(new Margins(0, 0, XDOM.getScrollBarWidth(), 0));

        gridWrapper.add(lockedGrid, lockedColumnLayoutData);

        //add non-locked section, taking up all remaining width
        gridWrapper.add(grid, new HorizontalLayoutData(1.0, 1.0));
    }

    return root;
}

From source file:com.lushprojects.circuitjs1.client.CheckboxAlignedMenuItem.java

License:Open Source License

public CheckboxAlignedMenuItem(String s, Command cmd) {
    super(SafeHtmlUtils.fromTrustedString(CheckboxMenuItem.checkBoxHtml + "&nbsp;</div>" + s), cmd);
}

From source file:com.lushprojects.circuitjs1.client.CirSim.java

License:Open Source License

MenuItem menuItemWithShortcut(String text, String shortcut, MyCommand cmd) {
    final String edithtml = "<div style=\"display:inline-block;width:80px;\">";
    String sn = edithtml + text + "</div>" + shortcut;
    return new MenuItem(SafeHtmlUtils.fromTrustedString(sn), cmd);
}

From source file:com.lushprojects.circuitjs1.client.CirSim.java

License:Open Source License

public void composeMainMenu(MenuBar mainMenuBar) {
    mainMenuBar.addItem(getClassCheckItem(LS("Add Wire"), "WireElm"));
    mainMenuBar.addItem(getClassCheckItem(LS("Add Resistor"), "ResistorElm"));

    MenuBar passMenuBar = new MenuBar(true);
    passMenuBar.addItem(getClassCheckItem(LS("Add Capacitor"), "CapacitorElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Capacitor (polarized)"), "PolarCapacitorElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Inductor"), "InductorElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Switch"), "SwitchElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Push Switch"), "PushSwitchElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add SPDT Switch"), "Switch2Elm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Potentiometer"), "PotElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Transformer"), "TransformerElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Tapped Transformer"), "TappedTransformerElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Transmission Line"), "TransLineElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Relay"), "RelayElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Memristor"), "MemristorElm"));
    passMenuBar.addItem(getClassCheckItem(LS("Add Spark Gap"), "SparkGapElm"));
    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(
            CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Passive Components")), passMenuBar);

    MenuBar inputMenuBar = new MenuBar(true);
    inputMenuBar.addItem(getClassCheckItem(LS("Add Ground"), "GroundElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Voltage Source (2-terminal)"), "DCVoltageElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add A/C Voltage Source (2-terminal)"), "ACVoltageElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Voltage Source (1-terminal)"), "RailElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add A/C Voltage Source (1-terminal)"), "ACRailElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Square Wave Source (1-terminal)"), "SquareRailElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Clock"), "ClockElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add A/C Sweep"), "SweepElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Variable Voltage"), "VarRailElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Antenna"), "AntennaElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add AM Source"), "AMElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add FM Source"), "FMElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Current Source"), "CurrentElm"));
    inputMenuBar.addItem(getClassCheckItem(LS("Add Noise Generator"), "NoiseElm"));

    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(
            CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Inputs and Sources")), inputMenuBar);

    MenuBar outputMenuBar = new MenuBar(true);
    outputMenuBar.addItem(getClassCheckItem(LS("Add Analog Output"), "OutputElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add LED"), "LEDElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Lamp"), "LampElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Text"), "TextElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Box"), "BoxElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Voltmeter/Scobe Probe"), "ProbeElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Labeled Node"), "LabeledNodeElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Test Point"), "TestPointElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Ammeter"), "AmmeterElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Data Export"), "DataRecorderElm"));
    outputMenuBar.addItem(getClassCheckItem(LS("Add Audio Output"), "AudioOutputElm"));
    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(
            CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Outputs and Labels")), outputMenuBar);

    MenuBar activeMenuBar = new MenuBar(true);
    activeMenuBar.addItem(getClassCheckItem(LS("Add Diode"), "DiodeElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Zener Diode"), "ZenerElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Transistor (bipolar, NPN)"), "NTransistorElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Transistor (bipolar, PNP)"), "PTransistorElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add MOSFET (N-Channel)"), "NMosfetElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add MOSFET (P-Channel)"), "PMosfetElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add JFET (N-Channel)"), "NJfetElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add JFET (P-Channel)"), "PJfetElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add SCR"), "SCRElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Darlington Pair (NPN)"), "NDarlingtonElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Darlington Pair (PNP)"), "PDarlingtonElm"));
    //       activeMenuBar.addItem(getClassCheckItem("Add Varactor/Varicap", "VaractorElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Tunnel Diode"), "TunnelDiodeElm"));
    activeMenuBar.addItem(getClassCheckItem(LS("Add Triode"), "TriodeElm"));
    //       activeMenuBar.addItem(getClassCheckItem("Add Diac", "DiacElm"));
    //       activeMenuBar.addItem(getClassCheckItem("Add Triac", "TriacElm"));
    //       activeMenuBar.addItem(getClassCheckItem("Add Photoresistor", "PhotoResistorElm"));
    //       activeMenuBar.addItem(getClassCheckItem("Add Thermistor", "ThermistorElm"));
    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(
            CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Active Components")), activeMenuBar);

    MenuBar activeBlocMenuBar = new MenuBar(true);
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Op Amp (- on top)"), "OpAmpElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Op Amp (+ on top)"), "OpAmpSwapElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Analog Switch (SPST)"), "AnalogSwitchElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Analog Switch (SPDT)"), "AnalogSwitch2Elm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Tristate Buffer"), "TriStateElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Schmitt Trigger"), "SchmittElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Schmitt Trigger (Inverting)"), "InvertingSchmittElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add CCII+"), "CC2Elm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add CCII-"), "CC2NegElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Comparator (Hi-Z/GND output)"), "ComparatorElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add OTA (LM13700 style)"), "OTAElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Voltage-Controlled Voltage Source"), "VCVSElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Voltage-Controlled Current Source"), "VCCSElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Current-Controlled Voltage Source"), "CCVSElm"));
    activeBlocMenuBar.addItem(getClassCheckItem(LS("Add Current-Controlled Current Source"), "CCCSElm"));
    mainMenuBar.addItem(//from   w  ww .j a  v a 2s  .c  o m
            SafeHtmlUtils.fromTrustedString(
                    CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Active Building Blocks")),
            activeBlocMenuBar);

    MenuBar gateMenuBar = new MenuBar(true);
    gateMenuBar.addItem(getClassCheckItem(LS("Add Logic Input"), "LogicInputElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add Logic Output"), "LogicOutputElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add Inverter"), "InverterElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add NAND Gate"), "NandGateElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add NOR Gate"), "NorGateElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add AND Gate"), "AndGateElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add OR Gate"), "OrGateElm"));
    gateMenuBar.addItem(getClassCheckItem(LS("Add XOR Gate"), "XorGateElm"));
    mainMenuBar.addItem(
            SafeHtmlUtils.fromTrustedString(
                    CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Logic Gates, Input and Output")),
            gateMenuBar);

    MenuBar chipMenuBar = new MenuBar(true);
    chipMenuBar.addItem(getClassCheckItem(LS("Add D Flip-Flop"), "DFlipFlopElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add JK Flip-Flop"), "JKFlipFlopElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add T Flip-Flop"), "TFlipFlopElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add 7 Segment LED"), "SevenSegElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add 7 Segment Decoder"), "SevenSegDecoderElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Multiplexer"), "MultiplexerElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Demultiplexer"), "DeMultiplexerElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add SIPO shift register"), "SipoShiftElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add PISO shift register"), "PisoShiftElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Counter"), "CounterElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Decade Counter"), "DecadeElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Latch"), "LatchElm"));
    //chipMenuBar.addItem(getClassCheckItem("Add Static RAM", "SRAMElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Sequence generator"), "SeqGenElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Full Adder"), "FullAdderElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Half Adder"), "HalfAdderElm"));
    chipMenuBar.addItem(getClassCheckItem(LS("Add Custom Logic"), "UserDefinedLogicElm"));
    mainMenuBar.addItem(
            SafeHtmlUtils.fromTrustedString(CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Digital Chips")),
            chipMenuBar);

    MenuBar achipMenuBar = new MenuBar(true);
    achipMenuBar.addItem(getClassCheckItem(LS("Add 555 Timer"), "TimerElm"));
    achipMenuBar.addItem(getClassCheckItem(LS("Add Phase Comparator"), "PhaseCompElm"));
    achipMenuBar.addItem(getClassCheckItem(LS("Add DAC"), "DACElm"));
    achipMenuBar.addItem(getClassCheckItem(LS("Add ADC"), "ADCElm"));
    achipMenuBar.addItem(getClassCheckItem(LS("Add VCO"), "VCOElm"));
    achipMenuBar.addItem(getClassCheckItem(LS("Add Monostable"), "MonostableElm"));
    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(
            CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Analog and Hybrid Chips")), achipMenuBar);

    MenuBar otherMenuBar = new MenuBar(true);
    CheckboxMenuItem mi;
    otherMenuBar.addItem(mi = getClassCheckItem(LS("Drag All"), "DragAll"));
    mi.addShortcut(LS("(Alt-drag)"));
    otherMenuBar.addItem(mi = getClassCheckItem(LS("Drag Row"), "DragRow"));
    mi.addShortcut(LS("(A-S-drag)"));
    otherMenuBar.addItem(mi = getClassCheckItem(LS("Drag Column"), "DragColumn"));
    mi.addShortcut(isMac ? LS("(A-Cmd-drag)") : LS("(A-M-drag)"));
    otherMenuBar.addItem(getClassCheckItem(LS("Drag Selected"), "DragSelected"));
    otherMenuBar.addItem(mi = getClassCheckItem(LS("Drag Post"), "DragPost"));
    mi.addShortcut("(" + ctrlMetaKey + "-drag)");

    mainMenuBar.addItem(SafeHtmlUtils.fromTrustedString(CheckboxMenuItem.checkBoxHtml + LS("&nbsp;</div>Drag")),
            otherMenuBar);

    mainMenuBar.addItem(mi = getClassCheckItem(LS("Select/Drag Sel"), "Select"));
    mi.addShortcut(LS("(space or Shift-drag)"));
}

From source file:com.lushprojects.circuitjs1.client.CirSim.java

License:Open Source License

static SafeHtml LSHTML(String s) {
    return SafeHtmlUtils.fromTrustedString(LS(s));
}

From source file:com.mattbertolini.hermes.MessagesProxy.java

License:Open Source License

private Object parseMessage(Method method, Object[] args) {
    String messageName;//from   w ww .  j  a v a 2  s  .  c om
    Key keyAnnotation = method.getAnnotation(Key.class);
    if (keyAnnotation == null) {
        messageName = method.getName();
    } else {
        messageName = keyAnnotation.value();
    }

    List<String> formsNames = new LinkedList<String>();
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    Class<?>[] parameterTypes = method.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++) {
        Annotation[] annotations = parameterAnnotations[i];
        Class<?> type = parameterTypes[i];
        for (Annotation annotation : annotations) {
            if (PluralCount.class.isAssignableFrom(annotation.annotationType())
                    && (int.class.isAssignableFrom(type) || Integer.class.isAssignableFrom(type)
                            || short.class.isAssignableFrom(type) || Short.class.isAssignableFrom(type))) {
                Number num = (Number) args[i];
                Plural plural;
                // Check for a custom plural rule.
                PluralCount pc = (PluralCount) annotation;
                Class<? extends PluralRule> pluralRuleClass = pc.value();
                if (!pluralRuleClass.isInterface() && PluralRule.class.isAssignableFrom(pluralRuleClass)) {
                    PluralRule customRule = this.instantiateCustomPluralRuleClass(pluralRuleClass);
                    plural = CustomPlural.fromNumber(customRule, num.intValue());
                } else {
                    plural = GwtPlural.fromNumber(this.pluralRules, num.doubleValue());
                }
                formsNames.add(plural.getGwtValue());
            } else if (Select.class.isAssignableFrom(annotation.annotationType())) {
                if (Enum.class.isAssignableFrom(type)) {
                    Enum<?> enumConstant = (Enum<?>) args[i];
                    String name;
                    if (enumConstant == null) {
                        name = "other";
                    } else {
                        name = enumConstant.name();
                    }
                    formsNames.add(name);
                } else if (String.class.isAssignableFrom(type)) {
                    String str = (String) args[i];
                    if (str == null) {
                        str = "other";
                    }
                    formsNames.add(str);
                } else if (type.isPrimitive() && (int.class.isAssignableFrom(type)
                        || long.class.isAssignableFrom(type) || float.class.isAssignableFrom(type)
                        || short.class.isAssignableFrom(type) || double.class.isAssignableFrom(type))) {
                    Number num = (Number) args[i];
                    formsNames.add(num.toString());
                }
            }
        }
    }

    String patternName = this.buildPatternName(messageName, formsNames);
    String pattern = this.getProperties().getProperty(patternName);
    if (pattern == null) {
        Map<String, String> altMsgMap = this.buildAlternateMessageMap(messageName, method);
        pattern = altMsgMap.get(patternName);
        if (pattern == null) {
            pattern = this.getProperties().getProperty(messageName);
            if (pattern == null) {
                DefaultMessage defaultMessage = method.getAnnotation(DefaultMessage.class);
                if (defaultMessage != null) {
                    pattern = defaultMessage.value();
                } else {
                    throw new RuntimeException("No message found for key " + messageName);
                }
            }
        }
    }

    MessageFormat formatter = new MessageFormat(pattern, this.getLocale());
    Object retVal;
    if (method.getReturnType().equals(SafeHtml.class)) {
        Object[] safeArgs = null;
        if (args != null) {
            safeArgs = new Object[args.length];
            for (int i = 0; i < args.length; i++) {
                Object arg = args[i];
                Class<?> argType = parameterTypes[i];
                if (SafeHtml.class.isAssignableFrom(argType)) {
                    SafeHtml sh = (SafeHtml) arg;
                    safeArgs[i] = sh.asString();
                } else if (Number.class.isAssignableFrom(argType) || Date.class.isAssignableFrom(argType)) {
                    // Because of the subformat pattern of dates and 
                    // numbers, we cannot escape them.
                    safeArgs[i] = arg;
                } else {
                    safeArgs[i] = SafeHtmlUtils.htmlEscape(arg.toString());
                }
            }
        }
        String formattedString = formatter.format(safeArgs, new StringBuffer(), null).toString();
        // Would rather use fromSafeConstant() but doesn't work on server.
        retVal = SafeHtmlUtils.fromTrustedString(formattedString);
    } else {
        retVal = formatter.format(args, new StringBuffer(), null).toString();
    }

    return retVal;
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.grid.LiveGroupSummaryExample.java

License:sencha.com license

@Override
public Widget asWidget() {
    List<Task> tasks = TestData.getTasks();

    TaskProperties properties = GWT.create(TaskProperties.class);
    final ListStore<Task> store = new ListStore<Task>(properties.key());
    store.addAll(tasks);//from w ww  .ja va  2  s.  c o  m

    SummaryColumnConfig<Task, String> desc = new SummaryColumnConfig<Task, String>(properties.description(), 65,
            "Task");
    desc.setSummaryType(new SummaryType.CountSummaryType<String>());
    desc.setSummaryRenderer(new SummaryRenderer<Task>() {

        @Override
        public SafeHtml render(Number value, Map<ValueProvider<? super Task, ?>, Number> data) {
            return SafeHtmlUtils
                    .fromTrustedString(value.intValue() > 1 ? "(" + value.intValue() + " Tasks)" : "(1 Task)");
        }
    });

    final SummaryColumnConfig<Task, String> project = new SummaryColumnConfig<Task, String>(
            properties.project(), 55, "Project");

    SummaryColumnConfig<Task, String> due = new SummaryColumnConfig<Task, String>(properties.due(), 20, "Due");

    SummaryColumnConfig<Task, Double> estimate = new SummaryColumnConfig<Task, Double>(properties.estimate(),
            20, "Estimate");
    estimate.setSummaryType(new SummaryType.SumSummaryType<Double>());
    estimate.setSummaryRenderer(new SummaryRenderer<Task>() {
        @Override
        public SafeHtml render(Number value, Map<ValueProvider<? super Task, ?>, Number> data) {
            return SafeHtmlUtils.fromTrustedString(value + " hours");
        }
    });
    estimate.setCell(new AbstractCell<Double>() {
        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, Double value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant(value + " hours");
        }
    });

    SummaryColumnConfig<Task, Double> rate = new SummaryColumnConfig<Task, Double>(properties.rate(), 20,
            "Rate");
    rate.setAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    rate.setCell(new NumberCell<Double>(NumberFormat.getCurrencyFormat()));
    rate.setSummaryType(new SummaryType.AvgSummaryType<Double>());
    rate.setSummaryFormat(NumberFormat.getCurrencyFormat());

    SummaryColumnConfig<Task, Task> cost = new SummaryColumnConfig<Task, Task>(
            new IdentityValueProvider<Task>(), 20, "Cost");
    cost.setColumnClassSuffix("cost");
    cost.setAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    cost.setCell(new AbstractCell<Task>() {
        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, Task value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant(
                    NumberFormat.getCurrencyFormat().format(value.getRate() * value.getEstimate()));
        }
    });
    cost.setSummaryFormat(NumberFormat.getCurrencyFormat());
    cost.setSummaryType(new SummaryType<Task, Double>() {

        @Override
        public <M> Double calculate(List<? extends M> m, ValueProvider<? super M, Task> valueProvider) {
            double value = 0;
            for (int i = 0; i < m.size(); i++) {
                Task t = valueProvider.getValue(m.get(i));
                value = value + (t.getRate() * t.getEstimate());
            }
            return value;
        }

    });
    cost.setComparator(new Comparator<Task>() {
        @Override
        public int compare(Task o1, Task o2) {
            return Double.valueOf(o1.getRate() * o1.getEstimate()).compareTo(o2.getRate() * o2.getEstimate());
        }
    });

    List<ColumnConfig<Task, ?>> cfgs = new ArrayList<ColumnConfig<Task, ?>>();
    cfgs.add(desc);
    cfgs.add(project);
    cfgs.add(due);
    cfgs.add(estimate);
    cfgs.add(rate);
    cfgs.add(cost);

    ColumnModel<Task> cm = new ColumnModel<Task>(cfgs);

    final GroupSummaryView<Task> summary = new GroupSummaryView<Task>();
    summary.setForceFit(true);
    summary.setShowGroupedColumn(false);

    Grid<Task> grid = new Grid<Task>(store, cm);
    grid.setBorders(true);
    grid.setView(summary);
    grid.getView().setShowDirtyCells(false);

    Scheduler.get().scheduleFinally(new ScheduledCommand() {
        @Override
        public void execute() {
            summary.groupBy(project);
        }
    });

    FramedPanel panel = new FramedPanel();
    panel.setHeadingHtml("Sponsored Projects");
    panel.setSize("800", "450");
    panel.add(grid);
    panel.addStyleName("margin-10");
    panel.setCollapsible(true);
    return panel;
}