Search in sources :

Example 1 with AbstractSafeHtmlRenderer

use of com.google.gwt.text.shared.AbstractSafeHtmlRenderer in project rstudio by rstudio.

the class EnvironmentObjectList method createExpandColumn.

private void createExpandColumn() {
    // the column containing the expand command; available only on objects
    // with contents (such as lists and data frames).
    SafeHtmlRenderer<String> expanderRenderer = new AbstractSafeHtmlRenderer<String>() {

        @Override
        public SafeHtml render(String object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant(object);
            return sb.toSafeHtml();
        }
    };
    objectExpandColumn_ = new Column<RObjectEntry, String>(new ClickableTextCell(expanderRenderer)) {

        @Override
        public String getValue(RObjectEntry object) {
            String imageUri = "";
            String imageStyle = style_.expandIcon();
            if (object.canExpand()) {
                imageStyle = imageStyle + " " + ThemeStyles.INSTANCE.handCursor();
                ImageResource expandImage = object.isExpanding ? CoreResources.INSTANCE.progress() : object.expanded ? new ImageResource2x(EnvironmentResources.INSTANCE.collapseIcon2x()) : new ImageResource2x(EnvironmentResources.INSTANCE.expandIcon2x());
                imageUri = expandImage.getSafeUri().asString();
            } else if (object.hasTraceInfo()) {
                imageUri = new ImageResource2x(EnvironmentResources.INSTANCE.tracedFunction2x()).getSafeUri().asString();
                imageStyle += (" " + style_.unclickableIcon());
            }
            if (imageUri.length() > 0) {
                return "<input type=\"image\" src=\"" + imageUri + "\" " + "class=\"" + imageStyle + "\" />";
            }
            return "";
        }
    };
    objectExpandColumn_.setFieldUpdater(new FieldUpdater<RObjectEntry, String>() {

        @Override
        public void update(int index, RObjectEntry object, String value) {
            if (!object.canExpand())
                return;
            expandObject(index, object);
        }
    });
}
Also used : AbstractSafeHtmlRenderer(com.google.gwt.text.shared.AbstractSafeHtmlRenderer) ImageResource(com.google.gwt.resources.client.ImageResource) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) JsArrayString(com.google.gwt.core.client.JsArrayString) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ClickableTextCell(com.google.gwt.cell.client.ClickableTextCell)

Example 2 with AbstractSafeHtmlRenderer

use of com.google.gwt.text.shared.AbstractSafeHtmlRenderer in project opennms by OpenNMS.

the class SearchControl method initializeCellAutocompleteWidget.

private void initializeCellAutocompleteWidget() {
    final AbstractSafeHtmlRenderer<NodeMarker> renderer = new AbstractSafeHtmlRenderer<NodeMarker>() {

        @Override
        public SafeHtml render(final NodeMarker marker) {
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            final String search = m_inputBox.getValue();
            builder.appendHtmlConstant("<div class=\"autocomplete-label\">");
            builder.appendHtmlConstant(marker.getNodeLabel());
            builder.appendHtmlConstant("</div>");
            String additionalSearchInfo = null;
            if (search != null && (search.contains(":") || search.contains("="))) {
                final String searchKey = search.replaceAll("[\\:\\=].*$", "").toLowerCase();
                LOG.info("searchKey = " + searchKey);
                final Map<String, String> props = marker.getProperties();
                if ("category".equals(searchKey) || "categories".equals(searchKey)) {
                    final String catString = props.get("categories");
                    if (catString != null) {
                        additionalSearchInfo = catString;
                    }
                }
                for (final Map.Entry<String, String> entry : props.entrySet()) {
                    final String key = entry.getKey().toLowerCase();
                    final Object value = entry.getValue();
                    if (key.equals(searchKey) && m_labels.containsKey(key)) {
                        additionalSearchInfo = m_labels.get(key) + ": " + value;
                        break;
                    }
                }
            }
            if (additionalSearchInfo != null) {
                builder.appendHtmlConstant("<div class=\"autocomplete-additional-info\">").appendHtmlConstant(additionalSearchInfo).appendHtmlConstant("</div>");
            }
            return builder.toSafeHtml();
        }
    };
    final AbstractSafeHtmlCell<NodeMarker> cell = new AbstractSafeHtmlCell<NodeMarker>(renderer, "keydown", "click", "dblclick", "touchstart") {

        @Override
        public void onBrowserEvent(final Context context, final com.google.gwt.dom.client.Element parent, final NodeMarker value, final NativeEvent event, final ValueUpdater<NodeMarker> valueUpdater) {
            LOG.info("SearchControl.AutocompleteCell.onBrowserEvent(): context = " + context + ", parent = " + parent + ", value = " + value + ", event = " + event);
            if (m_stateManager.handleAutocompleteEvent(event)) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
            }
        }

        @Override
        protected void render(final Context context, final SafeHtml data, final SafeHtmlBuilder builder) {
            builder.appendHtmlConstant("<div class=\"autocomplete-entry\">");
            if (data != null) {
                builder.append(data);
            }
            builder.appendHtmlConstant("</div>");
        }
    };
    m_autoComplete = new CellList<NodeMarker>(cell);
    m_autoComplete.setSelectionModel(m_selectionModel);
    m_autoComplete.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
    m_autoComplete.setVisible(false);
    m_autoComplete.addStyleName("search-autocomplete");
    setIdIfMissing(m_autoComplete, "searchControl.autoComplete");
}
Also used : AbstractSafeHtmlRenderer(com.google.gwt.text.shared.AbstractSafeHtmlRenderer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Element(com.google.gwt.user.client.Element) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) AbstractSafeHtmlCell(com.google.gwt.cell.client.AbstractSafeHtmlCell) HashMap(java.util.HashMap) Map(java.util.Map) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)2 AbstractSafeHtmlRenderer (com.google.gwt.text.shared.AbstractSafeHtmlRenderer)2 AbstractSafeHtmlCell (com.google.gwt.cell.client.AbstractSafeHtmlCell)1 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)1 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Element (com.google.gwt.user.client.Element)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)1 NodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1