summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2012-11-27 11:39:32 +0200
committerVaadin Code Review <review@vaadin.com>2012-11-28 08:38:54 +0000
commitc78e03fa5907845f745203da925f0264b1b3befc (patch)
treefab320adf75b046cc17b4f6faef881314546e0c8 /client
parentfd815c6981fe609a05262388041d1e5793c84692 (diff)
downloadvaadin-framework-c78e03fa5907845f745203da925f0264b1b3befc.tar.gz
vaadin-framework-c78e03fa5907845f745203da925f0264b1b3befc.zip
Properly support setWidgetEnabled for OptionGroupBased Selects #8985, #8986, #8987 and #8989.
Also fixes #7617 for OptionGroup, #9010 for TwinColSelect. Change-Id: Ia4c2a5e6ee93847970092fcb1cd685a0173897d7
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VListSelect.java8
-rw-r--r--client/src/com/vaadin/client/ui/VNativeSelect.java7
-rw-r--r--client/src/com/vaadin/client/ui/VOptionGroup.java34
-rw-r--r--client/src/com/vaadin/client/ui/VOptionGroupBase.java31
-rw-r--r--client/src/com/vaadin/client/ui/VTwinColSelect.java22
-rw-r--r--client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java11
6 files changed, 85 insertions, 28 deletions
diff --git a/client/src/com/vaadin/client/ui/VListSelect.java b/client/src/com/vaadin/client/ui/VListSelect.java
index e88e188f64..2215906af6 100644
--- a/client/src/com/vaadin/client/ui/VListSelect.java
+++ b/client/src/com/vaadin/client/ui/VListSelect.java
@@ -40,6 +40,8 @@ public class VListSelect extends VOptionGroupBase {
select.addClickHandler(this);
select.setVisibleItemCount(VISIBLE_COUNT);
setStyleName(CLASSNAME);
+
+ updateEnabledState();
}
@Override
@@ -66,7 +68,6 @@ public class VListSelect extends VOptionGroupBase {
@Override
public void buildOptions(UIDL uidl) {
select.setMultipleSelect(isMultiselect());
- select.setEnabled(!isDisabled() && !isReadonly());
select.clear();
if (!isMultiselect() && isNullSelectionAllowed()
&& !isNullSelectionItemAvailable()) {
@@ -134,6 +135,11 @@ public class VListSelect extends VOptionGroupBase {
}
@Override
+ protected void updateEnabledState() {
+ select.setEnabled(isEnabled() && !isReadonly());
+ }
+
+ @Override
public void focus() {
select.setFocus(true);
}
diff --git a/client/src/com/vaadin/client/ui/VNativeSelect.java b/client/src/com/vaadin/client/ui/VNativeSelect.java
index 5a64c39f01..76fd66815a 100644
--- a/client/src/com/vaadin/client/ui/VNativeSelect.java
+++ b/client/src/com/vaadin/client/ui/VNativeSelect.java
@@ -38,6 +38,7 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
select.addChangeHandler(this);
select.setStyleName(CLASSNAME + "-select");
+ updateEnabledState();
}
protected ListBox getOptionsContainer() {
@@ -46,7 +47,6 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
@Override
public void buildOptions(UIDL uidl) {
- select.setEnabled(!isDisabled() && !isReadonly());
select.clear();
firstValueIsTemporaryNullItem = false;
@@ -119,6 +119,11 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
}
@Override
+ protected void updateEnabledState() {
+ select.setEnabled(isEnabled() && !isReadonly());
+ }
+
+ @Override
public void focus() {
select.setFocus(true);
}
diff --git a/client/src/com/vaadin/client/ui/VOptionGroup.java b/client/src/com/vaadin/client/ui/VOptionGroup.java
index b928956214..1466c72ab1 100644
--- a/client/src/com/vaadin/client/ui/VOptionGroup.java
+++ b/client/src/com/vaadin/client/ui/VOptionGroup.java
@@ -16,6 +16,7 @@
package com.vaadin.client.ui;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -34,6 +35,7 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
+import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
@@ -53,6 +55,8 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
private final Map<CheckBox, String> optionsToKeys;
+ private final List<Boolean> optionsEnabled;
+
/** For internal use only. May be removed or replaced in the future. */
public boolean sendFocusEvents = false;
/** For internal use only. May be removed or replaced in the future. */
@@ -85,6 +89,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
super(CLASSNAME);
panel = (Panel) optionsContainer;
optionsToKeys = new HashMap<CheckBox, String>();
+ optionsEnabled = new ArrayList<Boolean>();
}
/*
@@ -93,6 +98,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
@Override
public void buildOptions(UIDL uidl) {
panel.clear();
+ optionsEnabled.clear();
for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
final UIDL opUidl = (UIDL) it.next();
CheckBox op;
@@ -124,12 +130,14 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
op.addStyleName(CLASSNAME_OPTION);
op.setValue(opUidl.getBooleanAttribute("selected"));
- boolean enabled = !opUidl
- .getBooleanAttribute(OptionGroupConstants.ATTRIBUTE_OPTION_DISABLED)
- && !isReadonly() && !isDisabled();
+ boolean optionEnabled = !opUidl
+ .getBooleanAttribute(OptionGroupConstants.ATTRIBUTE_OPTION_DISABLED);
+ boolean enabled = optionEnabled && !isReadonly() && isEnabled();
op.setEnabled(enabled);
+ optionsEnabled.add(optionEnabled);
setStyleName(op.getElement(),
- ApplicationConnection.DISABLED_CLASSNAME, !enabled);
+ ApplicationConnection.DISABLED_CLASSNAME,
+ !(optionEnabled && isEnabled()));
op.addClickHandler(this);
optionsToKeys.put(op, opUidl.getStringAttribute("key"));
panel.add(op);
@@ -169,6 +177,24 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
}
@Override
+ protected void updateEnabledState() {
+ int i = 0;
+ boolean optionGroupEnabled = isEnabled() && !isReadonly();
+ // sets options enabled according to the widget's enabled,
+ // readonly and each options own enabled
+ for (Widget w : panel) {
+ if (w instanceof HasEnabled) {
+ ((HasEnabled) w).setEnabled(optionsEnabled.get(i)
+ && optionGroupEnabled);
+ setStyleName(w.getElement(),
+ ApplicationConnection.DISABLED_CLASSNAME,
+ !(optionsEnabled.get(i) && isEnabled()));
+ }
+ i++;
+ }
+ }
+
+ @Override
public void focus() {
Iterator<Widget> iterator = panel.iterator();
if (iterator.hasNext()) {
diff --git a/client/src/com/vaadin/client/ui/VOptionGroupBase.java b/client/src/com/vaadin/client/ui/VOptionGroupBase.java
index d372f4caf8..c1bb84e886 100644
--- a/client/src/com/vaadin/client/ui/VOptionGroupBase.java
+++ b/client/src/com/vaadin/client/ui/VOptionGroupBase.java
@@ -27,6 +27,7 @@ import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
@@ -34,7 +35,7 @@ import com.vaadin.client.Focusable;
import com.vaadin.client.UIDL;
public abstract class VOptionGroupBase extends Composite implements Field,
- ClickHandler, ChangeHandler, KeyPressHandler, Focusable {
+ ClickHandler, ChangeHandler, KeyPressHandler, Focusable, HasEnabled {
public static final String CLASSNAME_OPTION = "v-select-option";
@@ -53,11 +54,9 @@ public abstract class VOptionGroupBase extends Composite implements Field,
/** For internal use only. May be removed or replaced in the future. */
public boolean multiselect;
- /** For internal use only. May be removed or replaced in the future. */
- public boolean disabled;
+ private boolean enabled;
- /** For internal use only. May be removed or replaced in the future. */
- public boolean readonly;
+ private boolean readonly;
/** For internal use only. May be removed or replaced in the future. */
public int cols = 0;
@@ -119,11 +118,11 @@ public abstract class VOptionGroupBase extends Composite implements Field,
return multiselect;
}
- protected boolean isDisabled() {
- return disabled;
+ public boolean isEnabled() {
+ return enabled;
}
- protected boolean isReadonly() {
+ public boolean isReadonly() {
return readonly;
}
@@ -184,11 +183,27 @@ public abstract class VOptionGroupBase extends Composite implements Field,
}
}
+ public void setReadonly(boolean readonly) {
+ if (this.readonly != readonly) {
+ this.readonly = readonly;
+ updateEnabledState();
+ }
+ }
+
+ public void setEnabled(boolean enabled) {
+ if (this.enabled != enabled) {
+ this.enabled = enabled;
+ updateEnabledState();
+ }
+ }
+
/** For internal use only. May be removed or replaced in the future. */
public abstract void buildOptions(UIDL uidl);
protected abstract String[] getSelectedItems();
+ protected abstract void updateEnabledState();
+
protected String getSelectedItem() {
final String[] sel = getSelectedItems();
if (sel.length > 0) {
diff --git a/client/src/com/vaadin/client/ui/VTwinColSelect.java b/client/src/com/vaadin/client/ui/VTwinColSelect.java
index 22aa74526c..e98fbaf75d 100644
--- a/client/src/com/vaadin/client/ui/VTwinColSelect.java
+++ b/client/src/com/vaadin/client/ui/VTwinColSelect.java
@@ -38,6 +38,7 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
+import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.shared.ui.twincolselect.TwinColSelectConstants;
@@ -139,6 +140,8 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
selections.addMouseDownHandler(this);
selections.addKeyDownHandler(this);
+
+ updateEnabledState();
}
public HTML getOptionsCaption() {
@@ -220,13 +223,8 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
@Override
public void buildOptions(UIDL uidl) {
- final boolean enabled = !isDisabled() && !isReadonly();
options.setMultipleSelect(isMultiselect());
selections.setMultipleSelect(isMultiselect());
- options.setEnabled(enabled);
- selections.setEnabled(enabled);
- add.setEnabled(enabled && !readonly);
- remove.setEnabled(enabled && !readonly);
options.clear();
selections.clear();
for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
@@ -245,9 +243,6 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
selections.setVisibleItemCount(getRows());
}
-
- add.setStyleName("v-disabled", readonly);
- remove.setStyleName("v-disabled", readonly);
}
@Override
@@ -429,6 +424,17 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
}
@Override
+ public void updateEnabledState() {
+ boolean enabled = isEnabled() && !isReadonly();
+ options.setEnabled(enabled);
+ selections.setEnabled(enabled);
+ add.setEnabled(enabled);
+ remove.setEnabled(enabled);
+ add.setStyleName(ApplicationConnection.DISABLED_CLASSNAME, !enabled);
+ remove.setStyleName(ApplicationConnection.DISABLED_CLASSNAME, !enabled);
+ }
+
+ @Override
public void focus() {
options.setFocus(true);
}
diff --git a/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java b/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java
index 36b69922fc..814b179e4a 100644
--- a/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java
+++ b/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java
@@ -40,8 +40,7 @@ public abstract class OptionGroupBaseConnector extends AbstractFieldConnector
getWidget().selectedKeys = uidl.getStringArrayVariableAsSet("selected");
- getWidget().readonly = isReadOnly();
- getWidget().disabled = !isEnabled();
+ getWidget().setReadonly(isReadOnly());
getWidget().multiselect = "multi".equals(uidl
.getStringAttribute("selectmode"));
getWidget().immediate = getState().immediate;
@@ -76,10 +75,10 @@ public abstract class OptionGroupBaseConnector extends AbstractFieldConnector
getWidget().newItemField = new VTextField();
getWidget().newItemField.addKeyPressHandler(getWidget());
}
- getWidget().newItemField.setEnabled(!getWidget().disabled
- && !getWidget().readonly);
- getWidget().newItemButton.setEnabled(!getWidget().disabled
- && !getWidget().readonly);
+ getWidget().newItemField.setEnabled(getWidget().isEnabled()
+ && !getWidget().isReadonly());
+ getWidget().newItemButton.setEnabled(getWidget().isEnabled()
+ && !getWidget().isReadonly());
if (getWidget().newItemField == null
|| getWidget().newItemField.getParent() != getWidget().container) {