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

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

Introduction

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

Prototype

public SafeHtmlBuilder append(SafeHtml html) 

Source Link

Document

Appends the contents of another SafeHtml object, without applying HTML-escaping to it.

Usage

From source file:org.drools.workbench.screens.guided.scorecard.client.widget.DynamicSelectionCell.java

License:Apache License

@Override
public void render(final Context context, final String value, final SafeHtmlBuilder sb) {
    // Get the view data.
    final Object key = context.getKey();
    String viewData = getViewData(key);
    if (viewData != null && viewData.equals(value)) {
        clearViewData(key);//from   w w w .  ja v  a 2 s.  com
        viewData = null;
    }

    final int selectedIndex = getSelectedIndex(viewData == null ? value : viewData);
    sb.appendHtmlConstant("<select tabindex=\"-1\">");
    int index = 0;
    for (String option : options) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option));
        } else {
            sb.append(template.deselected(option));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:org.ebayopensource.turmeric.policy.adminui.client.view.policy.CustomListCell.java

License:Open Source License

private void renderSelectList(final List<String> value, final SafeHtmlBuilder sb) {
    SafeHtmlBuilder content = new SafeHtmlBuilder();
    if (value != null && !value.isEmpty()) {
        for (String option : value) {
            content.append(template.deselected(option));
        }/*from  ww  w. j  a  v a  2s . c  om*/
    }
    sb.append(template.selectTag(String.valueOf(this.minScrollbarSize), content.toSafeHtml()));

}

From source file:org.eclipse.che.ide.ext.datasource.client.editdatasource.celllist.DatasourceCell.java

License:Open Source License

@Override
public void render(final Context context, final DatabaseConfigurationDTO value, final SafeHtmlBuilder sb) {
    if (value == null) {
        return;//from  www . ja v a  2  s.  c  om
    }

    final SafeHtml id = SafeHtmlUtils.fromString(value.getDatasourceId());
    final String connectorId = value.getConfigurationConnectorId();

    // for old datasources, the connector id was not recorded

    NewDatasourceConnector connector = this.connectorAgent.getConnector(connectorId);
    String dbType;
    if (connector != null) {
        dbType = connector.getTitle();
    } else {
        dbType = value.getDatabaseType().toString();
    }

    final SafeHtml type = SafeHtmlUtils.fromString(dbType);

    sb.append(this.template.datasourceItem(id, this.style.datasourceIdStyle(), type,
            this.style.datasourceTypeStyle(), this.style.datasourceIdCellStyle(),
            this.style.datasourceTypeCellStyle()));
}

From source file:org.eclipse.che.ide.ext.openshift.client.service.add.wizard.page.configure.ConfigureServiceViewImpl.java

License:Open Source License

private CellTable<Parameter> createVariablesTable(final CellTableResources tableResources) {
    envVariablesTable = new CellTable<>(50, tableResources);
    envVariablesTable.setTableLayoutFixed(true);
    envVariablesTable.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    envVariablesProvider.addDataDisplay(envVariablesTable);

    Column<Parameter, String> nameColumn = new Column<Parameter, String>(new TextCell()) {
        @Override/*ww w .  ja  va  2 s .  co m*/
        public String getValue(Parameter parameter) {
            return parameter.getName();
        }
    };

    TextInputCellWithPlaceHolder variablesCell = new TextInputCellWithPlaceHolder(
            locale.environmentVarialbesValuePlaceholder());
    Column<Parameter, String> valueColumn = new Column<Parameter, String>(variablesCell) {
        @Override
        public void onBrowserEvent(Cell.Context context, Element elem, Parameter parameter, NativeEvent event) {
            super.onBrowserEvent(context, elem, parameter, event);

            if (event.getType().equals(BrowserEvents.KEYUP)) {
                TextInputCellWithPlaceHolder cell = (TextInputCellWithPlaceHolder) envVariablesTable
                        .getColumn(context.getColumn()).getCell();
                String newValue = cell.getViewData(context.getKey()).getCurrentValue();

                if (parameter.getGenerate() == null && Strings.isNullOrEmpty(newValue)) {
                    elem.getParentElement().addClassName(resources.css().applicationTableError());
                } else {
                    elem.getParentElement().removeClassName(resources.css().applicationTableError());
                }
                getFieldUpdater().update(context.getIndex(), parameter, newValue);
                delegate.updateControls();
            }
        }

        @Override
        public String getCellStyleNames(Cell.Context context, Parameter parameter) {
            if (parameter != null && parameter.getGenerate() == null
                    && Strings.isNullOrEmpty(parameter.getValue())) {
                return resources.css().applicationTableError();
            }
            return null;
        }

        @Override
        public void render(Cell.Context context, Parameter parameter, SafeHtmlBuilder sb) {
            if (parameter.getGenerate() == null) {
                String value = parameter.getValue() == null ? "" : parameter.getValue();
                sb.append(template.input(value));
            } else {
                super.render(context, parameter, sb);
            }
        }

        @Override
        public String getValue(Parameter parameter) {
            return parameter.getValue();
        }
    };
    valueColumn.setFieldUpdater(new FieldUpdater<Parameter, String>() {
        @Override
        public void update(int index, Parameter parameter, String value) {
            parameter.setValue(value);
            delegate.updateControls();
        }
    });

    envVariablesTable.addColumn(nameColumn);
    envVariablesTable.setColumnWidth(nameColumn, 15, Style.Unit.PCT);
    envVariablesTable.addColumn(valueColumn);
    envVariablesTable.setColumnWidth(valueColumn, 20, Style.Unit.PCT);
    return envVariablesTable;
}

From source file:org.eclipse.che.ide.ext.openshift.client.service.add.wizard.page.configure.TextInputCellWithPlaceHolder.java

License:Open Source License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    value = (value == null) ? "" : value;
    sb.append(template.input(value, placeHolder));
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.console.panel.MessageBuilder.java

License:Open Source License

/** @return an instance of {@link SafeHtml} with all given information */
@Nonnull//from www .ja v  a2s  . c om
public SafeHtml build() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder().appendHtmlConstant("<pre style='margin:0px;'>");
    StringBuilder prefixes = new StringBuilder();

    for (Iterator<MessageType> iterator = types.iterator(); iterator.hasNext();) {
        MessageType type = iterator.next();

        if (UNDEFINED.equals(type)) {
            builder.append(SimpleHtmlSanitizer.sanitizeHtml(message));
        } else {
            String prefix = type.getPrefix();

            builder.appendHtmlConstant("[<span style='color:" + type.getColor() + ";'>")
                    .appendHtmlConstant("<b>" + prefix.replaceAll("[\\[\\]]", "") + "</b></span>]");

            prefixes.append(prefix);

            if (iterator.hasNext()) {
                prefixes.append(' ');
            }
        }
    }

    builder.append(SimpleHtmlSanitizer.sanitizeHtml(message.substring(prefixes.length())));

    return builder.appendHtmlConstant("</pre>").toSafeHtml();
}

