List of usage examples for com.vaadin.v7.ui Field setReadOnly
public void setReadOnly(boolean newStatus);
From source file:de.symeda.sormas.ui.contact.ContactDataForm.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateFollowUpStatusComponents() { getContent().removeComponent(CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC); getContent().removeComponent(LOST_FOLLOW_UP_BTN_LOC); Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(ContactDto.FOLLOW_UP_STATUS); boolean followUpVisible = getValue() != null && statusField.isVisible(); if (followUpVisible && UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT)) { FollowUpStatus followUpStatus = statusField.getValue(); if (followUpStatus == FollowUpStatus.FOLLOW_UP) { Button cancelButton = new Button(I18nProperties.getCaption(Captions.contactCancelFollowUp)); cancelButton.setWidth(100, Unit.PERCENTAGE); cancelButton.addClickListener(new ClickListener() { @Override/*from w w w .j av a2s .c om*/ public void buttonClick(ClickEvent event) { Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField( ContactDto.FOLLOW_UP_STATUS); statusField.setReadOnly(false); statusField.setValue(FollowUpStatus.CANCELED); statusField.setReadOnly(true); updateFollowUpStatusComponents(); } }); getContent().addComponent(cancelButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC); Button lostButton = new Button(I18nProperties.getCaption(Captions.contactLostToFollowUp)); lostButton.setWidth(100, Unit.PERCENTAGE); lostButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField( ContactDto.FOLLOW_UP_STATUS); statusField.setReadOnly(false); statusField.setValue(FollowUpStatus.LOST); statusField.setReadOnly(true); updateFollowUpStatusComponents(); } }); getContent().addComponent(lostButton, LOST_FOLLOW_UP_BTN_LOC); } else if (followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST) { Button resumeButton = new Button(I18nProperties.getCaption(Captions.contactResumeFollowUp)); resumeButton.addStyleName(CssStyles.FORCE_CAPTION); resumeButton.setWidth(100, Unit.PERCENTAGE); resumeButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField( ContactDto.FOLLOW_UP_STATUS); statusField.setReadOnly(false); statusField.setValue(FollowUpStatus.FOLLOW_UP); statusField.setReadOnly(true); updateFollowUpStatusComponents(); } }); getContent().addComponent(resumeButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC); } } }
From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java
License:Open Source License
protected AbstractEditForm(Class<DTO> type, String propertyI18nPrefix, UserRight editOrCreateUserRight, boolean addFields) { this.type = type; this.propertyI18nPrefix = propertyI18nPrefix; fieldGroup = new BeanFieldGroup<DTO>(type) { @Override//from ww w . j a v a 2 s . co m protected void configureField(Field<?> field) { field.setBuffered(isBuffered()); if (!isEnabled()) { field.setEnabled(false); } if (field.getPropertyDataSource().isReadOnly()) { field.setReadOnly(true); } else if (isReadOnly()) { field.setReadOnly(true); } } }; fieldGroup.addCommitHandler(this); fieldGroup.setFieldFactory(new SormasFieldGroupFieldFactory(editOrCreateUserRight)); setWidth(900, Unit.PIXELS); setHeightUndefined(); if (addFields) { addFields(); } if (editOrCreateUserRight != null && !UserProvider.getCurrent().hasUserRight(editOrCreateUserRight)) { getFieldGroup().setReadOnly(true); } }
From source file:de.symeda.sormas.ui.utils.FieldHelper.java
License:Open Source License
@SuppressWarnings("rawtypes") public static void setReadOnlyWhen(final FieldGroup fieldGroup, List<Object> targetPropertyIds, Object sourcePropertyId, final List<Object> sourceValues, final boolean clearOnReadOnly) { Field sourceField = fieldGroup.getField(sourcePropertyId); if (sourceField instanceof AbstractField<?>) { ((AbstractField) sourceField).setImmediate(true); }/* w w w . j a va2 s .co m*/ // initialize { boolean readOnly = sourceValues.contains(sourceField.getValue()); for (Object targetPropertyId : targetPropertyIds) { Field targetField = fieldGroup.getField(targetPropertyId); if (readOnly && clearOnReadOnly && targetField.getValue() != null) { targetField.setReadOnly(false); targetField.clear(); } targetField.setReadOnly(readOnly); if (readOnly) { // workaround to make sure the caption also knows the field is read-only targetField.addStyleName("v-readonly"); } else { targetField.removeStyleName("v-readonly"); } } } sourceField.addValueChangeListener(event -> { boolean readOnly = sourceValues.contains(event.getProperty().getValue()); for (Object targetPropertyId : targetPropertyIds) { Field targetField = fieldGroup.getField(targetPropertyId); if (readOnly && clearOnReadOnly && targetField.getValue() != null) { targetField.setReadOnly(false); targetField.clear(); } targetField.setReadOnly(readOnly); if (readOnly) { // workaround to make sure the caption also knows the field is read-only targetField.addStyleName("v-readonly"); } else { targetField.removeStyleName("v-readonly"); } } }); }
From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java
License:Apache License
/** * Configures a field with the settings set for this FieldBinder. * <p>/*w ww . j a va2s . c o m*/ * By default this updates the buffered, read only and enabled state of the * field. Also adds validators when applicable. Fields with read only data * source are always configured as read only. * <p> * Unlike the default implementation in FieldGroup, MBeanFieldGroup only * makes field read only based on the property's hint, not the opposite. * This way developer can in form code choose to make some fields read only. * * @param field The field to update */ @Override protected void configureField(Field<?> field) { boolean readOnlyStatus = isReadOnly() || field.getPropertyDataSource().isReadOnly(); super.configureField(field); // reset the badly set readOnlyStatus field.setReadOnly(readOnlyStatus); }