private boolean readonly;
- // Intentional removal of cols in compatibility package
+ /** For internal use only. May be removed or replaced in the future. */
+ public int cols = 0;
/** For internal use only. May be removed or replaced in the future. */
public int rows = 0;
return nullSelectionItemAvailable;
}
- // Intentional removal of getColumns in compatibility package
+ /**
+ * For internal use only. May be removed or replaced in the future.
+ *
+ * @return "cols" specified in uidl, 0 if not specified
+ */
+ public int getColumns() {
+ return cols;
+ }
/**
* For internal use only. May be removed or replaced in the future.
/** For internal use only. May be removed or replaced in the future. */
public void clearInternalWidths() {
- // Intentional removal of cols in compatibility package
- int cols = DEFAULT_COLUMN_COUNT;
+ int cols = -1;
+ if (getColumns() > 0) {
+ cols = getColumns();
+ } else {
+ cols = DEFAULT_COLUMN_COUNT;
+ }
if (cols >= 0) {
String colWidth = cols + "em";
getWidget().nullSelectionItemAvailable = uidl
.getBooleanAttribute("nullselectitem");
- // Support for cols has been dropped.
-
+ if (uidl.hasAttribute("cols")) {
+ getWidget().cols = uidl.getIntAttribute("cols");
+ }
if (uidl.hasAttribute("rows")) {
getWidget().rows = uidl.getIntAttribute("rows");
}
final UIDL ops = uidl.getChildUIDL(0);
- // Method getColumns has been removed
+ if (getWidget().getColumns() > 0) {
+ getWidget().container.setWidth(getWidget().getColumns() + "em");
+ if (getWidget().container != getWidget().optionsContainer) {
+ getWidget().optionsContainer.setWidth("100%");
+ }
+ }
getWidget().buildOptions(ops);
@Deprecated
public class ListSelect extends AbstractSelect {
+ private int columns = 0;
private int rows = 0;
public ListSelect() {
super(caption);
}
- // Columns are no longer used for width.
+ /**
+ * Sets the width of the component so that it can display approximately the
+ * given number of letters.
+ * <p>
+ * Calling {@code setColumns(10);} is equivalent to calling
+ * {@code setWidth("10em");}
+ * </p>
+ *
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ * @param columns
+ * the number of columns to set.
+ */
+ @Deprecated
+ public void setColumns(int columns) {
+ if (columns < 0) {
+ columns = 0;
+ }
+ if (this.columns != columns) {
+ this.columns = columns;
+ markAsDirty();
+ }
+ }
+
+ /**
+ * Gets the number of columns for the component.
+ *
+ * @see #setColumns(int)
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ */
+ @Deprecated
+ public int getColumns() {
+ return columns;
+ }
public int getRows() {
return rows;
@Override
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);
public class NativeSelect extends AbstractSelect
implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
+ // width in characters, mimics TextField
+ private int columns = 0;
+
public NativeSelect() {
super();
registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
}
+ /**
+ * Sets the width of the component so that it can display approximately the
+ * given number of letters.
+ * <p>
+ * Calling {@code setColumns(10);} is equivalent to calling
+ * {@code setWidth("10em");}
+ * </p>
+ *
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ * @param columns
+ * the number of columns to set.
+ */
+ @Deprecated
+ public void setColumns(int columns) {
+ if (columns < 0) {
+ columns = 0;
+ }
+ if (this.columns != columns) {
+ this.columns = columns;
+ markAsDirty();
+ }
+ }
+
+ /**
+ * Gets the number of columns for the component.
+ *
+ * @see #setColumns(int)
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ */
+ @Deprecated
+ public int getColumns() {
+ return columns;
+ }
+
@Override
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);
}
@Deprecated
public class TwinColSelect extends AbstractSelect {
+ private int columns = 0;
private int rows = 0;
private String leftColumnCaption;
setMultiSelect(true);
}
- // Columns are no longer used for width.
+ /**
+ * Sets the width of the component so that it displays approximately the
+ * given number of letters in each of the two selects.
+ * <p>
+ * Calling {@code setColumns(10);} is roughly equivalent to calling
+ * {@code setWidth((10*2+4)+"10em");}
+ * </p>
+ *
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ * @param columns
+ * the number of columns to set.
+ */
+ @Deprecated
+ public void setColumns(int columns) {
+ if (columns < 0) {
+ columns = 0;
+ }
+ if (this.columns != columns) {
+ this.columns = columns;
+ markAsDirty();
+ }
+ }
+
+ /**
+ * Gets the number of columns for the component.
+ *
+ * @see #setColumns(int)
+ * @deprecated As of 7.0. "Columns" does not reflect the exact number of
+ * characters that will be displayed. It is better to use
+ * setWidth together with "em" to control the width of the
+ * field.
+ */
+ @Deprecated
+ public int getColumns() {
+ return columns;
+ }
public int getRows() {
return rows;
@Override
public void paintContent(PaintTarget target) throws PaintException {
target.addAttribute("type", "twincol");
- // Width is no longer based on columns
+ // Adds the number of columns
+ if (columns != 0) {
+ target.addAttribute("cols", columns);
+ }
// Adds the number of rows
if (rows != 0) {
target.addAttribute("rows", rows);
public class ListSelects extends AbstractSelectTestCase<ListSelect> {
+ private Command<ListSelect, Integer> colsCommand = new Command<ListSelect, Integer>() {
+ @Override
+ public void execute(ListSelect c, Integer value, Object data) {
+ c.setColumns(value);
+ }
+ };
+
private Command<ListSelect, Integer> rowsCommand = new Command<ListSelect, Integer>() {
@Override
public void execute(ListSelect c, Integer value, Object data) {
protected void createActions() {
super.createActions();
createRowsAction(CATEGORY_FEATURES);
+ createColsAction(CATEGORY_FEATURES);
}
private void createRowsAction(String category) {
createSelectAction("Rows", category, options, "0", rowsCommand);
}
+ private void createColsAction(String category) {
+ LinkedHashMap<String, Integer> options = createIntegerOptions(20);
+ createSelectAction("Columns", category, options, "0", colsCommand);
+ }
}
}
};
+ private Command<TwinColSelect, Integer> colsCommand = new Command<TwinColSelect, Integer>() {
+ @Override
+ public void execute(TwinColSelect c, Integer value, Object data) {
+ c.setColumns(value);
+ }
+ };
+
private Command<TwinColSelect, String> leftColumnCaptionCommand = new Command<TwinColSelect, String>() {
@Override
protected void createActions() {
super.createActions();
createRowsAction(CATEGORY_FEATURES);
+ createColsAction(CATEGORY_FEATURES);
createCaptionActions(CATEGORY_FEATURES);
}
createSelectAction("Rows", category, options, "0", rowsCommand);
}
+ private void createColsAction(String category) {
+ LinkedHashMap<String, Integer> options = createIntegerOptions(20);
+ createSelectAction("Columns", category, options, "0", colsCommand);
+ }
+
private void createCaptionActions(String category) {
createSelectAction("Left column caption", category,
createCaptionOptions(), "-", leftColumnCaptionCommand);
protected void createActions() {
super.createActions();
createRowSelectAction();
+ createColumnSelectAction();
+ }
+
+ private void createColumnSelectAction() {
+ LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+ options.put("-", 0);
+ for (int i = 1; i <= 10; i++) {
+ options.put(String.valueOf(i), i);
+ }
+ options.put("50", 50);
+ options.put("100", 100);
+ options.put("1000", 1000);
+
+ super.createSelectAction("Columns", CATEGORY_DATA_SOURCE, options, "-",
+ columnsAction);
+
}
private void createRowSelectAction() {
}
+ private Command<TwinColSelect, Integer> columnsAction = new Command<TwinColSelect, Integer>() {
+
+ @Override
+ public void execute(TwinColSelect c, Integer value, Object data) {
+ c.setColumns(value);
+ }
+ };
+
private Command<TwinColSelect, Integer> rowsAction = new Command<TwinColSelect, Integer>() {
@Override
package com.vaadin.v7.tests.components.nativeselect;
+import java.util.LinkedHashMap;
+
import com.vaadin.tests.components.select.AbstractSelectTestCase;
import com.vaadin.v7.ui.NativeSelect;
@Override
protected void createActions() {
super.createActions();
+ createColumnSelectAction();
+ }
+
+ private void createColumnSelectAction() {
+ LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+ options.put("-", 0);
+ for (int i = 1; i <= 10; i++) {
+ options.put(String.valueOf(i), i);
+ }
+ options.put("50", 50);
+ options.put("100", 100);
+ options.put("1000", 1000);
+
+ super.createSelectAction("Columns", CATEGORY_DATA_SOURCE, options, "-",
+ columnsAction);
+
}
+ private Command<NativeSelect, Integer> columnsAction = new Command<NativeSelect, Integer>() {
+
+ @Override
+ public void execute(NativeSelect c, Integer value, Object data) {
+ c.setColumns(value);
+ }
+ };
}