Java Code Examples for com.google.gwt.safehtml.shared.SafeHtmlBuilder#append()

The following examples show how to use com.google.gwt.safehtml.shared.SafeHtmlBuilder#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessControlProviderDialog.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Widget asWidget() {
    VerticalPanel layout = new VerticalPanel();
    layout.setStyleName("window-content");
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(Console.MESSAGES.access_control_provider());
    layout.add(new HTML(builder.toSafeHtml()));

    DialogueOptions options = new DialogueOptions(
            Console.CONSTANTS.common_label_done(),
            event -> presenter.closeWindow(),
            Console.CONSTANTS.common_label_cancel(),
            event -> presenter.closeWindow()
    );
    options.showCancel(false);
    return new WindowContentBuilder(new ScrollPanel(layout), options).build();
}
 
Example 2
Source File: SearchPopup.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void render(Context context, TokenGroup tokenGroup, SafeHtmlBuilder safeHtmlBuilder) {
    SafeHtmlBuilder descriptions = new SafeHtmlBuilder();
    for (String description : tokenGroup.getDescriptions()) {
        descriptions.append(TEMPLATE.description(description));
    }
    String token = tokenGroup.getToken();
    try {
        // try to find a description for this token
        token = Console.TOKENS.getString(token.replace('-', '_'));
    } catch (MissingResourceException e) {
        System.err.println("No description found for token " + token + ": " + e.getMessage());
    }
    if (tokenGroup.getKeywords().isEmpty()) {
        safeHtmlBuilder.append(TEMPLATE.tokenGroup(token, descriptions.toSafeHtml()));
    } else {
        SafeHtmlBuilder keywords = new SafeHtmlBuilder();
        for (String keyword : tokenGroup.getKeywords()) {
            keywords.append(TEMPLATE.keyword(keyword));
        }
        safeHtmlBuilder.append(TEMPLATE.tokenGroup(token, descriptions.toSafeHtml(), keywords.toSafeHtml()));
    }
}
 
Example 3
Source File: CodeHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public static SafeHtml parseCode(String code) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    String[] splitted = code.replaceAll("\\\\s", " ").split("\\\\n\\s?");
    String[] arr$ = splitted;
    int len$ = splitted.length;

    for (int i$ = 0; i$ < len$; ++i$) {
        String s = arr$[i$];
        builder.append(SafeHtmlUtils.fromTrustedString(SafeHtmlUtils.htmlEscapeAllowEntities(s)));
        builder.appendHtmlConstant("<br>");
    }

    return builder.toSafeHtml();
}
 
Example 4
Source File: GwtTreeCell.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void render(Context context, TreeState.TreeNodeState value, SafeHtmlBuilder sb) {
  GwtHorizontalLayoutImpl layout = GwtComboBoxImplConnector.buildItem(value);

  SafeHtml safeValue = SafeHtmlUtils.fromSafeConstant(layout.toString());

  sb.append(safeValue);
}
 
Example 5
Source File: HostServerTable.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(
        Context context,
        String server,
        SafeHtmlBuilder safeHtmlBuilder)
{
    String icon = "icon-ok"; //server.isRunning() ? "icon-ok":"icon-ban-circle";
    String name = shortenStringIfNecessary(server, clipAt);
    safeHtmlBuilder.append(SERVER_TEMPLATE.message(name, icon));
}
 
Example 6
Source File: HostServerTable.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(
        Context context,
        String host,
        SafeHtmlBuilder safeHtmlBuilder)
{
    safeHtmlBuilder.append(HOST_TEMPLATE.message(shortenStringIfNecessary(host, clipAt)));
}
 
Example 7
Source File: ProfileCell.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(
        Context context,
        ProfileRecord record,
        SafeHtmlBuilder safeHtmlBuilder)
{

    safeHtmlBuilder.append(
                TEMPLATE.message("none", record.getName())
    );

}
 
Example 8
Source File: Templates.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static SafeHtml principalPreview(final Principal principal, Iterable<Assignment> includes,
        Iterable<Assignment> excludes) {
    SafeHtmlBuilder details = new SafeHtmlBuilder();
    details.appendHtmlConstant("<p>");
    if (!Iterables.isEmpty(excludes)) {
        List<Role> excludedRoles = Roles.orderedByName().immutableSortedCopy(distinctRoles(excludes));
        details.appendEscaped("Excluded from ");
        details.appendEscaped(Joiner.on(", ").join(Lists.transform(excludedRoles, Role::getName)));
        details.appendEscaped(".");
        details.appendHtmlConstant("<br/>");
    }
    if (!Iterables.isEmpty(includes)) {
        List<Role> assignedRoles = Roles.orderedByName().immutableSortedCopy(distinctRoles(includes));
        details.appendEscaped("Assigned to ");
        details.appendEscaped(Joiner.on(", ").join(Lists.transform(assignedRoles, Role::getName)));
        details.appendEscaped(".");
    }
    if (Iterables.isEmpty(excludes) && Iterables.isEmpty(includes)) {
        details.appendEscaped("No roles are assigned to this ");
        details.appendEscaped(principal.getType() == Principal.Type.USER ? "user" : "group");
        details.append('.');
    }
    details.appendHtmlConstant("</p>");
    return principal.getType() == Principal.Type.USER ?
            PREVIEWS.user(principal.getName(), details.toSafeHtml()) :
            PREVIEWS.group(principal.getName(), details.toSafeHtml());
}
 
