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;
}
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));
}
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");
}
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);
}
Aggregations