List of usage examples for com.vaadin.ui AbstractField setReadOnly
@Override public void setReadOnly(boolean readOnly)
The server ignores (potentially forged) value change requests from the client to fields that are read-only.
From source file:fi.semantum.strategia.widget.Indicator.java
License:Open Source License
public static String updateIndicatorValue(final Main main, HorizontalLayout hl, final Base base, final Indicator indicator, boolean canWrite) { final Database database = main.getDatabase(); Datatype dt = indicator.getDatatype(database); if (dt != null) { final AbstractField<?> field = dt.getEditor(main, base, indicator, false, null); field.setWidth("150px"); field.setReadOnly(!canWrite); hl.addComponent(field);// w ww . j av a2 s. c o m hl.setComponentAlignment(field, Alignment.MIDDLE_LEFT); Object value = field.getValue(); return value != null ? value.toString() : ""; } else { Object value = indicator.getValue(); final String formatted = value != null ? value.toString() : ""; final TextField tf = new TextField(); tf.setValue(formatted); tf.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 3547126051252580446L; @Override public void valueChange(ValueChangeEvent event) { try { double value = Double.parseDouble(tf.getValue()); indicator.updateWithComment(main, base, value, main.getUIState().forecastMeters, new AbstractCommentCallback() { public void canceled() { tf.setValue(formatted); } }); } catch (NumberFormatException e) { tf.setComponentError(new UserError("Arvon tulee olla numero")); } } }); tf.setWidth("150px"); tf.setReadOnly(!canWrite); hl.addComponent(tf); hl.setComponentAlignment(tf, Alignment.MIDDLE_LEFT); return tf.getValue(); } }
From source file:fr.amapj.view.engine.collectioneditor.CollectionEditor.java
License:Open Source License
/** * Permet l'ajout d'une ligne dans le tableau * //from ww w .j ava 2s . co m * Si bean est null, alors la ligne est charg avec les valeurs par dfaut * * @param bean */ private void addRow(BEANTYPE bean) { // Create the table row. final Row row = new Row(); BeanItem beanItem = null; if (bean != null) { beanItem = new BeanItem(bean); } // Ajout de toutes les colonnes for (ColumnInfo col : columns) { Object val1 = col.defaultValue; // Rcupration des donnes if (beanItem != null) { val1 = beanItem.getItemProperty(col.propertyId).getValue(); } AbstractField f = getField(col.fieldType, col); f.setConvertedValue(val1); f.setReadOnly(!col.editable); // GESTION DU FOCUS : on slectionne la ligne dont un lement a le focus if (shouldHaveFocusNotifier(f, col.editable)) { FocusNotifier tf = (FocusNotifier) f; tf.addFocusListener(e -> table.select(row.getItemId())); } row.addField(f); } // Ajout de la ligne et calcul de l'item id et memorisation de l'id eventuel Object idInfo = getIdBeanInfo(beanItem); rows.add(row, idInfo); // table.addItem(row.getColumnTable(), row.getItemId()); }
From source file:fr.amapj.view.engine.collectioneditor.Row.java
License:Open Source License
public void setFieldValue(int columns, Object val) { AbstractField f = fields.get(columns); if (f.isReadOnly()) { f.setReadOnly(false); f.setConvertedValue(val); f.setReadOnly(true);//from w ww .j a va2 s. c o m } else { f.setConvertedValue(val); } }
From source file:fr.amapj.view.engine.tools.InLineFormHelper.java
License:Open Source License
/** * Permet de positionner une form en mode Edition, avec un bouton cancel et * save/*from w ww .j av a 2 s . co m*/ * * @param footer * @param canceListener * @param saveListener * @param form */ private void formInCancelSaveMode(FormLayout form) { // form.removeStyleName("light"); // Iterator<Component> i = form.iterator(); while (i.hasNext()) { Component c = i.next(); if (c instanceof com.vaadin.ui.AbstractField) { AbstractField field = (AbstractField) c; field.setReadOnly(false); } } // footer.removeAllComponents(); footer.setMargin(false); footer.setSpacing(true); Label l = new Label(); footer.addComponent(l); footer.setExpandRatio(l, 1.0f); Button cancel = new Button("Annuler"); cancel.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { refreshListener.onPopupClose(); formInLectureMode(form); } }); footer.addComponent(cancel); Button save = new Button("Sauvegarder"); save.addStyleName("primary"); save.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { List<String> msg = validatorManager.validate(); if (msg.size() > 0) { msg.add(0, "Merci de corriger les points suivants :"); MessagePopup.open(new MessagePopup("Notification", msg)); return; } saveListener.buttonClick(null); refreshListener.onPopupClose(); formInLectureMode(form); } }); footer.addComponent(save); footer.setComponentAlignment(save, Alignment.MIDDLE_LEFT); }
From source file:fr.amapj.view.engine.tools.InLineFormHelper.java
License:Open Source License
/** * Permet de positionner une form en mode Lecture, avec un bouton Editer * /*ww w. j av a2 s. c o m*/ * @param footer * @param canceListener * @param saveListener * @param form */ private void formInLectureMode(FormLayout form) { // form.addStyleName("light"); // Iterator<Component> i = form.iterator(); while (i.hasNext()) { Component c = i.next(); if (c instanceof com.vaadin.ui.AbstractField) { AbstractField field = (AbstractField) c; field.setReadOnly(true); } } // footer.removeAllComponents(); footer.setMargin(new MarginInfo(true, false, true, false)); footer.setSpacing(true); Label l = new Label(); footer.addComponent(l); footer.setExpandRatio(l, 1.0f); Button edit = new Button(libModifier, new ClickListener() { @Override public void buttonClick(ClickEvent event) { formInCancelSaveMode(form); } }); footer.addComponent(edit); }
From source file:nz.co.senanque.vaadinsupport.HintsImpl.java
License:Apache License
public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property, final MessageSource messageSource) { ret.setWidth(getWidth());// ww w.j av a2s .co m ret.setReadThrough(true); ret.setPropertyDataSource(property); ret.setCaption(property.getLabel()); ret.setRequired(property.isRequired()); if (property.isRequired()) { ret.setInvalidCommitted(true); } if (property.isReadOnly()) { ret.setReadOnly(true); } ret.setEnabled(property.isEnabled()); ret.setVisible(property.isVisible()); ret.setImmediate(m_forceImmediate); ret.setLocale(LocaleContextHolder.getLocale()); MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource); ret.setDescription( messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription())); if (property.isNumeric()) { ret.addStyleName("v-textfield-align-right"); } ret.setErrorHandler(new ComponentErrorHandler() { private static final long serialVersionUID = -1393935533100204195L; public boolean handleComponentError(ComponentErrorEvent event) { Throwable t = event.getThrowable(); while (t != null) { if (t instanceof ValidationException) { ret.setComponentError(new UserError(((ValidationException) t).getMessage())); return true; } t = t.getCause(); } return false; } }); }
From source file:nz.co.senanque.vaadinsupport.TouchkitHintsImpl.java
License:Apache License
public void setCommonProperties(final AbstractField ret, final MaduraPropertyWrapper property, final MessageSource messageSource) { ret.setWidth(getWidth());/*ww w . j ava 2 s.c o m*/ ret.setReadThrough(true); ret.setPropertyDataSource(property); ret.setCaption(property.getLabel()); ret.setRequired(property.isRequired()); if (property.isRequired()) { ret.setInvalidCommitted(true); } ret.setReadOnly(property.isReadOnly()); ret.setEnabled(property.isEnabled()); ret.setVisible(property.isVisible()); ret.setImmediate(m_forceImmediate); ret.setLocale(LocaleContextHolder.getLocale()); MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource); ret.setDescription( messageSourceAccessor.getMessage(property.getDescription(), null, property.getDescription())); if (property.isNumeric()) { ret.addStyleName("v-textfield-align-right"); } ret.setErrorHandler(new ComponentErrorHandler() { private static final long serialVersionUID = -1393935533100204195L; public boolean handleComponentError(ComponentErrorEvent event) { Throwable t = event.getThrowable(); while (t != null) { if (t instanceof ValidationException) { ret.setComponentError(new UserError(((ValidationException) t).getMessage())); return true; } t = t.getCause(); } return false; } }); }
From source file:org.lunifera.runtime.web.vaadin.databinding.model.internal.PropertyReadonlyProperty.java
License:Open Source License
protected void doSetValue(Object source, Object value) { AbstractField<?> component = (AbstractField<?>) source; component.setReadOnly((Boolean) value); }
From source file:org.opencms.ui.CmsVaadinUtils.java
License:Open Source License
/** * Sets the value of a text field which may be set to read-only mode.<p> * * When setting a Vaadin field to read-only, you also can't set its value programmatically anymore. * So we need to temporarily disable read-only mode, set the value, and then switch back to read-only mode. * * @param field the field//from w w w .j a v a2 s . c o m * @param value the value to set */ public static <T> void setReadonlyValue(AbstractField<T> field, T value) { boolean readonly = field.isReadOnly(); try { field.setReadOnly(false); field.setValue(value); } finally { field.setReadOnly(readonly); } }
From source file:ru.codeinside.adm.ui.CrudNews.java
License:Mozilla Public License
private AbstractField createField(String caption, Boolean readOnly) { AbstractField textField; if (caption.equals("")) { textField = new RichTextArea(caption); } else {//from w w w .j av a 2 s .c o m textField = new TextField(caption); ((TextField) textField).setMaxLength(255); } textField.setImmediate(true); textField.setWidth("40%"); textField.setReadOnly(readOnly); return textField; }