com.vaadin.ui.Field Java Examples
The following examples show how to use
com.vaadin.ui.Field.
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: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Field createField(Item item, Object propertyId, Component uiContext) { BeanItem<?> beanItem = (BeanItem<?>) item; Field f = getField(propertyId, beanItem.getBean().getClass()); if (f != null) { f.setCaption(createCaptionByPropertyId(propertyId)); } else { // fail back to default f = super.createField(item, propertyId, uiContext); } applyFieldProcessors(f, propertyId); return f; }
Example #2
Source File: HttpServerConfigForm.java From sensorhub with Mozilla Public License 2.0 | 6 votes |
@Override protected Field<?> buildAndBindField(String label, String propId, Property<?> prop) { Field<?> field = super.buildAndBindField(label, propId, prop); if (propId.equals(PROP_SERVLET_ROOT)) { field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 2, 256, false)); } else if (propId.equals(PROP_HTTP_PORT)) { field.setWidth(100, Unit.PIXELS); //((TextField)field).getConverter(). field.addValidator(new Validator() { private static final long serialVersionUID = 1L; public void validate(Object value) throws InvalidValueException { int portNum = (Integer)value; if (portNum > 10000 || portNum <= 80) throw new InvalidValueException("Port number must be an integer number greater than 80 and lower than 10000"); } }); } return field; }
Example #3
Source File: DefaultFieldInitializer.java From vaadinator with Apache License 2.0 | 6 votes |
@Override public void initializeField(Component component, Component view) { if (view instanceof EagerValidatableView) { EagerValidatableView eagerValidatableView = (EagerValidatableView) view; if (component instanceof Field<?>) { ((AbstractComponent) component).setImmediate(true); ((Field<?>) component).addValueChangeListener(eagerValidatableView); if (component instanceof EagerValidateable) { ((EagerValidateable) component).setEagerValidation(true); } if (component instanceof TextChangeNotifier) { final TextChangeNotifier abstractTextField = (TextChangeNotifier) component; abstractTextField.addTextChangeListener(eagerValidatableView); } } } }
Example #4
Source File: SizeFieldProcessor.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void processField(Field field, Object propertyId) { String width = widths.get(propertyId); if (width == null) width = defaultWidth; if (width != null) field.setWidth(width); String height = heights.get(propertyId); if (height == null) height = defaultHeight; if (height != null) field.setHeight(height); }
Example #5
Source File: SimpleBoxFormBuilder.java From jdal with Apache License 2.0 | 5 votes |
public void add(Component c, String label, int width, Alignment alignment) { if (rows == 0 && rowsHeight.isEmpty()) { log.warn("You must call row() before adding components. I will add a row with default height for you"); row(); } if (label != null) c.setCaption(label); VerticalLayout column = getColumn(); column.addComponent(c); index++; setWidth(width); if (alignment != null) { column.setComponentAlignment(c, alignment); } if (rowCellSpand) { c.setWidth(100, Unit.PERCENTAGE); } if (useTabIndex && c instanceof Field) { ((Field<?>) c).setTabIndex(tabIndex++); } }
Example #6
Source File: AnnotationFieldFactory.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Field createField(Item item, Object propertyId, Component uiContext) { if (item instanceof BeanItem<?>) { BeanItem<?> bi = (BeanItem<?>) item; String name = (String) propertyId; Class<?> clazz = bi.getBean().getClass(); java.lang.reflect.Field field = ReflectionUtils.findField(clazz, name); Annotation[] fa = new Annotation[] {}; if (field != null) { fa = field.getAnnotations(); } java.lang.reflect.Method method = BeanUtils.getPropertyDescriptor(clazz, name).getReadMethod(); Annotation[] ma = method.getAnnotations(); Annotation[] annotations = (Annotation[]) ArrayUtils.addAll(fa, ma); Field f = null; for (Annotation a : annotations) { f = findField(a, clazz, name); if (f != null) { f.setCaption(createCaptionByPropertyId(propertyId)); applyFieldProcessors(f, propertyId); return f; } } } // fall back to default return super.createField(item, propertyId, uiContext); }
Example #7
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 5 votes |
/** * @param f */ protected void applyFieldProcessors(Field f, Object propertyId) { if (f != null) { for (FieldProcessor fp : fieldProcessors) fp.processField(f, propertyId); } }
Example #8
Source File: ComboBoxFieldBuilder.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Field<?> build(Class<?> clazz, String name) { ComboBox combo = new ComboBox(); fillComboBox(combo, clazz, name); combo.setItemCaptionMode(ItemCaptionMode.ID); return combo; }
Example #9
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Field createField(Item item, Object propertyId, Component uiContext) { Class<Field> clazz = fieldMap.get(propertyId); if (clazz != null) { try { return BeanUtils.instantiate(clazz); } catch(BeanInstantiationException bie) { log.error(bie); } } return null; }
Example #10
Source File: ContractApplicationChangeViewImplEx.java From vaadinator with Apache License 2.0 | 5 votes |
@Override public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) { super.onValidationError(validationErrors); StringBuilder sb = new StringBuilder(); for(Field<?> field: validationErrors.keySet()) { if(sb.length()!= 0) { sb.append(", "); } sb.append(field.getCaption()); } Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE); }
Example #11
Source File: SOSConfigForm.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
protected Field<?> buildAndBindField(String label, String propId, Property<?> prop) { Field<Object> field = (Field<Object>)super.buildAndBindField(label, propId, prop); if (propId.endsWith(PROP_ENDPOINT)) { field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false)); } else if (propId.endsWith(PROP_ENABLED)) { field.setVisible(true); } else if (propId.endsWith(PROP_URI)) { field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false)); } else if (propId.endsWith(PROP_STORAGEID)) { field = makeModuleSelectField(field, IStorageModule.class); } else if (propId.endsWith(PROP_SENSORID)) { field = makeModuleSelectField(field, ISensorModule.class); field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false)); } else if (propId.endsWith(PROP_DATAPROVIDERS + PROP_SEP + PROP_NAME)) field.setVisible(true); return field; }
Example #12
Source File: GenericConfigForm.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
/** * Method called to generate and bind the Field component corresponding to a * scalar property * @param label * @param propId * @param prop * @return the generated Field object */ protected Field<?> buildAndBindField(String label, String propId, Property<?> prop) { Field<?> field = fieldGroup.buildAndBind(label, propId); Class<?> propType = prop.getType(); if (propId.equals(PROP_ID)) field.setReadOnly(true); else if (propId.endsWith("." + PROP_ID)) field.setVisible(false); else if (propId.endsWith("." + PROP_NAME)) field.setVisible(false); else if (propId.endsWith(PROP_ENABLED)) field.setVisible(false); else if (propId.endsWith(PROP_MODULECLASS)) field.setReadOnly(true); if (propType.equals(String.class)) field.setWidth(500, Unit.PIXELS); else if (propType.equals(int.class) || propType.equals(Integer.class) || propType.equals(float.class) || propType.equals(Float.class) || propType.equals(double.class) || propType.equals(Double.class)) field.setWidth(200, Unit.PIXELS); else if (Enum.class.isAssignableFrom(propType)) ((ListSelect)field).setRows(3); if (field instanceof TextField) { ((TextField)field).setNullSettingAllowed(true); ((TextField)field).setNullRepresentation(""); } return field; }
Example #13
Source File: GenericStorageConfigForm.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
protected Field<?> buildAndBindField(String label, String propId, Property<?> prop) { Field<Object> field = (Field<Object>)super.buildAndBindField(label, propId, prop); if (propId.equals(PROP_STORAGE_PATH)) field.setVisible(false); else if (propId.equals(PROP_DATASRC_ID)) { field = makeModuleSelectField(field, IDataProducerModule.class); field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false)); } return field; }
Example #14
Source File: ContractApplicationEditViewImplEx.java From vaadinator with Apache License 2.0 | 5 votes |
@Override public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) { super.onValidationError(validationErrors); StringBuilder sb = new StringBuilder(); for(Field<?> field: validationErrors.keySet()) { if(sb.length()!= 0) { sb.append(", "); } sb.append(field.getCaption()); } Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE); }
Example #15
Source File: CommConfigForm.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
@Override protected Field<?> buildAndBindField(String label, String propId, Property<?> prop) { Field<?> field = super.buildAndBindField(label, propId, prop); if (propId.endsWith(UIConstants.PROP_ID)) field.setVisible(false); else if (propId.endsWith(UIConstants.PROP_NAME)) field.setVisible(false); else if (propId.endsWith(UIConstants.PROP_ENABLED)) field.setVisible(false); return field; }
Example #16
Source File: CommonDialogWindow.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
public ChangeListener(final Field<?> field) { this.field = field; }
Example #17
Source File: FieldWrapper.java From sensorhub with Mozilla Public License 2.0 | 4 votes |
public FieldWrapper(Field<T> innerField) { this.innerField = innerField; this.setCaption(innerField.getCaption()); innerField.setCaption(null); }
Example #18
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) { return createField(container.getItem(itemId), propertyId, uiContext); }
Example #19
Source File: EnumerationEditorComponent.java From XACML with MIT License | 4 votes |
private void initializeTable() { // // Add the current enumeration values into the // bean container. // for (ConstraintValue value : this.attribute.getConstraintValues()) { if (value.getProperty().equals("Enumeration")) { this.beanContainer.addBean(value); } } // // Now hook the bean container to the table // this.tableEnumerations.setContainerDataSource(beanContainer); // // We have to manually create the text field because we need // to set a validator. // this.tableEnumerations.setTableFieldFactory(new TableFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) { if (propertyId.toString().equals("value")) { final TextField text = new TextField(); text.setImmediate(true); text.setNullRepresentation(""); text.setNullSettingAllowed(false); text.setRequired(true); text.setRequiredError("Cannot have empty enumeration values."); text.addValidator(self); return text; } return null; } }); // // Finish setting up the table. // this.tableEnumerations.setVisibleColumns(new Object[] {"value"}); this.tableEnumerations.setColumnHeaders(new String[] {"Enumeration Value"}); this.tableEnumerations.setSelectable(true); this.tableEnumerations.setEditable(true); this.tableEnumerations.setImmediate(true); if (this.tableEnumerations.size() == 0) { this.tableEnumerations.setPageLength(3); } else { this.tableEnumerations.setPageLength(this.tableEnumerations.size() + 1); } // // As the user select items, enable/disable buttons // this.tableEnumerations.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { self.buttonRemove.setEnabled(self.tableEnumerations.getValue() != null); } }); }
Example #20
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * Try to find a field. It will tray the four configured maps in order: * <ol> * <li> propertyId to FieldBuilder map.</li> * <li> propertyId to Field map.</li> * <li> propertyClass to FieldBuilder map.</li> * <li> propertyClass to Field map.</li> * </ol> * @param propertyId the propertyId * @param clazz the bean class holding the propertyId * @return Field or null if none configured */ @SuppressWarnings("unchecked") protected Field getField(Object propertyId, Class<?> clazz) { // try id to builder map FieldBuilder builder = idBuilderMap.get(propertyId); if (builder != null) { if (log.isDebugEnabled()) log.debug("Found FieldBuilder in idBuilderMap: [" + builder.getClass().getSimpleName() +"]"); return builder.build(clazz, (String) propertyId); } // try id to class Map Class<?extends Field> fieldClass = idClassMap.get(propertyId); if (fieldClass != null) { if (log.isDebugEnabled()) log.debug("Found FieldBuilder in idClassMap: [" + fieldClass.getSimpleName() +"]"); return BeanUtils.instantiate(fieldClass); } // try class to builder map Class<?> propertyClass = BeanUtils.getPropertyDescriptor(clazz, (String) propertyId).getPropertyType(); builder = (FieldBuilder) findByClass(propertyClass, classBuilderMap); if (builder != null) { if (log.isDebugEnabled()) log.debug("Found FieldBuilder in classBuilderMap: [" + builder.getClass().getSimpleName() +"]"); return builder.build(clazz, (String) propertyId); } // try class to field map fieldClass = (Class<? extends Field>) findByClass(propertyClass, classFieldMap); if (fieldClass != null) { if (log.isDebugEnabled()) log.debug("Found FieldBuilder in classFieldMap: [" + fieldClass.getSimpleName() +"]"); return BeanUtils.instantiate(fieldClass); } log.debug("Not found field for propertyId: " + propertyId); return null; }
Example #21
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * @return the fieldMap */ public Map<Class<?>, Class<? extends Field>> getClassFieldMap() { return classFieldMap; }
Example #22
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * @param fieldMap the fieldMap to set */ public void setClassFieldMap(Map<Class<?>, Class<? extends Field>> fieldMap) { this.classFieldMap.clear(); this.classFieldMap.putAll(fieldMap); }
Example #23
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * @return the idClassMap */ public Map<Object, Class<? extends Field>> getIdClassMap() { return idClassMap; }
Example #24
Source File: ConfigurableFieldFactory.java From jdal with Apache License 2.0 | 4 votes |
/** * @param idClassMap the idClassMap to set */ public void setIdClassMap(Map<Object, Class<? extends Field>> idClassMap) { this.idClassMap = idClassMap; }
Example #25
Source File: GenericConfigForm.java From sensorhub with Mozilla Public License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") protected Field<Object> makeModuleSelectField(Field<Object> field, final Class<? extends IModule> moduleType) { field = new FieldWrapper<Object>(field) { private static final long serialVersionUID = -992750405944982226L; protected Component initContent() { HorizontalLayout layout = new HorizontalLayout(); layout.setSpacing(true); // inner field innerField.setReadOnly(true); layout.addComponent(innerField); layout.setComponentAlignment(innerField, Alignment.MIDDLE_LEFT); final Field<Object> wrapper = this; // select module button Button selectBtn = new Button(LINK_ICON); selectBtn.addStyleName(STYLE_QUIET); layout.addComponent(selectBtn); layout.setComponentAlignment(selectBtn, Alignment.MIDDLE_LEFT); selectBtn.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { // show popup to select among available module types ModuleInstanceSelectionPopup popup = new ModuleInstanceSelectionPopup(moduleType, new ModuleInstanceSelectionCallback() { public void moduleSelected(IModule module) { innerField.setReadOnly(false); wrapper.setValue(module.getLocalID()); innerField.setReadOnly(true); } }); popup.setModal(true); AdminUI.getInstance().addWindow(popup); } }); return layout; } }; return field; }
Example #26
Source File: FieldBuilder.java From jdal with Apache License 2.0 | 2 votes |
/** * Build a Field * @param name * @param clazz * @return the field */ Field build(Class<?> clazz, String name);
Example #27
Source File: FieldProcessor.java From jdal with Apache License 2.0 | 2 votes |
/** * Process a Field * @param field Field to process * @see ConfigurableFieldFactory * @since 1.1 */ void processField(Field field, Object propertyId);
Example #28
Source File: AnnotationFieldFactory.java From jdal with Apache License 2.0 | 2 votes |
/** * Find a field instance for Annotation * @param a Annotation * @param name * @param clazz * @return Field instance */ protected Field findField(Annotation a, Class<?> clazz, String name) { FieldBuilder builder = annotationMap.get(a.annotationType()); return builder != null ? builder.build(clazz, name) : null; }
Example #29
Source File: ContractApplicationAddViewImplEx.java From vaadinator with Apache License 2.0 | 2 votes |
@Override public void onFieldValidationError(Field<?> field, InvalidValueException excpetion) { }