select.setItemSelected(select.getItemCount() - 1, true);
}
}
+ if (getRows() > 0) {
+ select.setVisibleItemCount(getRows());
+ }
}
protected Object[] getSelectedItems() {
+ getSelectedItem() }, isImmediate());
}
}
+
}
\r
private boolean readonly;\r
\r
+ private int cols = 0;\r
+\r
+ private int rows = 0;\r
+\r
private boolean nullSelectionAllowed = true;\r
\r
private boolean nullSelectionItemAvailable = false;\r
return nullSelectionItemAvailable;\r
}\r
\r
+ /**\r
+ * @return "cols" specified in uidl, 0 if not specified\r
+ */\r
+ protected int getColumns() {\r
+ return cols;\r
+ }\r
+\r
+ /**\r
+ * @return "rows" specified in uidl, 0 if not specified\r
+ */\r
+\r
+ protected int getRows() {\r
+ return rows;\r
+ }\r
+\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
this.client = client;\r
id = uidl.getId();\r
nullSelectionAllowed = uidl.getBooleanAttribute("nullselect");\r
nullSelectionItemAvailable = uidl.getBooleanAttribute("nullselectitem");\r
\r
+ cols = uidl.getIntAttribute("cols");\r
+ rows = uidl.getIntAttribute("rows");\r
+\r
UIDL ops = uidl.getChildUIDL(0);\r
\r
+ if (getColumns() > 0) {\r
+ container.setWidth(getColumns() + "em");\r
+ if (container != optionsContainer) {\r
+ optionsContainer.setWidth("100%");\r
+ }\r
+ }\r
+\r
buildOptions(ops);\r
\r
if (uidl.getBooleanAttribute("allownewitem")) {\r
if (newItemField == null) {\r
newItemButton = new IButton();\r
newItemButton.setText("+");\r
+ newItemButton.setWidth("1.5em");\r
newItemButton.addClickListener(this);\r
newItemField = new ITextField();\r
newItemField.addKeyboardListener(this);\r
- newItemField.setColumns(16);\r
+ // newItemField.setColumns(16);\r
+ if (getColumns() > 0) {\r
+ newItemField.setWidth((getColumns() - 2) + "em");\r
+ }\r
}\r
newItemField.setEnabled(!disabled && !readonly);\r
newItemButton.setEnabled(!disabled && !readonly);\r
\r
- if (newItemField != null && newItemField.getParent() == container) {\r
- return;\r
+ if (newItemField == null || newItemField.getParent() != container) {\r
+ container.add(newItemField);\r
+ container.add(newItemButton);\r
}\r
- container.add(newItemField);\r
- container.add(newItemButton);\r
} else if (newItemField != null) {\r
container.remove(newItemField);\r
container.remove(newItemButton);\r
}
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) {}
+ }-*/;
}
public ITwinColSelect() {\r
super(CLASSNAME);\r
options = new ListBox();\r
+ options.addClickListener(this);\r
selections = new ListBox();\r
+ selections.addClickListener(this);\r
options.setVisibleItemCount(VISIBLE_COUNT);\r
selections.setVisibleItemCount(VISIBLE_COUNT);\r
options.setStyleName(CLASSNAME + "-options");\r
Panel buttons = new FlowPanel();\r
buttons.setStyleName(CLASSNAME + "-buttons");\r
add = new IButton();\r
- remove = new IButton();\r
add.setText(">>");\r
- remove.setText("<<");\r
add.addClickListener(this);\r
+ remove = new IButton();\r
+ remove.setText("<<");\r
remove.addClickListener(this);\r
Panel p = ((Panel) optionsContainer);\r
p.add(options);\r
buttons.add(add);\r
- HTML br = new HTML(" ");\r
+ HTML br = new HTML("<span/>");\r
br.setStyleName(CLASSNAME + "-deco");\r
buttons.add(br);\r
buttons.add(remove);\r
optionUidl.getStringAttribute("key"));\r
}\r
}\r
+ optionsContainer.setWidth(null);\r
+ if (getColumns() > 0) {\r
+ options.setWidth(getColumns() + "em");\r
+ selections.setWidth(getColumns() + "em");\r
+ }\r
+ if (getRows() > 0) {\r
+ options.setVisibleItemCount(getRows());\r
+ selections.setVisibleItemCount(getRows());\r
+ }\r
}\r
\r
protected Object[] getSelectedItems() {\r
String text = options.getItemText(optionIndex);\r
String value = options.getValue(optionIndex);\r
selections.addItem(text, value);\r
+ selections.setItemSelected(selections.getItemCount() - 1,\r
+ true);\r
options.removeItem(optionIndex);\r
}\r
}\r
String text = selections.getItemText(selectionIndex);\r
String value = selections.getValue(selectionIndex);\r
options.addItem(text, value);\r
+ options.setItemSelected(options.getItemCount() - 1, true);\r
selections.removeItem(selectionIndex);\r
}\r
}\r
client.updateVariable(id, "selected", selectedKeys.toArray(),\r
isImmediate());\r
+ } else if (sender == options) {\r
+ // unselect all in other list, to avoid mistakes (i.e wrong button)\r
+ int c = selections.getItemCount();\r
+ for (int i = 0; i < c; i++) {\r
+ selections.setItemSelected(i, false);\r
+ }\r
+ } else if (sender == selections) {\r
+ // unselect all in other list, to avoid mistakes (i.e wrong button)\r
+ int c = options.getItemCount();\r
+ for (int i = 0; i < c; i++) {\r
+ options.setItemSelected(i, false);\r
+ }\r
}\r
}\r
\r
.i-button {\r
cursor: pointer;\r
+ font-size: 13px;\r
}\r
.i-button.link {\r
border: 0px;\r
.i-select {\r
\r
}\r
-\r
.i-select-option {\r
\r
}\r
border-left-color: #d6d6d6;\r
*/\r
display: block;\r
+ font-size: 13px;\r
}\r
\r
/* Twincol style */\r
+.i-select-twincol {\r
+ white-space: nowrap;\r
+}\r
.i-select-twincol-options {\r
float: left;\r
+ font-size: 13px;\r
+}\r
+.i-select-twincol-selections {\r
+ font-size: 13px;\r
+ font-weight: bold;\r
}\r
\r
.i-select-twincol-buttons {\r
float: left;\r
- width: 40px;\r
+ padding: 2px; /* does not work in first render in FF ? */\r
text-align: center;\r
}\r
\r
.i-select-twincol-buttons .i-select-twincol-deco {\r
- display: inline; /* Needed to push the two buttons in stack */\r
+ clear:both;\r
}\r
\r
.i-select-twincol .i-textfield {\r
border: none;\r
}\r
\r
+/* TODO impl all textarea styles */\r
+.i-textarea {\r
+ background: #fff url(img/bg.png) repeat-x;\r
+ padding: 2px;\r
+ border: 1px solid #b6b6b6;\r
+ border-top-color: #9d9d9d;\r
+ border-bottom-color: #d6d6d6;\r
+ border-right-color: #d6d6d6;\r
+ margin: 0;\r
+ font-size: 13px;\r
+}\r
+\r
+\r
.i-richtextarea {\r
border: 1px solid #b6b6b6;\r
overflow: hidden;\r
--- /dev/null
+/**\r
+ * \r
+ */\r
+package com.itmill.toolkit.ui;\r
+\r
+import java.util.Collection;\r
+\r
+import com.itmill.toolkit.data.Container;\r
+\r
+/**\r
+ * A filtering dropdown single-select with newItemsAllowed. Items are filtered\r
+ * based on user input, and loaded dynamically ("lazy-loading") from the server.\r
+ * You can turn off newItemsAllowed and change filtering mode (and also turn it\r
+ * off), but you can not turn on multi-select mode.\r
+ * \r
+ */\r
+public class ComboBox extends Select {\r
+ public ComboBox() {\r
+ setMultiSelect(false);\r
+ setNewItemsAllowed(true);\r
+ }\r
+\r
+ public ComboBox(String caption, Collection options) {\r
+ super(caption, options);\r
+ setMultiSelect(false);\r
+ setNewItemsAllowed(true);\r
+ }\r
+\r
+ public ComboBox(String caption, Container dataSource) {\r
+ super(caption, dataSource);\r
+ setMultiSelect(false);\r
+ setNewItemsAllowed(true);\r
+ }\r
+\r
+ public ComboBox(String caption) {\r
+ super(caption);\r
+ setMultiSelect(false);\r
+ setNewItemsAllowed(true);\r
+ }\r
+\r
+ public void setMultiSelect(boolean multiSelect) {\r
+ if (multiSelect && !isMultiSelect()) {\r
+ throw new UnsupportedOperationException("Multiselect not supported");\r
+ }\r
+ super.setMultiSelect(multiSelect);\r
+ }\r
+\r
+}\r
*/
public class ListSelect extends AbstractSelect {
+ private int columns = 0;
+ private int rows = 0;
+
public ListSelect() {
super();
}
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);
}
}
*/
public class NativeSelect extends AbstractSelect {
+ // width in characters, mimics TextField
+ private int columns = 0;
+
public NativeSelect() {
super();
}
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);
}
*/
protected int pageLength = 10;
+ private int columns = 0;
+
// current page when the user is 'paging' trough options
private int currentPage;
}
}
+ // Adds the number of columns
+ if (columns != 0) {
+ target.addAttribute("cols", columns);
+ }
+
// Constructs selected keys array
String[] selectedKeys;
if (isMultiSelect()) {
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;
+ }
+
}
*/
public class TwinColSelect extends AbstractSelect {
+ private int columns = 0;
+ private int rows = 0;
+
/**
*
*/
setMultiSelect(true);
}
+ /**
+ * 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
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);
}