diff options
author | Marc Englund <marc.englund@itmill.com> | 2007-11-23 07:45:03 +0000 |
---|---|---|
committer | Marc Englund <marc.englund@itmill.com> | 2007-11-23 07:45:03 +0000 |
commit | 795e977f82d50dfb3c1a7f3bfb24a46c5cb4a407 (patch) | |
tree | d7b68affcdee7dbf430ccca25b396d8ed628b361 | |
parent | 1e4c89a511811135094a3e238dd04be452a3261c (diff) | |
download | vaadin-framework-795e977f82d50dfb3c1a7f3bfb24a46c5cb4a407.tar.gz vaadin-framework-795e977f82d50dfb3c1a7f3bfb24a46c5cb4a407.zip |
setColumns() and setRows() added to selects as appropriate, made to match width of TextField.
Fixes #898
svn changeset:2893/svn branch:trunk
13 files changed, 332 insertions, 28 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java index 3b65a6aa9e..43dfb3fa21 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java @@ -43,6 +43,9 @@ public class IListSelect extends IOptionGroupBase { select.setItemSelected(select.getItemCount() - 1, true); } } + if (getRows() > 0) { + select.setVisibleItemCount(getRows()); + } } protected Object[] getSelectedItems() { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java index efd18d13cc..95c954a4c0 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java @@ -58,4 +58,5 @@ public class INativeSelect extends IOptionGroupBase { + getSelectedItem() }, isImmediate()); } } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java index 5a1d624eef..baedab7f1a 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java @@ -32,6 +32,10 @@ abstract class IOptionGroupBase extends Composite implements Paintable, private boolean readonly;
+ private int cols = 0;
+
+ private int rows = 0;
+
private boolean nullSelectionAllowed = true;
private boolean nullSelectionItemAvailable = false;
@@ -94,6 +98,21 @@ abstract class IOptionGroupBase extends Composite implements Paintable, return nullSelectionItemAvailable;
}
+ /**
+ * @return "cols" specified in uidl, 0 if not specified
+ */
+ protected int getColumns() {
+ return cols;
+ }
+
+ /**
+ * @return "rows" specified in uidl, 0 if not specified
+ */
+
+ protected int getRows() {
+ return rows;
+ }
+
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
this.client = client;
id = uidl.getId();
@@ -111,27 +130,40 @@ abstract class IOptionGroupBase extends Composite implements Paintable, nullSelectionAllowed = uidl.getBooleanAttribute("nullselect");
nullSelectionItemAvailable = uidl.getBooleanAttribute("nullselectitem");
+ cols = uidl.getIntAttribute("cols");
+ rows = uidl.getIntAttribute("rows");
+
UIDL ops = uidl.getChildUIDL(0);
+ if (getColumns() > 0) {
+ container.setWidth(getColumns() + "em");
+ if (container != optionsContainer) {
+ optionsContainer.setWidth("100%");
+ }
+ }
+
buildOptions(ops);
if (uidl.getBooleanAttribute("allownewitem")) {
if (newItemField == null) {
newItemButton = new IButton();
newItemButton.setText("+");
+ newItemButton.setWidth("1.5em");
newItemButton.addClickListener(this);
newItemField = new ITextField();
newItemField.addKeyboardListener(this);
- newItemField.setColumns(16);
+ // newItemField.setColumns(16);
+ if (getColumns() > 0) {
+ newItemField.setWidth((getColumns() - 2) + "em");
+ }
}
newItemField.setEnabled(!disabled && !readonly);
newItemButton.setEnabled(!disabled && !readonly);
- if (newItemField != null && newItemField.getParent() == container) {
- return;
+ if (newItemField == null || newItemField.getParent() != container) {
+ container.add(newItemField);
+ container.add(newItemButton);
}
- container.add(newItemField);
- container.add(newItemButton);
} else if (newItemField != null) {
container.remove(newItemField);
container.remove(newItemButton);
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java index 7b1ed75f27..6b77aefebd 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java @@ -87,23 +87,25 @@ public class ITextField extends TextBoxBase implements Paintable, } private native void setColumns(Element e, int c) /*-{ - try { - switch(e.tagName.toLowerCase()) { - case "input": - e.size = c; - break; - case "textarea": - e.cols = c; - break; - default:; - } - } catch (e) {} - }-*/; + try { + switch(e.tagName.toLowerCase()) { + case "input": + //e.size = c; + e.style.width = c+"em"; + break; + case "textarea": + //e.cols = c; + e.style.width = c+"em"; + break; + default:; + } + } catch (e) {} + }-*/; private native void setRows(Element e, int r) /*-{ - try { - if(e.tagName.toLowerCase() == "textarea") - e.rows = r; - } catch (e) {} - }-*/; + try { + if(e.tagName.toLowerCase() == "textarea") + e.rows = r; + } catch (e) {} + }-*/; } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITwinColSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITwinColSelect.java index 5ed9cea2e9..614120db51 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITwinColSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITwinColSelect.java @@ -27,7 +27,9 @@ public class ITwinColSelect extends IOptionGroupBase { public ITwinColSelect() {
super(CLASSNAME);
options = new ListBox();
+ options.addClickListener(this);
selections = new ListBox();
+ selections.addClickListener(this);
options.setVisibleItemCount(VISIBLE_COUNT);
selections.setVisibleItemCount(VISIBLE_COUNT);
options.setStyleName(CLASSNAME + "-options");
@@ -35,15 +37,15 @@ public class ITwinColSelect extends IOptionGroupBase { Panel buttons = new FlowPanel();
buttons.setStyleName(CLASSNAME + "-buttons");
add = new IButton();
- remove = new IButton();
add.setText(">>");
- remove.setText("<<");
add.addClickListener(this);
+ remove = new IButton();
+ remove.setText("<<");
remove.addClickListener(this);
Panel p = ((Panel) optionsContainer);
p.add(options);
buttons.add(add);
- HTML br = new HTML(" ");
+ HTML br = new HTML("<span/>");
br.setStyleName(CLASSNAME + "-deco");
buttons.add(br);
buttons.add(remove);
@@ -71,6 +73,15 @@ public class ITwinColSelect extends IOptionGroupBase { optionUidl.getStringAttribute("key"));
}
}
+ optionsContainer.setWidth(null);
+ if (getColumns() > 0) {
+ options.setWidth(getColumns() + "em");
+ selections.setWidth(getColumns() + "em");
+ }
+ if (getRows() > 0) {
+ options.setVisibleItemCount(getRows());
+ selections.setVisibleItemCount(getRows());
+ }
}
protected Object[] getSelectedItems() {
@@ -118,6 +129,8 @@ public class ITwinColSelect extends IOptionGroupBase { String text = options.getItemText(optionIndex);
String value = options.getValue(optionIndex);
selections.addItem(text, value);
+ selections.setItemSelected(selections.getItemCount() - 1,
+ true);
options.removeItem(optionIndex);
}
}
@@ -136,11 +149,24 @@ public class ITwinColSelect extends IOptionGroupBase { String text = selections.getItemText(selectionIndex);
String value = selections.getValue(selectionIndex);
options.addItem(text, value);
+ options.setItemSelected(options.getItemCount() - 1, true);
selections.removeItem(selectionIndex);
}
}
client.updateVariable(id, "selected", selectedKeys.toArray(),
isImmediate());
+ } else if (sender == options) {
+ // unselect all in other list, to avoid mistakes (i.e wrong button)
+ int c = selections.getItemCount();
+ for (int i = 0; i < c; i++) {
+ selections.setItemSelected(i, false);
+ }
+ } else if (sender == selections) {
+ // unselect all in other list, to avoid mistakes (i.e wrong button)
+ int c = options.getItemCount();
+ for (int i = 0; i < c; i++) {
+ options.setItemSelected(i, false);
+ }
}
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/button/button.css b/src/com/itmill/toolkit/terminal/gwt/public/default/button/button.css index bb3ad4773f..2e5f3c8b4e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/button/button.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/button/button.css @@ -1,5 +1,6 @@ .i-button {
cursor: pointer;
+ font-size: 13px;
}
.i-button.link {
border: 0px;
diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css b/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css index 9ea1c263fa..5998c55f85 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css @@ -1,7 +1,6 @@ .i-select {
}
-
.i-select-option {
}
@@ -23,21 +22,30 @@ border-left-color: #d6d6d6;
*/
display: block;
+ font-size: 13px;
}
/* Twincol style */
+.i-select-twincol {
+ white-space: nowrap;
+}
.i-select-twincol-options {
float: left;
+ font-size: 13px;
+}
+.i-select-twincol-selections {
+ font-size: 13px;
+ font-weight: bold;
}
.i-select-twincol-buttons {
float: left;
- width: 40px;
+ padding: 2px; /* does not work in first render in FF ? */
text-align: center;
}
.i-select-twincol-buttons .i-select-twincol-deco {
- display: inline; /* Needed to push the two buttons in stack */
+ clear:both;
}
.i-select-twincol .i-textfield {
diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css b/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css index bf5d50219c..b8d4003e65 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css @@ -24,6 +24,19 @@ border: none;
}
+/* TODO impl all textarea styles */
+.i-textarea {
+ background: #fff url(img/bg.png) repeat-x;
+ padding: 2px;
+ border: 1px solid #b6b6b6;
+ border-top-color: #9d9d9d;
+ border-bottom-color: #d6d6d6;
+ border-right-color: #d6d6d6;
+ margin: 0;
+ font-size: 13px;
+}
+
+
.i-richtextarea {
border: 1px solid #b6b6b6;
overflow: hidden;
diff --git a/src/com/itmill/toolkit/ui/ComboBox.java b/src/com/itmill/toolkit/ui/ComboBox.java new file mode 100644 index 0000000000..55f2c317d3 --- /dev/null +++ b/src/com/itmill/toolkit/ui/ComboBox.java @@ -0,0 +1,48 @@ +/**
+ *
+ */
+package com.itmill.toolkit.ui;
+
+import java.util.Collection;
+
+import com.itmill.toolkit.data.Container;
+
+/**
+ * A filtering dropdown single-select with newItemsAllowed. Items are filtered
+ * based on user input, and loaded dynamically ("lazy-loading") from the server.
+ * You can turn off newItemsAllowed and change filtering mode (and also turn it
+ * off), but you can not turn on multi-select mode.
+ *
+ */
+public class ComboBox extends Select {
+ public ComboBox() {
+ setMultiSelect(false);
+ setNewItemsAllowed(true);
+ }
+
+ public ComboBox(String caption, Collection options) {
+ super(caption, options);
+ setMultiSelect(false);
+ setNewItemsAllowed(true);
+ }
+
+ public ComboBox(String caption, Container dataSource) {
+ super(caption, dataSource);
+ setMultiSelect(false);
+ setNewItemsAllowed(true);
+ }
+
+ public ComboBox(String caption) {
+ super(caption);
+ setMultiSelect(false);
+ setNewItemsAllowed(true);
+ }
+
+ public void setMultiSelect(boolean multiSelect) {
+ if (multiSelect && !isMultiSelect()) {
+ throw new UnsupportedOperationException("Multiselect not supported");
+ }
+ super.setMultiSelect(multiSelect);
+ }
+
+}
diff --git a/src/com/itmill/toolkit/ui/ListSelect.java b/src/com/itmill/toolkit/ui/ListSelect.java index 25f6f01110..235524a649 100644 --- a/src/com/itmill/toolkit/ui/ListSelect.java +++ b/src/com/itmill/toolkit/ui/ListSelect.java @@ -12,6 +12,9 @@ import com.itmill.toolkit.terminal.PaintTarget; */ public class ListSelect extends AbstractSelect { + private int columns = 0; + private int rows = 0; + public ListSelect() { super(); } @@ -28,8 +31,60 @@ public class ListSelect extends AbstractSelect { super(caption); } + /** + * Sets the number of columns in the editor. If the number of columns is set + * 0, the actual number of displayed columns is determined implicitly by the + * adapter. + * + * @param columns + * the number of columns to set. + */ + public void setColumns(int columns) { + if (columns < 0) { + columns = 0; + } + if (this.columns != columns) { + this.columns = columns; + requestRepaint(); + } + } + + public int getColumns() { + return columns; + } + + public int getRows() { + return rows; + } + + /** + * Sets the number of rows in the editor. If the number of rows is set 0, + * the actual number of displayed rows is determined implicitly by the + * adapter. + * + * @param rows + * the number of rows to set. + */ + public void setRows(int rows) { + if (rows < 0) { + rows = 0; + } + if (this.rows != rows) { + this.rows = rows; + requestRepaint(); + } + } + public void paintContent(PaintTarget target) throws PaintException { target.addAttribute("type", "list"); + // Adds the number of columns + if (columns != 0) { + target.addAttribute("cols", columns); + } + // Adds the number of rows + if (rows != 0) { + target.addAttribute("rows", rows); + } super.paintContent(target); } } diff --git a/src/com/itmill/toolkit/ui/NativeSelect.java b/src/com/itmill/toolkit/ui/NativeSelect.java index 353ca9c8d8..9c5859095e 100644 --- a/src/com/itmill/toolkit/ui/NativeSelect.java +++ b/src/com/itmill/toolkit/ui/NativeSelect.java @@ -14,6 +14,9 @@ import com.itmill.toolkit.terminal.PaintTarget; */ public class NativeSelect extends AbstractSelect { + // width in characters, mimics TextField + private int columns = 0; + public NativeSelect() { super(); } @@ -30,8 +33,35 @@ public class NativeSelect extends AbstractSelect { super(caption); } + /** + * Sets the number of columns in the editor. If the number of columns is set + * 0, the actual number of displayed columns is determined implicitly by the + * adapter. + * + * @param columns + * the number of columns to set. + */ + public void setColumns(int columns) { + if (columns < 0) { + columns = 0; + } + if (this.columns != columns) { + this.columns = columns; + requestRepaint(); + } + } + + public int getColumns() { + return columns; + } + public void paintContent(PaintTarget target) throws PaintException { target.addAttribute("type", "native"); + // Adds the number of columns + if (columns != 0) { + target.addAttribute("cols", columns); + } + super.paintContent(target); } diff --git a/src/com/itmill/toolkit/ui/Select.java b/src/com/itmill/toolkit/ui/Select.java index 12f8757096..a5a199f8da 100644 --- a/src/com/itmill/toolkit/ui/Select.java +++ b/src/com/itmill/toolkit/ui/Select.java @@ -67,6 +67,8 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { */ protected int pageLength = 10; + private int columns = 0; + // current page when the user is 'paging' trough options private int currentPage; @@ -142,6 +144,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { } } + // Adds the number of columns + if (columns != 0) { + target.addAttribute("cols", columns); + } + // Constructs selected keys array String[] selectedKeys; if (isMultiSelect()) { @@ -421,4 +428,27 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { public int getFilteringMode() { return filteringMode; } + + /** + * Sets the number of columns in the editor. If the number of columns is set + * 0, the actual number of displayed columns is determined implicitly by the + * adapter. + * + * @param columns + * the number of columns to set. + */ + public void setColumns(int columns) { + if (columns < 0) { + columns = 0; + } + if (this.columns != columns) { + this.columns = columns; + requestRepaint(); + } + } + + public int getColumns() { + return columns; + } + } diff --git a/src/com/itmill/toolkit/ui/TwinColSelect.java b/src/com/itmill/toolkit/ui/TwinColSelect.java index aab5bf62c1..3a77d868f4 100644 --- a/src/com/itmill/toolkit/ui/TwinColSelect.java +++ b/src/com/itmill/toolkit/ui/TwinColSelect.java @@ -15,6 +15,9 @@ import com.itmill.toolkit.terminal.PaintTarget; */ public class TwinColSelect extends AbstractSelect { + private int columns = 0; + private int rows = 0; + /** * */ @@ -41,6 +44,50 @@ public class TwinColSelect extends AbstractSelect { } /** + * Sets the number of columns in the editor. If the number of columns is set + * 0, the actual number of displayed columns is determined implicitly by the + * adapter. + * + * @param columns + * the number of columns to set. + */ + public void setColumns(int columns) { + if (columns < 0) { + columns = 0; + } + if (this.columns != columns) { + this.columns = columns; + requestRepaint(); + } + } + + public int getColumns() { + return columns; + } + + public int getRows() { + return rows; + } + + /** + * Sets the number of rows in the editor. If the number of rows is set 0, + * the actual number of displayed rows is determined implicitly by the + * adapter. + * + * @param rows + * the number of rows to set. + */ + public void setRows(int rows) { + if (rows < 0) { + rows = 0; + } + if (this.rows != rows) { + this.rows = rows; + requestRepaint(); + } + } + + /** * @param caption * @param options */ @@ -51,6 +98,14 @@ public class TwinColSelect extends AbstractSelect { public void paintContent(PaintTarget target) throws PaintException { target.addAttribute("type", "twincol"); + // Adds the number of columns + if (columns != 0) { + target.addAttribute("cols", columns); + } + // Adds the number of rows + if (rows != 0) { + target.addAttribute("rows", rows); + } super.paintContent(target); } |