diff options
-rw-r--r-- | src/com/vaadin/data/validator/CompositeValidator.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/terminal/Sizeable.java | 4 | ||||
-rw-r--r-- | src/com/vaadin/terminal/UserError.java | 6 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VButton.java | 85 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java | 87 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java | 80 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java | 83 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractComponent.java | 10 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractSelect.java | 112 | ||||
-rw-r--r-- | src/com/vaadin/ui/Button.java | 3 | ||||
-rw-r--r-- | src/com/vaadin/ui/NativeButton.java | 4 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 339 | ||||
-rw-r--r-- | tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java | 64 | ||||
-rw-r--r-- | tests/testbench/com/vaadin/tests/components/table/Tables.java | 71 |
14 files changed, 578 insertions, 372 deletions
diff --git a/src/com/vaadin/data/validator/CompositeValidator.java b/src/com/vaadin/data/validator/CompositeValidator.java index 083af70f30..956d773032 100644 --- a/src/com/vaadin/data/validator/CompositeValidator.java +++ b/src/com/vaadin/data/validator/CompositeValidator.java @@ -155,7 +155,7 @@ public class CompositeValidator implements Validator { */ public void setMode(CombinationMode mode) { if (mode == null) { - throw new IllegalStateException( + throw new IllegalArgumentException( "The validator can't be set to null"); } this.mode = mode; diff --git a/src/com/vaadin/terminal/Sizeable.java b/src/com/vaadin/terminal/Sizeable.java index 055c74f20f..e3c98e0fa9 100644 --- a/src/com/vaadin/terminal/Sizeable.java +++ b/src/com/vaadin/terminal/Sizeable.java @@ -129,14 +129,14 @@ public interface Sizeable extends Serializable { public static Unit getUnitFromSymbol(String symbol) { if (symbol == null) { - return null; + return Unit.PIXELS; // Defaults to pixels } for (Unit unit : Unit.values()) { if (symbol.equals(unit.getSymbol())) { return unit; } } - return null; + return Unit.PIXELS; // Defaults to pixels } } diff --git a/src/com/vaadin/terminal/UserError.java b/src/com/vaadin/terminal/UserError.java index 1cb79c146a..8ec45ac725 100644 --- a/src/com/vaadin/terminal/UserError.java +++ b/src/com/vaadin/terminal/UserError.java @@ -89,6 +89,12 @@ public class UserError implements ErrorMessage { public UserError(String message, ContentMode contentMode, ErrorLevel errorLevel) { + if (contentMode == null) { + contentMode = ContentMode.TEXT; + } + if (errorLevel == null) { + errorLevel = ErrorLevel.ERROR; + } msg = message; mode = contentMode; level = errorLevel; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java index 074df531a8..f8397d4a39 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java @@ -22,16 +22,13 @@ import com.google.gwt.user.client.ui.FocusWidget; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -public class VButton extends FocusWidget implements VPaintableWidget, - ClickHandler, FocusHandler, BlurHandler { +public class VButton extends FocusWidget implements ClickHandler, FocusHandler, + BlurHandler { public static final String CLASSNAME = "v-button"; private static final String CLASSNAME_PRESSED = "v-pressed"; @@ -43,7 +40,7 @@ public class VButton extends FocusWidget implements VPaintableWidget, protected int mousedownX = 0; protected int mousedownY = 0; - protected String id; + protected String paintableId; protected ApplicationConnection client; @@ -66,7 +63,7 @@ public class VButton extends FocusWidget implements VPaintableWidget, private int tabIndex = 0; - private boolean disableOnClick = false; + protected boolean disableOnClick = false; /* * BELOW PRIVATE MEMBERS COPY-PASTED FROM GWT CustomButton @@ -89,10 +86,10 @@ public class VButton extends FocusWidget implements VPaintableWidget, private boolean disallowNextClick = false; private boolean isHovering; - private HandlerRegistration focusHandlerRegistration; - private HandlerRegistration blurHandlerRegistration; + protected HandlerRegistration focusHandlerRegistration; + protected HandlerRegistration blurHandlerRegistration; - private int clickShortcut = 0; + protected int clickShortcut = 0; public VButton() { super(DOM.createDiv()); @@ -114,59 +111,6 @@ public class VButton extends FocusWidget implements VPaintableWidget, addClickHandler(this); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - // Ensure correct implementation, - // but don't let container manage caption etc. - if (client.updateComponent(this, uidl, false)) { - return; - } - - focusHandlerRegistration = EventHelper.updateFocusHandler(this, client, - focusHandlerRegistration); - blurHandlerRegistration = EventHelper.updateBlurHandler(this, client, - blurHandlerRegistration); - - // Save details - this.client = client; - id = uidl.getId(); - - // Set text - setText(uidl.getStringAttribute("caption")); - - disableOnClick = uidl.hasAttribute(ATTR_DISABLE_ON_CLICK); - - // handle error - if (uidl.hasAttribute("error")) { - if (errorIndicatorElement == null) { - errorIndicatorElement = DOM.createSpan(); - errorIndicatorElement.setClassName("v-errorindicator"); - } - wrapper.insertBefore(errorIndicatorElement, captionElement); - - } else if (errorIndicatorElement != null) { - wrapper.removeChild(errorIndicatorElement); - errorIndicatorElement = null; - } - - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - wrapper.insertBefore(icon.getElement(), captionElement); - } - icon.setUri(uidl.getStringAttribute("icon")); - } else { - if (icon != null) { - wrapper.removeChild(icon.getElement()); - icon = null; - } - } - - if (uidl.hasAttribute("keycode")) { - clickShortcut = uidl.getIntAttribute("keycode"); - } - } - public void setText(String text) { captionElement.setInnerText(text); } @@ -187,7 +131,7 @@ public class VButton extends FocusWidget implements VPaintableWidget, */ public void onBrowserEvent(Event event) { if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } if (DOM.eventGetType(event) == Event.ONLOAD) { Util.notifyParentOfSizeChange(this, true); @@ -349,7 +293,7 @@ public class VButton extends FocusWidget implements VPaintableWidget, * .dom.client.ClickEvent) */ public void onClick(ClickEvent event) { - if (id == null || client == null) { + if (paintableId == null || client == null) { return; } if (BrowserInfo.get().isSafari()) { @@ -357,15 +301,16 @@ public class VButton extends FocusWidget implements VPaintableWidget, } if (disableOnClick) { setEnabled(false); - client.updateVariable(id, "disabledOnClick", true, false); + client.updateVariable(paintableId, "disabledOnClick", true, false); } - client.updateVariable(id, "state", true, false); + client.updateVariable(paintableId, "state", true, false); // Add mouse details MouseEventDetails details = new MouseEventDetails( event.getNativeEvent(), getElement()); - client.updateVariable(id, "mousedetails", details.serialize(), true); + client.updateVariable(paintableId, "mousedetails", details.serialize(), + true); clickPending = false; } @@ -499,11 +444,11 @@ public class VButton extends FocusWidget implements VPaintableWidget, }-*/; public void onFocus(FocusEvent arg0) { - client.updateVariable(id, EventId.FOCUS, "", true); + client.updateVariable(paintableId, EventId.FOCUS, "", true); } public void onBlur(BlurEvent arg0) { - client.updateVariable(id, EventId.BLUR, "", true); + client.updateVariable(paintableId, EventId.BLUR, "", true); } public Widget getWidgetForPaintable() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java new file mode 100644 index 0000000000..1367d412a8 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java @@ -0,0 +1,87 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.EventHelper; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VButtonPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + // Ensure correct implementation, + // but don't let container manage caption etc. + if (client.updateComponent(this, uidl, false)) { + return; + } + + getWidgetForPaintable().focusHandlerRegistration = EventHelper + .updateFocusHandler(this, client, + getWidgetForPaintable().focusHandlerRegistration); + getWidgetForPaintable().blurHandlerRegistration = EventHelper + .updateBlurHandler(this, client, + getWidgetForPaintable().blurHandlerRegistration); + + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + + // Set text + getWidgetForPaintable().setText(uidl.getStringAttribute("caption")); + + getWidgetForPaintable().disableOnClick = uidl + .hasAttribute(VButton.ATTR_DISABLE_ON_CLICK); + + // handle error + if (uidl.hasAttribute("error")) { + if (getWidgetForPaintable().errorIndicatorElement == null) { + getWidgetForPaintable().errorIndicatorElement = DOM + .createSpan(); + getWidgetForPaintable().errorIndicatorElement + .setClassName("v-errorindicator"); + } + getWidgetForPaintable().wrapper.insertBefore( + getWidgetForPaintable().errorIndicatorElement, + getWidgetForPaintable().captionElement); + + } else if (getWidgetForPaintable().errorIndicatorElement != null) { + getWidgetForPaintable().wrapper + .removeChild(getWidgetForPaintable().errorIndicatorElement); + getWidgetForPaintable().errorIndicatorElement = null; + } + + if (uidl.hasAttribute("icon")) { + if (getWidgetForPaintable().icon == null) { + getWidgetForPaintable().icon = new Icon(client); + getWidgetForPaintable().wrapper.insertBefore( + getWidgetForPaintable().icon.getElement(), + getWidgetForPaintable().captionElement); + } + getWidgetForPaintable().icon + .setUri(uidl.getStringAttribute("icon")); + } else { + if (getWidgetForPaintable().icon != null) { + getWidgetForPaintable().wrapper + .removeChild(getWidgetForPaintable().icon.getElement()); + getWidgetForPaintable().icon = null; + } + } + + if (uidl.hasAttribute("keycode")) { + getWidgetForPaintable().clickShortcut = uidl + .getIntAttribute("keycode"); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VButton.class); + } + + @Override + public VButton getWidgetForPaintable() { + return (VButton) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java index 97d0747496..9991769e46 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java @@ -18,22 +18,19 @@ import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -public class VNativeButton extends Button implements VPaintableWidget, - ClickHandler, FocusHandler, BlurHandler { +public class VNativeButton extends Button implements ClickHandler, + FocusHandler, BlurHandler { public static final String CLASSNAME = "v-nativebutton"; protected String width = null; - protected String id; + protected String paintableId; protected ApplicationConnection client; @@ -50,10 +47,10 @@ public class VNativeButton extends Button implements VPaintableWidget, */ private boolean clickPending; - private HandlerRegistration focusHandlerRegistration; - private HandlerRegistration blurHandlerRegistration; + protected HandlerRegistration focusHandlerRegistration; + protected HandlerRegistration blurHandlerRegistration; - private boolean disableOnClick = false; + protected boolean disableOnClick = false; public VNativeButton() { setStyleName(CLASSNAME); @@ -68,56 +65,6 @@ public class VNativeButton extends Button implements VPaintableWidget, sinkEvents(Event.ONMOUSEUP); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - // Ensure correct implementation, - // but don't let container manage caption etc. - if (client.updateComponent(this, uidl, false)) { - return; - } - - disableOnClick = uidl.hasAttribute(VButton.ATTR_DISABLE_ON_CLICK); - - focusHandlerRegistration = EventHelper.updateFocusHandler(this, client, - focusHandlerRegistration); - blurHandlerRegistration = EventHelper.updateBlurHandler(this, client, - blurHandlerRegistration); - - // Save details - this.client = client; - id = uidl.getId(); - - // Set text - setText(uidl.getStringAttribute("caption")); - - // handle error - if (uidl.hasAttribute("error")) { - if (errorIndicatorElement == null) { - errorIndicatorElement = DOM.createSpan(); - errorIndicatorElement.setClassName("v-errorindicator"); - } - getElement().insertBefore(errorIndicatorElement, captionElement); - - } else if (errorIndicatorElement != null) { - getElement().removeChild(errorIndicatorElement); - errorIndicatorElement = null; - } - - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - getElement().insertBefore(icon.getElement(), captionElement); - } - icon.setUri(uidl.getStringAttribute("icon")); - } else { - if (icon != null) { - getElement().removeChild(icon.getElement()); - icon = null; - } - } - - } - @Override public void setText(String text) { captionElement.setInnerText(text); @@ -143,7 +90,7 @@ public class VNativeButton extends Button implements VPaintableWidget, } if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } @@ -161,7 +108,7 @@ public class VNativeButton extends Button implements VPaintableWidget, * .dom.client.ClickEvent) */ public void onClick(ClickEvent event) { - if (id == null || client == null) { + if (paintableId == null || client == null) { return; } @@ -170,24 +117,25 @@ public class VNativeButton extends Button implements VPaintableWidget, } if (disableOnClick) { setEnabled(false); - client.updateVariable(id, "disabledOnClick", true, false); + client.updateVariable(paintableId, "disabledOnClick", true, false); } // Add mouse details MouseEventDetails details = new MouseEventDetails( event.getNativeEvent(), getElement()); - client.updateVariable(id, "mousedetails", details.serialize(), false); + client.updateVariable(paintableId, "mousedetails", details.serialize(), + false); - client.updateVariable(id, "state", true, true); + client.updateVariable(paintableId, "state", true, true); clickPending = false; } public void onFocus(FocusEvent arg0) { - client.updateVariable(id, EventId.FOCUS, "", true); + client.updateVariable(paintableId, EventId.FOCUS, "", true); } public void onBlur(BlurEvent arg0) { - client.updateVariable(id, EventId.BLUR, "", true); + client.updateVariable(paintableId, EventId.BLUR, "", true); } @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java new file mode 100644 index 0000000000..5e0dceea75 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java @@ -0,0 +1,83 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.EventHelper; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VNativeButtonPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + // Ensure correct implementation, + // but don't let container manage caption etc. + if (client.updateComponent(this, uidl, false)) { + return; + } + + getWidgetForPaintable().disableOnClick = uidl + .hasAttribute(VButton.ATTR_DISABLE_ON_CLICK); + + getWidgetForPaintable().focusHandlerRegistration = EventHelper + .updateFocusHandler(this, client, + getWidgetForPaintable().focusHandlerRegistration); + getWidgetForPaintable().blurHandlerRegistration = EventHelper + .updateBlurHandler(this, client, + getWidgetForPaintable().blurHandlerRegistration); + + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + + // Set text + getWidgetForPaintable().setText(uidl.getStringAttribute("caption")); + + // handle error + if (uidl.hasAttribute("error")) { + if (getWidgetForPaintable().errorIndicatorElement == null) { + getWidgetForPaintable().errorIndicatorElement = DOM + .createSpan(); + getWidgetForPaintable().errorIndicatorElement + .setClassName("v-errorindicator"); + } + getWidgetForPaintable().getElement().insertBefore( + getWidgetForPaintable().errorIndicatorElement, + getWidgetForPaintable().captionElement); + + } else if (getWidgetForPaintable().errorIndicatorElement != null) { + getWidgetForPaintable().getElement().removeChild( + getWidgetForPaintable().errorIndicatorElement); + getWidgetForPaintable().errorIndicatorElement = null; + } + + if (uidl.hasAttribute("icon")) { + if (getWidgetForPaintable().icon == null) { + getWidgetForPaintable().icon = new Icon(client); + getWidgetForPaintable().getElement().insertBefore( + getWidgetForPaintable().icon.getElement(), + getWidgetForPaintable().captionElement); + } + getWidgetForPaintable().icon + .setUri(uidl.getStringAttribute("icon")); + } else { + if (getWidgetForPaintable().icon != null) { + getWidgetForPaintable().getElement().removeChild( + getWidgetForPaintable().icon.getElement()); + getWidgetForPaintable().icon = null; + } + } + + } + + @Override + protected Widget createWidget() { + return GWT.create(VNativeButton.class); + } + + @Override + public VNativeButton getWidgetForPaintable() { + return (VNativeButton) super.getWidgetForPaintable(); + } +}
\ No newline at end of file diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 4b9449c598..026b64299a 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -1324,9 +1324,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource /* * (non-Javadoc) * - * @see com.vaadin.terminal.Sizeable#setHeight(float, int) + * @see com.vaadin.terminal.Sizeable#setHeight(float, Unit) */ public void setHeight(float height, Unit unit) { + if (unit == null) { + throw new IllegalArgumentException("Unit can not be null"); + } this.height = height; heightUnit = unit; requestRepaint(); @@ -1356,9 +1359,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource /* * (non-Javadoc) * - * @see com.vaadin.terminal.Sizeable#setWidth(float, int) + * @see com.vaadin.terminal.Sizeable#setWidth(float, Unit) */ public void setWidth(float width, Unit unit) { + if (unit == null) { + throw new IllegalArgumentException("Unit can not be null"); + } this.width = width; widthUnit = unit; requestRepaint(); diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index b65cb61450..5e086f0b8d 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -61,41 +61,85 @@ public abstract class AbstractSelect extends AbstractField<Object> implements Container.PropertySetChangeNotifier, Container.ItemSetChangeNotifier, Container.ItemSetChangeListener { + public enum ItemCaptionMode { + /** + * Item caption mode: Item's ID's <code>String</code> representation is + * used as caption. + */ + ID, + /** + * Item caption mode: Item's <code>String</code> representation is used + * as caption. + */ + ITEM, + /** + * Item caption mode: Index of the item is used as caption. The index + * mode can only be used with the containers implementing the + * {@link com.vaadin.data.Container.Indexed} interface. + */ + INDEX, + /** + * Item caption mode: If an Item has a caption it's used, if not, Item's + * ID's <code>String</code> representation is used as caption. <b>This + * is the default</b>. + */ + EXPLICIT_DEFAULTS_ID, + /** + * Item caption mode: Captions must be explicitly specified. + */ + EXPLICIT, + /** + * Item caption mode: Only icons are shown, captions are hidden. + */ + ICON_ONLY, + /** + * Item caption mode: Item captions are read from property specified + * with <code>setItemCaptionPropertyId</code>. + */ + PROPERTY; + } + /** - * Item caption mode: Item's ID's <code>String</code> representation is used - * as caption. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_ID = 0; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_ID = ItemCaptionMode.ID; + /** - * Item caption mode: Item's <code>String</code> representation is used as - * caption. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_ITEM = 1; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_ITEM = ItemCaptionMode.ITEM; + /** - * Item caption mode: Index of the item is used as caption. The index mode - * can only be used with the containers implementing the - * {@link com.vaadin.data.Container.Indexed} interface. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_INDEX = 2; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_INDEX = ItemCaptionMode.INDEX; + /** - * Item caption mode: If an Item has a caption it's used, if not, Item's - * ID's <code>String</code> representation is used as caption. <b>This is - * the default</b>. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID = 3; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID = ItemCaptionMode.EXPLICIT_DEFAULTS_ID; + /** - * Item caption mode: Captions must be explicitly specified. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_EXPLICIT = 4; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_EXPLICIT = ItemCaptionMode.EXPLICIT; + /** - * Item caption mode: Only icons are shown, captions are hidden. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_ICON_ONLY = 5; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_ICON_ONLY = ItemCaptionMode.ICON_ONLY; + /** - * Item caption mode: Item captions are read from property specified with - * <code>setItemCaptionPropertyId</code>. + * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead */ - public static final int ITEM_CAPTION_MODE_PROPERTY = 6; + @Deprecated + public static final ItemCaptionMode ITEM_CAPTION_MODE_PROPERTY = ItemCaptionMode.PROPERTY; /** * Interface for option filtering, used to filter options based on user @@ -175,7 +219,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements /** * Item caption mode. */ - private int itemCaptionMode = ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID; + private ItemCaptionMode itemCaptionMode = ItemCaptionMode.EXPLICIT_DEFAULTS_ID; /** * Item caption source property id. @@ -1038,11 +1082,11 @@ public abstract class AbstractSelect extends AbstractField<Object> implements switch (getItemCaptionMode()) { - case ITEM_CAPTION_MODE_ID: + case ID: caption = itemId.toString(); break; - case ITEM_CAPTION_MODE_INDEX: + case INDEX: if (items instanceof Container.Indexed) { caption = String.valueOf(((Container.Indexed) items) .indexOfId(itemId)); @@ -1051,25 +1095,25 @@ public abstract class AbstractSelect extends AbstractField<Object> implements } break; - case ITEM_CAPTION_MODE_ITEM: + case ITEM: final Item i = getItem(itemId); if (i != null) { caption = i.toString(); } break; - case ITEM_CAPTION_MODE_EXPLICIT: + case EXPLICIT: caption = itemCaptions.get(itemId); break; - case ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID: + case EXPLICIT_DEFAULTS_ID: caption = itemCaptions.get(itemId); if (caption == null) { caption = itemId.toString(); } break; - case ITEM_CAPTION_MODE_PROPERTY: + case PROPERTY: final Property<?> p = getContainerProperty(itemId, getItemCaptionPropertyId()); if (p != null) { @@ -1086,7 +1130,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements } /** - * Sets the icon for an item. + * Sets tqhe icon for an item. * * @param itemId * the id of the item to be assigned an icon. @@ -1163,8 +1207,8 @@ public abstract class AbstractSelect extends AbstractField<Object> implements * @param mode * the One of the modes listed above. */ - public void setItemCaptionMode(int mode) { - if (ITEM_CAPTION_MODE_ID <= mode && mode <= ITEM_CAPTION_MODE_PROPERTY) { + public void setItemCaptionMode(ItemCaptionMode mode) { + if (mode != null) { itemCaptionMode = mode; requestRepaint(); } @@ -1198,7 +1242,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements * * @return the One of the modes listed above. */ - public int getItemCaptionMode() { + public ItemCaptionMode getItemCaptionMode() { return itemCaptionMode; } @@ -1689,7 +1733,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements public void addNotifierForItem(Object itemId) { switch (getItemCaptionMode()) { - case ITEM_CAPTION_MODE_ITEM: + case ITEM: final Item i = getItem(itemId); if (i == null) { return; @@ -1713,7 +1757,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements } break; - case ITEM_CAPTION_MODE_PROPERTY: + case PROPERTY: final Property<?> p = getContainerProperty(itemId, getItemCaptionPropertyId()); if (p != null && p instanceof Property.ValueChangeNotifier) { diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 6d9ef0b59d..8f677a9775 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -23,6 +23,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VButton; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable; import com.vaadin.tools.ReflectTools; import com.vaadin.ui.ClientWidget.LoadStyle; import com.vaadin.ui.Component.Focusable; @@ -36,7 +37,7 @@ import com.vaadin.ui.Component.Focusable; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(value = VButton.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VButtonPaintable.class, loadStyle = LoadStyle.EAGER) public class Button extends AbstractComponent implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, Focusable, Action.ShortcutNotifier { diff --git a/src/com/vaadin/ui/NativeButton.java b/src/com/vaadin/ui/NativeButton.java index 46d13c4150..b7b7fcb38c 100644 --- a/src/com/vaadin/ui/NativeButton.java +++ b/src/com/vaadin/ui/NativeButton.java @@ -3,10 +3,10 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VNativeButton; +import com.vaadin.terminal.gwt.client.ui.VNativeButtonPaintable; @SuppressWarnings("serial") -@ClientWidget(VNativeButton.class) +@ClientWidget(VNativeButtonPaintable.class) public class NativeButton extends Button { public NativeButton() { diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 6a946560cf..003ef6978c 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -116,91 +116,215 @@ public class Table extends AbstractSelect implements Action.Container, protected static final int CELL_FIRSTCOL = 5; + public enum Align { + /** + * Left column alignment. <b>This is the default behaviour. </b> + */ + LEFT("b"), + + /** + * Center column alignment. + */ + CENTER("c"), + + /** + * Right column alignment. + */ + RIGHT("e"); + + private String alignment; + + private Align(String alignment) { + this.alignment = alignment; + } + + @Override + public String toString() { + return alignment; + } + + public Align convertStringToAlign(String string) { + if (string == null) { + return null; + } + if (string.equals("b")) { + return Align.LEFT; + } else if (string.equals("c")) { + return Align.CENTER; + } else if (string.equals("e")) { + return Align.RIGHT; + } else { + return null; + } + } + } + /** - * Left column alignment. <b>This is the default behaviour. </b> + * @deprecated from 7.0, use {@link Align#LEFT} instead */ - public static final String ALIGN_LEFT = "b"; + @Deprecated + public static final Align ALIGN_LEFT = Align.LEFT; /** - * Center column alignment. + * @deprecated from 7.0, use {@link Align#CENTER} instead */ - public static final String ALIGN_CENTER = "c"; + @Deprecated + public static final Align ALIGN_CENTER = Align.CENTER; /** - * Right column alignment. + * @deprecated from 7.0, use {@link Align#RIGHT} instead */ - public static final String ALIGN_RIGHT = "e"; + @Deprecated + public static final Align ALIGN_RIGHT = Align.RIGHT; + + public enum ColumnHeaderMode { + /** + * Column headers are hidden. + */ + HIDDEN, + /** + * Property ID:s are used as column headers. + */ + ID, + /** + * Column headers are explicitly specified with + * {@link #setColumnHeaders(String[])}. + */ + EXPLICIT, + /** + * Column headers are explicitly specified with + * {@link #setColumnHeaders(String[])}. If a header is not specified for + * a given property, its property id is used instead. + * <p> + * <b>This is the default behavior. </b> + */ + EXPLICIT_DEFAULTS_ID + } /** - * Column header mode: Column headers are hidden. + * @deprecated from 7.0, use {@link ColumnHeaderMode#HIDDEN} instead */ - public static final int COLUMN_HEADER_MODE_HIDDEN = -1; + @Deprecated + public static final ColumnHeaderMode COLUMN_HEADER_MODE_HIDDEN = ColumnHeaderMode.HIDDEN; /** - * Column header mode: Property ID:s are used as column headers. + * @deprecated from 7.0, use {@link ColumnHeaderMode#ID} instead */ - public static final int COLUMN_HEADER_MODE_ID = 0; + @Deprecated + public static final ColumnHeaderMode COLUMN_HEADER_MODE_ID = ColumnHeaderMode.ID; /** - * Column header mode: Column headers are explicitly specified with - * {@link #setColumnHeaders(String[])}. + * @deprecated from 7.0, use {@link ColumnHeaderMode#EXPLICIT} instead */ - public static final int COLUMN_HEADER_MODE_EXPLICIT = 1; + @Deprecated + public static final ColumnHeaderMode COLUMN_HEADER_MODE_EXPLICIT = ColumnHeaderMode.EXPLICIT; /** - * Column header mode: Column headers are explicitly specified with - * {@link #setColumnHeaders(String[])}. If a header is not specified for a - * given property, its property id is used instead. - * <p> - * <b>This is the default behavior. </b> + * @deprecated from 7.0, use {@link ColumnHeaderMode#EXPLICIT_DEFAULTS_ID} + * instead */ - public static final int COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID = 2; + @Deprecated + public static final ColumnHeaderMode COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID = ColumnHeaderMode.EXPLICIT_DEFAULTS_ID; + + public enum RowHeaderMode { + /** + * Row caption mode: The row headers are hidden. <b>This is the default + * mode. </b> + */ + HIDDEN(null), + /** + * Row caption mode: Items Id-objects toString is used as row caption. + */ + ID(ItemCaptionMode.ID), + /** + * Row caption mode: Item-objects toString is used as row caption. + */ + ITEM(ItemCaptionMode.ITEM), + /** + * Row caption mode: Index of the item is used as item caption. The + * index mode can only be used with the containers implementing the + * {@link com.vaadin.data.Container.Indexed} interface. + */ + INDEX(ItemCaptionMode.INDEX), + /** + * Row caption mode: Item captions are explicitly specified, but if the + * caption is missing, the item id objects <code>toString()</code> is + * used instead. + */ + EXPLICIT_DEFAULTS_ID(ItemCaptionMode.EXPLICIT_DEFAULTS_ID), + /** + * Row caption mode: Item captions are explicitly specified. + */ + EXPLICIT(ItemCaptionMode.EXPLICIT), + /** + * Row caption mode: Only icons are shown, the captions are hidden. + */ + ICON_ONLY(ItemCaptionMode.ICON_ONLY), + /** + * Row caption mode: Item captions are read from property specified with + * {@link #setItemCaptionPropertyId(Object)}. + */ + PROPERTY(ItemCaptionMode.PROPERTY); + + ItemCaptionMode mode; + + private RowHeaderMode(ItemCaptionMode mode) { + this.mode = mode; + } + + public ItemCaptionMode getItemCaptionMode() { + return mode; + } + } /** - * Row caption mode: The row headers are hidden. <b>This is the default - * mode. </b> + * @deprecated from 7.0, use {@link RowHeaderMode#HIDDEN} instead */ - public static final int ROW_HEADER_MODE_HIDDEN = -1; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_HIDDEN = RowHeaderMode.HIDDEN; /** - * Row caption mode: Items Id-objects toString is used as row caption. + * @deprecated from 7.0, use {@link RowHeaderMode#ID} instead */ - public static final int ROW_HEADER_MODE_ID = AbstractSelect.ITEM_CAPTION_MODE_ID; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_ID = RowHeaderMode.ID; /** - * Row caption mode: Item-objects toString is used as row caption. + * @deprecated from 7.0, use {@link RowHeaderMode#ITEM} instead */ - public static final int ROW_HEADER_MODE_ITEM = AbstractSelect.ITEM_CAPTION_MODE_ITEM; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_ITEM = RowHeaderMode.ITEM; /** - * Row caption mode: Index of the item is used as item caption. The index - * mode can only be used with the containers implementing Container.Indexed - * interface. + * @deprecated from 7.0, use {@link RowHeaderMode#INDEX} instead */ - public static final int ROW_HEADER_MODE_INDEX = AbstractSelect.ITEM_CAPTION_MODE_INDEX; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_INDEX = RowHeaderMode.INDEX; /** - * Row caption mode: Item captions are explicitly specified. + * @deprecated from 7.0, use {@link RowHeaderMode#EXPLICIT_DEFAULTS_ID} + * instead */ - public static final int ROW_HEADER_MODE_EXPLICIT = AbstractSelect.ITEM_CAPTION_MODE_EXPLICIT; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID = RowHeaderMode.EXPLICIT_DEFAULTS_ID; /** - * Row caption mode: Item captions are read from property specified with - * {@link #setItemCaptionPropertyId(Object)}. + * @deprecated from 7.0, use {@link RowHeaderMode#EXPLICIT} instead */ - public static final int ROW_HEADER_MODE_PROPERTY = AbstractSelect.ITEM_CAPTION_MODE_PROPERTY; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_EXPLICIT = RowHeaderMode.EXPLICIT; /** - * Row caption mode: Only icons are shown, the captions are hidden. + * @deprecated from 7.0, use {@link RowHeaderMode#ICON_ONLY} instead */ - public static final int ROW_HEADER_MODE_ICON_ONLY = AbstractSelect.ITEM_CAPTION_MODE_ICON_ONLY; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_ICON_ONLY = RowHeaderMode.ICON_ONLY; /** - * Row caption mode: Item captions are explicitly specified, but if the - * caption is missing, the item id objects <code>toString()</code> is used - * instead. + * @deprecated from 7.0, use {@link RowHeaderMode#PROPERTY} instead */ - public static final int ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID = AbstractSelect.ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID; + @Deprecated + public static final RowHeaderMode ROW_HEADER_MODE_PROPERTY = RowHeaderMode.PROPERTY; /** * The default rate that table caches rows for smooth scrolling. @@ -255,7 +379,7 @@ public class Table extends AbstractSelect implements Action.Container, /** * Holds alignments for visible columns (by propertyId). */ - private HashMap<Object, String> columnAlignments = new HashMap<Object, String>(); + private HashMap<Object, Align> columnAlignments = new HashMap<Object, Align>(); /** * Holds column widths in pixels (Integer) or expand ratios (Float) for @@ -291,17 +415,17 @@ public class Table extends AbstractSelect implements Action.Container, /** * Holds value of property columnHeaderMode. */ - private int columnHeaderMode = COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID; + private ColumnHeaderMode columnHeaderMode = ColumnHeaderMode.EXPLICIT_DEFAULTS_ID; /** - * Should the Table footer be visible? + * Holds value of property rowHeaderMode. */ - private boolean columnFootersVisible = false; + private RowHeaderMode rowHeaderMode = RowHeaderMode.EXPLICIT_DEFAULTS_ID; /** - * True iff the row captions are hidden. + * Should the Table footer be visible? */ - private boolean rowCaptionsAreHidden = true; + private boolean columnFootersVisible = false; /** * Page contents buffer used in buffered mode. @@ -513,7 +637,7 @@ public class Table extends AbstractSelect implements Action.Container, final Object col = i.next(); if (!newVC.contains(col)) { setColumnHeader(col, null); - setColumnAlignment(col, null); + setColumnAlignment(col, (Align) null); setColumnIcon(col, null); } } @@ -657,21 +781,21 @@ public class Table extends AbstractSelect implements Action.Container, * {@link #getVisibleColumns()}. The possible values for the alignments * include: * <ul> - * <li>{@link #ALIGN_LEFT}: Left alignment</li> - * <li>{@link #ALIGN_CENTER}: Centered</li> - * <li>{@link #ALIGN_RIGHT}: Right alignment</li> + * <li>{@link Align#LEFT}: Left alignment</li> + * <li>{@link Align#CENTER}: Centered</li> + * <li>{@link Align#RIGHT}: Right alignment</li> * </ul> - * The alignments default to {@link #ALIGN_LEFT}: any null values are + * The alignments default to {@link Align#LEFT}: any null values are * rendered as align lefts. * </p> * * @return the Column alignments array. */ - public String[] getColumnAlignments() { + public Align[] getColumnAlignments() { if (columnAlignments == null) { return null; } - final String[] alignments = new String[visibleColumns.size()]; + final Align[] alignments = new Align[visibleColumns.size()]; int i = 0; for (final Iterator<Object> it = visibleColumns.iterator(); it .hasNext(); i++) { @@ -685,39 +809,29 @@ public class Table extends AbstractSelect implements Action.Container, * Sets the column alignments. * * <p> - * The items in the array must match the properties identified by - * {@link #getVisibleColumns()}. The possible values for the alignments - * include: + * The amount of items in the array must match the amount of properties + * identified by {@link #getVisibleColumns()}. The possible values for the + * alignments include: * <ul> - * <li>{@link #ALIGN_LEFT}: Left alignment</li> - * <li>{@link #ALIGN_CENTER}: Centered</li> - * <li>{@link #ALIGN_RIGHT}: Right alignment</li> + * <li>{@link Align#LEFT}: Left alignment</li> + * <li>{@link Align#CENTER}: Centered</li> + * <li>{@link Align#RIGHT}: Right alignment</li> * </ul> - * The alignments default to {@link #ALIGN_LEFT} + * The alignments default to {@link Align#LEFT} * </p> * * @param columnAlignments * the Column alignments array. */ - public void setColumnAlignments(String[] columnAlignments) { + public void setColumnAlignments(Align... columnAlignments) { if (columnAlignments.length != visibleColumns.size()) { throw new IllegalArgumentException( "The length of the alignments array must match the number of visible columns"); } - // Checks all alignments - for (int i = 0; i < columnAlignments.length; i++) { - final String a = columnAlignments[i]; - if (a != null && !a.equals(ALIGN_LEFT) && !a.equals(ALIGN_CENTER) - && !a.equals(ALIGN_RIGHT)) { - throw new IllegalArgumentException("Column " + i - + " aligment '" + a + "' is invalid"); - } - } - // Resets the alignments - final HashMap<Object, String> newCA = new HashMap<Object, String>(); + final HashMap<Object, Align> newCA = new HashMap<Object, Align>(); int i = 0; for (final Iterator<Object> it = visibleColumns.iterator(); it .hasNext() && i < columnAlignments.length; i++) { @@ -1035,13 +1149,13 @@ public class Table extends AbstractSelect implements Action.Container, * @return the header for the specified column if it has one. */ public String getColumnHeader(Object propertyId) { - if (getColumnHeaderMode() == COLUMN_HEADER_MODE_HIDDEN) { + if (getColumnHeaderMode() == ColumnHeaderMode.HIDDEN) { return null; } String header = columnHeaders.get(propertyId); - if ((header == null && getColumnHeaderMode() == COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID) - || getColumnHeaderMode() == COLUMN_HEADER_MODE_ID) { + if ((header == null && getColumnHeaderMode() == ColumnHeaderMode.EXPLICIT_DEFAULTS_ID) + || getColumnHeaderMode() == ColumnHeaderMode.ID) { header = propertyId.toString(); } @@ -1074,9 +1188,9 @@ public class Table extends AbstractSelect implements Action.Container, * the propertyID identifying the column. * @return the specified column's alignment if it as one; null otherwise. */ - public String getColumnAlignment(Object propertyId) { - final String a = columnAlignments.get(propertyId); - return a == null ? ALIGN_LEFT : a; + public Align getColumnAlignment(Object propertyId) { + final Align a = columnAlignments.get(propertyId); + return a == null ? Align.LEFT : a; } /** @@ -1084,8 +1198,8 @@ public class Table extends AbstractSelect implements Action.Container, * * <p> * Throws IllegalArgumentException if the alignment is not one of the - * following: {@link #ALIGN_LEFT}, {@link #ALIGN_CENTER} or - * {@link #ALIGN_RIGHT} + * following: {@link Align#LEFT}, {@link Align#CENTER} or + * {@link Align#RIGHT} * </p> * * @param propertyId @@ -1093,17 +1207,8 @@ public class Table extends AbstractSelect implements Action.Container, * @param alignment * the desired alignment. */ - public void setColumnAlignment(Object propertyId, String alignment) { - - // Checks for valid alignments - if (alignment != null && !alignment.equals(ALIGN_LEFT) - && !alignment.equals(ALIGN_CENTER) - && !alignment.equals(ALIGN_RIGHT)) { - throw new IllegalArgumentException("Column alignment '" + alignment - + "' is not supported."); - } - - if (alignment == null || alignment.equals(ALIGN_LEFT)) { + public void setColumnAlignment(Object propertyId, Align alignment) { + if (alignment == null || alignment == Align.LEFT) { columnAlignments.remove(propertyId); } else { columnAlignments.put(propertyId, alignment); @@ -1398,7 +1503,7 @@ public class Table extends AbstractSelect implements Action.Container, * * @return the Value of property columnHeaderMode. */ - public int getColumnHeaderMode() { + public ColumnHeaderMode getColumnHeaderMode() { return columnHeaderMode; } @@ -1408,10 +1513,12 @@ public class Table extends AbstractSelect implements Action.Container, * @param columnHeaderMode * the New value of property columnHeaderMode. */ - public void setColumnHeaderMode(int columnHeaderMode) { - if (columnHeaderMode != this.columnHeaderMode - && columnHeaderMode >= COLUMN_HEADER_MODE_HIDDEN - && columnHeaderMode <= COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID) { + public void setColumnHeaderMode(ColumnHeaderMode columnHeaderMode) { + if (columnHeaderMode == null) { + throw new IllegalArgumentException( + "Column header mode can not be null"); + } + if (columnHeaderMode != this.columnHeaderMode) { this.columnHeaderMode = columnHeaderMode; requestRepaint(); } @@ -1751,7 +1858,7 @@ public class Table extends AbstractSelect implements Action.Container, } } - final int headmode = getRowHeaderMode(); + final RowHeaderMode headmode = getRowHeaderMode(); final boolean[] iscomponent = new boolean[cols]; for (int i = 0; i < cols; i++) { iscomponent[i] = columnGenerators.containsKey(colids[i]) @@ -1772,7 +1879,7 @@ public class Table extends AbstractSelect implements Action.Container, cells[CELL_KEY][i] = itemIdMapper.key(id); if (headmode != ROW_HEADER_MODE_HIDDEN) { switch (headmode) { - case ROW_HEADER_MODE_INDEX: + case INDEX: cells[CELL_HEADER][i] = String.valueOf(i + firstIndex + 1); break; default: @@ -2071,17 +2178,17 @@ public class Table extends AbstractSelect implements Action.Container, * @param mode * the One of the modes listed above. */ - public void setRowHeaderMode(int mode) { - if (ROW_HEADER_MODE_HIDDEN == mode) { - rowCaptionsAreHidden = true; - } else { - rowCaptionsAreHidden = false; - setItemCaptionMode(mode); + public void setRowHeaderMode(RowHeaderMode mode) { + if (mode != null) { + rowHeaderMode = mode; + if (mode != RowHeaderMode.HIDDEN) { + setItemCaptionMode(mode.getItemCaptionMode()); + } + // Assures the visual refresh. No need to reset the page buffer + // before + // as the content has not changed, only the alignments. + refreshRenderedCells(); } - - // Assures the visual refresh. No need to reset the page buffer before - // as the content has not changed, only the alignments. - refreshRenderedCells(); } /** @@ -2090,9 +2197,8 @@ public class Table extends AbstractSelect implements Action.Container, * @return the Row header mode. * @see #setRowHeaderMode(int) */ - public int getRowHeaderMode() { - return rowCaptionsAreHidden ? ROW_HEADER_MODE_HIDDEN - : getItemCaptionMode(); + public RowHeaderMode getRowHeaderMode() { + return rowHeaderMode; } /** @@ -2929,7 +3035,7 @@ public class Table extends AbstractSelect implements Action.Container, } private boolean areColumnHeadersEnabled() { - return getColumnHeaderMode() != COLUMN_HEADER_MODE_HIDDEN; + return getColumnHeaderMode() != ColumnHeaderMode.HIDDEN; } private void paintVisibleColumns(PaintTarget target) throws PaintException { @@ -2960,8 +3066,9 @@ public class Table extends AbstractSelect implements Action.Container, target.addAttribute("sortable", true); } } - if (!ALIGN_LEFT.equals(getColumnAlignment(colId))) { - target.addAttribute("align", getColumnAlignment(colId)); + if (!Align.LEFT.equals(getColumnAlignment(colId))) { + target.addAttribute("align", getColumnAlignment(colId) + .toString()); } paintColumnWidth(target, colId); target.endTag("column"); @@ -3725,7 +3832,7 @@ public class Table extends AbstractSelect implements Action.Container, */ public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue, String columnHeader, Resource columnIcon, - String columnAlignment) throws UnsupportedOperationException { + Align columnAlignment) throws UnsupportedOperationException { if (!this.addContainerProperty(propertyId, type, defaultValue)) { return false; } diff --git a/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java b/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java index 04f436f5c4..299f9c79d4 100644 --- a/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java +++ b/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertArrayEquals; import org.junit.Test; import com.vaadin.ui.Table; +import com.vaadin.ui.Table.Align; public class TableColumnAlignments { @@ -15,7 +16,7 @@ public class TableColumnAlignments { properties, 10); Object[] expected = new Object[properties]; for (int i = 0; i < properties; i++) { - expected[i] = Table.ALIGN_LEFT; + expected[i] = Align.LEFT; } org.junit.Assert.assertArrayEquals("getColumnAlignments", expected, t.getColumnAlignments()); @@ -27,9 +28,8 @@ public class TableColumnAlignments { int properties = 5; Table t = TableGenerator .createTableWithDefaultContainer(properties, 10); - String[] explicitAlignments = new String[] { Table.ALIGN_CENTER, - Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT, - Table.ALIGN_LEFT }; + Align[] explicitAlignments = new Align[] { Align.CENTER, Align.LEFT, + Align.RIGHT, Align.RIGHT, Align.LEFT }; t.setColumnAlignments(explicitAlignments); @@ -40,28 +40,10 @@ public class TableColumnAlignments { @Test public void invalidColumnAlignmentStrings() { Table t = TableGenerator.createTableWithDefaultContainer(3, 7); - String[] defaultAlignments = new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT }; + Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT, + Align.LEFT }; try { - t.setColumnAlignments(new String[] { "a", "b", "c" }); - junit.framework.Assert - .fail("No exception thrown for invalid array length"); - } catch (IllegalArgumentException e) { - // Ok, expected - } - - assertArrayEquals("Invalid change affected alignments", - defaultAlignments, t.getColumnAlignments()); - - } - - @Test - public void invalidColumnAlignmentString() { - Table t = TableGenerator.createTableWithDefaultContainer(3, 7); - String[] defaultAlignments = new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT }; - try { - t.setColumnAlignment("Property 1", "a"); + t.setColumnAlignments(new Align[] { Align.RIGHT, Align.RIGHT }); junit.framework.Assert .fail("No exception thrown for invalid array length"); } catch (IllegalArgumentException e) { @@ -76,10 +58,10 @@ public class TableColumnAlignments { @Test public void columnAlignmentForPropertyNotInContainer() { Table t = TableGenerator.createTableWithDefaultContainer(3, 7); - String[] defaultAlignments = new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT }; + Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT, + Align.LEFT }; try { - t.setColumnAlignment("Property 1200", Table.ALIGN_LEFT); + t.setColumnAlignment("Property 1200", Align.LEFT); // FIXME: Uncomment as there should be an exception (#6475) // junit.framework.Assert // .fail("No exception thrown for property not in container"); @@ -100,12 +82,11 @@ public class TableColumnAlignments { @Test public void invalidColumnAlignmentsLength() { Table t = TableGenerator.createTableWithDefaultContainer(7, 7); - String[] defaultAlignments = new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT }; + Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT, + Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT }; try { - t.setColumnAlignments(new String[] { Table.ALIGN_LEFT }); + t.setColumnAlignments(new Align[] { Align.LEFT }); junit.framework.Assert .fail("No exception thrown for invalid array length"); } catch (IllegalArgumentException e) { @@ -115,7 +96,7 @@ public class TableColumnAlignments { defaultAlignments, t.getColumnAlignments()); try { - t.setColumnAlignments(new String[] {}); + t.setColumnAlignments(new Align[] {}); junit.framework.Assert .fail("No exception thrown for invalid array length"); } catch (IllegalArgumentException e) { @@ -125,10 +106,9 @@ public class TableColumnAlignments { defaultAlignments, t.getColumnAlignments()); try { - t.setColumnAlignments(new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT, - Table.ALIGN_LEFT }); + t.setColumnAlignments(new Align[] { Align.LEFT, Align.LEFT, + Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT, + Align.LEFT }); junit.framework.Assert .fail("No exception thrown for invalid array length"); } catch (IllegalArgumentException e) { @@ -144,13 +124,11 @@ public class TableColumnAlignments { int properties = 5; Table t = TableGenerator .createTableWithDefaultContainer(properties, 10); - String[] explicitAlignments = new String[] { Table.ALIGN_CENTER, - Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT, - Table.ALIGN_LEFT }; + Align[] explicitAlignments = new Align[] { Align.CENTER, Align.LEFT, + Align.RIGHT, Align.RIGHT, Align.LEFT }; - String[] currentAlignments = new String[] { Table.ALIGN_LEFT, - Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT, - Table.ALIGN_LEFT }; + Align[] currentAlignments = new Align[] { Align.LEFT, Align.LEFT, + Align.LEFT, Align.LEFT, Align.LEFT }; for (int i = 0; i < properties; i++) { t.setColumnAlignment("Property " + i, explicitAlignments[i]); diff --git a/tests/testbench/com/vaadin/tests/components/table/Tables.java b/tests/testbench/com/vaadin/tests/components/table/Tables.java index afdf72bb83..3b13c9136b 100644 --- a/tests/testbench/com/vaadin/tests/components/table/Tables.java +++ b/tests/testbench/com/vaadin/tests/components/table/Tables.java @@ -15,8 +15,10 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Label;
import com.vaadin.ui.Label.ContentMode;
import com.vaadin.ui.Table;
+import com.vaadin.ui.Table.Align;
import com.vaadin.ui.Table.CellStyleGenerator;
import com.vaadin.ui.Table.ColumnGenerator;
+import com.vaadin.ui.Table.ColumnHeaderMode;
import com.vaadin.ui.Table.ColumnResizeEvent;
import com.vaadin.ui.Table.ColumnResizeListener;
import com.vaadin.ui.Table.FooterClickEvent;
@@ -25,6 +27,7 @@ import com.vaadin.ui.Table.GeneratedRow; import com.vaadin.ui.Table.HeaderClickEvent;
import com.vaadin.ui.Table.HeaderClickListener;
import com.vaadin.ui.Table.RowGenerator;
+import com.vaadin.ui.Table.RowHeaderMode;
public class Tables<T extends Table> extends AbstractSelectTestCase<T>
implements ItemClickListener, HeaderClickListener, FooterClickListener,
@@ -42,9 +45,9 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
/* COMMANDS */
- private Command<T, String> columnAlignmentCommand = new Command<T, String>() {
+ private Command<T, Align> columnAlignmentCommand = new Command<T, Align>() {
- public void execute(T c, String alignment, Object propertyId) {
+ public void execute(T c, Align alignment, Object propertyId) {
c.setColumnAlignment(propertyId, alignment);
}
@@ -108,10 +111,10 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
};
- protected Command<T, Integer> rowHeaderModeCommand = new Command<T, Integer>() {
+ protected Command<T, RowHeaderMode> rowHeaderModeCommand = new Command<T, RowHeaderMode>() {
- public void execute(Table c, Integer value, Object data) {
- if (value == Table.ROW_HEADER_MODE_PROPERTY) {
+ public void execute(Table c, RowHeaderMode value, Object data) {
+ if (value == RowHeaderMode.PROPERTY) {
c.setItemCaptionPropertyId("Property 3");
}
c.setRowHeaderMode(value);
@@ -135,7 +138,7 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> protected Command<T, Object> alignColumnLeftCommand = new Command<T, Object>() {
public void execute(T c, Object propertyId, Object data) {
- c.setColumnAlignment(propertyId, (String) data);
+ c.setColumnAlignment(propertyId, (Align) data);
}
};
@@ -174,9 +177,9 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
};
- private Command<T, Integer> columnHeaderModeCommand = new Command<T, Integer>() {
+ private Command<T, ColumnHeaderMode> columnHeaderModeCommand = new Command<T, ColumnHeaderMode>() {
- public void execute(T c, Integer columnHeaderMode, Object data) {
+ public void execute(T c, ColumnHeaderMode columnHeaderMode, Object data) {
c.setColumnHeaderMode(columnHeaderMode);
}
@@ -477,13 +480,12 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
private void createColumnHeaderMode(String category) {
- LinkedHashMap<String, Integer> columnHeaderModeOptions = new LinkedHashMap<String, Integer>();
- columnHeaderModeOptions.put("Hidden", Table.COLUMN_HEADER_MODE_HIDDEN);
- columnHeaderModeOptions.put("Id", Table.COLUMN_HEADER_MODE_ID);
- columnHeaderModeOptions.put("Explicit",
- Table.COLUMN_HEADER_MODE_EXPLICIT);
+ LinkedHashMap<String, ColumnHeaderMode> columnHeaderModeOptions = new LinkedHashMap<String, ColumnHeaderMode>();
+ columnHeaderModeOptions.put("Hidden", ColumnHeaderMode.HIDDEN);
+ columnHeaderModeOptions.put("Id", ColumnHeaderMode.ID);
+ columnHeaderModeOptions.put("Explicit", ColumnHeaderMode.EXPLICIT);
columnHeaderModeOptions.put("Explicit defaults id",
- Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID);
+ ColumnHeaderMode.EXPLICIT_DEFAULTS_ID);
createSelectAction("Column header mode", category,
columnHeaderModeOptions, "Explicit defaults id",
@@ -603,10 +605,10 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> createBooleanAction("Collapsed", category, false, columnCollapsed,
propertyId);
t.log("Collapsed");
- LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
- options.put("Left", Table.ALIGN_LEFT);
- options.put("Center", Table.ALIGN_CENTER);
- options.put("Right", Table.ALIGN_RIGHT);
+ LinkedHashMap<String, Align> options = new LinkedHashMap<String, Align>();
+ options.put("Left", Align.LEFT);
+ options.put("Center", Align.CENTER);
+ options.put("Right", Align.RIGHT);
createSelectAction("Alignment", category, options, "Left",
columnAlignmentCommand, propertyId);
@@ -652,16 +654,15 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
private void createRowHeaderModeSelect(String category) {
- LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
- options.put("Explicit", Table.ROW_HEADER_MODE_EXPLICIT);
- options.put("Explicit defaults id",
- Table.ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID);
- options.put("Hidden", Table.ROW_HEADER_MODE_HIDDEN);
- options.put("Icon only", Table.ROW_HEADER_MODE_ICON_ONLY);
- options.put("Id", Table.ROW_HEADER_MODE_ID);
- options.put("Index", Table.ROW_HEADER_MODE_INDEX);
- options.put("Item", Table.ROW_HEADER_MODE_ITEM);
- options.put("'Property 3' property", Table.ROW_HEADER_MODE_PROPERTY);
+ LinkedHashMap<String, RowHeaderMode> options = new LinkedHashMap<String, RowHeaderMode>();
+ options.put("Explicit", RowHeaderMode.EXPLICIT);
+ options.put("Explicit defaults id", RowHeaderMode.EXPLICIT_DEFAULTS_ID);
+ options.put("Hidden", RowHeaderMode.HIDDEN);
+ options.put("Icon only", RowHeaderMode.ICON_ONLY);
+ options.put("Id", RowHeaderMode.ID);
+ options.put("Index", RowHeaderMode.INDEX);
+ options.put("Item", RowHeaderMode.ITEM);
+ options.put("'Property 3' property", RowHeaderMode.PROPERTY);
createSelectAction("Row header mode", category, options, "Hidden",
rowHeaderModeCommand);
@@ -741,17 +742,17 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }
protected void createHeaderVisibilitySelect(String category) {
- LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
- options.put("Explicit", Table.COLUMN_HEADER_MODE_EXPLICIT);
+ LinkedHashMap<String, ColumnHeaderMode> options = new LinkedHashMap<String, ColumnHeaderMode>();
+ options.put("Explicit", ColumnHeaderMode.EXPLICIT);
options.put("Explicit defaults id",
- Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID);
- options.put("Id", Table.COLUMN_HEADER_MODE_ID);
- options.put("Hidden", Table.COLUMN_HEADER_MODE_HIDDEN);
+ ColumnHeaderMode.EXPLICIT_DEFAULTS_ID);
+ options.put("Id", ColumnHeaderMode.ID);
+ options.put("Hidden", ColumnHeaderMode.HIDDEN);
createSelectAction("Header mode", category, options,
- "Explicit defaults id", new Command<T, Integer>() {
+ "Explicit defaults id", new Command<T, ColumnHeaderMode>() {
- public void execute(T c, Integer value, Object data) {
+ public void execute(T c, ColumnHeaderMode value, Object data) {
c.setColumnHeaderMode(value);
}
|