clickEventHandler.handleEventHandlerRegistration();
- window.setClosable(!isReadOnly());
+ window.setClosable(state.closable);
// initialize position from state
updateWindowPosition();
/**
* An abstract base class for compatibility components.
* <p>
- * Used since immediate property has been removed in Vaadin 8 from
- * {@link AbstractComponent}.
+ * Used since immediate and read-only properties has been removed in Vaadin 8
+ * from {@link AbstractComponent}.
*
* @author Vaadin Ltd
* @since 8.0
getState().immediate = immediate;
}
+ /**
+ * Tests whether the component is in the read-only mode. The user can not
+ * change the value of a read-only component. As only {@code AbstractField}
+ * or {@code LegacyField} components normally have a value that can be input
+ * or changed by the user, this is mostly relevant only to field components,
+ * though not restricted to them.
+ *
+ * <p>
+ * Notice that the read-only mode only affects whether the user can change
+ * the <i>value</i> of the component; it is possible to, for example, scroll
+ * a read-only table.
+ * </p>
+ *
+ * <p>
+ * The method will return {@code true} if the component or any of its
+ * parents is in the read-only mode.
+ * </p>
+ *
+ * @return <code>true</code> if the component or any of its parents is in
+ * read-only mode, <code>false</code> if not.
+ * @see #setReadOnly(boolean)
+ */
+ @Override
+ public boolean isReadOnly() {
+ return getState(false).readOnly;
+ }
+
+ /**
+ * Sets the read-only mode of the component to the specified mode. The user
+ * can not change the value of a read-only component.
+ *
+ * <p>
+ * As only {@code AbstractField} or {@code LegacyField} components normally
+ * have a value that can be input or changed by the user, this is mostly
+ * relevant only to field components, though not restricted to them.
+ * </p>
+ *
+ * <p>
+ * Notice that the read-only mode only affects whether the user can change
+ * the <i>value</i> of the component; it is possible to, for example, scroll
+ * a read-only table.
+ * </p>
+ *
+ * <p>
+ * In Vaadin 8 the read-only property is part of {@link HasValue} API.
+ * </p>
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ getState().readOnly = readOnly;
+ }
+
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
* @return <code>true</code> if visible, <code>false</code> if not
*/
public boolean isRequiredIndicatorVisible();
+
+ /**
+ * Sets the read-only mode of this {@code HasValue} to given mode. The user
+ * can't change the value when in read-only mode.
+ * <p>
+ * A {@code HasValue} with a visual component in read-only mode typically
+ * looks visually different to signal to the user that the value cannot be
+ * edited.
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ public void setReadOnly(boolean readOnly);
+
+ /**
+ * Returns whether this {@code HasValue} is in read-only mode or not.
+ *
+ * @return {@code false} if the user can modify the value, {@code true} if
+ * not.
+ */
+ public boolean isReadOnly();
}
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
import com.vaadin.server.VaadinSession;
-import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.Upload.FailedEvent;
+ connector.getConnectorId()
+ " because the component was disabled");
}
- if ((connector instanceof Component)
- && ((Component) connector).isReadOnly()) {
- // Only checked for legacy reasons
- throw new UploadException(
- "File upload ignored because the component is read-only");
- }
} finally {
session.unlock();
}
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
+import com.vaadin.data.HasValue;
import com.vaadin.event.ActionManager;
import com.vaadin.event.ConnectorActionManager;
import com.vaadin.event.ContextClickEvent;
markAsDirty();
}
- /*
- * Tests if the component is in read-only mode. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public boolean isReadOnly() {
- return getState(false).readOnly;
- }
-
- /*
- * Sets the component's read-only mode. Don't add a JavaDoc comment here, we
- * use the default documentation from implemented interface.
- */
- @Override
- public void setReadOnly(boolean readOnly) {
- getState().readOnly = readOnly;
- }
-
/*
* Notify the component that it's attached to a window. Don't add a JavaDoc
* comment here, we use the default documentation from implemented
return false;
}
+ /**
+ * Sets the read-only status in the state of this {@code AbstractComponent}.
+ * This method should be made public in {@link Component Components} that
+ * implement {@link HasValue}.
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ protected void setReadOnly(boolean readOnly) {
+ if (readOnly != isReadOnly()) {
+ getState().readOnly = readOnly;
+ }
+ }
+
+ /**
+ * Returns the read-only status from the state of this
+ * {@code AbstractComponent}. This method should be made public in
+ * {@link Component Components} that implement {@link HasValue}.
+ *
+ * @return {@code true} if state has read-only on; {@code false} if not
+ * @see #setReadOnly(boolean)
+ */
+ protected boolean isReadOnly() {
+ return getState(false).readOnly;
+ }
+
/**
* Reads the size of this component from the given design attributes. If the
* attributes do not contain relevant size information, defaults is
setValue(value, false);
}
- /**
- * Returns whether the value of this field can be changed by the user or
- * not. By default fields are not read-only.
- *
- * @return {@code true} if this field is in read-only mode, {@code false}
- * otherwise.
- *
- * @see #setReadOnly(boolean)
- */
@Override
public boolean isReadOnly() {
return super.isReadOnly();
}
/**
- * Sets whether the value of this field can be changed by the user or not. A
- * field in read-only mode typically looks visually different to signal to
- * the user that the value cannot be edited.
+ * {@inheritDoc}
* <p>
* The server ignores (potentially forged) value change requests from the
* client to fields that are read-only. Programmatically changing the field
super.writeDesign(design, designContext);
AbstractField<T> def = designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
- DesignAttributeHandler.writeAttribute("readonly", attr,
- super.isReadOnly(), def.isReadOnly(), Boolean.class,
- designContext);
+ DesignAttributeHandler.writeAttribute("readonly", attr, isReadOnly(),
+ def.isReadOnly(), Boolean.class, designContext);
}
@Override
@Override
protected RequiredIndicatorState getState(boolean markAsDirty) {
return (RequiredIndicatorState) super.getState(markAsDirty);
- };
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
public boolean isRequiredIndicatorVisible() {
return super.isRequiredIndicatorVisible();
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
*
* @param listener
* the Listener to be removed.
- *
+ *
* @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
* registration object returned from
* {@link #addClickListener(ClickListener)}.
* No action is taken is the button is disabled.
*/
public void click() {
- if (isEnabled() && !isReadOnly()) {
+ if (isEnabled()) {
fireClick();
}
}
@Override
public HasComponents getParent();
- /**
- * Tests whether the component is in the read-only mode. The user can not
- * change the value of a read-only component. As only {@code AbstractField}
- * or {@code LegacyField} components normally have a value that can be input
- * or changed by the user, this is mostly relevant only to field components,
- * though not restricted to them.
- *
- * <p>
- * Notice that the read-only mode only affects whether the user can change
- * the <i>value</i> of the component; it is possible to, for example, scroll
- * a read-only table.
- * </p>
- *
- * <p>
- * The method will return {@code true} if the component or any of its
- * parents is in the read-only mode.
- * </p>
- *
- * @return <code>true</code> if the component or any of its parents is in
- * read-only mode, <code>false</code> if not.
- * @see #setReadOnly(boolean)
- */
- public boolean isReadOnly();
-
- /**
- * Sets the read-only mode of the component to the specified mode. The user
- * can not change the value of a read-only component.
- *
- * <p>
- * As only {@code AbstractField} or{@code LegacyField} components normally
- * have a value that can be input or changed by the user, this is mostly
- * relevant only to field components, though not restricted to them.
- * </p>
- *
- * <p>
- * Notice that the read-only mode only affects whether the user can change
- * the <i>value</i> of the component; it is possible to, for example, scroll
- * a read-only table.
- * </p>
- *
- * <p>
- * This method will trigger a {@link RepaintRequestEvent}.
- * </p>
- *
- * @param readOnly
- * a boolean value specifying whether the component is put
- * read-only mode or not
- */
- public void setReadOnly(boolean readOnly);
-
/**
* Gets the caption of the component.
*
* close event to the server. Setting closable to false will remove the X
* from the window and prevent the user from closing the window.
*
- * Note! For historical reasons readonly controls the closability of the
- * window and therefore readonly and closable affect each other. Setting
- * readonly to true will set closable to false and vice versa.
- * <p/>
- *
* @return true if the window can be closed by the user.
*/
public boolean isClosable() {
- return !isReadOnly();
+ return getState(false).closable;
}
/**
* close event to the server. Setting closable to false will remove the X
* from the window and prevent the user from closing the window.
*
- * Note! For historical reasons readonly controls the closability of the
- * window and therefore readonly and closable affect each other. Setting
- * readonly to true will set closable to false and vice versa.
- * <p/>
- *
* @param closable
* determines if the window can be closed by the user.
*/
public void setClosable(boolean closable) {
- setReadOnly(!closable);
+ if (closable != isClosable()) {
+ getState().closable = closable;
+ }
}
/**
* Indicates whether a window can be dragged or not. By default a window is
* draggable.
- * <p/>
*
- * @param draggable
- * true if the window can be dragged by the user
+ * @return {@code true} if window is draggable; {@code false} if not
*/
public boolean isDraggable() {
return getState(false).draggable;
private static Logger getLogger() {
return Logger.getLogger(ColorPickerPopup.class.getName());
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
public boolean isRequiredIndicatorVisible() {
return super.isRequiredIndicatorVisible();
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
* declarative test for a real component should extend it and implement abstract
* methods to be able to test the common properties. Components specific
* properties should be tested additionally in the subclasses implementations.
- *
+ *
* @author Vaadin Ltd
*
*/
/**
* Returns expected element tag for the tested component.
- *
+ *
* @return expected element tag
*/
protected abstract String getComponentTag();
/**
* Returns component class which is a subject to test
- *
+ *
* @return the component class
*/
protected abstract Class<? extends T> getComponentClass();
component.setIcon(new FileResource(new File(icon)));
component.setLocale(locale);
component.setPrimaryStyleName(primaryStyle);
- component.setReadOnly(readOnly);
+ try {
+ component.getClass()
+ .getMethod("setReadOnly", new Class[] { boolean.class })
+ .invoke(component, readOnly);
+ } catch (Exception e) {
+ // Ignore
+ }
component.setResponsive(responsive);
component.setStyleName(styleName);
component.setVisible(visible);
Assert.assertFalse("Disabled button fires click events", clicked);
}
- @Test
- public void testClickReadOnly() {
- Button b = getButton();
- b.setReadOnly(true);
- b.click();
- Assert.assertFalse("Read only button fires click events", clicked);
- }
-
private Button getButton() {
Button b = new Button();
UI ui = createUI();
@NoLayout
public boolean centered = false;
@NoLayout
+ public boolean closable = true;
+ @NoLayout
public int positionX = -1;
@NoLayout
public int positionY = -1;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Layout.SpacingHandler;
+import com.vaadin.v7.ui.AbstractLegacyComponent;
import com.vaadin.v7.ui.Field;
public abstract class AbstractComponentTestCase<T extends AbstractComponent>
protected Command<T, String> descriptionCommand = (c, value, data) -> c
.setDescription(value);
- protected Command<T, Boolean> readonlyCommand = (c, enabled, data) -> c
- .setReadOnly(enabled);
+ protected Command<T, Boolean> readonlyCommand = (c, enabled, data) -> {
+ if (c instanceof HasValue) {
+ ((HasValue) c).setReadOnly(enabled);
+ } else if (c instanceof AbstractLegacyComponent) {
+ ((AbstractLegacyComponent) c).setReadOnly(enabled);
+ }
+ };
protected Command<T, Boolean> visibleCommand = (c, enabled, data) -> c
.setVisible(enabled);
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.v7.ui.AbstractLegacyComponent;
import com.vaadin.v7.ui.AbstractSelect;
import com.vaadin.v7.ui.ListSelect;
import com.vaadin.v7.ui.NativeSelect;
cb.addValueChangeListener(event -> {
for (Component c : layout) {
if (c instanceof AbstractSelect) {
- c.setReadOnly(!c.isReadOnly());
+ AbstractLegacyComponent legacyComponent = (AbstractLegacyComponent) c;
+ legacyComponent.setReadOnly(!legacyComponent.isReadOnly());
}
}
});
addComponent(upload);
- addButton("Set readonly", new Button.ClickListener() {
- @Override
- public void buttonClick(Button.ClickEvent event) {
- upload.setReadOnly(true);
- }
- });
-
addButton("Set disabled", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
+import com.vaadin.v7.ui.AbstractLegacyComponent;
import com.vaadin.v7.ui.Field;
import com.vaadin.v7.ui.NativeSelect;
import com.vaadin.v7.ui.OptionGroup;
protected void setReadOnly(boolean value) {
for (Component c : components) {
- c.setReadOnly(value);
+ if (c instanceof HasValue) {
+ ((HasValue<String>) c).setReadOnly(value);
+ } else if (c instanceof AbstractLegacyComponent) {
+ ((AbstractLegacyComponent) c).setReadOnly(value);
+ }
}
}
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
-import com.vaadin.ui.themes.ValoTheme;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.themes.ValoTheme;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.TextArea;
* @author Vaadin Ltd
*/
public class Forms extends VerticalLayout implements View {
+
+ private boolean readOnly = true;
+
public Forms() {
setSpacing(true);
setMargin(true);
"<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
form.addComponent(bio);
- form.setReadOnly(true);
bio.setReadOnly(true);
Button edit = new Button("Edit", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- boolean readOnly = form.isReadOnly();
if (readOnly) {
bio.setReadOnly(false);
- form.setReadOnly(false);
form.removeStyleName(ValoTheme.FORMLAYOUT_LIGHT);
event.getButton().setCaption("Save");
event.getButton().addStyleName(ValoTheme.BUTTON_PRIMARY);
} else {
bio.setReadOnly(true);
- form.setReadOnly(true);
form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
event.getButton().setCaption("Edit");
event.getButton().removeStyleName(ValoTheme.BUTTON_PRIMARY);
}
+ readOnly = !readOnly;
}
});
return upload.findElement(By.className("v-button"));
}
- @Test
- public void buttonIsReadonly() {
- assertThat(getUploadButtonClass(), not(containsString("v-disabled")));
-
- clickButton("Set readonly");
-
- assertThat(getUploadButtonClass(), containsString("v-disabled"));
- }
-
@Test
public void buttonIsDisabled() {
assertThat(getUploadButtonClass(), not(containsString("v-disabled")));