aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2015-11-05 10:51:56 +0200
committerHenri Sara <hesara@vaadin.com>2016-01-15 14:42:56 +0200
commitb214cb8ca3fe07515483f986169c51f127bf66be (patch)
tree1e457de6f435b3a8901b5317a07893661e0ee82d
parent1549f1437c0b6ee99dd35f9b556c6c4670410873 (diff)
downloadvaadin-framework-b214cb8ca3fe07515483f986169c51f127bf66be.tar.gz
vaadin-framework-b214cb8ca3fe07515483f986169c51f127bf66be.zip
Use shared state in ComboBox (#19229)
This change uses shared state for the read-only flag, text input allowed flag and input prompt. Change-Id: I3bdc6843288c5309311461a3d036293d79004e22
-rw-r--r--client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java45
-rw-r--r--server/src/com/vaadin/ui/ComboBox.java34
-rw-r--r--shared/src/com/vaadin/shared/ui/combobox/ComboBoxConstants.java27
-rw-r--r--shared/src/com/vaadin/shared/ui/combobox/ComboBoxState.java18
4 files changed, 51 insertions, 73 deletions
diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index 1224a2eaf2..961fc3cec1 100644
--- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -23,13 +23,14 @@ import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.Paintable;
+import com.vaadin.client.Profiler;
import com.vaadin.client.UIDL;
+import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.client.ui.VFilterSelect;
import com.vaadin.client.ui.VFilterSelect.FilterSelectSuggestion;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.combobox.ComboBoxConstants;
import com.vaadin.shared.ui.combobox.ComboBoxState;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.ui.ComboBox;
@@ -42,6 +43,28 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
// update textbox text by a changed item caption.
private boolean oldSuggestionTextMatchTheOldSelection;
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ Profiler.enter("ComboBoxConnector.onStateChanged update content");
+
+ getWidget().readonly = isReadOnly();
+ getWidget().updateReadOnly();
+
+ getWidget().immediate = getState().immediate;
+
+ getWidget().setTextInputEnabled(getState().textInputAllowed);
+
+ if (getState().inputPrompt != null) {
+ getWidget().inputPrompt = getState().inputPrompt;
+ } else {
+ getWidget().inputPrompt = "";
+ }
+
+ Profiler.leave("ComboBoxConnector.onStateChanged update content");
+ }
+
/*
* (non-Javadoc)
*
@@ -54,20 +77,10 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().client = client;
getWidget().paintableId = uidl.getId();
- getWidget().readonly = isReadOnly();
- getWidget().updateReadOnly();
-
if (!isRealUpdate(uidl)) {
return;
}
- // Inverse logic here to make the default case (text input enabled)
- // work without additional UIDL messages
- boolean noTextInput = uidl
- .hasAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT)
- && uidl.getBooleanAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT);
- getWidget().setTextInputEnabled(!noTextInput);
-
// not a FocusWidget -> needs own tabindex handling
getWidget().tb.setTabIndex(getState().tabIndex);
@@ -76,8 +89,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
.getStringAttribute("filteringmode"));
}
- getWidget().immediate = getState().immediate;
-
getWidget().nullSelectionAllowed = uidl.hasAttribute("nullselect");
getWidget().nullSelectItem = uidl.hasAttribute("nullselectitem")
@@ -89,14 +100,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements
getWidget().pageLength = uidl.getIntAttribute("pagelength");
}
- if (uidl.hasAttribute(ComboBoxConstants.ATTR_INPUTPROMPT)) {
- // input prompt changed from server
- getWidget().inputPrompt = uidl
- .getStringAttribute(ComboBoxConstants.ATTR_INPUTPROMPT);
- } else {
- getWidget().inputPrompt = "";
- }
-
getWidget().suggestionPopup.updateStyleNames(uidl, getState());
getWidget().allowNewItem = uidl.hasAttribute("allownewitem");
diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java
index b632cb0d8d..ee52f2fe77 100644
--- a/server/src/com/vaadin/ui/ComboBox.java
+++ b/server/src/com/vaadin/ui/ComboBox.java
@@ -34,7 +34,6 @@ import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.server.Resource;
-import com.vaadin.shared.ui.combobox.ComboBoxConstants;
import com.vaadin.shared.ui.combobox.ComboBoxState;
import com.vaadin.shared.ui.combobox.FilteringMode;
@@ -75,8 +74,6 @@ public class ComboBox extends AbstractSelect implements
public String getStyle(ComboBox source, Object itemId);
}
- private String inputPrompt = null;
-
/**
* Holds value of property pageLength. 0 disables paging.
*/
@@ -121,13 +118,6 @@ public class ComboBox extends AbstractSelect implements
*/
private boolean scrollToSelectedItem = true;
- /**
- * If text input is not allowed, the ComboBox behaves like a pretty
- * NativeSelect - the user can not enter any text and clicking the text
- * field opens the drop down with options
- */
- private boolean textInputAllowed = true;
-
private ItemStyleGenerator itemStyleGenerator = null;
public ComboBox() {
@@ -164,7 +154,7 @@ public class ComboBox extends AbstractSelect implements
* @return the current input prompt, or null if not enabled
*/
public String getInputPrompt() {
- return inputPrompt;
+ return getState(false).inputPrompt;
}
/**
@@ -175,8 +165,7 @@ public class ComboBox extends AbstractSelect implements
* the desired input prompt, or null to disable
*/
public void setInputPrompt(String inputPrompt) {
- this.inputPrompt = inputPrompt;
- markAsDirty();
+ getState().inputPrompt = inputPrompt;
}
private boolean isFilteringNeeded() {
@@ -188,15 +177,6 @@ public class ComboBox extends AbstractSelect implements
public void paintContent(PaintTarget target) throws PaintException {
isPainting = true;
try {
- if (inputPrompt != null) {
- target.addAttribute(ComboBoxConstants.ATTR_INPUTPROMPT,
- inputPrompt);
- }
-
- if (!textInputAllowed) {
- target.addAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT, true);
- }
-
// clear caption change listeners
getCaptionChangeListener().clear();
@@ -368,8 +348,7 @@ public class ComboBox extends AbstractSelect implements
* selection
*/
public void setTextInputAllowed(boolean textInputAllowed) {
- this.textInputAllowed = textInputAllowed;
- markAsDirty();
+ getState().textInputAllowed = textInputAllowed;
}
/**
@@ -381,7 +360,7 @@ public class ComboBox extends AbstractSelect implements
* @return
*/
public boolean isTextInputAllowed() {
- return textInputAllowed;
+ return getState(false).textInputAllowed;
}
@Override
@@ -389,6 +368,11 @@ public class ComboBox extends AbstractSelect implements
return (ComboBoxState) super.getState();
}
+ @Override
+ protected ComboBoxState getState(boolean markAsDirty) {
+ return (ComboBoxState) super.getState(markAsDirty);
+ }
+
/**
* Returns the filtered options for the current page using a container
* filter.
diff --git a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxConstants.java b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxConstants.java
deleted file mode 100644
index aeb04ba75f..0000000000
--- a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxConstants.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.shared.ui.combobox;
-
-import java.io.Serializable;
-
-@Deprecated
-public class ComboBoxConstants implements Serializable {
- @Deprecated
- public static final String ATTR_INPUTPROMPT = "prompt";
- @Deprecated
- public static final String ATTR_NO_TEXT_INPUT = "noInput";
-
-}
diff --git a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxState.java b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxState.java
index 46e24aa266..1856aac00d 100644
--- a/shared/src/com/vaadin/shared/ui/combobox/ComboBoxState.java
+++ b/shared/src/com/vaadin/shared/ui/combobox/ComboBoxState.java
@@ -26,4 +26,22 @@ public class ComboBoxState extends AbstractSelectState {
{
primaryStyleName = "v-filterselect";
}
+
+ /**
+ * If text input is not allowed, the ComboBox behaves like a pretty
+ * NativeSelect - the user can not enter any text and clicking the text
+ * field opens the drop down with options.
+ *
+ * @since
+ */
+ public boolean textInputAllowed = true;
+
+ /**
+ * A textual prompt that is displayed when the select would otherwise be
+ * empty, to prompt the user for input.
+ *
+ * @since
+ */
+ public String inputPrompt = null;
+
}