public static Validator getValidator(DataType dataType, HasValue<String> value) { Validator validator = null; switch (dataType) { case DATE: validator = new DateFormatValidator(value); break; case DOUBLE: case FLOAT: validator = new NumberValidator(value, true); break; case LONG: case INTEGER: validator = new NumberValidator(value, false); break; case STRING: break; default: break; } return validator; }
public FieldsEditor(ApiService service, String key) { super(""); this.service = service; this.key = key; root = new CheckBox(key.isEmpty() ? "Select all/none" : key); root.setValue(false); root.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { for (HasValue<Boolean> checkBox : children.values()) { checkBox.setValue(event.getValue(), true); } } }); add(root); }
private static Object getData(UIObject ui) { if (ui instanceof HasValue) { return ((HasValue)ui).getValue(); } else if (ui instanceof HasText) { return ((HasText)ui).getText(); } else if (ui instanceof HasData) { return ((HasData)ui).getData(); } else if (ui instanceof ListBox) { ListBox listBox = (ListBox) ui; if(listBox.getSelectedIndex() > 0) { return listBox.getValue(listBox.getSelectedIndex()); } } else if (ui instanceof ValueSpinner) { ValueSpinner spinner = (ValueSpinner) ui; return spinner.getTextBox().getValue(); } return null; }
/** * Creates a controller that will manage the date/time range * consisting of 2 date/time controls and an optional * allDayCheckbox. */ public UTCDateTimeRangeController(UTCDateBox startDate, UTCTimeBox startTime, UTCDateBox endDate, UTCTimeBox endTime, HasValue<Boolean> allDayCheckbox) { this.startDate = startDate; this.startTime = startTime; this.endDate = endDate; this.endTime = endTime; this.allDayCheckbox = allDayCheckbox; updateInterval(); // attach the event handlers if (allDayCheckbox != null) { allDayCheckbox.addValueChangeHandler(new AllDayCheckboxHandler()); } StartDateTimeHandler startHandler = new StartDateTimeHandler(); EndDateTimeHandler endHandler = new EndDateTimeHandler(); startDate.addValueChangeHandler(startHandler); startTime.addValueChangeHandler(startHandler); endDate.addValueChangeHandler(endHandler); endTime.addValueChangeHandler(endHandler); }
public RegExValidator(final RegExValidatableWidget<?> validatableWidget, final HasValue<String> value, final boolean isMandatory, final boolean isMultiplePattern, final boolean isPatternValidator, final String patternDelimiter, final DCMARemoteServiceAsync remoteServiceAsync) { this._value = value; this.validatableWidget = validatableWidget; this.isMandatory = isMandatory; this.isMultiplePattern = isMultiplePattern; this.isOnlyPatternValidator = isPatternValidator; this.patternDelimiter = patternDelimiter; this.remoteService = remoteServiceAsync; }
@Override protected void onLoad() { super.onLoad(); HandlerRegistration handlerRegistration = addClickHandler(event -> { // Stop propagation of event when checkbox / other elements has // been clicked to avoid duplicate events. if (Element.as(event.getNativeEvent().getEventTarget()) != getElement()) { if (getType() == CollectionType.CHECKBOX) { event.stopPropagation(); event.preventDefault(); } } for (Widget w : MaterialCollectionItem.this) { if (w instanceof MaterialCollectionSecondary) { for (Widget a : (MaterialCollectionSecondary) w) { if (a instanceof HasValue) { try { @SuppressWarnings("unchecked") HasValue<Boolean> cb = (HasValue<Boolean>) a; if (cb.getValue()) { cb.setValue(false); } else { cb.setValue(true); } } catch (ClassCastException ex) { // Ignore non-boolean has value handlers. } } } } } }); registerHandler(handlerRegistration); JsMaterialElement.initDismissableCollection(); }
public static <H extends HasValueChangeHandlers & HasValue & HasEnabled & HasAttachHandlers> void checkValueChangeEvent( H widget, Object value, Object secondValue) { assertNotSame(value, secondValue); // Widget must be enabled before firing the event widget.setEnabled(true); assertTrue(widget.isEnabled()); // Ensure the widget is attached to the root panel assertTrue(widget.isAttached()); // Register value change handler that listens when the widget // set the value final boolean[] isValueChanged = {false}; widget.addValueChangeHandler(event -> isValueChanged[0] = true); // By default setValue(boolean) will not fire the value change event. widget.setValue(value); assertEquals(value, widget.getValue()); // Expected result : false assertFalse(isValueChanged[0]); // Calling setValue(value, fireEvents) with fireEvents set to false widget.setValue(secondValue, false); // Expected result : secondValue assertEquals(secondValue, widget.getValue()); // Expected result : false assertFalse(isValueChanged[0]); // Calling setValue(value, fireEvents) with fireEvents set to true widget.setValue(value, true); // Expected result : true assertTrue(isValueChanged[0]); // Expected result : value assertEquals(value, widget.getValue()); }
/** * Returns this field's checked value, or if it has children, whether all its * children are checked. */ @Override public Boolean getValue() { if (children.isEmpty()) { return root.getValue(); } return Iterables.all(children.entrySet(), new Predicate<Map.Entry<String, HasValue<Boolean>>>() { @Override public boolean apply(Entry<String, HasValue<Boolean>> input) { return input.getValue().getValue(); } }); }
/** * Sets this field's checked value, and all of its childrens' if it has any. */ @Override public void setValue(Boolean value) { for (HasValue<Boolean> hasValue : children.values()) { hasValue.setValue(value); } this.root.setValue(value); }
private void gatherForm(Map<String, String> aFormData, HasWidgets aContainer) { Iterator<Widget> widgets = aContainer.iterator(); while (widgets.hasNext()) { Widget w = widgets.next(); if (w instanceof HasValue<?> && w instanceof HasJsName) { String name = ((HasJsName) w).getJsName(); Object value = ((HasValue<Object>) w).getValue(); if (name != null && !name.isEmpty() && (value == null || value instanceof String || value instanceof Number)) { aFormData.put(name, value != null ? value.toString() : null); } } if (w instanceof HasWidgets) gatherForm(aFormData, (HasWidgets) w); } }
public void add(HasValue<Boolean> aItem) { if (!grouped.contains(aItem)) { if (aItem instanceof HasName) { ((HasName) aItem).setName(groupName); } groupedHandlers.put(aItem, aItem.addValueChangeHandler(this)); grouped.add(aItem); } }
public boolean remove(HasValue<Boolean> aItem) { HandlerRegistration handler = groupedHandlers.get(aItem); if (handler != null) { handler.removeHandler(); } if (aItem instanceof HasName) { ((HasName) aItem).setName(""); } return grouped.remove(aItem); }
public HasPublished getChild(int i) { HasValue<Boolean> child = super.get(i); if (child instanceof HasPublished) return (HasPublished) child; else return null; }
private void placeWidgetToMenu(Widget aWidget, ButtonGroup aBtnGroup, String aStyleName) { aWidget.getElement().getStyle().setWidth(elementWidth, Style.Unit.PX); aWidget.getElement().getStyle().setHeight(elementHeight, Style.Unit.PX); if (aStyleName != null && !aStyleName.isEmpty()) { aWidget.addStyleName(aStyleName); } if (aBtnGroup != null) { if (aWidget instanceof HasValue) { aBtnGroup.add((HasValue<Boolean>) aWidget); } } toolBar.add(aWidget); }
@SuppressWarnings("unchecked") @Override public void setValue(final T pvalue, final boolean pfireEvents) { if (this.contents.getWidget() instanceof TakesValue<?>) { this.clearErrors(); if (this.contents.getWidget() instanceof HasValue<?>) { ((HasValue<T>) this.contents.getWidget()).setValue(pvalue, pfireEvents); } else { ((TakesValue<T>) this.contents.getWidget()).setValue(pvalue); } } }
@Override public <F> Registration bind(final String id, final HasValue<F> widget, Strategy strategy) { assert widget instanceof IsWidget : "HasValue parameter must be of type IsWidget"; // Add update handler HandlerRegistration handlerRegistration = strategy.bind((IsWidget) widget, new Command() { @Override public void execute() { fireValueChangeEvent(id, widget); } }); if (bindings.containsKey(id)) { // If id were already bound, then update the binding WidgetBinding widgetBinding = bindings.get(id); if (widgetBinding.widgetHandlerRegistration != null) { // Remove previous existing handler avoiding memory leak widgetBinding.widgetHandlerRegistration.removeHandler(); } widgetBinding.widget = widget; widgetBinding.widgetHandlerRegistration = handlerRegistration; } else { WidgetBinding widgetBinding = new WidgetBinding(widget, handlerRegistration); bindings.put(id, widgetBinding); } return BinderRegistration.of(this, id); }
public void testBindWidget() { doTestBindWidget(new BindWidgetCallback() { @Override public HandlerRegistration bind(ViewEngine engine, String propertyId, IsWidget widget) { return engine.bind(propertyId, (HasValue<?>) widget, Strategy.ON_CHANGE); } }); }
@Override protected HasValue<RecordField> createBody(HasErrorMessage hasErrorMessage) { RecordPanel field = new RecordPanel( Utils.constants.configurationBody(), hasErrorMessage, false, false); configurationFormDataLoader = new ConfigurationFormDataLoader(); field.setFormDataLoader(configurationFormDataLoader); field.getRecordWidget().setForceNavigation(true); field.setPreferredHeightPx(200); return field; }
public <T extends IsWidget & HasValue<String>> void init(Wrapper<T> textBox, ExpressionReplacer expressionReplacer) { this.textBox = textBox.getInstance(); this.expressionReplacer = expressionReplacer; eventRegistrar.registerInputHandler(textBox.getInstance(), listener); }
private boolean isInstanceOfHasValue(VariableElement variableElement) { return types.isAssignable(variableElement.asType(), types.erasure(requireType(elements, HasValue.class).asType())); }
public FileNameValidator(HasValue<String> value) { this.value = value; }
public void setValue(HasValue<String> value) { this.value = value; }
public RegExValidator(final RegExValidatableWidget<?> validatableWidget, final String pattern, final HasValue<String> value, final DCMARemoteServiceAsync remoteServiceAsync) { this(validatableWidget, value, true, false, false, null, remoteServiceAsync); this.pattern = pattern; }
public SuggestBoxValidator(HasValue<String> value, Collection<String> suggestValues) { this.value = value; this.suggestValues = suggestValues; }
public EmptyStringValidator(HasValue<String> value) { this.value = value; }
public DateFormatValidator(HasValue<String> value) { this("dd/MM/yyyy", value); }
public DateFormatValidator(String pattern, HasValue<String> value) { format = DateTimeFormat.getFormat(pattern); this.value = value; }
public PatternValidator(HasValue<String> value, List<String> patternStr) { this.value = value; this.patternStr = patternStr; }
public NumberValidator(HasValue<String> value) { this.value = value; }
public NumberValidator(HasValue<String> value, boolean isFloat) { this.value = value; this.isFloat = isFloat; }
public NumberValidator(HasValue<String> value, boolean isFloat, boolean skipNullCheck) { this.value = value; this.isFloat = isFloat; this.skipNullCheck = skipNullCheck; }
public NumberValidator(HasValue<String> value, boolean isFloat, boolean skipNullCheck, boolean isOnlyPositive) { this.value = value; this.isFloat = isFloat; this.skipNullCheck = skipNullCheck; this.isOnlyPositive = isOnlyPositive; }
@Override public HasValue<String> getKaaHost() { return kaaHost; }
@Override public HasValue<Boolean> welcomeField() { return showWelcome; }
@SuppressWarnings("unchecked") public ValuePropertyAdapter(HasValue<?> hasValue) { this.hasValue = (HasValue<Object>) hasValue; }