Example 9
Source File: PropertyCell.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(Context context, PropertyRecord value, SafeHtmlBuilder sb) {
    sb.append(TEMPLATE.message(
            "cell-record",
            value.getKey(),
            value.getValue()
    )
    );
}
 
Example 10
Source File: ServerGroupCell.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(
        Context context,
        ServerGroupRecord groupRecord,
        SafeHtmlBuilder safeHtmlBuilder)
{

    safeHtmlBuilder.append(
                TEMPLATE.message("cross-reference",
                    groupRecord.getName(),
                    groupRecord.getProfileName()
            )
    );

}
 
Example 11
Source File: TextLinkCell.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(Context context, T value, SafeHtmlBuilder sb) {


    String css = !visible ? "textlink-cell rbac-suppressed" : "textlink-cell";
    SafeHtml html = new SafeHtmlBuilder()
            .appendHtmlConstant("<a href='javascript:void(0)' tabindex=\"-1\" class='"+css+"'>")
            .appendHtmlConstant(title)
            .appendHtmlConstant("</a>")
            .toSafeHtml();


    sb.append(html);
}
 
Example 12
Source File: ViewLinkCell.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void render(Context context, T value, SafeHtmlBuilder sb) {
    SafeHtml html = new SafeHtmlBuilder()
            .appendHtmlConstant("<a href='javascript:void(0)' tabindex=\"-1\" class='viewlink-cell'>")
            .appendHtmlConstant(title)
            .appendHtmlConstant("&nbsp;")
            .appendHtmlConstant("<i class='icon-chevron-right'></i>")
            .appendHtmlConstant("</a>")
            .toSafeHtml();

    sb.append(html);
}
 
Example 13
Source File: DrawArea.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, MenuItem value, SafeHtmlBuilder sb) {
  SafeHtml html = SafeHtmlUtils.fromSafeConstant("<div class='cell'> " + value + "</div>");
  sb.append(html);
}
 
Example 14
Source File: PropertyEditor.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void render(final Context context, final SafeHtml value, final SafeHtmlBuilder sb) {
    if (value != null) {
        sb.append(VALUE_TEMPLATE.value(value));
    }
}
 
Example 15
Source File: MemberDialog.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Widget asWidget() {
    ProvidesKey<Principal> keyProvider = Principal::getId;

    AbstractCell<Principal> roleCell = new AbstractCell<Principal>() {
        @Override
        public void render(final Context context, final Principal value, final SafeHtmlBuilder sb) {
            sb.append(Templates.memberItem("navigation-column-item", value));
        }
    };
    DefaultCellList<Principal> list = new DefaultCellList<>(roleCell, keyProvider);
    list.setPageSize(30);
    list.setKeyboardPagingPolicy(INCREASE_RANGE);
    list.setKeyboardSelectionPolicy(BOUND_TO_SELECTION);

    ListDataProvider<Principal> dataProvider = new ListDataProvider<>(keyProvider);
    dataProvider.setList(Principals.orderedByType()
            .compound(Principals.orderedByName())
            .immutableSortedCopy(unassignedPrincipals));
    dataProvider.addDataDisplay(list);

    SingleSelectionModel<Principal> selectionModel = new SingleSelectionModel<>(keyProvider);
    list.setSelectionModel(selectionModel);
    selectionModel.setSelected(dataProvider.getList().get(0), true);
    Scheduler.get().scheduleDeferred(() -> list.setFocus(true));

    Label errorMessage = new Label();
    errorMessage.setVisible(false);
    errorMessage.getElement().getStyle().setColor("#c82e2e");
    errorMessage.getElement().getStyle().setPadding(7, PX);

    VerticalPanel layout = new VerticalPanel();
    layout.setStyleName("window-content");
    layout.add(errorMessage);
    layout.add(list);

    DialogueOptions options = new DialogueOptions(
            event -> {
                if (selectionModel.getSelectedObject() == null) {
                    errorMessage.setText(Console.CONSTANTS.pleaseSelectPrincipal());
                    errorMessage.setVisible(true);
                } else {
                    Assignment assignment = new Assignment(selectionModel.getSelectedObject(), role,
                            include);
                    circuit.dispatch(new AddAssignment(assignment, ROLE_TO_PRINCIPAL));
                    presenter.closeWindow();
                }
            },
            event -> presenter.closeWindow()
    );

    return new WindowContentBuilder(layout, options).build();
}
 
