Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

Introduction

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

Prototype

public SafeHtmlBuilder appendHtmlConstant(String html) 

Source Link

Document

Appends a compile-time-constant string, which will not be escaped.

Usage

From source file:gwt.material.design.client.base.MaterialImageCell.java

License:Apache License

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, MaterialImage value, SafeHtmlBuilder sb) {
    sb.appendHtmlConstant(value.getElement().getString());
}

From source file:io.pelle.mango.client.gwt.modules.dictionary.search.DictionarySearchResultModuleUI.java

License:Open Source License

public void showResults(List<SearchResultItem> result) {

    if (resultContainer != null) {
        resultContainer.removeFromParent();
    }/*from   ww w  .j  a v  a  2  s  . co m*/

    resultContainer = new Div();
    container.add(resultContainer);
    resultContainer.addStyleName(DICTIONARY_SEARCH_RESULT_PANEL_STYLE);

    if (result.size() == 0) {
        Div noSearchResults = new Div();
        noSearchResults.add(new HTML(MangoClientWeb.getInstance().getMessages().noSearchResults()));
        resultContainer.add(noSearchResults);
    } else {
        for (final SearchResultItem searchResultItem : result) {

            IDictionaryModel dictionaryModel = DictionaryModelProvider
                    .getDictionary(searchResultItem.getDictionaryId());

            Div resultItemContainer = new Div();
            resultItemContainer.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_PANEL_STYLE);

            Hyperlink title = new Hyperlink();
            title.setText(DictionaryUtil.getLabel(dictionaryModel) + ": " + searchResultItem.getLabel());

            title.addHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    DictionaryEditorModuleFactory.openEditorForId(searchResultItem.getDictionaryId(),
                            searchResultItem.getId());
                }
            }, ClickEvent.getType());

            title.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_TITLE_STYLE);
            resultItemContainer.add(title);

            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            boolean first = true;

            for (Map.Entry<String, String> attributeEntry : searchResultItem.getAttributes().entrySet()) {

                Optional<IBaseControlModel> baseControlModel = DictionaryModelQuery.create(dictionaryModel)
                        .getControls().getControlModelByAttributePath(attributeEntry.getKey());

                if (baseControlModel.isPresent()) {

                    if (!first) {
                        sb.appendHtmlConstant(", ");
                    }
                    first = false;

                    sb.appendHtmlConstant(DictionaryModelUtil.getColumnLabel(baseControlModel.get()));
                    sb.appendHtmlConstant(": ");
                    HtmlUtils.highlightTexts(getModule().getSearchText(), attributeEntry.getValue(), sb);
                }
            }

            HTML text = new HTML(sb.toSafeHtml());
            text.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_TEXT_STYLE);
            resultItemContainer.add(text);

            resultContainer.add(resultItemContainer);
        }
    }
}

From source file:mat.client.shared.MatButtonCell.java

License:Apache License

@Override
public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {

    sb.appendHtmlConstant("<button type=\"button\" title=\" " + ButtonTitle + "\" tabindex=\"0\" class=\" "
            + cssClass + "\">");
    if (data != null) {
        sb.append(data);/*from  w ww .ja v a2  s.  c o  m*/
    }
    sb.appendHtmlConstant("</button>");
}

From source file:n3phele.client.widgets.StyledButtonCell.java

License:Open Source License

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    if (value != null) {
        sb.appendHtmlConstant("<button type=\"button\" class=\"" + this.style + "\""
                + (tip != null ? "title=\"" + this.tip + "\" " : "") + " tabindex=\"-1\">"
                + (this.text == null ? "" : this.text) + "</button>");
    } else {/*from   w ww .  j a v a2s  .  c o m*/
        //sb.appendHtmlConstant("<span></span>");
        sb.appendHtmlConstant("<button type=\"button\" class=\"" + this.style
                + "\" style=\"visibility: hidden;\" tabindex=\"-1\">" + (this.text == null ? "" : this.text)
                + "</button>");

    }
}

From source file:net.cbtltd.client.field.table.ListCell.java

