summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2013-09-02 15:49:53 +0200
committerVaadin Code Review <review@vaadin.com>2013-09-04 07:00:10 +0000
commit6dcece817b67122e5677f38ca4d80bc2f7cea110 (patch)
treee5328aa6d80eeb0843b3b09ba2801794e8712d1c /client
parentfca0f7a6b70160e94d4504537110d7689a3c4344 (diff)
downloadvaadin-framework-6dcece817b67122e5677f38ca4d80bc2f7cea110.tar.gz
vaadin-framework-6dcece817b67122e5677f38ca4d80bc2f7cea110.zip
Allow creating TextBox or SuggestionPopup when extending VFilterSelect (#12491)
This patch adds two methods, that one can override when extending VFilterSelect. By doing so, the developer can for example change the behavior of setting text, or performing clicks in the suggestion popup. This change is backwards compatible, as it just offers two new methods to override. Change-Id: Icc8fd154ef1abaed96e6af742af77c3225db3fe4
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java67
1 files changed, 53 insertions, 14 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java
index 7aac581008..9b14fbbb37 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -916,6 +916,27 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
}
}
+ /**
+ * TextBox variant used as input element for filter selects, which prevents
+ * selecting text when disabled.
+ *
+ * @since 7.1.5
+ */
+ public class FilterSelectTextBox extends TextBox {
+
+ /**
+ * Overridden to avoid selecting text when text input is disabled
+ */
+ @Override
+ public void setSelectionRange(int pos, int length) {
+ if (textInputEnabled) {
+ super.setSelectionRange(pos, length);
+ } else {
+ super.setSelectionRange(getValue().length(), 0);
+ }
+ }
+ }
+
@Deprecated
public static final FilteringMode FILTERINGMODE_OFF = FilteringMode.OFF;
@Deprecated
@@ -938,21 +959,10 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
* <p>
* For internal use only. May be removed or replaced in the future.
*/
- public final TextBox tb = new TextBox() {
-
- // Overridden to avoid selecting text when text input is disabled
- @Override
- public void setSelectionRange(int pos, int length) {
- if (textInputEnabled) {
- super.setSelectionRange(pos, length);
- } else {
- super.setSelectionRange(getValue().length(), 0);
- }
- };
- };
+ public final TextBox tb;
/** For internal use only. May be removed or replaced in the future. */
- public final SuggestionPopup suggestionPopup = new SuggestionPopup();
+ public final SuggestionPopup suggestionPopup;
/**
* Used when measuring the width of the popup
@@ -1096,9 +1106,12 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
private boolean textInputEnabled = true;
/**
- * Default constructor
+ * Default constructor.
*/
public VFilterSelect() {
+ tb = createTextBox();
+ suggestionPopup = createSuggestionPopup();
+
selectedItemIcon.setStyleName("v-icon");
selectedItemIcon.addLoadHandler(new LoadHandler() {
@@ -1136,6 +1149,32 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
setStyleName(CLASSNAME);
}
+ /**
+ * This method will create the TextBox used by the VFilterSelect instance.
+ * It is invoked during the Constructor and should only be overridden if a
+ * custom TextBox shall be used. The overriding method cannot use any
+ * instance variables.
+ *
+ * @since 7.1.5
+ * @return TextBox instance used by this VFilterSelect
+ */
+ protected TextBox createTextBox() {
+ return new FilterSelectTextBox();
+ }
+
+ /**
+ * This method will create the SuggestionPopup used by the VFilterSelect
+ * instance. It is invoked during the Constructor and should only be
+ * overridden if a custom SuggestionPopup shall be used. The overriding
+ * method cannot use any instance variables.
+ *
+ * @since 7.1.5
+ * @return SuggestionPopup instance used by this VFilterSelect
+ */
+ protected SuggestionPopup createSuggestionPopup() {
+ return new SuggestionPopup();
+ }
+
@Override
public void setStyleName(String style) {
super.setStyleName(style);