Search in sources :

Example 1 with ValueUpdater

use of com.google.gwt.cell.client.ValueUpdater in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method editableTextColumn.

private Column<KeyboardShortcutEntry, String> editableTextColumn(String name, final ValueGetter<KeyboardShortcutEntry> getter) {
    EditTextCell editTextCell = new EditTextCell() {

        @Override
        public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> updater) {
            // handler.
            if (event.getType().equals("keyup") && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                parent.getFirstChildElement().blur();
                return;
            }
            super.onBrowserEvent(context, parent, value, event, updater);
        }
    };
    Column<KeyboardShortcutEntry, String> column = new Column<KeyboardShortcutEntry, String>(editTextCell) {

        @Override
        public String getValue(KeyboardShortcutEntry binding) {
            return getter.getValue(binding);
        }
    };
    column.setFieldUpdater(new FieldUpdater<KeyboardShortcutEntry, String>() {

        @Override
        public void update(int index, KeyboardShortcutEntry binding, String value) {
            KeySequence keys = KeySequence.fromShortcutString(value);
            // adding a new key sequence.
            if (keys.equals(binding.getOriginalKeySequence())) {
                changes_.remove(binding);
                binding.restoreOriginalKeySequence();
            } else {
                KeyboardShortcutEntry newBinding = new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys, binding.getCommandType(), true, binding.getContext());
                changes_.put(binding, newBinding);
                binding.setKeySequence(keys);
            }
            table_.setKeyboardSelectedColumn(0);
            updateData(dataProvider_.getList());
        }
    });
    column.setSortable(true);
    table_.addColumn(column, new TextHeader(name));
    return column;
}
Also used : EditTextCell(com.google.gwt.cell.client.EditTextCell) Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) TextHeader(com.google.gwt.user.cellview.client.TextHeader) JsArrayString(com.google.gwt.core.client.JsArrayString) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 2 with ValueUpdater

use of com.google.gwt.cell.client.ValueUpdater in project activityinfo by bedatadriven.

the class HierarchyTest method buildViewModelTest.

@Test
public void buildViewModelTest() {
    FormClass campForm = assertResolves(locator.getFormClass(CAMP_CLASS));
    FormField adminField = campForm.getField(CuidAdapter.field(CAMP_CLASS, CuidAdapter.ADMIN_FIELD));
    Set<RecordRef> fieldValue = Collections.singleton(new RecordRef(CAMP_DISTRICT_CLASS, entity(325703)));
    Hierarchy tree = assertResolves(Hierarchy.get(locator, (ReferenceType) adminField.getType()));
    prettyPrintTree(tree);
    assertThat(tree.getRoots(), hasSize(1));
    createWidgets(tree);
    Presenter presenter = new Presenter(locator, tree, widgets, new ValueUpdater() {

        @Override
        public void update(Object value) {
            System.out.println("VALUE = " + value);
        }
    });
    assertResolves(presenter.setInitialSelection(fieldValue));
    assertThat(presenter.getSelectionLabel(CAMP_DISTRICT_CLASS), equalTo("District 5"));
    // now try to get options for the root level
    List<Choice> choices = assertResolves(widgets.get(REGION).choices.get());
    System.out.println(choices);
    assertThat(choices, hasSize(3));
    // if we change the root item, then all descendants should be cleared
    widgets.get(REGION).setSelection("South");
    prettyPrintWidgets(tree);
    assertThat(widgets.get(CAMP_DISTRICT_CLASS).selection, isEmptyOrNullString());
    assertThat(widgets.get(GOVERNORATE_ID).choices, Matchers.notNullValue());
    List<Choice> governorateChoices = assertResolves(widgets.get(GOVERNORATE_ID).choices.get());
    System.out.println(governorateChoices);
    assertThat(governorateChoices, hasSize(4));
}
Also used : ValueUpdater(com.google.gwt.cell.client.ValueUpdater) FormClass(org.activityinfo.model.form.FormClass) RecordRef(org.activityinfo.model.type.RecordRef) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType) Test(org.junit.Test)

