From 112572a700c288fc49df60ea23a2ade7c51c5165 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 4 Sep 2012 08:27:07 +0300 Subject: Moved ReflectTools to com.vaadin.util (#4294) --- server/src/com/vaadin/Application.java | 2 +- .../src/com/vaadin/data/fieldgroup/FieldGroup.java | 2 +- server/src/com/vaadin/event/FieldEvents.java | 2 +- server/src/com/vaadin/event/LayoutEvents.java | 2 +- server/src/com/vaadin/event/MouseEvents.java | 2 +- server/src/com/vaadin/server/AddonContext.java | 2 +- .../vaadin/server/JavaScriptCallbackHelper.java | 2 +- server/src/com/vaadin/server/Page.java | 2 +- server/src/com/vaadin/tools/ReflectTools.java | 138 --------------------- server/src/com/vaadin/ui/AbstractComponent.java | 2 +- server/src/com/vaadin/ui/AbstractSplitPanel.java | 2 +- server/src/com/vaadin/ui/Button.java | 2 +- server/src/com/vaadin/ui/Tree.java | 2 +- server/src/com/vaadin/ui/UI.java | 2 +- server/src/com/vaadin/util/ReflectTools.java | 138 +++++++++++++++++++++ 15 files changed, 151 insertions(+), 151 deletions(-) delete mode 100644 server/src/com/vaadin/tools/ReflectTools.java create mode 100644 server/src/com/vaadin/util/ReflectTools.java (limited to 'server') diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 7af5852512..fd8c73aa8f 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -69,12 +69,12 @@ import com.vaadin.server.WrappedRequest; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.server.WrappedResponse; import com.vaadin.shared.ui.ui.UIConstants; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Table; import com.vaadin.ui.UI; import com.vaadin.ui.Window; +import com.vaadin.util.ReflectTools; /** *

diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index d79697f548..9fe99610b2 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -29,10 +29,10 @@ import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.Validator.InvalidValueException; import com.vaadin.data.util.TransactionalPropertyWrapper; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.Form; +import com.vaadin.util.ReflectTools; /** * FieldGroup provides an easy way of binding fields to data and handling diff --git a/server/src/com/vaadin/event/FieldEvents.java b/server/src/com/vaadin/event/FieldEvents.java index 10df08291e..3da60ee466 100644 --- a/server/src/com/vaadin/event/FieldEvents.java +++ b/server/src/com/vaadin/event/FieldEvents.java @@ -21,12 +21,12 @@ import java.lang.reflect.Method; import com.vaadin.shared.EventId; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.Component; import com.vaadin.ui.Component.Event; import com.vaadin.ui.Field; import com.vaadin.ui.Field.ValueChangeEvent; import com.vaadin.ui.TextField; +import com.vaadin.util.ReflectTools; /** * Interface that serves as a wrapper for {@link Field} related events. diff --git a/server/src/com/vaadin/event/LayoutEvents.java b/server/src/com/vaadin/event/LayoutEvents.java index 7f88ddc640..c113ff1595 100644 --- a/server/src/com/vaadin/event/LayoutEvents.java +++ b/server/src/com/vaadin/event/LayoutEvents.java @@ -21,9 +21,9 @@ import java.lang.reflect.Method; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.shared.Connector; import com.vaadin.shared.MouseEventDetails; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.Component; import com.vaadin.ui.ComponentContainer; +import com.vaadin.util.ReflectTools; public interface LayoutEvents { diff --git a/server/src/com/vaadin/event/MouseEvents.java b/server/src/com/vaadin/event/MouseEvents.java index 0fe9902b2e..6712ef79a5 100644 --- a/server/src/com/vaadin/event/MouseEvents.java +++ b/server/src/com/vaadin/event/MouseEvents.java @@ -19,8 +19,8 @@ package com.vaadin.event; import java.lang.reflect.Method; import com.vaadin.shared.MouseEventDetails; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.Component; +import com.vaadin.util.ReflectTools; /** * Interface that serves as a wrapper for mouse related events. diff --git a/server/src/com/vaadin/server/AddonContext.java b/server/src/com/vaadin/server/AddonContext.java index b3cd5ea226..c9f2ac07eb 100644 --- a/server/src/com/vaadin/server/AddonContext.java +++ b/server/src/com/vaadin/server/AddonContext.java @@ -24,7 +24,7 @@ import java.util.ServiceLoader; import com.vaadin.Application; import com.vaadin.event.EventRouter; -import com.vaadin.tools.ReflectTools; +import com.vaadin.util.ReflectTools; /** * Point of entry for add-ons for integrating into various aspects of the diff --git a/server/src/com/vaadin/server/JavaScriptCallbackHelper.java b/server/src/com/vaadin/server/JavaScriptCallbackHelper.java index 19b19ce824..d17ae71114 100644 --- a/server/src/com/vaadin/server/JavaScriptCallbackHelper.java +++ b/server/src/com/vaadin/server/JavaScriptCallbackHelper.java @@ -27,10 +27,10 @@ import java.util.Set; import com.vaadin.external.json.JSONArray; import com.vaadin.external.json.JSONException; import com.vaadin.shared.JavaScriptConnectorState; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.AbstractJavaScriptComponent; import com.vaadin.ui.JavaScript.JavaScriptCallbackRpc; import com.vaadin.ui.JavaScriptFunction; +import com.vaadin.util.ReflectTools; /** * Internal helper class used to implement functionality common to diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index da172ed837..b5718d10bb 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -28,10 +28,10 @@ import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.ui.PageClientRpc; import com.vaadin.shared.ui.ui.UIConstants; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.JavaScript; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; +import com.vaadin.util.ReflectTools; public class Page implements Serializable { diff --git a/server/src/com/vaadin/tools/ReflectTools.java b/server/src/com/vaadin/tools/ReflectTools.java deleted file mode 100644 index fcfe00564e..0000000000 --- a/server/src/com/vaadin/tools/ReflectTools.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tools; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * An util class with helpers for reflection operations. Used internally by - * Vaadin and should not be used by application developers. Subject to change at - * any time. - * - * @since 6.2 - */ -public class ReflectTools { - /** - * Locates the method in the given class. Returns null if the method is not - * found. Throws an ExceptionInInitializerError if there is a problem - * locating the method as this is mainly called from static blocks. - * - * @param cls - * Class that contains the method - * @param methodName - * The name of the method - * @param parameterTypes - * The parameter types for the method. - * @return A reference to the method - * @throws ExceptionInInitializerError - * Wraps any exception in an {@link ExceptionInInitializerError} - * so this method can be called from a static initializer. - */ - public static Method findMethod(Class cls, String methodName, - Class... parameterTypes) throws ExceptionInInitializerError { - try { - return cls.getDeclaredMethod(methodName, parameterTypes); - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - } - - /** - * Returns the value of the java field. - *

- * Uses getter if present, otherwise tries to access even private fields - * directly. - * - * @param object - * The object containing the field - * @param field - * The field we want to get the value for - * @return The value of the field in the object - * @throws InvocationTargetException - * If the value could not be retrieved - * @throws IllegalAccessException - * If the value could not be retrieved - * @throws IllegalArgumentException - * If the value could not be retrieved - */ - public static Object getJavaFieldValue(Object object, - java.lang.reflect.Field field) throws IllegalArgumentException, - IllegalAccessException, InvocationTargetException { - PropertyDescriptor pd; - try { - pd = new PropertyDescriptor(field.getName(), object.getClass()); - Method getter = pd.getReadMethod(); - if (getter != null) { - return getter.invoke(object, (Object[]) null); - } - } catch (IntrospectionException e1) { - // Ignore this and try to get directly using the field - } - - // Try to get the value or throw an exception - if (!field.isAccessible()) { - // Try to gain access even if field is private - field.setAccessible(true); - } - return field.get(object); - } - - /** - * Sets the value of a java field. - *

- * Uses setter if present, otherwise tries to access even private fields - * directly. - * - * @param object - * The object containing the field - * @param field - * The field we want to set the value for - * @param value - * The value to set - * @throws IllegalAccessException - * If the value could not be assigned to the field - * @throws IllegalArgumentException - * If the value could not be assigned to the field - * @throws InvocationTargetException - * If the value could not be assigned to the field - */ - public static void setJavaFieldValue(Object object, - java.lang.reflect.Field field, Object value) - throws IllegalAccessException, IllegalArgumentException, - InvocationTargetException { - PropertyDescriptor pd; - try { - pd = new PropertyDescriptor(field.getName(), object.getClass()); - Method setter = pd.getWriteMethod(); - if (setter != null) { - // Exceptions are thrown forward if this fails - setter.invoke(object, value); - } - } catch (IntrospectionException e1) { - // Ignore this and try to set directly using the field - } - - // Try to set the value directly to the field or throw an exception - if (!field.isAccessible()) { - // Try to gain access even if field is private - field.setAccessible(true); - } - field.set(object, value); - } -} diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 97883b780f..37ca9f1a03 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -41,7 +41,7 @@ import com.vaadin.server.Terminal; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; import com.vaadin.shared.ui.ComponentStateUtil; -import com.vaadin.tools.ReflectTools; +import com.vaadin.util.ReflectTools; /** * An abstract class that defines default implementation for the diff --git a/server/src/com/vaadin/ui/AbstractSplitPanel.java b/server/src/com/vaadin/ui/AbstractSplitPanel.java index c5df57b36f..93c4ec4f59 100644 --- a/server/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/server/src/com/vaadin/ui/AbstractSplitPanel.java @@ -28,7 +28,7 @@ import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelRpc; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState; -import com.vaadin.tools.ReflectTools; +import com.vaadin.util.ReflectTools; /** * AbstractSplitPanel. diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index bbed7d540f..ec75d2da9b 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -33,8 +33,8 @@ import com.vaadin.event.ShortcutListener; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.button.ButtonServerRpc; import com.vaadin.shared.ui.button.ButtonState; -import com.vaadin.tools.ReflectTools; import com.vaadin.ui.Component.Focusable; +import com.vaadin.util.ReflectTools; /** * A generic button component. diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java index 03895a12bb..ad3674fe1e 100644 --- a/server/src/com/vaadin/ui/Tree.java +++ b/server/src/com/vaadin/ui/Tree.java @@ -56,7 +56,7 @@ import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.dd.VerticalDropLocation; import com.vaadin.shared.ui.tree.TreeConstants; -import com.vaadin.tools.ReflectTools; +import com.vaadin.util.ReflectTools; /** * Tree component. A Tree can be used to select an item (or multiple items) from diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 0f914d3947..4b861d7a25 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -49,7 +49,7 @@ import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.shared.ui.ui.UIServerRpc; import com.vaadin.shared.ui.ui.UIState; -import com.vaadin.tools.ReflectTools; +import com.vaadin.util.ReflectTools; /** * The topmost component in any component hierarchy. There is one UI for every diff --git a/server/src/com/vaadin/util/ReflectTools.java b/server/src/com/vaadin/util/ReflectTools.java new file mode 100644 index 0000000000..285d876e1c --- /dev/null +++ b/server/src/com/vaadin/util/ReflectTools.java @@ -0,0 +1,138 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.util; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * An util class with helpers for reflection operations. Used internally by + * Vaadin and should not be used by application developers. Subject to change at + * any time. + * + * @since 6.2 + */ +public class ReflectTools { + /** + * Locates the method in the given class. Returns null if the method is not + * found. Throws an ExceptionInInitializerError if there is a problem + * locating the method as this is mainly called from static blocks. + * + * @param cls + * Class that contains the method + * @param methodName + * The name of the method + * @param parameterTypes + * The parameter types for the method. + * @return A reference to the method + * @throws ExceptionInInitializerError + * Wraps any exception in an {@link ExceptionInInitializerError} + * so this method can be called from a static initializer. + */ + public static Method findMethod(Class cls, String methodName, + Class... parameterTypes) throws ExceptionInInitializerError { + try { + return cls.getDeclaredMethod(methodName, parameterTypes); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + + /** + * Returns the value of the java field. + *

+ * Uses getter if present, otherwise tries to access even private fields + * directly. + * + * @param object + * The object containing the field + * @param field + * The field we want to get the value for + * @return The value of the field in the object + * @throws InvocationTargetException + * If the value could not be retrieved + * @throws IllegalAccessException + * If the value could not be retrieved + * @throws IllegalArgumentException + * If the value could not be retrieved + */ + public static Object getJavaFieldValue(Object object, + java.lang.reflect.Field field) throws IllegalArgumentException, + IllegalAccessException, InvocationTargetException { + PropertyDescriptor pd; + try { + pd = new PropertyDescriptor(field.getName(), object.getClass()); + Method getter = pd.getReadMethod(); + if (getter != null) { + return getter.invoke(object, (Object[]) null); + } + } catch (IntrospectionException e1) { + // Ignore this and try to get directly using the field + } + + // Try to get the value or throw an exception + if (!field.isAccessible()) { + // Try to gain access even if field is private + field.setAccessible(true); + } + return field.get(object); + } + + /** + * Sets the value of a java field. + *

+ * Uses setter if present, otherwise tries to access even private fields + * directly. + * + * @param object + * The object containing the field + * @param field + * The field we want to set the value for + * @param value + * The value to set + * @throws IllegalAccessException + * If the value could not be assigned to the field + * @throws IllegalArgumentException + * If the value could not be assigned to the field + * @throws InvocationTargetException + * If the value could not be assigned to the field + */ + public static void setJavaFieldValue(Object object, + java.lang.reflect.Field field, Object value) + throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + PropertyDescriptor pd; + try { + pd = new PropertyDescriptor(field.getName(), object.getClass()); + Method setter = pd.getWriteMethod(); + if (setter != null) { + // Exceptions are thrown forward if this fails + setter.invoke(object, value); + } + } catch (IntrospectionException e1) { + // Ignore this and try to set directly using the field + } + + // Try to set the value directly to the field or throw an exception + if (!field.isAccessible()) { + // Try to gain access even if field is private + field.setAccessible(true); + } + field.set(object, value); + } +} -- cgit v1.2.3 From 52c4b1905e311f72fdf8080a1917e87c30355a61 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 4 Sep 2012 09:38:38 +0300 Subject: ItemStyleGenerator.getStyle now includes source component (#5822) --- server/src/com/vaadin/ui/Table.java | 11 +++++++---- server/src/com/vaadin/ui/Tree.java | 7 +++++-- uitest/src/com/vaadin/tests/Components.java | 4 ++-- .../vaadin/tests/components/table/CellStyleGeneratorTest.java | 3 ++- uitest/src/com/vaadin/tests/components/table/Tables.java | 3 ++- .../com/vaadin/tests/components/tree/ItemStyleGenerator.java | 2 +- uitest/src/com/vaadin/tests/components/tree/Trees.java | 4 ++-- .../com/vaadin/tests/components/treetable/TreeTableTest.java | 5 +++-- uitest/src/com/vaadin/tests/tickets/Ticket1857.java | 5 +++-- uitest/src/com/vaadin/tests/tickets/Ticket2125.java | 5 +++-- uitest/src/com/vaadin/tests/tickets/Ticket2208.java | 5 +++-- 11 files changed, 33 insertions(+), 21 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 5eb18ee61f..65189fed0c 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -3479,8 +3479,8 @@ public class Table extends AbstractSelect implements Action.Container, * target. */ if (cellStyleGenerator != null) { - String cellStyle = cellStyleGenerator - .getStyle(itemId, columnId); + String cellStyle = cellStyleGenerator.getStyle(this, itemId, + columnId); if (cellStyle != null && !cellStyle.equals("")) { target.addAttribute("style-" + columnIdMap.key(columnId), cellStyle); @@ -3567,7 +3567,7 @@ public class Table extends AbstractSelect implements Action.Container, * to the target. */ if (cellStyleGenerator != null) { - String rowStyle = cellStyleGenerator.getStyle(itemId, null); + String rowStyle = cellStyleGenerator.getStyle(this, itemId, null); if (rowStyle != null && !rowStyle.equals("")) { target.addAttribute("rowstyle", rowStyle); } @@ -4602,6 +4602,8 @@ public class Table extends AbstractSelect implements Action.Container, /** * Called by Table when a cell (and row) is painted. * + * @param source + * the source Table * @param itemId * The itemId of the painted cell * @param propertyId @@ -4610,7 +4612,8 @@ public class Table extends AbstractSelect implements Action.Container, * name will be v-table-cell-content-[style name], or * v-table-row-[style name] for rows) */ - public abstract String getStyle(Object itemId, Object propertyId); + public abstract String getStyle(Table source, Object itemId, + Object propertyId); } @Override diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java index ad3674fe1e..306d1f18ba 100644 --- a/server/src/com/vaadin/ui/Tree.java +++ b/server/src/com/vaadin/ui/Tree.java @@ -611,7 +611,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } if (itemStyleGenerator != null) { - String stylename = itemStyleGenerator.getStyle(itemId); + String stylename = itemStyleGenerator + .getStyle(this, itemId); if (stylename != null) { target.addAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE, stylename); @@ -1255,12 +1256,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, /** * Called by Tree when an item is painted. * + * @param source + * the source Tree * @param itemId * The itemId of the item to be painted * @return The style name to add to this item. (the CSS class name will * be v-tree-node-[style name] */ - public abstract String getStyle(Object itemId); + public abstract String getStyle(Tree source, Object itemId); } // Overriden so javadoc comes from Container.Hierarchical diff --git a/uitest/src/com/vaadin/tests/Components.java b/uitest/src/com/vaadin/tests/Components.java index 5882c5cdb1..7ac1b55d35 100644 --- a/uitest/src/com/vaadin/tests/Components.java +++ b/uitest/src/com/vaadin/tests/Components.java @@ -25,9 +25,9 @@ import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Tree; import com.vaadin.ui.Tree.ItemStyleGenerator; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; public class Components extends Application.LegacyApplication { @@ -138,7 +138,7 @@ public class Components extends Application.LegacyApplication { naviTree.setItemStyleGenerator(new ItemStyleGenerator() { @Override - public String getStyle(Object itemId) { + public String getStyle(Tree source, Object itemId) { Class cls = (Class) itemId; if (!isAbstract(cls)) { return "blue"; diff --git a/uitest/src/com/vaadin/tests/components/table/CellStyleGeneratorTest.java b/uitest/src/com/vaadin/tests/components/table/CellStyleGeneratorTest.java index 35f35c1407..fb4bc5a045 100644 --- a/uitest/src/com/vaadin/tests/components/table/CellStyleGeneratorTest.java +++ b/uitest/src/com/vaadin/tests/components/table/CellStyleGeneratorTest.java @@ -17,7 +17,8 @@ public class CellStyleGeneratorTest extends TestBase { CellStyleGenerator g = new CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, + Object propertyId) { if (propertyId != null && propertyId.equals("red")) { return "red"; } else if (itemId.equals("blue") && propertyId == null) { diff --git a/uitest/src/com/vaadin/tests/components/table/Tables.java b/uitest/src/com/vaadin/tests/components/table/Tables.java index 1431155b1a..a08533fdbd 100644 --- a/uitest/src/com/vaadin/tests/components/table/Tables.java +++ b/uitest/src/com/vaadin/tests/components/table/Tables.java @@ -335,7 +335,8 @@ public class Tables extends AbstractSelectTestCase c.setCellStyleGenerator(new CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, + Object propertyId) { if (cellStyleInfo.appliesTo(itemId, propertyId)) { return cellStyleInfo.styleName; } diff --git a/uitest/src/com/vaadin/tests/components/tree/ItemStyleGenerator.java b/uitest/src/com/vaadin/tests/components/tree/ItemStyleGenerator.java index 33bd4cef65..c561781d2b 100644 --- a/uitest/src/com/vaadin/tests/components/tree/ItemStyleGenerator.java +++ b/uitest/src/com/vaadin/tests/components/tree/ItemStyleGenerator.java @@ -33,7 +33,7 @@ public class ItemStyleGenerator extends TestBase { tree.setItemStyleGenerator(new Tree.ItemStyleGenerator() { @Override - public String getStyle(Object itemId) { + public String getStyle(Tree source, Object itemId) { // simple return itemId as css style name return itemId.toString(); } diff --git a/uitest/src/com/vaadin/tests/components/tree/Trees.java b/uitest/src/com/vaadin/tests/components/tree/Trees.java index 3ee1d7b0de..8796fb854c 100644 --- a/uitest/src/com/vaadin/tests/components/tree/Trees.java +++ b/uitest/src/com/vaadin/tests/components/tree/Trees.java @@ -27,7 +27,7 @@ public class Trees extends AbstractSelectTestCase implements private ItemStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Tree.ItemStyleGenerator() { @Override - public String getStyle(Object itemId) { + public String getStyle(Tree source, Object itemId) { Hierarchical c = (Container.Hierarchical) getComponent() .getContainerDataSource(); if (c.isRoot(itemId)) { @@ -52,7 +52,7 @@ public class Trees extends AbstractSelectTestCase implements private ItemStyleGenerator evenItemsBold = new com.vaadin.ui.Tree.ItemStyleGenerator() { @Override - public String getStyle(Object itemId) { + public String getStyle(Tree source, Object itemId) { Hierarchical c = (Container.Hierarchical) getComponent() .getContainerDataSource(); int idx = 0; diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableTest.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableTest.java index f27a47f12b..8fafdb2d26 100644 --- a/uitest/src/com/vaadin/tests/components/treetable/TreeTableTest.java +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableTest.java @@ -9,6 +9,7 @@ import com.vaadin.data.Container; import com.vaadin.data.Container.Hierarchical; import com.vaadin.data.util.HierarchicalContainer; import com.vaadin.tests.components.table.Tables; +import com.vaadin.ui.Table; import com.vaadin.ui.Table.CellStyleGenerator; import com.vaadin.ui.Tree.CollapseEvent; import com.vaadin.ui.Tree.CollapseListener; @@ -28,7 +29,7 @@ public class TreeTableTest extends Tables implements private CellStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Table.CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, Object propertyId) { if (propertyId != null) { return null; } @@ -56,7 +57,7 @@ public class TreeTableTest extends Tables implements private CellStyleGenerator evenItemsBold = new CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, Object propertyId) { if (propertyId != null) { return null; } diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket1857.java b/uitest/src/com/vaadin/tests/tickets/Ticket1857.java index 039f867fff..be0158e0fb 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket1857.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket1857.java @@ -7,8 +7,8 @@ import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.ui.CheckBox; import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Table; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; public class Ticket1857 extends Application.LegacyApplication implements @@ -60,7 +60,8 @@ public class Ticket1857 extends Application.LegacyApplication implements if (cellStylesEnabler.getValue().booleanValue()) { t.setCellStyleGenerator(new Table.CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, + Object propertyId) { Object cell = t.getContainerProperty(itemId, propertyId).getValue(); if (!(cell instanceof Integer)) { diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2125.java b/uitest/src/com/vaadin/tests/tickets/Ticket2125.java index bc1f886418..defd7f4a22 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2125.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2125.java @@ -5,10 +5,10 @@ import com.vaadin.data.util.MethodProperty; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.Label; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Table; import com.vaadin.ui.Table.CellStyleGenerator; import com.vaadin.ui.Table.ColumnGenerator; +import com.vaadin.ui.UI.LegacyWindow; public class Ticket2125 extends Application.LegacyApplication { @@ -42,7 +42,8 @@ public class Ticket2125 extends Application.LegacyApplication { }); table.setCellStyleGenerator(new CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, + Object propertyId) { if (new Integer(4).equals(itemId)) { if (propertyId == null) { return "MYROW"; diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2208.java b/uitest/src/com/vaadin/tests/tickets/Ticket2208.java index f622f093ee..98cd6724d4 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2208.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2208.java @@ -4,10 +4,10 @@ import com.vaadin.Application; import com.vaadin.data.Item; import com.vaadin.ui.Component; import com.vaadin.ui.Label; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Table; import com.vaadin.ui.Table.CellStyleGenerator; import com.vaadin.ui.Table.ColumnGenerator; +import com.vaadin.ui.UI.LegacyWindow; public class Ticket2208 extends Application.LegacyApplication { @@ -40,7 +40,8 @@ public class Ticket2208 extends Application.LegacyApplication { t.setCellStyleGenerator(new CellStyleGenerator() { @Override - public String getStyle(Object itemId, Object propertyId) { + public String getStyle(Table source, Object itemId, + Object propertyId) { if ("col 1 (red)".equals(propertyId)) { return "red"; } -- cgit v1.2.3 From 17ea270b740bdea84143c3467166bf8618ab6ef5 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 09:20:51 +0300 Subject: Make LegacyApplication set current UI (#9443) --- server/src/com/vaadin/Application.java | 1 + 1 file changed, 1 insertion(+) (limited to 'server') diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index fd8c73aa8f..636204cbf0 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -250,6 +250,7 @@ public class Application implements Terminal.ErrorListener, Serializable { // initialized return null; } else { + UI.setCurrent(uiInstance); return uiInstance; } } -- cgit v1.2.3 From dd6265dcf5376fe4ead3fab7dbe10df2099389c7 Mon Sep 17 00:00:00 2001 From: Pekka Hyvönen Date: Tue, 4 Sep 2012 10:33:22 +0300 Subject: inner Event classes converted to static nested classes (#5855) --- .../data/util/sqlcontainer/query/TableQuery.java | 2 +- server/src/com/vaadin/event/FieldEvents.java | 5 +++-- server/src/com/vaadin/event/MouseEvents.java | 4 ++-- server/src/com/vaadin/server/Page.java | 4 ++-- server/src/com/vaadin/ui/AbstractSelect.java | 25 ++++++++++++++++------ server/src/com/vaadin/ui/AbstractSplitPanel.java | 6 +++--- server/src/com/vaadin/ui/AbstractTextField.java | 2 +- server/src/com/vaadin/ui/Button.java | 2 +- server/src/com/vaadin/ui/Component.java | 4 ++-- server/src/com/vaadin/ui/ComponentContainer.java | 4 ++-- server/src/com/vaadin/ui/LoginForm.java | 8 +++---- server/src/com/vaadin/ui/PopupView.java | 4 ++-- server/src/com/vaadin/ui/TabSheet.java | 4 ++-- server/src/com/vaadin/ui/Window.java | 4 ++-- .../server/navigator/UriFragmentManagerTest.java | 3 +-- 15 files changed, 46 insertions(+), 35 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java index a6a1a5a8fb..8a3dabbf0e 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java @@ -678,7 +678,7 @@ public class TableQuery implements QueryDelegate, /** * Simple RowIdChangeEvent implementation. */ - public class RowIdChangeEvent extends EventObject implements + public static class RowIdChangeEvent extends EventObject implements QueryDelegate.RowIdChangeEvent { private final RowId oldId; private final RowId newId; diff --git a/server/src/com/vaadin/event/FieldEvents.java b/server/src/com/vaadin/event/FieldEvents.java index 3da60ee466..1a1bc95305 100644 --- a/server/src/com/vaadin/event/FieldEvents.java +++ b/server/src/com/vaadin/event/FieldEvents.java @@ -144,7 +144,7 @@ public interface FieldEvents { * @since 6.2 */ @SuppressWarnings("serial") - public class FocusEvent extends Component.Event { + public static class FocusEvent extends Component.Event { /** * Identifier for event that can be used in {@link EventRouter} @@ -184,7 +184,7 @@ public interface FieldEvents { * @since 6.2 */ @SuppressWarnings("serial") - public class BlurEvent extends Component.Event { + public static class BlurEvent extends Component.Event { /** * Identifier for event that can be used in {@link EventRouter} @@ -243,6 +243,7 @@ public interface FieldEvents { * @since 6.5 */ public static abstract class TextChangeEvent extends Component.Event { + public TextChangeEvent(Component source) { super(source); } diff --git a/server/src/com/vaadin/event/MouseEvents.java b/server/src/com/vaadin/event/MouseEvents.java index 6712ef79a5..e287055c2b 100644 --- a/server/src/com/vaadin/event/MouseEvents.java +++ b/server/src/com/vaadin/event/MouseEvents.java @@ -43,7 +43,7 @@ public interface MouseEvents { * @see ClickListener * @since 6.2 */ - public class ClickEvent extends Component.Event { + public static class ClickEvent extends Component.Event { public static final int BUTTON_LEFT = MouseEventDetails.BUTTON_LEFT; public static final int BUTTON_MIDDLE = MouseEventDetails.BUTTON_MIDDLE; public static final int BUTTON_RIGHT = MouseEventDetails.BUTTON_RIGHT; @@ -202,7 +202,7 @@ public interface MouseEvents { * @author Vaadin Ltd. * @since 6.2 */ - public class DoubleClickEvent extends Component.Event { + public static class DoubleClickEvent extends Component.Event { public DoubleClickEvent(Component source) { super(source); diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index b5718d10bb..015c6c907f 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -54,7 +54,7 @@ public class Page implements Serializable { /** * Event that is fired when a browser window containing a uI is resized. */ - public class BrowserWindowResizeEvent extends EventObject { + public static class BrowserWindowResizeEvent extends EventObject { private final int width; private final int height; @@ -233,7 +233,7 @@ public class Page implements Serializable { /** * Event fired when uri fragment changes. */ - public class FragmentChangedEvent extends EventObject { + public static class FragmentChangedEvent extends EventObject { /** * The new uri fragment diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 2fc3bf4080..2f420b9286 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -19,6 +19,7 @@ package com.vaadin.ui; import java.io.Serializable; import java.util.Collection; import java.util.Collections; +import java.util.EventObject; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -1612,7 +1613,8 @@ public abstract class AbstractSelect extends AbstractField implements protected void firePropertySetChange() { if (propertySetEventListeners != null && !propertySetEventListeners.isEmpty()) { - final Container.PropertySetChangeEvent event = new PropertySetChangeEvent(); + final Container.PropertySetChangeEvent event = new PropertySetChangeEvent( + this); final Object[] listeners = propertySetEventListeners.toArray(); for (int i = 0; i < listeners.length; i++) { ((Container.PropertySetChangeListener) listeners[i]) @@ -1627,7 +1629,8 @@ public abstract class AbstractSelect extends AbstractField implements */ protected void fireItemSetChange() { if (itemSetEventListeners != null && !itemSetEventListeners.isEmpty()) { - final Container.ItemSetChangeEvent event = new ItemSetChangeEvent(); + final Container.ItemSetChangeEvent event = new ItemSetChangeEvent( + this); final Object[] listeners = itemSetEventListeners.toArray(); for (int i = 0; i < listeners.length; i++) { ((Container.ItemSetChangeListener) listeners[i]) @@ -1640,8 +1643,12 @@ public abstract class AbstractSelect extends AbstractField implements /** * Implementation of item set change event. */ - private class ItemSetChangeEvent implements Serializable, - Container.ItemSetChangeEvent { + private static class ItemSetChangeEvent extends EventObject implements + Serializable, Container.ItemSetChangeEvent { + + private ItemSetChangeEvent(Container source) { + super(source); + } /** * Gets the Property where the event occurred. @@ -1650,7 +1657,7 @@ public abstract class AbstractSelect extends AbstractField implements */ @Override public Container getContainer() { - return AbstractSelect.this; + return (Container) getSource(); } } @@ -1658,9 +1665,13 @@ public abstract class AbstractSelect extends AbstractField implements /** * Implementation of property set change event. */ - private class PropertySetChangeEvent implements + private static class PropertySetChangeEvent extends EventObject implements Container.PropertySetChangeEvent, Serializable { + private PropertySetChangeEvent(Container source) { + super(source); + } + /** * Retrieves the Container whose contents have been modified. * @@ -1668,7 +1679,7 @@ public abstract class AbstractSelect extends AbstractField implements */ @Override public Container getContainer() { - return AbstractSelect.this; + return (Container) getSource(); } } diff --git a/server/src/com/vaadin/ui/AbstractSplitPanel.java b/server/src/com/vaadin/ui/AbstractSplitPanel.java index 93c4ec4f59..dd6ff50efb 100644 --- a/server/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/server/src/com/vaadin/ui/AbstractSplitPanel.java @@ -392,8 +392,8 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * Allowed units are UNITS_PERCENTAGE and UNITS_PIXELS */ public void setMaxSplitPosition(float pos, Unit unit) { - setSplitPositionLimits(getSplitterState().minPosition, posMinUnit, - pos, unit); + setSplitPositionLimits(getSplitterState().minPosition, posMinUnit, pos, + unit); } /** @@ -492,7 +492,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { public void splitterClick(SplitterClickEvent event); } - public class SplitterClickEvent extends ClickEvent { + public static class SplitterClickEvent extends ClickEvent { public SplitterClickEvent(Component source, MouseEventDetails mouseEventDetails) { diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index 0cb74dae6d..3dd2b4dae8 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -570,7 +570,7 @@ public abstract class AbstractTextField extends AbstractField implements return textChangeEventTimeout; } - public class TextChangeEventImpl extends TextChangeEvent { + public static class TextChangeEventImpl extends TextChangeEvent { private String curText; private int cursorPosition; diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index ec75d2da9b..02b7689259 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -108,7 +108,7 @@ public class Button extends AbstractComponent implements * @author Vaadin Ltd. * @since 3.0 */ - public class ClickEvent extends Component.Event { + public static class ClickEvent extends Component.Event { private final MouseEventDetails details; diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index 01033ff560..5bd1d53b86 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -670,7 +670,7 @@ public interface Component extends ClientConnector, Sizeable, Serializable { * @see Component.Listener */ @SuppressWarnings("serial") - public class Event extends EventObject { + public static class Event extends EventObject { /** * Constructs a new event with the specified source component. @@ -860,7 +860,7 @@ public interface Component extends ClientConnector, Sizeable, Serializable { *

*/ @SuppressWarnings("serial") - public class ErrorEvent extends Event { + public static class ErrorEvent extends Event { private final ErrorMessage message; diff --git a/server/src/com/vaadin/ui/ComponentContainer.java b/server/src/com/vaadin/ui/ComponentContainer.java index cee6d7300b..50a6e7e148 100644 --- a/server/src/com/vaadin/ui/ComponentContainer.java +++ b/server/src/com/vaadin/ui/ComponentContainer.java @@ -174,7 +174,7 @@ public interface ComponentContainer extends HasComponents { * Component attach event sent when a component is attached to container. */ @SuppressWarnings("serial") - public class ComponentAttachEvent extends Component.Event { + public static class ComponentAttachEvent extends Component.Event { private final Component component; @@ -218,7 +218,7 @@ public interface ComponentContainer extends HasComponents { * Component detach event sent when a component is detached from container. */ @SuppressWarnings("serial") - public class ComponentDetachEvent extends Component.Event { + public static class ComponentDetachEvent extends Component.Event { private final Component component; diff --git a/server/src/com/vaadin/ui/LoginForm.java b/server/src/com/vaadin/ui/LoginForm.java index abcc7ff607..61846eab4e 100644 --- a/server/src/com/vaadin/ui/LoginForm.java +++ b/server/src/com/vaadin/ui/LoginForm.java @@ -108,7 +108,7 @@ public class LoginForm extends CustomComponent { String value = (parameters.get(key))[0]; params.put(key, value); } - LoginEvent event = new LoginEvent(params); + LoginEvent event = new LoginEvent(LoginForm.this, params); fireEvent(event); return true; } @@ -200,12 +200,12 @@ public class LoginForm extends CustomComponent { /** * This event is sent when login form is submitted. */ - public class LoginEvent extends Event { + public static class LoginEvent extends Event { private Map params; - private LoginEvent(Map params) { - super(LoginForm.this); + private LoginEvent(Component source, Map params) { + super(source); this.params = params; } diff --git a/server/src/com/vaadin/ui/PopupView.java b/server/src/com/vaadin/ui/PopupView.java index 8d6d28e121..182e71d6c9 100644 --- a/server/src/com/vaadin/ui/PopupView.java +++ b/server/src/com/vaadin/ui/PopupView.java @@ -20,10 +20,10 @@ import java.lang.reflect.Method; import java.util.Iterator; import java.util.Map; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.LegacyPaint; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.server.LegacyComponent; /** * @@ -421,7 +421,7 @@ public class PopupView extends AbstractComponentContainer implements * event with {@link #getPopupView()}. * */ - public class PopupVisibilityEvent extends Event { + public static class PopupVisibilityEvent extends Event { public PopupVisibilityEvent(PopupView source) { super(source); diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java index eb66de519f..291aea3bd6 100644 --- a/server/src/com/vaadin/ui/TabSheet.java +++ b/server/src/com/vaadin/ui/TabSheet.java @@ -32,11 +32,11 @@ import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.event.FieldEvents.FocusNotifier; import com.vaadin.server.ErrorMessage; import com.vaadin.server.KeyMapper; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.LegacyPaint; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.tabsheet.TabsheetBaseConstants; import com.vaadin.shared.ui.tabsheet.TabsheetConstants; import com.vaadin.ui.Component.Focusable; @@ -743,7 +743,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, * @author Vaadin Ltd. * @since 3.0 */ - public class SelectedTabChangeEvent extends Component.Event { + public static class SelectedTabChangeEvent extends Component.Event { /** * New instance of selected tab change event diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index 5c94a4c929..d7a33d742c 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -299,7 +299,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, } } - public class CloseEvent extends Component.Event { + public static class CloseEvent extends Component.Event { /** * @@ -422,7 +422,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * (e.g. the browser window is resized). The frequency may vary across * browsers. */ - public class ResizeEvent extends Component.Event { + public static class ResizeEvent extends Component.Event { /** * diff --git a/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java b/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java index d58ff28b00..905ddb529b 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java @@ -56,8 +56,7 @@ public class UriFragmentManagerTest extends TestCase { navigator.navigateTo("test"); control.replay(); - FragmentChangedEvent event = page.new FragmentChangedEvent(page, - "oldtest"); + FragmentChangedEvent event = new FragmentChangedEvent(page, "oldtest"); manager.fragmentChanged(event); } } -- cgit v1.2.3 From ebe75aa2b803db493fd8daab5b4e90f33e2e39d5 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 10:36:20 +0300 Subject: Make two more event classes static (#5855) --- server/src/com/vaadin/Application.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 636204cbf0..e4e49391bb 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -674,18 +674,20 @@ public class Application implements Terminal.ErrorListener, Serializable { * This event is sent each time a window is removed from the application * with {@link com.vaadin.Application#removeWindow(Window)}. */ - public class WindowDetachEvent extends EventObject { + public static class WindowDetachEvent extends EventObject { private final Window window; /** * Creates a event. * + * @param application + * the application to which the detached window belonged. * @param window * the Detached window. */ - public WindowDetachEvent(Window window) { - super(Application.this); + public WindowDetachEvent(Application application, Window window) { + super(application); this.window = window; } @@ -714,18 +716,20 @@ public class Application implements Terminal.ErrorListener, Serializable { * This event is sent each time a window is attached tothe application with * {@link com.vaadin.Application#addWindow(Window)}. */ - public class WindowAttachEvent extends EventObject { + public static class WindowAttachEvent extends EventObject { private final Window window; /** * Creates a event. * + * @param application + * the application to which the detached window belonged. * @param window * the Attached window. */ - public WindowAttachEvent(Window window) { - super(Application.this); + public WindowAttachEvent(Application application, Window window) { + super(application); this.window = window; } -- cgit v1.2.3 From f4d93126ca75631702a2086d770d068d8c13d547 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 10:10:21 +0300 Subject: Make DeploymentConfiguration configurable (#9402) --- .../com/vaadin/server/DeploymentConfiguration.java | 11 +- server/src/com/vaadin/server/VaadinPortlet.java | 198 +++++++++---------- server/src/com/vaadin/server/VaadinServlet.java | 219 ++++++++++----------- .../vaadin/launcher/ApplicationRunnerServlet.java | 24 ++- 4 files changed, 220 insertions(+), 232 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index acfba405e6..6150edbafb 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -32,14 +32,19 @@ import javax.servlet.ServletContext; * @since 7.0 */ public interface DeploymentConfiguration extends Serializable { - /** - * Gets the base URL of the location of Vaadin's static files. + * Return the URL from where static files, e.g. the widgetset and the theme, + * are served. In a standard configuration the VAADIN folder inside the + * returned folder is what is used for widgetsets and themes. + * + * The returned folder is usually the same as the context path and + * independent of the application. * * @param request * the request for which the location should be determined * - * @return a string with the base URL for static files + * @return The location of static resources (should contain the VAADIN + * directory). Never ends with a slash (/). */ public String getStaticFileLocation(WrappedRequest request); diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 25512e9237..4d6d7b84f0 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -66,11 +66,94 @@ import com.vaadin.ui.UI; * * @author peholmst */ -public class VaadinPortlet extends GenericPortlet implements - Constants { +public class VaadinPortlet extends GenericPortlet implements Constants { public static final String RESOURCE_URL_ID = "APP"; + public static class PortletDeploymentConfiguration extends + AbstractDeploymentConfiguration { + private final VaadinPortlet portlet; + + public PortletDeploymentConfiguration(VaadinPortlet portlet, + Properties applicationProperties) { + super(portlet.getClass(), applicationProperties); + this.portlet = portlet; + } + + protected VaadinPortlet getPortlet() { + return portlet; + } + + @Override + public String getConfiguredWidgetset(WrappedRequest request) { + + String widgetset = getApplicationOrSystemProperty( + PARAMETER_WIDGETSET, null); + + if (widgetset == null) { + // If no widgetset defined for the application, check the + // portal property + widgetset = WrappedPortletRequest.cast(request) + .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET); + } + + if (widgetset == null) { + // If no widgetset defined for the portal, use the default + widgetset = DEFAULT_WIDGETSET; + } + + return widgetset; + } + + @Override + public String getConfiguredTheme(WrappedRequest request) { + + // is the default theme defined by the portal? + String themeName = WrappedPortletRequest.cast(request) + .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME); + + if (themeName == null) { + // no, using the default theme defined by Vaadin + themeName = DEFAULT_THEME_NAME; + } + + return themeName; + } + + @Override + public boolean isStandalone(WrappedRequest request) { + return false; + } + + @Override + public String getStaticFileLocation(WrappedRequest request) { + String staticFileLocation = WrappedPortletRequest.cast(request) + .getPortalProperty( + Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); + if (staticFileLocation != null) { + // remove trailing slash if any + while (staticFileLocation.endsWith(".")) { + staticFileLocation = staticFileLocation.substring(0, + staticFileLocation.length() - 1); + } + return staticFileLocation; + } else { + // default for Liferay + return "/html"; + } + } + + @Override + public String getMimeType(String resourceName) { + return getPortlet().getPortletContext().getMimeType(resourceName); + } + + @Override + public SystemMessages getSystemMessages() { + return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; + } + } + public static class WrappedHttpAndPortletRequest extends WrappedPortletRequest { @@ -177,8 +260,7 @@ public class VaadinPortlet extends GenericPortlet implements private final VaadinPortlet portlet; - public AbstractApplicationPortletWrapper( - VaadinPortlet portlet) { + public AbstractApplicationPortletWrapper(VaadinPortlet portlet) { this.portlet = portlet; } @@ -236,101 +318,17 @@ public class VaadinPortlet extends GenericPortlet implements config.getInitParameter(name)); } - deploymentConfiguration = new AbstractDeploymentConfiguration( - getClass(), applicationProperties) { - @Override - public String getConfiguredWidgetset(WrappedRequest request) { - - String widgetset = getApplicationOrSystemProperty( - PARAMETER_WIDGETSET, null); - - if (widgetset == null) { - // If no widgetset defined for the application, check the - // portal property - widgetset = WrappedPortletRequest.cast(request) - .getPortalProperty( - PORTAL_PARAMETER_VAADIN_WIDGETSET); - } - - if (widgetset == null) { - // If no widgetset defined for the portal, use the default - widgetset = DEFAULT_WIDGETSET; - } - - return widgetset; - } - - @Override - public String getConfiguredTheme(WrappedRequest request) { - - // is the default theme defined by the portal? - String themeName = WrappedPortletRequest.cast(request) - .getPortalProperty( - Constants.PORTAL_PARAMETER_VAADIN_THEME); - - if (themeName == null) { - // no, using the default theme defined by Vaadin - themeName = DEFAULT_THEME_NAME; - } - - return themeName; - } - - @Override - public boolean isStandalone(WrappedRequest request) { - return false; - } - - /* - * (non-Javadoc) - * - * @see - * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation - * (com.vaadin.terminal.WrappedRequest) - * - * Return the URL from where static files, e.g. the widgetset and - * the theme, are served. In a standard configuration the VAADIN - * folder inside the returned folder is what is used for widgetsets - * and themes. - * - * @return The location of static resources (inside which there - * should be a VAADIN directory). Does not end with a slash (/). - */ - - @Override - public String getStaticFileLocation(WrappedRequest request) { - String staticFileLocation = WrappedPortletRequest - .cast(request) - .getPortalProperty( - Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); - if (staticFileLocation != null) { - // remove trailing slash if any - while (staticFileLocation.endsWith(".")) { - staticFileLocation = staticFileLocation.substring(0, - staticFileLocation.length() - 1); - } - return staticFileLocation; - } else { - // default for Liferay - return "/html"; - } - } - - @Override - public String getMimeType(String resourceName) { - return getPortletContext().getMimeType(resourceName); - } - - @Override - public SystemMessages getSystemMessages() { - return VaadinPortlet.this.getSystemMessages(); - } - }; + deploymentConfiguration = createDeploymentConfiguration(applicationProperties); addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } + protected DeploymentConfiguration createDeploymentConfiguration( + Properties applicationProperties) { + return new PortletDeploymentConfiguration(this, applicationProperties); + } + @Override public void destroy() { super.destroy(); @@ -913,15 +911,6 @@ public class VaadinPortlet extends GenericPortlet implements } } - /** - * Get system messages from the current application class - * - * @return - */ - protected SystemMessages getSystemMessages() { - return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; - } - private void handleServiceException(WrappedPortletRequest request, WrappedPortletResponse response, Application application, Throwable e) throws IOException, PortletException { @@ -930,7 +919,8 @@ public class VaadinPortlet extends GenericPortlet implements // if this was an UIDL request, response UIDL back to client if (getRequestType(request) == RequestType.UIDL) { - SystemMessages ci = getSystemMessages(); + SystemMessages ci = getDeploymentConfiguration() + .getSystemMessages(); criticalNotification(request, response, ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), null, ci.getInternalErrorURL()); diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 0766d46e93..a10ad965c5 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -54,6 +54,90 @@ import com.vaadin.ui.UI; @SuppressWarnings("serial") public class VaadinServlet extends HttpServlet implements Constants { + public static class ServletDeploymentConfiguration extends + AbstractDeploymentConfiguration { + private final VaadinServlet servlet; + + public ServletDeploymentConfiguration(VaadinServlet servlet, + Properties applicationProperties) { + super(servlet.getClass(), applicationProperties); + this.servlet = servlet; + } + + protected VaadinServlet getServlet() { + return servlet; + } + + @Override + public String getStaticFileLocation(WrappedRequest request) { + HttpServletRequest servletRequest = WrappedHttpServletRequest + .cast(request); + String staticFileLocation; + // if property is defined in configurations, use that + staticFileLocation = getApplicationOrSystemProperty( + PARAMETER_VAADIN_RESOURCES, null); + if (staticFileLocation != null) { + return staticFileLocation; + } + + // the last (but most common) option is to generate default location + // from request + + // if context is specified add it to widgetsetUrl + String ctxPath = servletRequest.getContextPath(); + + // FIXME: ctxPath.length() == 0 condition is probably unnecessary + // and + // might even be wrong. + + if (ctxPath.length() == 0 + && request + .getAttribute("javax.servlet.include.context_path") != null) { + // include request (e.g portlet), get context path from + // attribute + ctxPath = (String) request + .getAttribute("javax.servlet.include.context_path"); + } + + // Remove heading and trailing slashes from the context path + ctxPath = removeHeadingOrTrailing(ctxPath, "/"); + + if (ctxPath.equals("")) { + return ""; + } else { + return "/" + ctxPath; + } + } + + @Override + public String getConfiguredWidgetset(WrappedRequest request) { + return getApplicationOrSystemProperty( + VaadinServlet.PARAMETER_WIDGETSET, + VaadinServlet.DEFAULT_WIDGETSET); + } + + @Override + public String getConfiguredTheme(WrappedRequest request) { + // Use the default + return VaadinServlet.getDefaultTheme(); + } + + @Override + public boolean isStandalone(WrappedRequest request) { + return true; + } + + @Override + public String getMimeType(String resourceName) { + return getServlet().getServletContext().getMimeType(resourceName); + } + + @Override + public SystemMessages getSystemMessages() { + return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; + } + } + private static class AbstractApplicationServletWrapper implements Callback { private final VaadinServlet servlet; @@ -116,50 +200,17 @@ public class VaadinServlet extends HttpServlet implements Constants { servletConfig.getInitParameter(name)); } - deploymentConfiguration = new AbstractDeploymentConfiguration( - getClass(), applicationProperties) { - - @Override - public String getStaticFileLocation(WrappedRequest request) { - HttpServletRequest servletRequest = WrappedHttpServletRequest - .cast(request); - return VaadinServlet.this - .getStaticFilesLocation(servletRequest); - } - - @Override - public String getConfiguredWidgetset(WrappedRequest request) { - return getApplicationOrSystemProperty( - VaadinServlet.PARAMETER_WIDGETSET, - VaadinServlet.DEFAULT_WIDGETSET); - } - - @Override - public String getConfiguredTheme(WrappedRequest request) { - // Use the default - return VaadinServlet.getDefaultTheme(); - } - - @Override - public boolean isStandalone(WrappedRequest request) { - return true; - } - - @Override - public String getMimeType(String resourceName) { - return getServletContext().getMimeType(resourceName); - } - - @Override - public SystemMessages getSystemMessages() { - return VaadinServlet.this.getSystemMessages(); - } - }; + deploymentConfiguration = createDeploymentConfiguration(applicationProperties); addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } + protected ServletDeploymentConfiguration createDeploymentConfiguration( + Properties applicationProperties) { + return new ServletDeploymentConfiguration(this, applicationProperties); + } + @Override public void destroy() { super.destroy(); @@ -430,10 +481,12 @@ public class VaadinServlet extends HttpServlet implements Constants { // This can be removed if cookieless mode (#3228) is supported if (request.getRequestedSessionId() == null) { // User has cookies disabled - criticalNotification(request, response, getSystemMessages() - .getCookiesDisabledCaption(), getSystemMessages() - .getCookiesDisabledMessage(), null, getSystemMessages() - .getCookiesDisabledURL()); + SystemMessages systemMessages = getDeploymentConfiguration() + .getSystemMessages(); + criticalNotification(request, response, + systemMessages.getCookiesDisabledCaption(), + systemMessages.getCookiesDisabledMessage(), null, + systemMessages.getCookiesDisabledURL()); return false; } } @@ -695,7 +748,8 @@ public class VaadinServlet extends HttpServlet implements Constants { Throwable e) throws IOException, ServletException { // if this was an UIDL request, response UIDL back to client if (getRequestType(request) == RequestType.UIDL) { - SystemMessages ci = getSystemMessages(); + SystemMessages ci = getDeploymentConfiguration() + .getSystemMessages(); criticalNotification(request, response, ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), null, ci.getInternalErrorURL()); @@ -758,7 +812,8 @@ public class VaadinServlet extends HttpServlet implements Constants { } try { - SystemMessages ci = getSystemMessages(); + SystemMessages ci = getDeploymentConfiguration() + .getSystemMessages(); if (getRequestType(request) != RequestType.UIDL) { // 'plain' http req - e.g. browser reload; // just go ahead redirect the browser @@ -800,7 +855,8 @@ public class VaadinServlet extends HttpServlet implements Constants { } try { - SystemMessages ci = getSystemMessages(); + SystemMessages ci = getDeploymentConfiguration() + .getSystemMessages(); if (getRequestType(request) != RequestType.UIDL) { // 'plain' http req - e.g. browser reload; // just go ahead redirect the browser @@ -1184,77 +1240,6 @@ public class VaadinServlet extends HttpServlet implements Constants { return request.getParameter(ApplicationConstants.PARAM_UNLOADBURST) != null; } - /** - * Get system messages - * - * @return - */ - protected SystemMessages getSystemMessages() { - return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; - } - - /** - * Return the URL from where static files, e.g. the widgetset and the theme, - * are served. In a standard configuration the VAADIN folder inside the - * returned folder is what is used for widgetsets and themes. - * - * The returned folder is usually the same as the context path and - * independent of the application. - * - * @param request - * @return The location of static resources (should contain the VAADIN - * directory). Never ends with a slash (/). - */ - protected String getStaticFilesLocation(HttpServletRequest request) { - - return getWebApplicationsStaticFileLocation(request); - } - - /** - * The default method to fetch static files location (URL). This method does - * not check for request attribute {@value #REQUEST_VAADIN_STATIC_FILE_PATH} - * - * @param request - * @return - */ - private String getWebApplicationsStaticFileLocation( - HttpServletRequest request) { - String staticFileLocation; - // if property is defined in configurations, use that - staticFileLocation = getDeploymentConfiguration() - .getApplicationOrSystemProperty(PARAMETER_VAADIN_RESOURCES, - null); - if (staticFileLocation != null) { - return staticFileLocation; - } - - // the last (but most common) option is to generate default location - // from request - - // if context is specified add it to widgetsetUrl - String ctxPath = request.getContextPath(); - - // FIXME: ctxPath.length() == 0 condition is probably unnecessary and - // might even be wrong. - - if (ctxPath.length() == 0 - && request.getAttribute("javax.servlet.include.context_path") != null) { - // include request (e.g portlet), get context path from - // attribute - ctxPath = (String) request - .getAttribute("javax.servlet.include.context_path"); - } - - // Remove heading and trailing slashes from the context path - ctxPath = removeHeadingOrTrailing(ctxPath, "/"); - - if (ctxPath.equals("")) { - return ""; - } else { - return "/" + ctxPath; - } - } - /** * Remove any heading or trailing "what" from the "string". * diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index bbe6e061fb..11685033a9 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -21,6 +21,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @@ -30,8 +31,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.server.VaadinServlet; import com.vaadin.server.AbstractUIProvider; +import com.vaadin.server.VaadinServlet; import com.vaadin.server.WrappedHttpServletRequest; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.TestBase; @@ -257,14 +258,21 @@ public class ApplicationRunnerServlet extends VaadinServlet { } @Override - protected String getStaticFilesLocation(HttpServletRequest request) { - URIS uris = getApplicationRunnerURIs(request); - String staticFilesPath = uris.staticFilesPath; - if (staticFilesPath.equals("/")) { - staticFilesPath = ""; - } + protected ServletDeploymentConfiguration createDeploymentConfiguration( + Properties applicationProperties) { + return new ServletDeploymentConfiguration(this, applicationProperties) { + @Override + public String getStaticFileLocation(WrappedRequest request) { + URIS uris = getApplicationRunnerURIs(WrappedHttpServletRequest + .cast(request)); + String staticFilesPath = uris.staticFilesPath; + if (staticFilesPath.equals("/")) { + staticFilesPath = ""; + } - return staticFilesPath; + return staticFilesPath; + } + }; } @Override -- cgit v1.2.3 From e810fed27a55b9ea888b29658e52329a06698322 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 15:48:07 +0300 Subject: Do detach() before clearing application (#9419) --- server/src/com/vaadin/ui/UI.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 4b861d7a25..ee4cb9fd2c 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -691,13 +691,14 @@ public abstract class UI extends AbstractComponentContainer implements if ((application == null) == (this.application == null)) { throw new IllegalStateException("Application has already been set"); } else { + if (application == null) { + detach(); + } this.application = application; } if (application != null) { attach(); - } else { - detach(); } } -- cgit v1.2.3 From b2e861254c0b25a98464653100e731b834a0dadd Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 15:49:16 +0300 Subject: Update test to make UI.getApplication() return an instance (#9419) --- .../server/component/abstractfield/RemoveListenersOnDetach.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java index 5dbab8467e..18567b62f0 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java @@ -18,6 +18,9 @@ public class RemoveListenersOnDetach { int numReadOnlyChanges = 0; AbstractField field = new AbstractField() { + final private Application application = new Application() { + + }; private UI uI = new UI() { @Override @@ -25,8 +28,10 @@ public class RemoveListenersOnDetach { } - }; - private Application application = new Application() { + @Override + public Application getApplication() { + return application; + } }; -- cgit v1.2.3 From 99a423cea5a273d7ddcc39a959895931d12533df Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 15:57:56 +0300 Subject: Fix test to not use removed fields and methods in VaadinServlet --- ...tractApplicationServletStaticFilesLocation.java | 66 ++++------------------ 1 file changed, 11 insertions(+), 55 deletions(-) (limited to 'server') diff --git a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java index 3ae41610fa..b936cae1a5 100644 --- a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java +++ b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java @@ -5,23 +5,21 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; -import java.util.Enumeration; import java.util.Properties; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import junit.framework.TestCase; +import com.vaadin.server.VaadinServlet.ServletDeploymentConfiguration; + public class TestAbstractApplicationServletStaticFilesLocation extends TestCase { VaadinServlet servlet; - private Method getStaticFilesLocationMethod; + // private Method getStaticFilesLocationMethod; @Override protected void setUp() throws Exception { @@ -30,53 +28,11 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase servlet = new VaadinServlet(); // Workaround to avoid calling init and creating servlet config - Field f = VaadinServlet.class.getDeclaredField("applicationProperties"); + Field f = VaadinServlet.class + .getDeclaredField("deploymentConfiguration"); f.setAccessible(true); - f.set(servlet, new Properties()); - - getStaticFilesLocationMethod = VaadinServlet.class.getDeclaredMethod( - "getStaticFilesLocation", - new Class[] { javax.servlet.http.HttpServletRequest.class }); - getStaticFilesLocationMethod.setAccessible(true); - - } - - public class DummyServletConfig implements ServletConfig { - - // public DummyServletConfig(Map initParameters, ) - @Override - public String getInitParameter(String name) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getInitParameterNames() { - return new Enumeration() { - - @Override - public boolean hasMoreElements() { - return false; - } - - @Override - public Object nextElement() { - return null; - } - }; - } - - @Override - public ServletContext getServletContext() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getServletName() { - // TODO Auto-generated method stub - return null; - } + f.set(servlet, new ServletDeploymentConfiguration(servlet, + new Properties())); } @@ -122,8 +78,8 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase // Set request into replay mode replay(request); - String location = (String) getStaticFilesLocationMethod.invoke(servlet, - request); + String location = servlet.getDeploymentConfiguration() + .getStaticFileLocation(servlet.createWrappedRequest(request)); return location; } @@ -135,8 +91,8 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase // Set request into replay mode replay(request); - String location = (String) getStaticFilesLocationMethod.invoke(servlet, - request); + String location = servlet.getDeploymentConfiguration() + .getStaticFileLocation(servlet.createWrappedRequest(request)); return location; } -- cgit v1.2.3 From e8a5f2082d854085fc9da33d5f837900ef347f4f Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 4 Sep 2012 16:47:42 +0300 Subject: Fix SQLContainer indexed access and related tests (#9472) --- .../com/vaadin/data/util/sqlcontainer/SQLContainer.java | 14 +++++++++++--- .../data/util/sqlcontainer/SQLContainerTableQueryTest.java | 7 ++++++- .../vaadin/data/util/sqlcontainer/SQLContainerTest.java | 9 +++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index 7a63e8c6c2..1b479a21d8 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -661,7 +661,8 @@ public class SQLContainer implements Container, Container.Filterable, throw new IndexOutOfBoundsException("Index is negative! index=" + index); } - + // make sure the size field is valid + updateCount(); if (index < size) { if (itemIndexes.keySet().contains(index)) { return itemIndexes.get(index); @@ -671,7 +672,9 @@ public class SQLContainer implements Container, Container.Filterable, } else { // The index is in the added items int offset = index - size; - return addedItems.get(offset).getId(); + // TODO this is very inefficient if looping - should improve + // getItemIds(int, int) + return getFilteredAddedItems().get(offset).getId(); } } @@ -694,7 +697,12 @@ public class SQLContainer implements Container, Container.Filterable, @Override public Object nextItemId(Object itemId) { - return getIdByIndex(indexOfId(itemId) + 1); + int index = indexOfId(itemId) + 1; + try { + return getIdByIndex(index); + } catch (IndexOutOfBoundsException e) { + return null; + } } /* diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java index 438c40823d..7b3d8a4cf2 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java @@ -1468,7 +1468,12 @@ public class SQLContainerTableQueryTest { container.getContainerProperty(container.getIdByIndex(3), "NAME").getValue()); - Assert.assertNull(container.getIdByIndex(4)); + try { + container.getIdByIndex(4); + Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container"); + } catch (IndexOutOfBoundsException e) { + // should throw exception - item is filtered out + } Assert.assertNull(container.nextItemId(container.getIdByIndex(3))); Assert.assertFalse(container.containsId(id2)); diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java index 6649bc16e8..0856b3c08c 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java @@ -2322,8 +2322,13 @@ public class SQLContainerTest { container.getContainerProperty(container.getIdByIndex(3), "NAME").getValue()); - Assert.assertNull(container.getIdByIndex(4)); - Assert.assertNull(container.nextItemId(container.getIdByIndex(3))); + try { + container.getIdByIndex(4); + Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container"); + } catch (IndexOutOfBoundsException e) { + // should throw exception - item is filtered out + } + container.nextItemId(container.getIdByIndex(3)); Assert.assertFalse(container.containsId(id2)); Assert.assertFalse(container.getItemIds().contains(id2)); -- cgit v1.2.3