From source file:org.eclipse.che.ide.jseditor.client.preference.editorselection.EditorSelectionCell.java

License:Open Source License

@Override
public void render(final Context context, final EditorType editorType, final SafeHtmlBuilder sb) {
    // Get the view data.
    final FileType filetype = (FileType) context.getKey();
    String viewData = getViewData(filetype);
    if (viewData != null && viewData.equals(editorType.getEditorTypeKey())) {
        clearViewData(filetype);//www. j av a  2s  . com
        viewData = null;
    }

    int selectedIndex = getIndex(this.editorTypes, viewData, editorType);
    Log.debug(EditorSelectionCell.class, "File type " + filetype + " - found selection " + selectedIndex);
    if (selectedIndex == -1) {
        selectedIndex = getDefaultIndex(this.editorTypes);
        Log.debug(EditorSelectionCell.class, "... using default value " + selectedIndex + " instead.");
    }

    final SafeStyles widthStyle = SafeStylesUtils.forWidth(this.selectWidthValue, this.selectWidthUnit);
    sb.append(template.select(this.stylename, widthStyle));
    int index = 0;
    for (final EditorType option : this.editorTypes) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option.getEditorTypeKey(), this.editorTypeRegistry.getName(option)));
        } else {
            sb.append(template.deselected(option.getEditorTypeKey(), this.editorTypeRegistry.getName(option)));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:org.eclipse.che.ide.jseditor.client.preference.keymaps.KeymapSelectionCell.java

License:Open Source License

@Override
public void render(final Context context, final Keymap keymap, final SafeHtmlBuilder sb) {
    // Get the view data.
    EditorType editorType = (EditorType) context.getKey();
    String viewData = getViewData(editorType);
    if (viewData != null && viewData.equals(keymap.getKey())) {
        clearViewData(editorType);//from   w  ww  .  jav a 2 s . c om
        viewData = null;
    }

    final List<Keymap> keymapsForRow = Keymap.getInstances(editorType);
    final int selectedIndex = getIndex(keymapsForRow, viewData, keymap);

    if (keymapsForRow == null || keymapsForRow.isEmpty()) {
        return;
    }
    sb.append(template.select(this.stylename, this.widthStylename));
    int index = 0;
    for (final Keymap option : keymapsForRow) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option.getKey(), option.getDisplay()));
        } else {
            sb.append(template.deselected(option.getKey(), option.getDisplay()));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:org.eclipse.che.ide.processes.runtime.CellTableRuntimeInfoWidgetFactory.java

License:Open Source License

private Widget createCellTable(ListDataProvider<RuntimeInfo> dataProvider) {
    CellTable<RuntimeInfo> table = new CellTable<>(100, resources);
    table.ensureDebugId("runtimeInfoCellTable");

    TextColumn<RuntimeInfo> referenceColumn = new TextColumn<RuntimeInfo>() {
        @Override//from ww w  .j  ava  2  s . co m
        public String getValue(RuntimeInfo record) {
            return valueOrDefault(record.getReference());
        }

        @Override
        public void render(Context context, RuntimeInfo object, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "runtime-info-reference-"
                    + context.getIndex() + "\">");
            super.render(context, object, sb);
        }
    };

    TextColumn<RuntimeInfo> portColumn = new TextColumn<RuntimeInfo>() {
        @Override
        public String getValue(RuntimeInfo record) {
            return valueOrDefault(record.getPort());
        }

        @Override
        public void render(Context context, RuntimeInfo object, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "runtime-info-port-"
                    + context.getIndex() + "\">");
            super.render(context, object, sb);
        }
    };

    TextColumn<RuntimeInfo> protocolColumn = new TextColumn<RuntimeInfo>() {
        @Override
        public String getValue(RuntimeInfo record) {
            return valueOrDefault(record.getProtocol());
        }

        @Override
        public void render(Context context, RuntimeInfo object, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "runtime-info-protocol-"
                    + context.getIndex() + "\">");
            super.render(context, object, sb);
        }
    };

    Column<RuntimeInfo, SafeHtml> urlColumn = new Column<RuntimeInfo, SafeHtml>(
            new AbstractCell<SafeHtml>("click", "keydown") {

                @Override
                public void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
                    sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "runtime-info-url-"
                            + context.getIndex() + "\">");

                    if (value != null) {
                        sb.append(value);
                    }
                }

                @Override
                protected void onEnterKeyDown(Context context, Element parent, SafeHtml value,
                        NativeEvent event, ValueUpdater<SafeHtml> valueUpdater) {
                    if (valueUpdater != null) {
                        valueUpdater.update(value);
                    }
                }

                @Override
                public void onBrowserEvent(Context context, Element parent, SafeHtml value, NativeEvent event,
                        ValueUpdater<SafeHtml> valueUpdater) {
                    super.onBrowserEvent(context, parent, value, event, valueUpdater);
                    if ("click".equals(event.getType())) {
                        onEnterKeyDown(context, parent, value, event, valueUpdater);
                    }
                }
            }) {
        @Override
        public SafeHtml getValue(RuntimeInfo record) {
            String value = valueOrDefault(record.getUrl());

            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant("<a target=\"_blank\" href=\"" + value + "\">");
            sb.appendEscaped(value);
            sb.appendHtmlConstant("</a>");
            return sb.toSafeHtml();
        }
    };

    table.addColumn(referenceColumn, locale.cellTableReferenceColumn());
    table.addColumn(portColumn, locale.cellTablePortColumn());
    table.addColumn(protocolColumn, locale.cellTableProtocolColumn());
    table.addColumn(urlColumn, locale.cellTableUrlColumn());

    table.setColumnWidth(referenceColumn, 15., Unit.PCT);
    table.setColumnWidth(portColumn, 7., Unit.PCT);
    table.setColumnWidth(protocolColumn, 7., Unit.PCT);
    table.setColumnWidth(urlColumn, 71., Unit.PCT);

    dataProvider.addDataDisplay(table);

    return table;
}

From source file:org.eclipse.che.plugin.debugger.ide.debug.FrameItemRender.java

License:Open Source License

@Override
public void render(Element itemElement, StackFrameDump itemData) {
    TableCellElement label = Elements.createTDElement();

    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendEscaped(itemData.getLocation().getMethod().getName());
    sb.appendEscaped("(");

    List<? extends Variable> arguments = itemData.getLocation().getMethod().getArguments();
    for (int i = 0; i < arguments.size(); i++) {
        String type = arguments.get(i).getType();
        sb.appendEscaped(type.substring(type.lastIndexOf(".") + 1));

        if (i != arguments.size() - 1) {
            sb.appendEscaped(", ");
        }/*from   w w w .  ja va 2  s  .  c o m*/
    }

    sb.appendEscaped("):");
    sb.append(itemData.getLocation().getLineNumber());
    sb.appendEscaped(", ");

    Path path = Path.valueOf(itemData.getLocation().getTarget());

    String className;
    if (path.isAbsolute()) {
        className = path.removeFileExtension().lastSegment();
    } else {
        className = path.lastSegment();
    }

    sb.appendEscaped(className);

    label.setInnerHTML(sb.toSafeHtml().asString());
    itemElement.appendChild(label);
}