Example 16
Source File: AssignmentDialog.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Widget asWidget() {
    ProvidesKey<Role> keyProvider = Role::getId;

    AbstractCell<Role> roleCell = new AbstractCell<Role>() {
        @Override
        public void render(final Context context, final Role value, final SafeHtmlBuilder sb) {
            sb.append(Templates.roleItem("navigation-column-item", value));
        }
    };
    DefaultCellList<Role> list = new DefaultCellList<>(roleCell, keyProvider);
    list.setPageSize(30);
    list.setKeyboardPagingPolicy(INCREASE_RANGE);
    list.setKeyboardSelectionPolicy(BOUND_TO_SELECTION);

    ListDataProvider<Role> dataProvider = new ListDataProvider<>(keyProvider);
    dataProvider.setList(
            Roles.orderedByType().compound(Roles.orderedByName()).immutableSortedCopy(unassignedRoles));
    dataProvider.addDataDisplay(list);

    SingleSelectionModel<Role> selectionModel = new SingleSelectionModel<>(keyProvider);
    list.setSelectionModel(selectionModel);
    selectionModel.setSelected(dataProvider.getList().get(0), true);
    Scheduler.get().scheduleDeferred(() -> list.setFocus(true));

    Label errorMessage = new Label();
    errorMessage.setVisible(false);
    errorMessage.getElement().getStyle().setColor("#c82e2e");
    errorMessage.getElement().getStyle().setPadding(7, PX);

    VerticalPanel layout = new VerticalPanel();
    layout.setStyleName("window-content");
    layout.add(errorMessage);
    layout.add(list);

    DialogueOptions options = new DialogueOptions(
            event -> {
                if (selectionModel.getSelectedObject() == null) {
                    errorMessage.setText(Console.CONSTANTS.pleaseSelectRole());
                    errorMessage.setVisible(true);
                } else {
                    Assignment assignment = new Assignment(principal, selectionModel.getSelectedObject(),
                            include);
                    circuit.dispatch(new AddAssignment(assignment, PRINCIPAL_TO_ROLE));
                    presenter.closeWindow();
                }
            },
            event -> presenter.closeWindow()
    );

    return new WindowContentBuilder(layout, options).build();
}
 
Example 17
Source File: CellBrowser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void renderRowValues(SafeHtmlBuilder sb, List<T> values, int start,
                               SelectionModel<? super T> selectionModel) {
  Cell<T> cell = getCell();
  String keyboardSelectedItem = " " + style.cellBrowserKeyboardSelectedItem();
  String selectedItem = " " + style.cellBrowserSelectedItem();
  String openItem = " " + style.cellBrowserOpenItem();
  String evenItem = style.cellBrowserEvenItem();
  String oddItem = style.cellBrowserOddItem();
  int keyboardSelectedRow = getKeyboardSelectedRow() + getPageStart();
  int length = values.size();
  int end = start + length;
  for (int i = start; i < end; i++) {
    T value = values.get(i - start);
    boolean isSelected = selectionModel == null ? false : selectionModel.isSelected(value);
    boolean isOpen = isOpen(i);
    StringBuilder classesBuilder = new StringBuilder();
    classesBuilder.append(i % 2 == 0 ? evenItem : oddItem);
    if (isOpen) {
      classesBuilder.append(openItem);
    }
    if (isSelected) {
      classesBuilder.append(selectedItem);
    }

    SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
    Context context = new Context(i, 0, getValueKey(value));
    cell.render(context, value, cellBuilder);

    // Figure out which image to use.
    SafeHtml image;
    if (isOpen) {
      image = openImageHtml;
    } else if (isLeaf(value)) {
      image = LEAF_IMAGE;
    } else {
      image = closedImageHtml;
    }

    SafeStyles padding =
            SafeStylesUtils.fromTrustedString("padding-right: " + imageWidth + "px;");
    if (i == keyboardSelectedRow) {
      // This is the focused item.
      if (isFocused) {
        classesBuilder.append(keyboardSelectedItem);
      }
      char accessKey = getAccessKey();
      if (accessKey != 0) {
        sb.append(template.divFocusableWithKey(i, classesBuilder.toString(), padding,
                                               getTabIndex(), getAccessKey(), image, cellBuilder.toSafeHtml()));
      } else {
        sb.append(template.divFocusable(i, classesBuilder.toString(), padding, getTabIndex(),
                                        image, cellBuilder.toSafeHtml()));
      }
    } else {
      sb.append(template.div(i, classesBuilder.toString(), padding, image, cellBuilder
              .toSafeHtml()));
    }
  }

  // Update the child state.
  updateChildState(this, true);
}
 
Example 18
Source File: ExpressionCell.java    From core with GNU Lesser General Public License v2.1 3 votes vote down vote up
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {

    expr = Expression.fromString(value);
    SafeHtml html = new SafeHtmlBuilder()
            .appendHtmlConstant( "<div tabindex=\"-1\" class='expression-cell'>"+expr.toString()+"</div>").toSafeHtml();

    sb.append(html);

}