diff options
Diffstat (limited to 'server/src/com')
-rw-r--r-- | server/src/com/vaadin/data/util/filter/Compare.java | 29 | ||||
-rw-r--r-- | server/src/com/vaadin/navigator/Navigator.java | 64 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/AbstractComponentContainer.java | 13 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/AbstractOrderedLayout.java | 12 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/ComponentContainer.java | 14 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/CssLayout.java | 13 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/GridLayout.java | 13 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/UI.java | 6 |
8 files changed, 83 insertions, 81 deletions
diff --git a/server/src/com/vaadin/data/util/filter/Compare.java b/server/src/com/vaadin/data/util/filter/Compare.java index 7730bace6b..a13a5bfaa7 100644 --- a/server/src/com/vaadin/data/util/filter/Compare.java +++ b/server/src/com/vaadin/data/util/filter/Compare.java @@ -47,7 +47,8 @@ public abstract class Compare implements Filter { * A {@link Compare} filter that accepts items for which the identified * property value is equal to <code>value</code>. * - * For in-memory filters, equals() is used for the comparison. For other + * For in-memory filters, {@link Comparable#compareTo(Object)} or, if not + * Comparable, {@link #equals(Object)} is used for the comparison. For other * containers, the comparison implementation is container dependent and may * use e.g. database comparison operations. * @@ -248,8 +249,7 @@ public abstract class Compare implements Filter { Object value = p.getValue(); switch (getOperation()) { case EQUAL: - return (null == this.value) ? (null == value) : this.value - .equals(value); + return compareEquals(value); case GREATER: return compareValue(value) > 0; case LESS: @@ -263,6 +263,29 @@ public abstract class Compare implements Filter { return false; } + /** + * Checks if the this value equals the given value. Favors Comparable over + * equals to better support e.g. BigDecimal where equals is stricter than + * compareTo. + * + * @param otherValue + * The value to compare to + * @return true if the values are equal, false otherwise + */ + private boolean compareEquals(Object otherValue) { + if (value == null || otherValue == null) { + return (otherValue == value); + } else if (value == otherValue) { + return true; + } else if (value instanceof Comparable + && otherValue.getClass() + .isAssignableFrom(getValue().getClass())) { + return ((Comparable) value).compareTo(otherValue) == 0; + } else { + return value.equals(otherValue); + } + } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected int compareValue(Object value1) { if (null == value) { diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index acfaf45516..72128adddf 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -360,20 +360,18 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the current {@link Page} and replacing the contents of a - * {@link ComponentContainer} with the active view. - * <p> - * In case the container is not on the current page, use another - * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created - * {@link ComponentContainerViewDisplay}. + * of the {@link Page} containing the given UI and replacing the contents of + * a {@link ComponentContainer} with the active view. * <p> * All components of the container are removed each time before adding the * active {@link View}. Views must implement {@link Component} when using * this constructor. * <p> - * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -387,18 +385,16 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the current {@link Page} and replacing the contents of a - * {@link SingleComponentContainer} with the active view. - * <p> - * In case the container is not on the current page, use another - * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created - * {@link SingleComponentContainerViewDisplay}. + * of the {@link Page} containing the given UI and replacing the contents of + * a {@link SingleComponentContainer} with the active view. * <p> * Views must implement {@link Component} when using this constructor. * <p> - * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -412,11 +408,13 @@ public class Navigator implements Serializable { /** * Creates a navigator that is tracking the active view using URI fragments - * of the Page containing the given UI. + * of the {@link Page} containing the given UI. * <p> - * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -430,13 +428,14 @@ public class Navigator implements Serializable { /** * Creates a navigator. * <p> - * When a custom navigation state manager is not needed, use the constructor - * {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based - * state manager. + * When a custom navigation state manager is not needed, use one of the + * other constructors which use a URI fragment based state manager. * <p> - * After all {@link View}s and {@link ViewProvider}s have been registered, - * the application should trigger navigation to the current fragment using - * {@link #navigate()}. + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. * * @param ui * The UI to which this Navigator is attached. @@ -457,15 +456,6 @@ public class Navigator implements Serializable { } /** - * Navigates to the current navigation state. This method should be called - * when all required {@link View}s, {@link ViewProvider}s, and - * {@link ViewChangeListener}s have been added to the navigator. - */ - public void navigate() { - navigateTo(getStateManager().getState()); - } - - /** * Navigates to a view and initialize the view with given parameters. * <p> * The view string consists of a view name optionally followed by a slash diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java index b5cc3da861..135194f12c 100644 --- a/server/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java @@ -43,6 +43,19 @@ public abstract class AbstractComponentContainer extends AbstractComponent super(); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.ComponentContainer#addComponents(com.vaadin.ui.Component[]) + */ + @Override + public void addComponents(Component... components) { + for (Component c : components) { + addComponent(c); + } + } + /** * Removes all components from the container. This should probably be * re-implemented in extending classes for a more powerful implementation. diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index 729862a93e..5f5768a237 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -113,18 +113,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements } /** - * Adds the given components in the given order to the container. - * - * @param components - * The components to add. - */ - public void addComponents(Component... components) { - for (Component c : components) { - addComponent(c); - } - } - - /** * Adds a component into indexed position in this container. * * @param c diff --git a/server/src/com/vaadin/ui/ComponentContainer.java b/server/src/com/vaadin/ui/ComponentContainer.java index 5ef41d7cbf..5c544ceffb 100644 --- a/server/src/com/vaadin/ui/ComponentContainer.java +++ b/server/src/com/vaadin/ui/ComponentContainer.java @@ -21,9 +21,9 @@ import java.util.Iterator; import com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier; /** - * Extension to the {@link Component} interface which adds to it the capacity to - * contain other components. All UI elements that can have child elements - * implement this interface. + * A special type of parent which allows the user to add and remove components + * to it. Typically does not have any restrictions on the number of children it + * can contain. * * @author Vaadin Ltd. * @since 3.0 @@ -40,6 +40,14 @@ public interface ComponentContainer extends HasComponents, public void addComponent(Component c); /** + * Adds the components in the given order to this component container. + * + * @param components + * The components to add. + */ + public void addComponents(Component... components); + + /** * Removes the component from this container. * * @param c diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index aa072df946..228624769f 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -126,19 +126,6 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { } /** - * Adds the given components into this container. Each component is added to - * the right or below the previous component. - * - * @param components - * The components to add. - */ - public void addComponents(Component... components) { - for (Component c : components) { - addComponent(c); - } - } - - /** * Adds a component into this container. The component is added to the left * or on top of the other components. * diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 8fda05baf1..2504592058 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -275,19 +275,6 @@ public class GridLayout extends AbstractLayout implements } /** - * Adds the given components to the grid starting from the current cursor - * position. - * - * @param components - * Components to add. - */ - public void addComponents(Component... components) { - for (Component c : components) { - this.addComponent(c); - } - } - - /** * Tests if the given area overlaps with any of the items already on the * grid. * diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index a5e8f5e508..89a36e198e 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -552,6 +552,12 @@ public abstract class UI extends AbstractSingleComponentContainer implements // Call the init overridden by the application developer init(request); + + Navigator navigator = getNavigator(); + if (navigator != null) { + // Kickstart navigation if a navigator was attached in init() + navigator.navigateTo(navigator.getState()); + } } /** |