License:Apache License

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    sb.appendHtmlConstant("<select id='ListCell" + id + "' class='" + style + "'>");
    for (int index = 0; index < text.length; index++) {
        if (text[index].equalsIgnoreCase(selected)) {
            sb.appendHtmlConstant("<option selected='selected'>" + text[index] + "</option>");
        } else {//from  w ww . j a va 2s .c  om
            sb.appendHtmlConstant("<option value='" + text[index] + "'>" + text[index] + "</option>");
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:net.officefloor.demo.chat.client.ChatWidget.java

License:Open Source License

/**
 * Initiate.//from   ww  w  . ja  va  2 s . co m
 */
public ChatWidget() {

    // Provide means to send a message
    HorizontalPanel messagePanel = new HorizontalPanel();
    // messagePanel.setSpacing(10);
    messagePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    this.add(messagePanel);

    // Provide message text box
    this.messageText.setStylePrimaryName("message");
    messagePanel.add(this.messageText);
    this.messageText.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            ChatWidget.this.ensureHaveUserName();
        }
    });

    // Provide send button for message
    Button sendButton = new Button("send");
    sendButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            ChatWidget.this.sendChatMessage();
        }
    });
    messagePanel.add(sendButton);

    // Provide messages in scroll area
    VerticalPanel messagesPanel = new VerticalPanel();
    messagesPanel.setSize("100%", "100%");
    ScrollPanel scrollMessagesPanel = new ScrollPanel(messagesPanel);
    scrollMessagesPanel.setStylePrimaryName("messages");
    this.add(scrollMessagesPanel);

    // Provide label to display typing users
    final Label typingLabel = new Label();
    typingLabel.setStylePrimaryName("typing");
    messagesPanel.add(typingLabel);
    typingLabel.setVisible(false); // initially hidden as no typing users

    // List to contain chat messages
    Cell<ChatMessage> chatCell = new AbstractCell<ChatMessage>() {
        @Override
        public void render(Context context, ChatMessage value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<span><b>");
            sb.appendEscaped(value.getUserName());
            sb.appendHtmlConstant("</b>");
            sb.appendEscaped(" > ");
            sb.appendEscaped(value.getMessage());
            sb.appendHtmlConstant("</span>");
        }
    };
    CellList<ChatMessage> chatList = new CellList<ChatMessage>(chatCell);
    messagesPanel.add(chatList);

    // Add the data
    final ListDataProvider<ChatMessage> chatEntries = new ListDataProvider<ChatMessage>();
    chatEntries.addDataDisplay(chatList);

    // Handle listening for messages
    OfficeFloorComet.subscribe(ConversationSubscription.class, new ConversationSubscription() {
        @Override
        public void message(ChatMessage message) {

            // Determine if typing notification
            String userName = message.getUserName();
            if ((ChatWidget.this.userName == null) || (!(ChatWidget.this.userName.equals(userName)))) {
                // Not user so provide notification of typing
                if (message.isTyping()) {
                    // Include user as typing
                    if (!(ChatWidget.this.typingUserNames.contains(userName))) {
                        ChatWidget.this.typingUserNames.add(userName);
                    }
                } else {
                    // User has stopped typing
                    ChatWidget.this.typingUserNames.remove(userName);
                }
            }

            // Display typing notification
            if (ChatWidget.this.typingUserNames.size() == 0) {
                // No typing users
                typingLabel.setVisible(false);

            } else {
                // Display the typing users
                StringBuilder typingUsers = new StringBuilder();
                boolean isFirst = true;
                for (String typingUserName : ChatWidget.this.typingUserNames) {
                    if (!isFirst) {
                        typingUsers.append(", ");
                    }
                    isFirst = false;
                    typingUsers.append(typingUserName);
                }
                typingUsers.append(" ... (typing)");
                typingLabel.setText(typingUsers.toString());
                typingLabel.setVisible(true);
            }

            // Add the message (if one provided)
            String text = message.getMessage();
            if (text != null) {
                List<ChatMessage> list = chatEntries.getList();
                if (list.size() == 0) {
                    list.add(message);
                } else {
                    list.add(0, message);
                }
            }
        }
    }, null);

    // Handle submitting a message
    this.messageText.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {

            // Obtain the message text and cursor position
            String message = ChatWidget.this.messageText.getText();
            int cursorPosition = ChatWidget.this.messageText.getCursorPos();

            // Handle various scenarios of keys for sending/notification
            switch (event.getNativeKeyCode()) {
            case KeyCodes.KEY_ENTER:
                ChatWidget.this.sendChatMessage();
                break;

            case KeyCodes.KEY_BACKSPACE:
                if (ChatWidget.this.isTyping && (message.length() == 1) && (cursorPosition == 1)) {
                    // No longer typing as deleting last character
                    ChatWidget.this.sendChatMessage(false, null);
                }
                break;

            case KeyCodes.KEY_DELETE:
                if (ChatWidget.this.isTyping && (message.length() == 1) && (cursorPosition == 0)) {
                    // No longer typing as deleting last character
                    ChatWidget.this.sendChatMessage(false, null);
                }
                break;

            case KeyCodes.KEY_ALT:
            case KeyCodes.KEY_CTRL:
            case KeyCodes.KEY_DOWN:
            case KeyCodes.KEY_END:
            case KeyCodes.KEY_ESCAPE:
            case KeyCodes.KEY_HOME:
            case KeyCodes.KEY_LEFT:
            case KeyCodes.KEY_PAGEDOWN:
            case KeyCodes.KEY_PAGEUP:
            case KeyCodes.KEY_RIGHT:
            case KeyCodes.KEY_SHIFT:
            case KeyCodes.KEY_UP:
                // Do nothing
                break;

            default:
                if ((!ChatWidget.this.isTyping) && (message.length() == 0)) {
                    // Started typing a message
                    ChatWidget.this.sendChatMessage(true, null);
                }
                break;
            }
        }
    });
}