Example 3 with ValueUpdater

use of com.google.gwt.cell.client.ValueUpdater 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 4 with ValueUpdater

use of com.google.gwt.cell.client.ValueUpdater in project kie-wb-common by kiegroup.

the class ImportsWidgetViewImpl method setup.

private void setup() {
    // Setup table
    table.setStriped(true);
    table.setCondensed(true);
    table.setBordered(true);
    table.setEmptyTableWidget(new Label(ImportConstants.INSTANCE.noImportsDefined()));
    // Columns
    final TextColumn<Import> importTypeColumn = new TextColumn<Import>() {

        @Override
        public String getValue(final Import importType) {
            return importType.getType();
        }
    };
    final ButtonCell deleteImportButton = new ButtonCell(IconType.TRASH, ButtonType.DANGER, ButtonSize.SMALL) {

        @Override
        public void render(final com.google.gwt.cell.client.Cell.Context context, final SafeHtml data, final SafeHtmlBuilder sb) {
            // Don't render a "Delete" button for "internal" Fact Types
            if (isExternalImport(context.getIndex())) {
                super.render(context, data, sb);
            }
        }

        @Override
        public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> valueUpdater) {
            // Don't act on cell interactions for "internal" Fact Types
            if (isExternalImport(context.getIndex())) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
            }
        }

        @Override
        protected void onEnterKeyDown(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> valueUpdater) {
            // Don't act on cell interactions for "internal" Fact Types
            if (isExternalImport(context.getIndex())) {
                super.onEnterKeyDown(context, parent, value, event, valueUpdater);
            }
        }
    };
    final Column<Import, String> deleteImportColumn = new Column<Import, String>(deleteImportButton) {

        @Override
        public String getValue(final Import importType) {
            return ImportConstants.INSTANCE.remove();
        }
    };
    deleteImportColumn.setFieldUpdater((index, importType, value) -> {
        if (isReadOnly) {
            return;
        }
        final YesNoCancelPopup confirm = YesNoCancelPopup.newYesNoCancelPopup(ImportConstants.INSTANCE.remove(), ImportConstants.INSTANCE.promptForRemovalOfImport0(importType.getType()), () -> getRemoveImportCommand().execute(importType), () -> {
        /*Nothing*/
        }, null);
        confirm.show();
    });
    table.addColumn(importTypeColumn, new TextHeader(ImportConstants.INSTANCE.importType()));
    table.addColumn(deleteImportColumn, ImportConstants.INSTANCE.remove());
    // Link display
    getDataProvider().addDataDisplay(table);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Element(com.google.gwt.dom.client.Element) Label(org.gwtbootstrap3.client.ui.Label) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup) TextHeader(com.google.gwt.user.cellview.client.TextHeader) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) ButtonCell(org.gwtbootstrap3.client.ui.gwt.ButtonCell) TextColumn(com.google.gwt.user.cellview.client.TextColumn) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

ValueUpdater (com.google.gwt.cell.client.ValueUpdater)4 NativeEvent (com.google.gwt.dom.client.NativeEvent)3 Element (com.google.gwt.dom.client.Element)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)2 Column (com.google.gwt.user.cellview.client.Column)2 TextColumn (com.google.gwt.user.cellview.client.TextColumn)2 TextHeader (com.google.gwt.user.cellview.client.TextHeader)2 AbstractSafeHtmlCell (com.google.gwt.cell.client.AbstractSafeHtmlCell)1 EditTextCell (com.google.gwt.cell.client.EditTextCell)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 AbstractSafeHtmlRenderer (com.google.gwt.text.shared.AbstractSafeHtmlRenderer)1 Element (com.google.gwt.user.client.Element)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceType (org.activityinfo.model.type.ReferenceType)1