com.vaadin.ui.AbstractField Java Examples

The following examples show how to use com.vaadin.ui.AbstractField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * adds a listener to a component. Depending on the type of component a
 * valueChange-, textChange- or itemSetChangeListener will be added.
 */
public void addComponentListeners() {
    // avoid duplicate registration
    removeListeners();

    for (final AbstractField<?> field : allComponents) {
        if (field instanceof TextChangeNotifier) {
            ((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
        }

        if (field instanceof Table) {
            ((Table) field).addItemSetChangeListener(new ChangeListener(field));
        }
        field.addValueChangeListener(new ChangeListener(field));
    }
}
 
Example #2
Source File: ElementCollectionField.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public void setPersisted(ET v, boolean persisted) {
    int row = itemsIdentityIndexOf(v) + 1;
    if (isAllowRemovingItems()) {
        Button c = (Button) layout.getComponent(layout.getColumns() - 1, row);
        if (persisted) {
            c.setDescription(getDeleteElementDescription());
        } else {
            for (int i = 0; i < getVisibleProperties().size(); i++) {
                try {
                    AbstractField f = (AbstractField) layout.
                            getComponent(i,
                                    row);
                    // FIXME
                    //f.setValidationVisible(false);
                } catch (Exception e) {

                }
            }
            c.setDescription(getDisabledDeleteElementDescription());
        }
        c.setEnabled(persisted);
    }
}
 
Example #3
Source File: FormFactoryImpl.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the display property converters.
 *
 * @param                     <T> the generic type
 * @param displayProperties   the display properties
 * @param formContent         the form content
 * @param binder              the binder
 * @param propertyDescriptors the property descriptors
 */
private static <T extends Serializable> void createDisplayPropertyConverters(final List<String> displayProperties,
		final ComponentContainer formContent, final Binder<T> binder, final PropertyDescriptor[] propertyDescriptors) {
	for (final String property : displayProperties) {
		final Class<?> typeOfProperty = getTypeOfProperty(propertyDescriptors, property);

		if (typeOfProperty != null) {
			final AbstractField<?> field = new TextField();
			field.setReadOnly(true);
			field.setCaption(property);
			field.setWidth(ContentSize.FULL_SIZE);
			formContent.addComponent(field);
			final Converter converter = getConverterForType(typeOfProperty);

			if (converter != null) {
				binder.forField(field).withConverter(converter).bind(property);
			} else {
				binder.forField(field).bind(property);
			} 
		}
	}
}
 
Example #4
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private static List<AbstractField<?>> getAllComponents(final AbstractLayout abstractLayout) {
    final List<AbstractField<?>> components = new ArrayList<>();

    final Iterator<Component> iterate = abstractLayout.iterator();
    while (iterate.hasNext()) {
        final Component c = iterate.next();
        if (c instanceof AbstractLayout) {
            components.addAll(getAllComponents((AbstractLayout) c));
        }

        if (c instanceof AbstractField) {
            components.add((AbstractField<?>) c);
        }

        if (c instanceof FlexibleOptionGroupItemComponent) {
            components.add(((FlexibleOptionGroupItemComponent) c).getOwner());
        }

        if (c instanceof TabSheet) {
            final TabSheet tabSheet = (TabSheet) c;
            components.addAll(getAllComponentsFromTabSheet(tabSheet));
        }
    }
    return components;
}
 
Example #5
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private static List<AbstractField<?>> getAllComponentsFromTabSheet(final TabSheet tabSheet) {
    final List<AbstractField<?>> components = new ArrayList<>();
    for (final Iterator<Component> i = tabSheet.iterator(); i.hasNext();) {
        final Component component = i.next();
        if (component instanceof AbstractLayout) {
            components.addAll(getAllComponents((AbstractLayout) component));
        }
    }
    return components;
}
 
Example #6
Source File: FieldAccessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public void setControlValue(Object value) {
	AbstractField<Object> field = (AbstractField<Object>) getControl();
	
	field.setValue(value);
	
}
 
Example #7
Source File: VaadinBindingUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
public static void registerControlAccessors(ConfigurableControlAccessorFactory accessorFactory) {
	Map<Class<?>, Class<?extends ControlAccessor>> accessors = accessorFactory.getAccessors();
	
	accessors.put(AbstractField.class, FieldAccessor.class);
	accessors.put(TextField.class, TextFieldAccessor.class);
	accessors.put(Label.class, LabelAccessor.class);
	accessors.put(PageableTable.class, PageableTableAccessor.class);
	accessors.put(Table.class, TableAccessor.class);
	accessors.put(TableEditor.class, TableEditorAccessor.class);
}
 
Example #8
Source File: UserErrorProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void reset() {
	for (AbstractField<?> f : fieldSet)
		f.setComponentError(null);
	
	fieldSet.clear();
}
 
Example #9
Source File: UserErrorProcessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void processError(Object control, FieldError error) {
	if (control instanceof AbstractField) {
		AbstractField<?> f = (AbstractField<?>) control;
		f.setComponentError(new UserError(StaticMessageSource.getMessage(error)));
		fieldSet.add(f);
	}
}
 
Example #10
Source File: AbstractForm.java    From viritin with Apache License 2.0 5 votes vote down vote up
private boolean findFieldAndFocus(Component compositionRoot) {
    if (compositionRoot instanceof AbstractComponentContainer) {
        AbstractComponentContainer cc = (AbstractComponentContainer) compositionRoot;

        for (Component component : cc) {
            if (component instanceof AbstractTextField) {
                AbstractTextField abstractTextField = (AbstractTextField) component;
                if (!abstractTextField.isReadOnly()) {
                    abstractTextField.selectAll();
                    return true;
                }
            }
            if (component instanceof AbstractField) {
                AbstractField abstractField = (AbstractField) component;
                if (!abstractField.isReadOnly()) {
                    abstractField.focus();
                    return true;
                }
            }
            if (component instanceof AbstractComponentContainer) {
                if (findFieldAndFocus(component)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #11
Source File: FormFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Serializable> void addRequestInputFormFields(final FormLayout panelContent, final T item,
		final Class<T> beanType, final List<String> displayProperties,final String buttonLabel,final ClickListener buttonListener) {
	final BeanValidationBinder<T> binder = new BeanValidationBinder<>(beanType);
	binder.setBean(item);
	binder.setReadOnly(true);

	for (final String property : displayProperties) {

		final AbstractField buildAndBind = createField(property);
		binder.bind(buildAndBind,property);
		buildAndBind.setCaption(property);
		buildAndBind.setId(MessageFormat.format("{0}.{1}", buttonLabel, property));
		buildAndBind.setReadOnly(false);
		buildAndBind.setWidth(ContentSize.HALF_SIZE);

		panelContent.addComponent(buildAndBind);
	}

	final VerticalLayout verticalLayout = new VerticalLayout();
	verticalLayout.setWidth("50%");

	final Button button = new Button(buttonLabel,new CommitFormWrapperClickListener(binder,buttonListener));
	button.setId(buttonLabel);
	button.setWidth("25%");
	button.setIcon(VaadinIcons.BULLSEYE);
	button.setEnabled(false);
	binder.addStatusChangeListener(event -> button.setEnabled(event.getBinder().isValid()));
	
	
	verticalLayout.addComponent(button);
	verticalLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);

	panelContent.addComponent(verticalLayout);
}
 
Example #12
Source File: FormFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the field.
 *
 * @param property the property
 * @return the abstract field
 */
private static AbstractField<?> createField(final String property) {
	if (StringUtils.containsIgnoreCase(property,HIDDEN_FIELD_NAME)) {
		return new PasswordField();
	} else {
		return new TextField();
	}
}
 
Example #13
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void removeListeners() {
    for (final AbstractField<?> field : allComponents) {
        removeTextListener(field);
        removeValueChangeListener(field);
        removeItemSetChangeistener(field);
    }
}
 
Example #14
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasNullValidator(final Component component) {

        if (component instanceof AbstractField<?>) {
            final AbstractField<?> fieldComponent = (AbstractField<?>) component;
            for (final Validator validator : fieldComponent.getValidators()) {
                if (validator instanceof NullValidator) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example #15
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isMandatoryFieldNotEmptyAndValid(final Component currentChangedComponent, final Object newValue) {

        boolean valid = true;
        final List<AbstractField<?>> requiredComponents = allComponents.stream().filter(AbstractField::isRequired)
                .filter(AbstractField::isEnabled).collect(Collectors.toList());

        requiredComponents.addAll(allComponents.stream().filter(this::hasNullValidator).collect(Collectors.toList()));

        for (final AbstractField field : requiredComponents) {
            Object value = getCurrentValue(currentChangedComponent, newValue, field);

            if (Set.class.equals(field.getType())) {
                value = emptyToNull((Collection<?>) value);
            }

            if (value == null) {
                return false;
            }

            // We need to loop through all of components for validity testing.
            // Otherwise the UI will only mark the first field with errors and
            // then stop. Setting the value is necessary because not all
            // required input fields have empty string validator, but emptiness
            // is checked during isValid() call. Setting the value could be
            // redundant, check if it could be removed in the future.
            field.setValue(value);
            if (!field.isValid()) {
                valid = false;
            }
        }

        return valid;
    }
 
Example #16
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private boolean shouldMandatoryLabelShown() {
    for (final AbstractField<?> field : allComponents) {
        if (field.isRequired()) {
            return true;
        }
    }

    return false;
}
 
Example #17
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private static Object getCurrentValue(final Component currentChangedComponent, final Object newValue,
        final AbstractField<?> field) {
    Object currentValue = field.getValue();
    if (field instanceof Table) {
        currentValue = ((Table) field).getContainerDataSource().getItemIds();
    }

    if (field.equals(currentChangedComponent)) {
        currentValue = newValue;
    }
    return currentValue;
}
 
Example #18
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isValuesChanged(final Component currentChangedComponent, final Object newValue) {
    for (final AbstractField<?> field : allComponents) {
        Object originalValue = orginalValues.get(field);
        if (field instanceof CheckBox && originalValue == null) {
            originalValue = Boolean.FALSE;
        }
        final Object currentValue = getCurrentValue(currentChangedComponent, newValue, field);

        if (!Objects.equals(originalValue, currentValue)) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * saves the original values in a Map so we can use them for detecting
 * changes
 */
public final void setOrginaleValues() {
    for (final AbstractField<?> field : allComponents) {
        Object value = field.getValue();

        if (field instanceof Table) {
            value = ((Table) field).getContainerDataSource().getItemIds();
        }
        orginalValues.put(field, value);
    }
    saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
}
 
Example #20
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void removeValueChangeListener(final AbstractField<?> field) {
    for (final Object listener : field.getListeners(ValueChangeEvent.class)) {
        if (listener instanceof ChangeListener) {
            field.removeValueChangeListener((ChangeListener) listener);
        }
    }
}
 
Example #21
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void removeTextListener(final AbstractField<?> field) {
    if (!(field instanceof TextChangeNotifier)) {
        return;
    }
    for (final Object listener : field.getListeners(TextChangeEvent.class)) {
        if (listener instanceof ChangeListener) {
            ((TextChangeNotifier) field).removeTextChangeListener((ChangeListener) listener);
        }
    }
}
 
Example #22
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void removeItemSetChangeistener(final AbstractField<?> field) {
    if (!(field instanceof Table)) {
        return;
    }
    for (final Object listener : field.getListeners(ItemSetChangeEvent.class)) {
        if (listener instanceof ChangeListener) {
            ((Table) field).removeItemSetChangeListener((ChangeListener) listener);
        }
    }
}
 
Example #23
Source File: FieldAccessor.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Object getControlValue() {
	AbstractField<?> field = (AbstractField<?>) getControl();
	
	return field.getValue();
}
 
Example #24
Source File: CommonDialogWindow.java    From hawkbit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Adds the component manually to the allComponents-List and adds a
 * ValueChangeListener to it. Necessary in Update Distribution Type as the
 * CheckBox concerned is an ItemProperty...
 *
 * @param component
 *            AbstractField
 */
public void updateAllComponents(final AbstractField<?> component) {

    allComponents.add(component);
    component.addValueChangeListener(new ChangeListener(component));
}