Search in sources :

Example 46 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project perun by CESNET.

the class UnaccentMultiWordSuggestOracle method convertToFormattedSuggestions.

/**
	 * Returns real suggestions with the given query in <code>strong</code> html
	 * font.
	 *
	 * @param query query string
	 * @param candidates candidates
	 * @return real suggestions
	 */
private List<MultiWordSuggestion> convertToFormattedSuggestions(String query, List<String> candidates) {
    List<MultiWordSuggestion> suggestions = new ArrayList<MultiWordSuggestion>();
    for (int i = 0; i < candidates.size(); i++) {
        String candidate = candidates.get(i);
        int cursor = 0;
        int index = 0;
        // Use real suggestion for assembly.
        String formattedSuggestion = toRealSuggestions.get(candidate);
        // Create strong search string.
        SafeHtmlBuilder accum = new SafeHtmlBuilder();
        String[] searchWords = query.split(WHITESPACE_STRING);
        while (true) {
            WordBounds wordBounds = findNextWord(candidate, searchWords, index);
            if (wordBounds == null) {
                break;
            }
            if (wordBounds.startIndex == 0 || WHITESPACE_CHAR == candidate.charAt(wordBounds.startIndex - 1)) {
                String part1 = formattedSuggestion.substring(cursor, wordBounds.startIndex);
                String part2 = formattedSuggestion.substring(wordBounds.startIndex, wordBounds.endIndex);
                cursor = wordBounds.endIndex;
                accum.appendEscaped(part1);
                accum.appendHtmlConstant("<strong>");
                accum.appendEscaped(part2);
                accum.appendHtmlConstant("</strong>");
            }
            index = wordBounds.endIndex;
        }
        // Check to make sure the search was found in the string.
        if (cursor == 0) {
            continue;
        }
        accum.appendEscaped(formattedSuggestion.substring(cursor));
        MultiWordSuggestion suggestion = createSuggestion(formattedSuggestion, accum.toSafeHtml().asString());
        suggestions.add(suggestion);
    }
    return suggestions;
}
Also used : SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 47 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project perun by CESNET.

the class ApplicationFormGui method loadVo.

/**
	 * Loads the VO by the parameter
	 */
public void loadVo(final JsonCallbackEvents events) {
    voName = Location.getParameter("vo");
    groupName = Location.getParameter("group");
    Initialize req = new Initialize(voName, groupName, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            JsArray<Attribute> list = JsonUtils.jsoAsArray(jso);
            // recreate VO and group
            vo = new JSONObject().getJavaScriptObject().cast();
            if (groupName != null && !groupName.isEmpty()) {
                group = new JSONObject().getJavaScriptObject().cast();
            }
            for (int i = 0; i < list.length(); i++) {
                Attribute a = list.get(i);
                if (a.getFriendlyName().equalsIgnoreCase("id")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setId(Integer.parseInt(a.getValue()));
                        if (group != null) {
                            group.setVoId(Integer.parseInt(a.getValue()));
                        }
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setId(Integer.parseInt(a.getValue()));
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("name")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setName(a.getValue());
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("shortName")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setShortName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("description")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setDescription(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("contactEmail")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:def")) {
                        // set contact email
                        for (int n = 0; n < a.getValueAsJsArray().length(); n++) {
                            SafeHtmlBuilder s = new SafeHtmlBuilder();
                            if (n > 0) {
                                //others
                                s.appendHtmlConstant(voContact.getHTML().concat(", <a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            } else {
                                // first
                                s.appendHtmlConstant(voContact.getHTML().concat("<a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            }
                            voContact.setHTML(s.toSafeHtml());
                        }
                    }
                }
            }
            // store attrs
            vo.setAttributes(list);
            loadPerunPrincipal(events);
        }

        @Override
        public void onError(PerunError error) {
            // hides the loading box
            loadingBox.hide();
            RootLayoutPanel panel = RootLayoutPanel.get();
            panel.clear();
            panel.add(getErrorWidget(error));
        }
    });
    req.setHidden(true);
    req.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Initialize(cz.metacentrum.perun.webgui.json.registrarManager.Initialize)

Example 48 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class HighlightSuggestion method getDisplayString.

@Override
public String getDisplayString() {
    int start = 0;
    int keyLen = keyword.length();
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    for (; ; ) {
        int index = value.indexOf(keyword, start);
        if (index == -1) {
            builder.appendEscaped(value.substring(start));
            break;
        }
        builder.appendEscaped(value.substring(start, index));
        builder.appendHtmlConstant("<strong>");
        start = index + keyLen;
        builder.appendEscaped(value.substring(index, start));
        builder.appendHtmlConstant("</strong>");
    }
    return builder.toSafeHtml().asString();
}
Also used : SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 49 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder 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)

Example 50 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project drools-wb by kiegroup.

the class AuditLogEntryCellHelper method buildColumnDetailsUpdate.

private void buildColumnDetailsUpdate(final ConditionColumnDetails details, final ConditionColumnDetails originalDetails, final List<BaseColumnFieldDiff> diffs, final SafeHtmlBuilder sb) {
    sb.append(TEMPLATE.commentHeader(GuidedDecisionTableConstants.INSTANCE.DecisionTableAuditLogUpdateCondition(details.getColumnHeader())));
    SafeHtmlBuilder sbFields = null;
    // Show changed fields too.
    if (diffs != null && !diffs.isEmpty()) {
        sbFields = new SafeHtmlBuilder();
        for (BaseColumnFieldDiff diff : diffs) {
            String changedFieldName = diff.getFieldName();
            if (changedFieldName.equals(DTColumnConfig52.FIELD_HEADER)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.ColumnHeader(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_FACT_FIELD)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.Field(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_OPERATOR)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.Operator(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_VALUE_LIST)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.ValueList(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_BINDING)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.Binding(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_CONSTRAINT_VALUE_TYPE)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.CalculationType(), getLiteralForCalculationType((Integer) diff.getOldValue()), getLiteralForCalculationType((Integer) diff.getValue()), sbFields);
            } else if (changedFieldName.equals(DTColumnConfig52.FIELD_DEFAULT_VALUE)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.DefaultValue(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(DTColumnConfig52.FIELD_HIDE_COLUMN)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.HideThisColumn(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(Pattern52.FIELD_ENTRY_POINT_NAME)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.DTLabelFromEntryPoint(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(Pattern52.FIELD_FACT_TYPE)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.FactType(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(Pattern52.FIELD_BOUND_NAME)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.Binding(), diff.getOldValue(), diff.getValue(), sbFields);
            } else if (changedFieldName.equals(ConditionCol52.FIELD_FIELD_TYPE)) {
                buildColumnUpdateFields(GuidedDecisionTableConstants.INSTANCE.FieldType(), diff.getOldValue(), diff.getValue(), sbFields);
            }
        }
    }
    if (sbFields != null) {
        sb.append(TEMPLATE.updatedFields(sbFields.toSafeHtml(), labelClass));
    }
}
Also used : BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Aggregations

SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)62 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)12 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)10 Column (com.google.gwt.user.cellview.client.Column)10 MenuItem (com.google.gwt.user.client.ui.MenuItem)7 Cell (com.google.gwt.cell.client.Cell)5 Command (com.google.gwt.user.client.Command)5 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)4 TextCell (com.google.gwt.cell.client.TextCell)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 Test (org.junit.Test)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)3 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)3 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)3 Application (cz.metacentrum.perun.webgui.model.Application)3 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)3 PerunAppTypeCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAppTypeCell)3 AppCommand (org.rstudio.core.client.command.AppCommand)3 ButtonCell (com.google.gwt.cell.client.ButtonCell)2