From source file:nl.strohalm.cyclos.mobile.client.ui.widgets.DataList.java

License:Open Source License

/**
 * Creates the render representation of the model object
 */// ww w .ja  v  a  2 s.  co m
private void createCell() {
    cell = new AbstractCell<T>() {
        @Override
        public void render(Context context, T value, SafeHtmlBuilder sb) {
            Widget widget = onRender(context, value);
            if (widget != null) {
                sb.appendHtmlConstant(widget.toString());
            }
        }
    };
}

From source file:org.activityinfo.core.shared.validation.ValidationUtils.java

License:Open Source License

public static void addMessage(String message, DivElement divContainer) {
    final SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
    safeHtmlBuilder.appendHtmlConstant(divContainer.getInnerHTML()).appendHtmlConstant("<br/>")
            .append(SafeHtmlUtils.fromString(message));

    divContainer.setInnerHTML(safeHtmlBuilder.toSafeHtml().asString());
}

From source file:org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer.java

License:Open Source License

public void syncWithModel() {
    final SafeHtmlBuilder label = new SafeHtmlBuilder();

    if (!Strings.isNullOrEmpty(formField.getCode())) { // append code
        label.appendHtmlConstant("<span class='small'>"
                + SafeHtmlUtils.fromString(formField.getCode()).asString() + "</span>&nbsp;");
    }//from w ww  .  ja v  a  2 s  .com

    label.append(SafeHtmlUtils.fromString(Strings.nullToEmpty(formField.getLabel())));
    if (formField.isRequired()) {
        label.append(LABEL_TEMPLATE.mandatoryMarker());
    }
    formFieldWidget.setReadOnly(formField.isReadOnly());

    String labelHtml = label.toSafeHtml().asString();
    if (!formField.isVisible()) {
        labelHtml = "<del>" + labelHtml + "</del>";
    }
    widgetContainer.getLabel().setHTML(labelHtml);
    formFieldWidget.setType(formField.getType());
}

From source file:org.activityinfo.ui.client.page.entry.column.AdminColumnRenderer.java

License:Open Source License

private Object render(SiteDTO model) {

    StringBuilder qtip = new StringBuilder();
    SafeHtmlBuilder summary = new SafeHtmlBuilder();

    // we use this set to keep track of names that we've added
    // to the summary to avoid duplication that is common between
    // territories, zones de sante, provinces and districts, etc
    seen.clear();/*from   www. j  a v a  2 s  .c  o m*/

    int summaryLines = 0;

    for (AdminLevelDTO level : levels) {
        AdminEntityDTO entity = model.getAdminEntity(level.getId());

        if (entity != null) {
            String name = entity.getName();
            if (qtip.length() > 0) {
                qtip.append("<br>");
            }
            qtip.append(level.getName()).append(": ").append(name);
            if (summaryLines < 3 && !seen.contains(name)) {
                if (summaryLines > 0) {
                    summary.appendHtmlConstant("<br/>");
                }
                summary.appendEscaped(name);
                seen.add(name);
                summaryLines++;
            }
        }
    }
    // return summary.toSafeHtml().asString();
    return ColumnTemplates.INSTANCE.adminCell(qtip.toString(), summary.toSafeHtml()).asString();
}