@Override public Subscription addValueChangeListener(String componentName, Consumer<HasValue.ValueChangeEvent> listener) { Component component = frame.getComponent(componentName); if (component == null) throw new RuntimeException("Component not found: " + componentName); if (component instanceof HasValue) { return ((HasValue) component).addValueChangeListener(listener); } else if (component instanceof ListComponent) { throw new UnsupportedOperationException("List component is not supported yet"); } else { throw new RuntimeException("Unable to add listener to the component " + component); } }
default void clear() { setValue(getEmptyValue()); }
default boolean isEmpty() { return Objects.equals(getValue(), getEmptyValue()); }
@Override public void paramChanged(Param oldParam, Param newParam) { Component oldDefaultValueComponent = defaultValueComponent; createDefaultValueComponent(); if (defaultValueComponent != null && defaultValueComponent instanceof HasValue && oldDefaultValueComponent != null && oldDefaultValueComponent instanceof HasValue) { if (oldParam.getJavaClass().equals(newParam.getJavaClass()) && defaultValueComponent.getClass().equals(oldDefaultValueComponent.getClass())) { ((HasValue) defaultValueComponent).setValue(((HasValue) oldDefaultValueComponent).getValue()); } } } });
@SuppressWarnings("unchecked") @Override public void setValue(String property, Object value) { final Component component = frame.getComponent(property); if (component instanceof HasValue) { ((HasValue) component).setValue(value); } else { throw new UnsupportedOperationException(); } }
/** * @deprecated Inject field instance and use typed component instead of this method. */ @Deprecated default Object getFieldValue(FieldConfig fc) { return ((HasValue) fc.getComponentNN()).getValue(); } /**
@Override public void removeValueChangeListener(String componentName, Consumer<HasValue.ValueChangeEvent> listener) { Component component = frame.getComponent(componentName); if (component == null) throw new RuntimeException("Component not found: " + componentName); if (component instanceof HasValue) { ((HasValue) component).removeValueChangeListener(listener); } else if (component instanceof ListComponent) { throw new UnsupportedOperationException("List component is not supported yet"); } else { throw new RuntimeException("Unable to add listener to the component " + component); } } }
component.setVisible(false);
@Override public void setParamValue(String paramName, Object value) { Component component = getOwnComponent(paramName); if (component instanceof HasValue) { ((HasValue) component).setValue(value); } }
@Override public Object getParamValue(String paramName) { Component component = getOwnComponent(paramName); if (component instanceof HasValue) { return ((HasValue) component).getValue(); } return null; }
/** * @deprecated Inject field instance and use typed component instead of this method. */ @Deprecated default void setFieldValue(FieldConfig fc, Object value) { ((HasValue) fc.getComponentNN()).setValue(value); } /**
@Override public boolean isModified() { return !Objects.equals(component.getValue(), source.getValue()); }
public <E extends Entity> void bind() { if (source instanceof EntityOptions && component instanceof HasValue) { this.componentValueChangeSubscription = ((HasValue<?>) component).addValueChangeListener(this::componentValueChanged); this.sourceValueChangeSupscription = ((EntityOptions<E>) source).addValueChangeListener(this::optionsSourceValueChanged); } this.sourceStateChangeSupscription = source.addStateChangeListener(this::optionsSourceStateChanged); this.sourceOptionsChangeSupscription = source.addOptionsChangeListener(this::optionsSourceOptionsChanged); }
@SuppressWarnings("unchecked") protected void optionsSourceValueChanged(EntityOptions.ValueChangeEvent<? extends Entity> event) { ((HasValue) optionsTarget).setValue(event.getValue()); }
@SuppressWarnings("unchecked") protected <T> T getValue(Component component) { if (component instanceof HasValue) { return (T) ((HasValue) component).getValue(); } else if (component instanceof ListComponent) { ListComponent list = (ListComponent) component; //noinspection unchecked return list.isMultiSelect() ? (T)list.getSelected() : (T)list.getSingleSelected(); } else { return null; } }
public void bind() { this.componentValueChangeSubscription = component.addValueChangeListener(this::componentValueChanged); this.sourceValueChangeSubscription = source.addValueChangeListener(this::sourceValueChanged); this.sourceStateChangeSubscription = source.addStateChangeListener(this::valueSourceStateChanged); if (source instanceof EntityValueSource) { this.sourceInstanceChangeSubscription = ((EntityValueSource<Entity, V>) source).addInstanceChangeListener(this::sourceInstanceChanged); } }
@Override public void setBuffered(boolean buffered) { this.buffered = buffered; if (!buffered && source.getState() == BindingState.ACTIVE) { // reset value of the component component.setValue(source.getValue()); } }
@Override public void write() { if (isBuffered() && isModified()) { setValueToSource(component.getValue()); } }
@Override public void activate() { if (source.getState() == BindingState.ACTIVE) { component.setValue(source.getValue()); } }
protected void valueSourceStateChanged(ValueSource.StateChangeEvent event) { if (event.getState() == BindingState.ACTIVE) { // read value to component component.setValue(source.getValue()); } }