From 9661839707a76de888a4ede6da4ab9a12d3c023a Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 17 Aug 2016 09:24:32 +0300 Subject: [PATCH] Remove Form and FormFieldFactory Form was deprecated in Vaadin 7 when FieldGroup was introduced. In Vaadin 8, FieldGroup is deprecated in favor of Binder. Having three different "forms" would be very confusing. Change-Id: I17775c922940edc5df7dd5bdc80bfe9652588270 --- .../main/java/com/vaadin/client/ui/VForm.java | 139 -- .../vaadin/client/ui/form/FormConnector.java | 236 --- .../vaadin/data/fieldgroup/FieldGroup.java | 247 ++- .../com/vaadin/legacy/ui/LegacyDateField.java | 59 - .../vaadin/server/ComponentSizeValidator.java | 80 +- .../com/vaadin/ui/DefaultFieldFactory.java | 41 +- server/src/main/java/com/vaadin/ui/Form.java | 1425 ----------------- .../java/com/vaadin/ui/FormFieldFactory.java | 57 - .../tests/server/SerializationTest.java | 21 +- .../tests/server/component/form/FormTest.java | 68 - .../com/vaadin/shared/ui/form/FormState.java | 27 - .../button/ButtonWithShortcutNotRendered.java | 172 -- .../AbstractNestedFormExample.java | 76 - .../components/customfield/AddressField.java | 97 -- .../customfield/AddressFormExample.java | 50 - .../customfield/BooleanFieldExample.java | 89 - .../components/customfield/EmbeddedForm.java | 67 - .../customfield/EmbeddedFormExample.java | 17 - .../customfield/NestedFormExample.java | 15 - .../customfield/NestedPersonForm.java | 99 -- .../components/datefield/CommitInvalid.java | 143 -- .../datefield/DateFieldInSubWindow.java | 150 -- .../ShowSelectedDateAfterInvalid.java | 58 - .../form/FormCaptionClickFocusing.java | 29 - .../form/FormClearDatasourceRepaint.java | 73 - .../form/FormCommitWithInvalidValues.java | 73 - .../components/form/FormDescription.java | 42 - .../components/form/FormErrorVisible.java | 66 - .../components/form/FormFieldCaptions.java | 86 - .../form/FormFieldCaptionsStyles.java | 48 - .../form/FormNotGettingSmaller.java | 52 - .../components/form/FormPrimaryStyleName.java | 47 - .../components/form/FormRenderingFlicker.java | 66 - .../tests/components/form/FormTest.java | 269 ---- .../tests/components/form/FormTooltips.java | 58 - .../form/FormWithEnterShortCut.java | 47 - .../form/FormWithPaddingsAndBorders.java | 46 - .../FormWithPropertyFormatterConnected.java | 91 -- .../form/FormWithRelativelySizedLayout.java | 52 - ...definedWideFormWithRelativeWideFooter.java | 36 - .../gridlayout/GridLayoutInForm.java | 84 - .../KeyboardNavigationDatasourceChange.java | 137 -- .../OutOfSyncIssueWithKeyboardShortcut.java | 194 --- .../UndefinedHeightSubWindowAndContent.java | 60 - .../sqlcontainer/CheckboxUpdateProblem.java | 114 -- .../tests/fieldgroup/FormManyToMany.java | 28 - .../tests/fieldgroup/FormOneToMany.java | 43 - .../vaadin/tests/fieldgroup/FormOneToOne.java | 38 - .../vaadin/tests/fields/FormManyToMany.java | 28 - .../vaadin/tests/fields/FormOneToMany.java | 43 - .../com/vaadin/tests/fields/FormOneToOne.java | 38 - .../tests/layouts/GridLayoutCaptions.java | 230 --- .../vaadin/tests/layouts/HtmlInCaption.java | 10 +- .../tests/layouts/TestAbsoluteLayout.java | 326 ---- .../com/vaadin/tests/tickets/Ticket1710.java | 414 ----- .../com/vaadin/tests/tickets/Ticket1878.java | 391 ----- .../com/vaadin/tests/tickets/Ticket2204.java | 181 --- .../com/vaadin/tests/tickets/Ticket2244.java | 130 -- .../com/vaadin/tests/tickets/Ticket2364.java | 37 - .../com/vaadin/tests/tickets/Ticket2407.java | 21 - .../com/vaadin/tests/tickets/Ticket677.java | 226 --- .../com/vaadin/tests/tickets/Ticket736.java | 190 --- .../validation/EmptyFieldErrorIndicators.java | 147 -- .../validation/RequiredErrorMessage.java | 52 - .../RequiredIndicatorForReadOnly.java | 33 - .../tests/validation/TestValidators.java | 179 --- .../components/form/FormTooltipsTest.java | 60 - ...ndefinedHeightSubWindowAndContentTest.java | 35 - 68 files changed, 171 insertions(+), 7912 deletions(-) delete mode 100644 client/src/main/java/com/vaadin/client/ui/VForm.java delete mode 100644 client/src/main/java/com/vaadin/client/ui/form/FormConnector.java delete mode 100644 server/src/main/java/com/vaadin/ui/Form.java delete mode 100644 server/src/main/java/com/vaadin/ui/FormFieldFactory.java delete mode 100644 server/src/test/java/com/vaadin/tests/server/component/form/FormTest.java delete mode 100644 shared/src/main/java/com/vaadin/shared/ui/form/FormState.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/button/ButtonWithShortcutNotRendered.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/AbstractNestedFormExample.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/AddressField.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/AddressFormExample.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/BooleanFieldExample.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedForm.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedFormExample.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/NestedFormExample.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/customfield/NestedPersonForm.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/datefield/CommitInvalid.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldInSubWindow.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/datefield/ShowSelectedDateAfterInvalid.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormCaptionClickFocusing.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormClearDatasourceRepaint.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormCommitWithInvalidValues.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormDescription.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormErrorVisible.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptions.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptionsStyles.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormNotGettingSmaller.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormPrimaryStyleName.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormRenderingFlicker.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormTest.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormTooltips.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormWithEnterShortCut.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormWithPaddingsAndBorders.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/form/UndefinedWideFormWithRelativeWideFooter.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutInForm.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/table/KeyboardNavigationDatasourceChange.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/textfield/OutOfSyncIssueWithKeyboardShortcut.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContent.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fieldgroup/FormManyToMany.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToMany.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToOne.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fields/FormManyToMany.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fields/FormOneToMany.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/fields/FormOneToOne.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/layouts/GridLayoutCaptions.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/layouts/TestAbsoluteLayout.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket1710.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket1878.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket2204.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket2244.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket2364.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket2407.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket677.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/tickets/Ticket736.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/validation/RequiredErrorMessage.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/validation/RequiredIndicatorForReadOnly.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/validation/TestValidators.java delete mode 100644 uitest/src/test/java/com/vaadin/tests/components/form/FormTooltipsTest.java delete mode 100644 uitest/src/test/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContentTest.java diff --git a/client/src/main/java/com/vaadin/client/ui/VForm.java b/client/src/main/java/com/vaadin/client/ui/VForm.java deleted file mode 100644 index ca38ea070b..0000000000 --- a/client/src/main/java/com/vaadin/client/ui/VForm.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2000-2014 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.client.ui; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.event.dom.client.KeyDownEvent; -import com.google.gwt.event.dom.client.KeyDownHandler; -import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.ComplexPanel; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.VErrorMessage; - -public class VForm extends ComplexPanel implements KeyDownHandler { - - public static final String CLASSNAME = "v-form"; - - /** For internal use only. May be removed or replaced in the future. */ - public String id; - - /** For internal use only. May be removed or replaced in the future. */ - public Widget lo; - - /** For internal use only. May be removed or replaced in the future. */ - public Element legend = DOM.createLegend(); - - /** For internal use only. May be removed or replaced in the future. */ - public Element caption = DOM.createSpan(); - - /** For internal use only. May be removed or replaced in the future. */ - public Element desc = DOM.createDiv(); - - /** For internal use only. May be removed or replaced in the future. */ - public Icon icon; - - /** For internal use only. May be removed or replaced in the future. */ - public VErrorMessage errorMessage = new VErrorMessage(); - - /** For internal use only. May be removed or replaced in the future. */ - public Element fieldContainer = DOM.createDiv(); - - /** For internal use only. May be removed or replaced in the future. */ - public Element footerContainer = DOM.createDiv(); - - /** For internal use only. May be removed or replaced in the future. */ - public Element fieldSet = DOM.createFieldSet(); - - /** For internal use only. May be removed or replaced in the future. */ - public Widget footer; - - /** For internal use only. May be removed or replaced in the future. */ - public ApplicationConnection client; - - /** For internal use only. May be removed or replaced in the future. */ - public ShortcutActionHandler shortcutHandler; - - /** For internal use only. May be removed or replaced in the future. */ - public HandlerRegistration keyDownRegistration; - - public VForm() { - setElement(DOM.createDiv()); - getElement().appendChild(fieldSet); - setStyleName(CLASSNAME); - fieldSet.appendChild(legend); - legend.appendChild(caption); - - fieldSet.appendChild(desc); // Adding description for initial padding - // measurements, removed later if no - // description is set - - fieldSet.appendChild(fieldContainer); - errorMessage.setVisible(false); - - fieldSet.appendChild(errorMessage.getElement()); - fieldSet.appendChild(footerContainer); - - errorMessage.setOwner(this); - } - - @Override - public void setStyleName(String style) { - super.setStyleName(style); - updateStyleNames(); - } - - @Override - public void setStylePrimaryName(String style) { - super.setStylePrimaryName(style); - updateStyleNames(); - } - - protected void updateStyleNames() { - fieldContainer.setClassName(getStylePrimaryName() + "-content"); - errorMessage.setStyleName(getStylePrimaryName() + "-errormessage"); - desc.setClassName(getStylePrimaryName() + "-description"); - footerContainer.setClassName(getStylePrimaryName() + "-footer"); - } - - @Override - public void onKeyDown(KeyDownEvent event) { - shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent())); - } - - public void setFooterWidget(Widget footerWidget) { - if (footer != null) { - remove(footer); - } - if (footerWidget != null) { - super.add(footerWidget, footerContainer); - } - footer = footerWidget; - } - - public void setLayoutWidget(Widget newLayoutWidget) { - if (lo != null) { - remove(lo); - } - if (newLayoutWidget != null) { - super.add(newLayoutWidget, fieldContainer); - } - lo = newLayoutWidget; - } -} diff --git a/client/src/main/java/com/vaadin/client/ui/form/FormConnector.java b/client/src/main/java/com/vaadin/client/ui/form/FormConnector.java deleted file mode 100644 index 857c2bd40e..0000000000 --- a/client/src/main/java/com/vaadin/client/ui/form/FormConnector.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2000-2014 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.client.ui.form; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.KeyDownEvent; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.ComponentConnector; -import com.vaadin.client.ConnectorHierarchyChangeEvent; -import com.vaadin.client.LayoutManager; -import com.vaadin.client.Paintable; -import com.vaadin.client.TooltipInfo; -import com.vaadin.client.UIDL; -import com.vaadin.client.VCaption; -import com.vaadin.client.ui.AbstractComponentContainerConnector; -import com.vaadin.client.ui.ShortcutActionHandler; -import com.vaadin.client.ui.VForm; -import com.vaadin.client.ui.layout.ElementResizeEvent; -import com.vaadin.client.ui.layout.ElementResizeListener; -import com.vaadin.client.ui.layout.MayScrollChildren; -import com.vaadin.shared.ui.ComponentStateUtil; -import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.form.FormState; -import com.vaadin.ui.Form; - -@Connect(Form.class) -public class FormConnector extends AbstractComponentContainerConnector - implements Paintable, MayScrollChildren { - - private final ElementResizeListener footerResizeListener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - VForm form = getWidget(); - - LayoutManager lm = getLayoutManager(); - int footerHeight = 0; - if (form.footer != null) { - footerHeight += lm.getOuterHeight(form.footer.getElement()); - } - - if (form.errorMessage.isVisible()) { - footerHeight += lm.getOuterHeight(form.errorMessage - .getElement()); - footerHeight -= lm.getMarginTop(form.errorMessage.getElement()); - form.errorMessage.getElement().getStyle() - .setMarginTop(-footerHeight, Unit.PX); - form.footerContainer.getStyle().clearMarginTop(); - } else { - form.footerContainer.getStyle().setMarginTop(-footerHeight, - Unit.PX); - } - - form.fieldContainer.getStyle().setPaddingBottom(footerHeight, - Unit.PX); - } - }; - - @Override - protected void init() { - getLayoutManager().addElementResizeListener( - getWidget().errorMessage.getElement(), footerResizeListener); - } - - @Override - public void onUnregister() { - VForm form = getWidget(); - getLayoutManager().removeElementResizeListener( - form.errorMessage.getElement(), footerResizeListener); - if (form.footer != null) { - getLayoutManager().removeElementResizeListener( - form.footer.getElement(), footerResizeListener); - } - } - - @Override - public boolean delegateCaptionHandling() { - return false; - } - - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidget().client = client; - getWidget().id = uidl.getId(); - - if (!isRealUpdate(uidl)) { - return; - } - - boolean legendEmpty = true; - if (getState().caption != null) { - VCaption.setCaptionText(getWidget().caption, getState()); - legendEmpty = false; - } else { - getWidget().caption.setInnerText(""); - } - if (getWidget().icon != null) { - getWidget().legend.removeChild(getWidget().icon.getElement()); - } - if (getIconUri() != null) { - getWidget().icon = client.getIcon(getIconUri()); - getWidget().legend.insertFirst(getWidget().icon.getElement()); - - legendEmpty = false; - } - if (legendEmpty) { - getWidget().addStyleDependentName("nocaption"); - } else { - getWidget().removeStyleDependentName("nocaption"); - } - - if (null != getState().errorMessage) { - getWidget().errorMessage.updateMessage(getState().errorMessage); - getWidget().errorMessage.setVisible(true); - } else { - getWidget().errorMessage.setVisible(false); - } - - if (ComponentStateUtil.hasDescription(getState())) { - getWidget().desc.setInnerHTML(getState().description); - if (getWidget().desc.getParentElement() == null) { - getWidget().fieldSet.insertAfter(getWidget().desc, - getWidget().legend); - } - } else { - getWidget().desc.setInnerHTML(""); - if (getWidget().desc.getParentElement() != null) { - getWidget().fieldSet.removeChild(getWidget().desc); - } - } - - // also recalculates size of the footer if undefined size form - see - // #3710 - client.runDescendentsLayout(getWidget()); - - // We may have actions attached - if (uidl.getChildCount() >= 1) { - UIDL childUidl = uidl.getChildByTagName("actions"); - if (childUidl != null) { - if (getWidget().shortcutHandler == null) { - getWidget().shortcutHandler = new ShortcutActionHandler( - getConnectorId(), client); - getWidget().keyDownRegistration = getWidget() - .addDomHandler(getWidget(), KeyDownEvent.getType()); - } - getWidget().shortcutHandler.updateActionMap(childUidl); - } - } else if (getWidget().shortcutHandler != null) { - getWidget().keyDownRegistration.removeHandler(); - getWidget().shortcutHandler = null; - getWidget().keyDownRegistration = null; - } - } - - @Override - public void updateCaption(ComponentConnector component) { - // NOP form don't render caption for neither field layout nor footer - // layout - } - - @Override - public VForm getWidget() { - return (VForm) super.getWidget(); - } - - @Override - public boolean isReadOnly() { - return super.isReadOnly() || getState().propertyReadOnly; - } - - @Override - public FormState getState() { - return (FormState) super.getState(); - } - - private ComponentConnector getFooter() { - return (ComponentConnector) getState().footer; - } - - private ComponentConnector getLayout() { - return (ComponentConnector) getState().layout; - } - - @Override - public void onConnectorHierarchyChange( - ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { - Widget newFooterWidget = null; - ComponentConnector footer = getFooter(); - - if (footer != null) { - newFooterWidget = footer.getWidget(); - Widget currentFooter = getWidget().footer; - if (currentFooter != null) { - // Remove old listener - getLayoutManager().removeElementResizeListener( - currentFooter.getElement(), footerResizeListener); - } - getLayoutManager().addElementResizeListener( - newFooterWidget.getElement(), footerResizeListener); - } - getWidget().setFooterWidget(newFooterWidget); - - Widget newLayoutWidget = null; - ComponentConnector newLayout = getLayout(); - if (newLayout != null) { - newLayoutWidget = newLayout.getWidget(); - } - getWidget().setLayoutWidget(newLayoutWidget); - } - - @Override - public TooltipInfo getTooltipInfo(Element element) { - // Form shows its description and error message - // as a part of the actual layout - return null; - } - - @Override - public boolean hasTooltip() { - return false; - } -} diff --git a/server/src/main/java/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/main/java/com/vaadin/data/fieldgroup/FieldGroup.java index acf35f154e..c880ef4335 100644 --- a/server/src/main/java/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/main/java/com/vaadin/data/fieldgroup/FieldGroup.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -28,21 +28,18 @@ import java.util.Map; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.TransactionalPropertyWrapper; -import com.vaadin.legacy.ui.LegacyField; import com.vaadin.legacy.data.Validator.InvalidValueException; import com.vaadin.legacy.ui.LegacyAbstractField; +import com.vaadin.legacy.ui.LegacyField; import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; import com.vaadin.util.ReflectTools; /** * FieldGroup provides an easy way of binding fields to data and handling * commits of these fields. *

- * The functionality of FieldGroup is similar to {@link Form} but - * {@link FieldGroup} does not handle layouts in any way. The typical use case - * is to create a layout outside the FieldGroup and then use FieldGroup to bind - * the fields to a data source. + * The typical use case is to create a layout outside the FieldGroup and then + * use FieldGroup to bind the fields to a data source. *

*

* {@link FieldGroup} is not a UI component so it cannot be added to a layout. @@ -50,7 +47,7 @@ import com.vaadin.util.ReflectTools; * using a FieldGroupFieldFactory but you still have to add them to the correct * position in your layout. *

- * + * * @author Vaadin Ltd * @since 7.0 */ @@ -75,15 +72,14 @@ public class FieldGroup implements Serializable { /** * Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a * data source for the field binder. - * + * */ public FieldGroup() { - } /** * Constructs a field binder that uses the given data source. - * + * * @param itemDataSource * The data source to bind the fields to */ @@ -94,7 +90,7 @@ public class FieldGroup implements Serializable { /** * Updates the item that is used by this FieldBinder. Rebinds all fields to * the properties in the new item. - * + * * @param itemDataSource * The new item to use */ @@ -110,10 +106,10 @@ public class FieldGroup implements Serializable { * Gets the item used by this FieldBinder. Note that you must call * {@link #commit()} for the item to be updated unless buffered mode has * been switched off. - * + * * @see #setBuffered(boolean) * @see #commit() - * + * * @return The item used by this FieldBinder */ public Item getItemDataSource() { @@ -123,12 +119,12 @@ public class FieldGroup implements Serializable { /** * Checks the buffered mode for the bound fields. *

- * + * * @see #setBuffered(boolean) for more details on buffered mode - * + * * @see LegacyField#isBuffered() * @return true if buffered mode is on, false otherwise - * + * */ public boolean isBuffered() { return buffered; @@ -144,7 +140,7 @@ public class FieldGroup implements Serializable { *

* The default is to use buffered mode. *

- * + * * @see LegacyField#setBuffered(boolean) * @param buffered * true to turn on buffered mode, false otherwise @@ -166,7 +162,7 @@ public class FieldGroup implements Serializable { * Note that this will not accurately represent the enabled status of all * fields if you change the enabled status of the fields through some other * method than {@link #setEnabled(boolean)}. - * + * * @return true if the fields are enabled, false otherwise */ public boolean isEnabled() { @@ -175,7 +171,7 @@ public class FieldGroup implements Serializable { /** * Updates the enabled state of all bound fields. - * + * * @param fieldsEnabled * true to enable all bound fields, false to disable them */ @@ -193,7 +189,7 @@ public class FieldGroup implements Serializable { * Note that this will not accurately represent the read only status of all * fields if you change the read only status of the fields through some * other method than {@link #setReadOnly(boolean)}. - * + * * @return true if the fields are set to read only, false otherwise */ public boolean isReadOnly() { @@ -204,7 +200,7 @@ public class FieldGroup implements Serializable { * Sets the read only state to the given value for all fields with writable * data source. Fields with read only data source will always be set to read * only. - * + * * @param fieldsReadOnly * true to set the fields with writable data source to read only, * false to set them to read write @@ -226,7 +222,7 @@ public class FieldGroup implements Serializable { *

* The fields are not returned in any specific order. *

- * + * * @return A collection with all bound Fields */ public Collection> getFields() { @@ -240,7 +236,7 @@ public class FieldGroup implements Serializable { *

* This method also adds validators when applicable. *

- * + * * @param field * The field to bind * @param propertyId @@ -249,7 +245,8 @@ public class FieldGroup implements Serializable { * If the field is null or the property id is already bound to * another field by this field binder */ - public void bind(LegacyField field, Object propertyId) throws BindException { + public void bind(LegacyField field, Object propertyId) + throws BindException { throwIfFieldIsNull(field, propertyId); throwIfPropertyIdAlreadyBound(field, propertyId); @@ -275,7 +272,8 @@ public class FieldGroup implements Serializable { return; } - field.setPropertyDataSource(wrapInTransactionalProperty(getItemProperty(propertyId))); + field.setPropertyDataSource( + wrapInTransactionalProperty(getItemProperty(propertyId))); configureField(field); } @@ -289,14 +287,14 @@ public class FieldGroup implements Serializable { private void throwIfFieldIsNull(LegacyField field, Object propertyId) { if (field == null) { - throw new BindException( - String.format( - "Cannot bind property id '%s' to a null field.", - propertyId)); + throw new BindException(String.format( + "Cannot bind property id '%s' to a null field.", + propertyId)); } } - private void throwIfPropertyIdAlreadyBound(LegacyField field, Object propertyId) { + private void throwIfPropertyIdAlreadyBound(LegacyField field, + Object propertyId) { if (propertyIdToField.containsKey(propertyId) && propertyIdToField.get(propertyId) != field) { throw new BindException("Property id " + propertyId @@ -306,7 +304,7 @@ public class FieldGroup implements Serializable { /** * Gets the property with the given property id from the item. - * + * * @param propertyId * The id if the property to find * @return The property with the given id from the item @@ -335,7 +333,7 @@ public class FieldGroup implements Serializable { * Note that the field is not detached from its property data source if it * is no longer connected to the same property id it was bound to using this * FieldBinder. - * + * * @param field * The field to detach * @throws BindException @@ -374,7 +372,7 @@ public class FieldGroup implements Serializable { * By default this updates the buffered, read only and enabled state of the * field. Also adds validators when applicable. Fields with read only data * source are always configured as read only. - * + * * @param field * The field to update */ @@ -392,24 +390,20 @@ public class FieldGroup implements Serializable { /** * Gets the type of the property with the given property id. - * + * * @param propertyId * The propertyId. Must be find * @return The type of the property */ protected Class getPropertyType(Object propertyId) throws BindException { if (getItemDataSource() == null) { - throw new BindException( - "Property type for '" - + propertyId - + "' could not be determined. No item data source has been set."); + throw new BindException("Property type for '" + propertyId + + "' could not be determined. No item data source has been set."); } Property p = getItemDataSource().getItemProperty(propertyId); if (p == null) { - throw new BindException( - "Property type for '" - + propertyId - + "' could not be determined. No property with that id was found."); + throw new BindException("Property type for '" + propertyId + + "' could not be determined. No property with that id was found."); } return p.getType(); @@ -425,7 +419,7 @@ public class FieldGroup implements Serializable { *

* No guarantee is given for the order of the property ids *

- * + * * @return A collection of bound property ids */ public Collection getBoundPropertyIds() { @@ -442,7 +436,7 @@ public class FieldGroup implements Serializable { *

* No guarantee is given for the order of the property ids *

- * + * * @return A collection of property ids that have not been bound to fields */ public Collection getUnboundPropertyIds() { @@ -463,7 +457,7 @@ public class FieldGroup implements Serializable { * restored to what it was before commit was called if any * {@link CommitHandler} throws a CommitException or there is a problem * committing the fields - * + * * @throws CommitException * If the commit was aborted */ @@ -497,7 +491,7 @@ public class FieldGroup implements Serializable { /** * Tries to commit all bound fields one by one and gathers any validation * exceptions in a map, which is returned to the caller - * + * * @return a propertyId to validation exception map which is empty if all * commits succeeded */ @@ -518,16 +512,16 @@ public class FieldGroup implements Serializable { /** * Exception which wraps InvalidValueExceptions from all invalid fields in a * FieldGroup - * + * * @since 7.4 */ - public static class FieldGroupInvalidValueException extends - InvalidValueException { + public static class FieldGroupInvalidValueException + extends InvalidValueException { private Map, InvalidValueException> invalidValueExceptions; /** * Constructs a new exception with the specified validation exceptions. - * + * * @param invalidValueExceptions * a property id to exception map */ @@ -554,9 +548,9 @@ public class FieldGroup implements Serializable { Property.Transactional property = (Property.Transactional) f .getPropertyDataSource(); if (property == null) { - throw new CommitException("Property \"" - + fieldToPropertyId.get(f) - + "\" not bound to datasource."); + throw new CommitException( + "Property \"" + fieldToPropertyId.get(f) + + "\" not bound to datasource."); } property.startTransaction(); } @@ -581,7 +575,7 @@ public class FieldGroup implements Serializable { /** * Sends a preCommit event to all registered commit handlers - * + * * @throws CommitException * If the commit should be aborted */ @@ -596,7 +590,7 @@ public class FieldGroup implements Serializable { /** * Sends a postCommit event to all registered commit handlers - * + * * @throws CommitException * If the commit should be aborted */ @@ -613,7 +607,7 @@ public class FieldGroup implements Serializable { * Discards all changes done to the bound fields. *

* Only has effect if buffered mode is used. - * + * */ public void discard() { for (LegacyField f : fieldToPropertyId.keySet()) { @@ -629,7 +623,7 @@ public class FieldGroup implements Serializable { /** * Returns the field that is bound to the given property id - * + * * @param propertyId * The property id to use to lookup the field * @return The field that is bound to the property id or null if no field is @@ -641,7 +635,7 @@ public class FieldGroup implements Serializable { /** * Returns the property id that is bound to the given field - * + * * @param field * The field to use to lookup the property id * @return The property id that is bound to the field or null if the field @@ -659,7 +653,7 @@ public class FieldGroup implements Serializable { * has been updated ({@link CommitHandler#postCommit(CommitEvent)}). If a * {@link CommitHandler} throws a CommitException the whole commit is * aborted and the fields retain their old values. - * + * * @param commitHandler * The commit handler to add */ @@ -669,9 +663,9 @@ public class FieldGroup implements Serializable { /** * Removes the given commit handler. - * + * * @see #addCommitHandler(CommitHandler) - * + * * @param commitHandler * The commit handler to remove */ @@ -685,7 +679,7 @@ public class FieldGroup implements Serializable { * Use {@link #addCommitHandler(CommitHandler)} and * {@link #removeCommitHandler(CommitHandler)} to register or unregister a * commit handler. - * + * * @return A collection of commit handlers */ protected Collection getCommitHandlers() { @@ -704,7 +698,7 @@ public class FieldGroup implements Serializable { * updated. *

* Throw a {@link CommitException} to abort the commit. - * + * * @param commitEvent * An event containing information regarding the commit * @throws CommitException @@ -717,7 +711,7 @@ public class FieldGroup implements Serializable { * updated. *

* Throw a {@link CommitException} to abort the commit. - * + * * @param commitEvent * An event containing information regarding the commit * @throws CommitException @@ -728,7 +722,7 @@ public class FieldGroup implements Serializable { /** * FIXME javadoc - * + * */ public static class CommitEvent implements Serializable { private FieldGroup fieldBinder; @@ -739,7 +733,7 @@ public class FieldGroup implements Serializable { /** * Returns the field binder that this commit relates to - * + * * @return The FieldBinder that is being committed. */ public FieldGroup getFieldBinder() { @@ -751,9 +745,9 @@ public class FieldGroup implements Serializable { /** * Checks the validity of the bound fields. *

- * Call the {@link LegacyField#validate()} for the fields to get the individual - * error messages. - * + * Call the {@link LegacyField#validate()} for the fields to get the + * individual error messages. + * * @return true if all bound fields are valid, false otherwise. */ public boolean isValid() { @@ -769,7 +763,7 @@ public class FieldGroup implements Serializable { /** * Checks if any bound field has been modified. - * + * * @return true if at least one field has been modified, false otherwise */ public boolean isModified() { @@ -784,9 +778,9 @@ public class FieldGroup implements Serializable { /** * Gets the field factory for the {@link FieldGroup}. The field factory is * only used when {@link FieldGroup} creates a new field. - * + * * @return The field factory in use - * + * */ public FieldGroupFieldFactory getFieldFactory() { return fieldFactory; @@ -795,7 +789,7 @@ public class FieldGroup implements Serializable { /** * Sets the field factory for the {@link FieldGroup}. The field factory is * only used when {@link FieldGroup} creates a new field. - * + * * @param fieldFactory * The field factory to use */ @@ -814,24 +808,24 @@ public class FieldGroup implements Serializable { *

*

* For example: - * + * *

      * public class MyForm extends VerticalLayout {
      * private TextField firstName = new TextField("First name");
-     * @PropertyId("last")
-     * private TextField lastName = new TextField("Last name"); 
+     * @PropertyId("last")
+     * private TextField lastName = new TextField("Last name");
      * private TextField age = new TextField("Age"); ... }
-     * 
-     * MyForm myForm = new MyForm(); 
-     * ... 
+     *
+     * MyForm myForm = new MyForm();
+     * ...
      * fieldGroup.bindMemberFields(myForm);
      * 
- * + * *

* This binds the firstName TextField to a "firstName" property in the item, * lastName TextField to a "last" property and the age TextField to a "age" * property. - * + * * @param objectWithMemberFields * The object that contains (Java) member fields to bind * @throws BindException @@ -847,35 +841,35 @@ public class FieldGroup implements Serializable { * that have not been initialized. *

* This method processes all (Java) member fields whose type extends - * {@link LegacyField} and that can be mapped to a property id. Property ids are - * searched in the following order: @{@link PropertyId} annotations, exact - * field name matches and the case-insensitive matching that ignores + * {@link LegacyField} and that can be mapped to a property id. Property ids + * are searched in the following order: @{@link PropertyId} annotations, + * exact field name matches and the case-insensitive matching that ignores * underscores. Fields that are not initialized (null) are built using the * field factory. All non-null fields for which a property id can be * determined are bound to the property id. *

*

* For example: - * + * *

      * public class MyForm extends VerticalLayout {
      * private TextField firstName = new TextField("First name");
-     * @PropertyId("last")
-     * private TextField lastName = new TextField("Last name"); 
+     * @PropertyId("last")
+     * private TextField lastName = new TextField("Last name");
      * private TextField age;
-     * 
-     * MyForm myForm = new MyForm(); 
-     * ... 
+     *
+     * MyForm myForm = new MyForm();
+     * ...
      * fieldGroup.buildAndBindMemberFields(myForm);
      * 
- * + * *

*

* This binds the firstName TextField to a "firstName" property in the item, * lastName TextField to a "last" property and builds an age TextField using * the field factory and then binds it to the "age" property. *

- * + * * @param objectWithMemberFields * The object that contains (Java) member fields to build and * bind @@ -892,14 +886,14 @@ public class FieldGroup implements Serializable { * member fields that have not been initialized. *

* This method processes all (Java) member fields whose type extends - * {@link LegacyField} and that can be mapped to a property id. Property ids are - * searched in the following order: @{@link PropertyId} annotations, exact - * field name matches and the case-insensitive matching that ignores + * {@link LegacyField} and that can be mapped to a property id. Property ids + * are searched in the following order: @{@link PropertyId} annotations, + * exact field name matches and the case-insensitive matching that ignores * underscores. Fields that are not initialized (null) are built using the * field factory is buildFields is true. All non-null fields for which a * property id can be determined are bound to the property id. *

- * + * * @param objectWithMemberFields * The object that contains (Java) member fields to build and * bind @@ -910,7 +904,8 @@ public class FieldGroup implements Serializable { boolean buildFields) throws BindException { Class objectClass = objectWithMemberFields.getClass(); - for (java.lang.reflect.Field memberField : getFieldsInDeclareOrder(objectClass)) { + for (java.lang.reflect.Field memberField : getFieldsInDeclareOrder( + objectClass)) { if (!LegacyField.class.isAssignableFrom(memberField.getType())) { // Process next field @@ -1012,7 +1007,7 @@ public class FieldGroup implements Serializable { * buildAndBindMemberFields} can easily be customized by overriding this * method. No other changes are needed. *

- * + * * @param memberField * The field an object id is searched for * @return @@ -1020,10 +1015,8 @@ public class FieldGroup implements Serializable { protected Object findPropertyId(java.lang.reflect.Field memberField) { String fieldName = memberField.getName(); if (getItemDataSource() == null) { - throw new SearchException( - "Property id type for field '" - + fieldName - + "' could not be determined. No item data source has been set."); + throw new SearchException("Property id type for field '" + fieldName + + "' could not be determined. No item data source has been set."); } Item dataSource = getItemDataSource(); if (dataSource.getItemProperty(fieldName) != null) { @@ -1049,11 +1042,11 @@ public class FieldGroup implements Serializable { /** * Exception thrown by a FieldGroup when the commit operation fails. - * + * * Provides information about validation errors through * {@link #getInvalidFields()} if the cause of the failure is that all bound * fields did not pass validation - * + * */ public static class CommitException extends Exception { @@ -1099,7 +1092,7 @@ public class FieldGroup implements Serializable { /** * Returns the field group where the exception occurred - * + * * @since 7.4 * @return the field group */ @@ -1136,7 +1129,7 @@ public class FieldGroup implements Serializable { /** * Builds a field and binds it to the given property id using the field * binder. - * + * * @param propertyId * The property id to bind to. Must be present in the field * finder. @@ -1153,7 +1146,7 @@ public class FieldGroup implements Serializable { /** * Builds a field using the given caption and binds it to the given property * id using the field binder. - * + * * @param caption * The caption for the field * @param propertyId @@ -1161,7 +1154,8 @@ public class FieldGroup implements Serializable { * finder. * @throws BindException * If there is a problem while building or binding - * @return The created and bound field. Can be any type of {@link LegacyField}. + * @return The created and bound field. Can be any type of + * {@link LegacyField}. */ public LegacyField buildAndBind(String caption, Object propertyId) throws BindException { @@ -1171,7 +1165,7 @@ public class FieldGroup implements Serializable { /** * Builds a field using the given caption and binds it to the given property * id using the field binder. Ensures the new field is of the given type. - * + * * @param caption * The caption for the field * @param propertyId @@ -1179,11 +1173,12 @@ public class FieldGroup implements Serializable { * finder. * @throws BindException * If the field could not be created - * @return The created and bound field. Can be any type of {@link LegacyField}. + * @return The created and bound field. Can be any type of + * {@link LegacyField}. */ - public T buildAndBind(String caption, Object propertyId, - Class fieldType) throws BindException { + public T buildAndBind(String caption, + Object propertyId, Class fieldType) throws BindException { Class type = getPropertyType(propertyId); T field = build(caption, type, fieldType); @@ -1196,10 +1191,10 @@ public class FieldGroup implements Serializable { * Creates a field based on the given data type. *

* The data type is the type that we want to edit using the field. The field - * type is the type of field we want to create, can be {@link LegacyField} if any - * LegacyField is good. + * type is the type of field we want to create, can be {@link LegacyField} + * if any LegacyField is good. *

- * + * * @param caption * The caption for the new field * @param dataType @@ -1214,9 +1209,9 @@ public class FieldGroup implements Serializable { Class fieldType) throws BindException { T field = getFieldFactory().createField(dataType, fieldType); if (field == null) { - throw new BindException("Unable to build a field of type " - + fieldType.getName() + " for editing " - + dataType.getName()); + throw new BindException( + "Unable to build a field of type " + fieldType.getName() + + " for editing " + dataType.getName()); } field.setCaption(caption); @@ -1224,11 +1219,11 @@ public class FieldGroup implements Serializable { } /** - * Returns an array containing LegacyField objects reflecting all the fields of - * the class or interface represented by this Class object. The elements in - * the array returned are sorted in declare order from sub class to super + * Returns an array containing LegacyField objects reflecting all the fields + * of the class or interface represented by this Class object. The elements + * in the array returned are sorted in declare order from sub class to super * class. - * + * * @param searchClass * @return */ @@ -1248,7 +1243,7 @@ public class FieldGroup implements Serializable { /** * Clears the value of all fields. - * + * * @since 7.4 */ public void clear() { diff --git a/server/src/main/java/com/vaadin/legacy/ui/LegacyDateField.java b/server/src/main/java/com/vaadin/legacy/ui/LegacyDateField.java index 4bb114bbd5..2a91cd7b7b 100644 --- a/server/src/main/java/com/vaadin/legacy/ui/LegacyDateField.java +++ b/server/src/main/java/com/vaadin/legacy/ui/LegacyDateField.java @@ -18,7 +18,6 @@ package com.vaadin.legacy.ui; import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Locale; @@ -44,7 +43,6 @@ import com.vaadin.shared.ui.datefield.DateFieldConstants; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.shared.ui.datefield.TextualDateFieldState; import com.vaadin.ui.Component; -import com.vaadin.ui.Form; import com.vaadin.ui.LegacyComponent; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; @@ -603,16 +601,6 @@ public class LegacyDateField extends LegacyAbstractField implements fireValueChange(false); } - /* - * Because of our custom implementation of isValid(), that - * also checks the parsingSucceeded flag, we must also - * notify the form (if this is used in one) that the - * validity of this field has changed. - * - * Normally fields validity doesn't change without value - * change and form depends on this implementation detail. - */ - notifyFormOfValidityChange(); markAsDirty(); } } else if (newDate != oldDate @@ -699,21 +687,6 @@ public class LegacyDateField extends LegacyAbstractField implements * and flags about invalid input. */ setInternalValue(null); - - /* - * Due to DateField's special implementation of isValid(), - * datefields validity may change although the logical value does - * not change. This is an issue for Form which expects that validity - * of Fields cannot change unless actual value changes. - * - * So we check if this field is inside a form and the form has - * registered this as a field. In this case we repaint the form. - * Without this hacky solution the form might not be able to clean - * validation errors etc. We could avoid this by firing an extra - * value change event, but feels like at least as bad solution as - * this. - */ - notifyFormOfValidityChange(); markAsDirty(); return; } @@ -721,38 +694,6 @@ public class LegacyDateField extends LegacyAbstractField implements super.setValue(newValue, repaintIsNotNeeded); } - /** - * Detects if this field is used in a Form (logically) and if so, notifies - * it (by repainting it) that the validity of this field might have changed. - */ - private void notifyFormOfValidityChange() { - Component parenOfDateField = getParent(); - boolean formFound = false; - while (parenOfDateField != null || formFound) { - if (parenOfDateField instanceof Form) { - Form f = (Form) parenOfDateField; - Collection visibleItemProperties = f.getItemPropertyIds(); - for (Object fieldId : visibleItemProperties) { - LegacyField field = f.getField(fieldId); - if (equals(field)) { - /* - * this datefield is logically in a form. Do the same - * thing as form does in its value change listener that - * it registers to all fields. - */ - f.markAsDirty(); - formFound = true; - break; - } - } - } - if (formFound) { - break; - } - parenOfDateField = parenOfDateField.getParent(); - } - } - @Override protected void setInternalValue(Date newValue) { // Also set the internal dateString diff --git a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java index b8b06c780f..a03059c61c 100644 --- a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java +++ b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -34,10 +34,8 @@ import com.vaadin.ui.AbstractSplitPanel; import com.vaadin.ui.Component; import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Form; import com.vaadin.ui.GridLayout; import com.vaadin.ui.GridLayout.Area; -import com.vaadin.ui.Layout; import com.vaadin.ui.Panel; import com.vaadin.ui.TabSheet; import com.vaadin.ui.UI; @@ -52,7 +50,7 @@ public class ComponentSizeValidator implements Serializable { /** * Recursively checks given component and its subtree for invalid layout * setups. Prints errors to std err stream. - * + * * @param component * component to check * @return set of first level errors found @@ -91,16 +89,6 @@ public class ComponentSizeValidator implements Serializable { errors = validateComponentRelativeSizes(it.next(), errors, parent); } - } else if (component instanceof Form) { - Form form = (Form) component; - if (form.getLayout() != null) { - errors = validateComponentRelativeSizes(form.getLayout(), - errors, parent); - } - if (form.getFooter() != null) { - errors = validateComponentRelativeSizes(form.getFooter(), - errors, parent); - } } return errors; @@ -127,7 +115,8 @@ public class ComponentSizeValidator implements Serializable { err.append("Layout problem detected: "); err.append(msg); err.append("\n"); - err.append("Relative sizes were replaced by undefined sizes, components may not render as expected.\n"); + err.append( + "Relative sizes were replaced by undefined sizes, components may not render as expected.\n"); errorStream.println(err); } @@ -181,7 +170,8 @@ public class ComponentSizeValidator implements Serializable { private final Vector subErrors = new Vector(); - public InvalidLayout(Component component, boolean height, boolean width) { + public InvalidLayout(Component component, boolean height, + boolean width) { this.component = component; invalidHeight = height; invalidWidth = width; @@ -289,7 +279,8 @@ public class ComponentSizeValidator implements Serializable { } - private static Stack getHeightAttributes(Component component) { + private static Stack getHeightAttributes( + Component component) { Stack attributes = new Stack(); attributes .add(new ComponentInfo(component, getHeightString(component))); @@ -303,7 +294,8 @@ public class ComponentSizeValidator implements Serializable { return attributes; } - private static Stack getWidthAttributes(Component component) { + private static Stack getWidthAttributes( + Component component) { Stack attributes = new Stack(); attributes.add(new ComponentInfo(component, getWidthString(component))); Component parent = component.getParent(); @@ -320,7 +312,8 @@ public class ComponentSizeValidator implements Serializable { String width = "width: "; if (hasRelativeWidth(component)) { width += "RELATIVE, " + component.getWidth() + " %"; - } else if (component instanceof Window && component.getParent() == null) { + } else if (component instanceof Window + && component.getParent() == null) { width += "MAIN WINDOW"; } else if (component.getWidth() >= 0) { width += "ABSOLUTE, " + component.getWidth() + " " @@ -336,7 +329,8 @@ public class ComponentSizeValidator implements Serializable { String height = "height: "; if (hasRelativeHeight(component)) { height += "RELATIVE, " + component.getHeight() + " %"; - } else if (component instanceof Window && component.getParent() == null) { + } else if (component instanceof Window + && component.getParent() == null) { height += "MAIN WINDOW"; } else if (component.getHeight() > 0) { height += "ABSOLUTE, " + component.getHeight() + " " @@ -427,8 +421,8 @@ public class ComponentSizeValidator implements Serializable { if (parent instanceof VerticalLayout) { horizontal = false; } - if (horizontal - && hasNonRelativeHeightComponent((AbstractOrderedLayout) parent)) { + if (horizontal && hasNonRelativeHeightComponent( + (AbstractOrderedLayout) parent)) { return true; } else { return false; @@ -484,11 +478,12 @@ public class ComponentSizeValidator implements Serializable { } private static boolean hasRelativeHeight(Component component) { - return (component.getHeightUnits() == Unit.PERCENTAGE && component - .getHeight() > 0); + return (component.getHeightUnits() == Unit.PERCENTAGE + && component.getHeight() > 0); } - private static boolean hasNonRelativeWidthComponent(AbstractOrderedLayout ol) { + private static boolean hasNonRelativeWidthComponent( + AbstractOrderedLayout ol) { Iterator it = ol.getComponentIterator(); while (it.hasNext()) { if (!hasRelativeWidth(it.next())) { @@ -536,7 +531,8 @@ public class ComponentSizeValidator implements Serializable { boolean columnHasWidth = false; for (int col = componentArea.getColumn1(); !columnHasWidth && col <= componentArea.getColumn2(); col++) { - for (int row = 0; !columnHasWidth && row < gl.getRows(); row++) { + for (int row = 0; !columnHasWidth + && row < gl.getRows(); row++) { Component c = gl.getComponent(col, row); if (c != null) { columnHasWidth = !hasRelativeWidth(c); @@ -549,12 +545,6 @@ public class ComponentSizeValidator implements Serializable { // Other components define column width return true; } - } else if (parent instanceof Form) { - /* - * If some other part of the form is not relative it determines - * the component width - */ - return hasNonRelativeWidthComponent((Form) parent); } else if (parent instanceof AbstractSplitPanel || parent instanceof TabSheet || parent instanceof CustomComponent) { @@ -591,20 +581,6 @@ public class ComponentSizeValidator implements Serializable { } - private static boolean hasNonRelativeWidthComponent(Form form) { - Layout layout = form.getLayout(); - Layout footer = form.getFooter(); - - if (layout != null && !hasRelativeWidth(layout)) { - return true; - } - if (footer != null && !hasRelativeWidth(footer)) { - return true; - } - - return false; - } - private static Map creationLocations = new HashMap(); private static Map widthLocations = new HashMap(); private static Map heightLocations = new HashMap(); @@ -638,7 +614,8 @@ public class ComponentSizeValidator implements Serializable { setLocation(heightLocations, object); } - private static void setLocation(Map map, Object object) { + private static void setLocation(Map map, + Object object) { StackTraceElement[] traceLines = Thread.currentThread().getStackTrace(); for (StackTraceElement traceElement : traceLines) { Class cls; @@ -650,7 +627,8 @@ public class ComponentSizeValidator implements Serializable { } cls = Class.forName(className); - if (cls == ComponentSizeValidator.class || cls == Thread.class) { + if (cls == ComponentSizeValidator.class + || cls == Thread.class) { continue; } @@ -675,7 +653,7 @@ public class ComponentSizeValidator implements Serializable { /** * Validates the layout and returns a collection of errors - * + * * @since 7.1 * @param ui * The UI to validate diff --git a/server/src/main/java/com/vaadin/ui/DefaultFieldFactory.java b/server/src/main/java/com/vaadin/ui/DefaultFieldFactory.java index fc096e6bb7..9078c6095e 100644 --- a/server/src/main/java/com/vaadin/ui/DefaultFieldFactory.java +++ b/server/src/main/java/com/vaadin/ui/DefaultFieldFactory.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -15,10 +15,10 @@ */ package com.vaadin.ui; +import java.text.Normalizer.Form; import java.util.Date; import com.vaadin.data.Container; -import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.legacy.ui.LegacyCheckBox; import com.vaadin.legacy.ui.LegacyDateField; @@ -27,23 +27,22 @@ import com.vaadin.legacy.ui.LegacyTextField; import com.vaadin.shared.util.SharedUtil; /** - * This class contains a basic implementation for both {@link FormFieldFactory} - * and {@link TableFieldFactory}. The class is singleton, use {@link #get()} - * method to get reference to the instance. - * + * This class contains a basic implementation for {@link TableFieldFactory}. The + * class is singleton, use {@link #get()} method to get reference to the + * instance. + * *

* There are also some static helper methods available for custom built field * factories. - * + * */ -public class DefaultFieldFactory - implements FormFieldFactory, TableFieldFactory { +public class DefaultFieldFactory implements TableFieldFactory { private static final DefaultFieldFactory instance = new DefaultFieldFactory(); /** * Singleton method to get an instance of DefaultFieldFactory. - * + * * @return an instance of DefaultFieldFactory */ public static DefaultFieldFactory get() { @@ -53,15 +52,6 @@ public class DefaultFieldFactory protected DefaultFieldFactory() { } - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - Class type = item.getItemProperty(propertyId).getType(); - LegacyField field = createFieldByPropertyType(type); - field.setCaption(createCaptionByPropertyId(propertyId)); - return field; - } - @Override public LegacyField createField(Container container, Object itemId, Object propertyId, Component uiContext) { @@ -76,7 +66,7 @@ public class DefaultFieldFactory /** * If name follows method naming conventions, convert the name to spaced * upper case text. For example, convert "firstName" to "First Name" - * + * * @param propertyId * @return the formatted caption string */ @@ -95,7 +85,7 @@ public class DefaultFieldFactory * Item: {@link Form}.
* default field type: {@link LegacyTextField}. *

- * + * * @param type * the type of the property * @return the most suitable generic {@link LegacyField} for given type @@ -106,11 +96,6 @@ public class DefaultFieldFactory return null; } - // Item field - if (Item.class.isAssignableFrom(type)) { - return new Form(); - } - // Date field if (Date.class.isAssignableFrom(type)) { final LegacyDateField df = new LegacyDateField(); diff --git a/server/src/main/java/com/vaadin/ui/Form.java b/server/src/main/java/com/vaadin/ui/Form.java deleted file mode 100644 index ff747f429f..0000000000 --- a/server/src/main/java/com/vaadin/ui/Form.java +++ /dev/null @@ -1,1425 +0,0 @@ -/* - * Copyright 2000-2014 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.ui; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import com.vaadin.data.Buffered; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.util.BeanItem; -import com.vaadin.event.Action; -import com.vaadin.event.Action.Handler; -import com.vaadin.event.Action.ShortcutNotifier; -import com.vaadin.event.ActionManager; -import com.vaadin.legacy.data.Validatable; -import com.vaadin.legacy.data.Validator; -import com.vaadin.legacy.data.Validator.InvalidValueException; -import com.vaadin.legacy.ui.LegacyAbstractField; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.server.AbstractErrorMessage; -import com.vaadin.server.CompositeErrorMessage; -import com.vaadin.server.ErrorMessage; -import com.vaadin.server.PaintException; -import com.vaadin.server.PaintTarget; -import com.vaadin.server.UserError; -import com.vaadin.shared.ui.form.FormState; - -/** - * Form component provides easy way of creating and managing sets fields. - * - *

- * Form is a container for fields implementing {@link LegacyField} - * interface. It provides support for any layouts and provides buffering - * interface for easy connection of commit and discard buttons. All the form - * fields can be customized by adding validators, setting captions and icons, - * setting immediateness, etc. Also direct mechanism for replacing existing - * fields with selections is given. - *

- * - *

- * Form provides customizable editor for classes implementing - * {@link com.vaadin.data.Item} interface. Also the form itself implements this - * interface for easier connectivity to other items. To use the form as editor - * for an item, just connect the item to form with - * {@link Form#setItemDataSource(Item)}. If only a part of the item needs to be - * edited, {@link Form#setItemDataSource(Item,Collection)} can be used instead. - * After the item has been connected to the form, the automatically created - * fields can be customized and new fields can be added. If you need to connect - * a class that does not implement {@link com.vaadin.data.Item} interface, most - * properties of any class following bean pattern, can be accessed trough - * {@link com.vaadin.data.util.BeanItem}. - *

- * - * @author Vaadin Ltd. - * @since 3.0 - * @deprecated As of 7.0, use {@link FieldGroup} instead of {@link Form} for - * more flexibility. - */ -@Deprecated -public class Form extends LegacyAbstractField implements Item.Editor, - Buffered, Item, Validatable, Action.Notifier, HasComponents, - LegacyComponent { - - private Object propertyValue; - - /** - * Item connected to this form as datasource. - */ - private Item itemDatasource; - - /** - * Ordered list of property ids in this editor. - */ - private final LinkedList propertyIds = new LinkedList<>(); - - /** - * Current buffered source exception. - */ - private Buffered.SourceException currentBufferedSourceException = null; - - /** - * Is the form in buffered mode. - */ - private boolean buffered = false; - - /** - * Mapping from propertyName to corresponding field. - */ - private final HashMap> fields = new HashMap<>(); - - /** - * Form may act as an Item, its own properties are stored here. - */ - private final HashMap> ownProperties = new HashMap<>(); - - /** - * Field factory for this form. - */ - private FormFieldFactory fieldFactory; - - /** - * Visible item properties. - */ - private Collection visibleItemProperties; - - /** - * Form needs to repaint itself if child fields value changes due possible - * change in form validity. - * - * TODO introduce ValidityChangeEvent (#6239) and start using it instead. - * See e.g. DateField#notifyFormOfValidityChange(). - */ - private final ValueChangeListener fieldValueChangeListener = new ValueChangeListener() { - @Override - public void valueChange( - com.vaadin.data.Property.ValueChangeEvent event) { - markAsDirty(); - } - }; - - /** - * If this is true, commit implicitly calls setValidationVisible(true). - */ - private boolean validationVisibleOnCommit = true; - - // special handling for gridlayout; remember initial cursor pos - private int gridlayoutCursorX = -1; - private int gridlayoutCursorY = -1; - - /** - * Keeps track of the Actions added to this component, and manages the - * painting and handling as well. Note that the extended LegacyAbstractField - * is a {@link ShortcutNotifier} and has a actionManager that delegates - * actions to the containing window. This one does not delegate. - */ - private ActionManager ownActionManager = new ActionManager(this); - - /** - * Constructs a new form with default layout. - * - *

- * By default the form uses {@link FormLayout}. - *

- */ - public Form() { - this(null); - setValidationVisible(false); - } - - /** - * Constructs a new form with given {@link Layout}. - * - * @param formLayout - * the layout of the form. - */ - public Form(Layout formLayout) { - this(formLayout, DefaultFieldFactory.get()); - } - - /** - * Constructs a new form with given {@link Layout} and - * {@link FormFieldFactory}. - * - * @param formLayout - * the layout of the form. - * @param fieldFactory - * the FieldFactory of the form. - */ - public Form(Layout formLayout, FormFieldFactory fieldFactory) { - super(); - setLayout(formLayout); - setFooter(new HorizontalLayout()); - setFormFieldFactory(fieldFactory); - setValidationVisible(false); - setWidth(100, UNITS_PERCENTAGE); - } - - @Override - protected FormState getState() { - return (FormState) super.getState(); - } - - @Override - protected FormState getState(boolean markAsDirty) { - return (FormState) super.getState(markAsDirty); - } - - /* Documented in interface */ - @Override - public void paintContent(PaintTarget target) throws PaintException { - if (ownActionManager != null) { - ownActionManager.paintActions(null, target); - } - } - - @Override - public void changeVariables(Object source, Map variables) { - // Actions - if (ownActionManager != null) { - ownActionManager.handleActions(variables, this); - } - } - - /** - * The error message of a Form is the error of the first field with a - * non-empty error. - * - * Empty error messages of the contained fields are skipped, because an - * empty error indicator would be confusing to the user, especially if there - * are errors that have something to display. This is also the reason why - * the calculation of the error message is separate from validation, because - * validation fails also on empty errors. - */ - @Override - public ErrorMessage getErrorMessage() { - - // Reimplement the checking of validation error by using - // getErrorMessage() recursively instead of validate(). - ErrorMessage validationError = null; - if (isValidationVisible()) { - for (final Iterator i = propertyIds.iterator(); i - .hasNext();) { - Object f = fields.get(i.next()); - if (f instanceof AbstractComponent) { - AbstractComponent field = (AbstractComponent) f; - - validationError = field.getErrorMessage(); - if (validationError != null) { - // Show caption as error for fields with empty errors - if ("".equals(validationError.toString())) { - validationError = new UserError(field.getCaption()); - } - break; - } else if (f instanceof LegacyField && !((LegacyField) f) - .isValid()) { - // Something is wrong with the field, but no proper - // error is given. Generate one. - validationError = new UserError(field.getCaption()); - break; - } - } - } - } - - // Return if there are no errors at all - if (getComponentError() == null && validationError == null - && currentBufferedSourceException == null) { - return null; - } - - // Throw combination of the error types - return new CompositeErrorMessage( - new ErrorMessage[] { - getComponentError(), - validationError, - AbstractErrorMessage - .getErrorMessageForException( - currentBufferedSourceException) }); - } - - /** - * Controls the making validation visible implicitly on commit. - * - * Having commit() call setValidationVisible(true) implicitly is the default - * behaviour. You can disable the implicit setting by setting this property - * as false. - * - * It is useful, because you usually want to start with the form free of - * errors and only display them after the user clicks Ok. You can disable - * the implicit setting by setting this property as false. - * - * @param makeVisible - * If true (default), validation is made visible when commit() is - * called. If false, the visibility is left as it is. - */ - public void setValidationVisibleOnCommit(boolean makeVisible) { - validationVisibleOnCommit = makeVisible; - } - - /** - * Is validation made automatically visible on commit? - * - * See setValidationVisibleOnCommit(). - * - * @return true if validation is made automatically visible on commit. - */ - public boolean isValidationVisibleOnCommit() { - return validationVisibleOnCommit; - } - - /* - * Commit changes to the data source Don't add a JavaDoc comment here, we - * use the default one from the interface. - */ - @Override - public void commit() throws Buffered.SourceException, - InvalidValueException { - - LinkedList problems = null; - - // Only commit on valid state if so requested - if (!isInvalidCommitted() && !isValid()) { - /* - * The values are not ok and we are told not to commit invalid - * values - */ - if (validationVisibleOnCommit) { - setValidationVisible(true); - } - - // Find the first invalid value and throw the exception - validate(); - } - - // Try to commit all - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - try { - final LegacyField f = (fields.get(i.next())); - // Commit only non-readonly fields. - if (!f.isReadOnly()) { - f.commit(); - } - } catch (final Buffered.SourceException e) { - if (problems == null) { - problems = new LinkedList<>(); - } - problems.add(e); - } - } - - // No problems occurred - if (problems == null) { - if (currentBufferedSourceException != null) { - currentBufferedSourceException = null; - markAsDirty(); - } - return; - } - - // Commit problems - final Throwable[] causes = new Throwable[problems.size()]; - int index = 0; - for (final Iterator i = problems.iterator(); i - .hasNext();) { - causes[index++] = i.next(); - } - final Buffered.SourceException e = new Buffered.SourceException(this, - causes); - currentBufferedSourceException = e; - markAsDirty(); - throw e; - } - - /* - * Discards local changes and refresh values from the data source Don't add - * a JavaDoc comment here, we use the default one from the interface. - */ - @Override - public void discard() throws Buffered.SourceException { - - LinkedList problems = null; - - // Try to discard all changes - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - try { - (fields.get(i.next())).discard(); - } catch (final Buffered.SourceException e) { - if (problems == null) { - problems = new LinkedList<>(); - } - problems.add(e); - } - } - - // No problems occurred - if (problems == null) { - if (currentBufferedSourceException != null) { - currentBufferedSourceException = null; - markAsDirty(); - } - return; - } - - // Discards problems occurred - final Throwable[] causes = new Throwable[problems.size()]; - int index = 0; - for (final Iterator i = problems.iterator(); i - .hasNext();) { - causes[index++] = i.next(); - } - final Buffered.SourceException e = new Buffered.SourceException(this, - causes); - currentBufferedSourceException = e; - markAsDirty(); - throw e; - } - - /* - * Is the object modified but not committed? Don't add a JavaDoc comment - * here, we use the default one from the interface. - */ - @Override - public boolean isModified() { - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - final LegacyField f = fields.get(i.next()); - if (f != null && f.isModified()) { - return true; - } - - } - return false; - } - - /* - * Sets the editor's buffered mode to the specified status. Don't add a - * JavaDoc comment here, we use the default one from the interface. - */ - @Override - public void setBuffered(boolean buffered) { - if (buffered != this.buffered) { - this.buffered = buffered; - for (final Iterator i = propertyIds.iterator(); i - .hasNext();) { - (fields.get(i.next())).setBuffered(buffered); - } - } - } - - /** - * Adds a new property to form and create corresponding field. - * - * @see com.vaadin.data.Item#addItemProperty(Object, Property) - */ - @Override - public boolean addItemProperty(Object id, Property property) { - - // Checks inputs - if (id == null || property == null) { - throw new NullPointerException("Id and property must be non-null"); - } - - // Checks that the property id is not reserved - if (propertyIds.contains(id)) { - return false; - } - - propertyIds.add(id); - ownProperties.put(id, property); - - // Gets suitable field - final LegacyField field = fieldFactory.createField(this, id, this); - if (field == null) { - return false; - } - - // Configures the field - bindPropertyToField(id, property, field); - - // Register and attach the created field - addField(id, field); - - return true; - } - - /** - * Registers the field with the form and adds the field to the form layout. - * - *

- * The property id must not be already used in the form. - *

- * - *

- * This field is added to the layout using the - * {@link #attachField(Object, LegacyField)} method. - *

- * - * @param propertyId - * the Property id the the field. - * @param field - * the field which should be added to the form. - */ - public void addField(Object propertyId, LegacyField field) { - registerField(propertyId, field); - attachField(propertyId, field); - markAsDirty(); - } - - /** - * Register the field with the form. All registered fields are validated - * when the form is validated and also committed when the form is committed. - * - *

- * The property id must not be already used in the form. - *

- * - * - * @param propertyId - * the Property id of the field. - * @param field - * the LegacyField that should be registered - */ - private void registerField(Object propertyId, LegacyField field) { - if (propertyId == null || field == null) { - return; - } - - fields.put(propertyId, field); - field.addListener(fieldValueChangeListener); - if (!propertyIds.contains(propertyId)) { - // adding a field directly - propertyIds.addLast(propertyId); - } - - // Update the buffered mode and immediate to match the - // form. - // Should this also include invalidCommitted (#3993)? - field.setBuffered(buffered); - if (isImmediate() && field instanceof AbstractComponent) { - ((AbstractComponent) field).setImmediate(true); - } - } - - /** - * Adds the field to the form layout. - *

- * The field is added to the form layout in the default position (the - * position used by {@link Layout#addComponent(Component)}. If the - * underlying layout is a {@link CustomLayout} the field is added to the - * CustomLayout location given by the string representation of the property - * id using {@link CustomLayout#addComponent(Component, String)}. - *

- * - *

- * Override this method to control how the fields are added to the layout. - *

- * - * @param propertyId - * @param field - */ - protected void attachField(Object propertyId, LegacyField field) { - if (propertyId == null || field == null) { - return; - } - - Layout layout = getLayout(); - if (layout instanceof CustomLayout) { - ((CustomLayout) layout).addComponent(field, propertyId.toString()); - } else { - layout.addComponent(field); - } - - } - - /** - * The property identified by the property id. - * - *

- * The property data source of the field specified with property id is - * returned. If there is a (with specified property id) having no data - * source, the field is returned instead of the data source. - *

- * - * @see com.vaadin.data.Item#getItemProperty(Object) - */ - @Override - public Property getItemProperty(Object id) { - final LegacyField field = fields.get(id); - if (field == null) { - // field does not exist or it is not (yet) created for this property - return ownProperties.get(id); - } - final Property property = field.getPropertyDataSource(); - - if (property != null) { - return property; - } else { - return field; - } - } - - /** - * Gets the field identified by the propertyid. - * - * @param propertyId - * the id of the property. - */ - public LegacyField getField(Object propertyId) { - return fields.get(propertyId); - } - - /* Documented in interface */ - @Override - public Collection getItemPropertyIds() { - return Collections.unmodifiableCollection(propertyIds); - } - - /** - * Removes the property and corresponding field from the form. - * - * @see com.vaadin.data.Item#removeItemProperty(Object) - */ - @Override - public boolean removeItemProperty(Object id) { - ownProperties.remove(id); - - final LegacyField field = fields.get(id); - - if (field != null) { - propertyIds.remove(id); - fields.remove(id); - detachField(field); - field.removeListener(fieldValueChangeListener); - return true; - } - - return false; - } - - /** - * Called when a form field is detached from a Form. Typically when a new - * Item is assigned to Form via {@link #setItemDataSource(Item)}. - *

- * Override this method to control how the fields are removed from the - * layout. - *

- * - * @param field - * the field to be detached from the forms layout. - */ - protected void detachField(final LegacyField field) { - Component p = field.getParent(); - if (p instanceof ComponentContainer) { - ((ComponentContainer) p).removeComponent(field); - } - } - - /** - * Removes all properties and fields from the form. - * - * @return the Success of the operation. Removal of all fields succeeded if - * (and only if) the return value is true. - */ - public boolean removeAllProperties() { - final Object[] properties = propertyIds.toArray(); - boolean success = true; - - for (int i = 0; i < properties.length; i++) { - if (!removeItemProperty(properties[i])) { - success = false; - } - } - - return success; - } - - /* Documented in the interface */ - @Override - public Item getItemDataSource() { - return itemDatasource; - } - - /** - * Sets the item datasource for the form. - * - *

- * Setting item datasource clears any fields, the form might contain and - * adds all the properties as fields to the form. - *

- * - * @see com.vaadin.data.Item.Viewer#setItemDataSource(Item) - */ - @Override - public void setItemDataSource(Item newDataSource) { - setItemDataSource(newDataSource, - newDataSource != null ? newDataSource.getItemPropertyIds() - : null); - } - - /** - * Set the item datasource for the form, but limit the form contents to - * specified properties of the item. - * - *

- * Setting item datasource clears any fields, the form might contain and - * adds the specified the properties as fields to the form, in the specified - * order. - *

- * - * @see com.vaadin.data.Item.Viewer#setItemDataSource(Item) - */ - public void setItemDataSource(Item newDataSource, - Collection propertyIds) { - - if (getLayout() instanceof GridLayout) { - GridLayout gl = (GridLayout) getLayout(); - if (gridlayoutCursorX == -1) { - // first setItemDataSource, remember initial cursor - gridlayoutCursorX = gl.getCursorX(); - gridlayoutCursorY = gl.getCursorY(); - } else { - // restore initial cursor - gl.setCursorX(gridlayoutCursorX); - gl.setCursorY(gridlayoutCursorY); - } - } - - // Removes all fields first from the form - removeAllProperties(); - - // Sets the datasource - itemDatasource = newDataSource; - - // If the new datasource is null, just set null datasource - if (itemDatasource == null) { - markAsDirty(); - return; - } - - // Adds all the properties to this form - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - final Object id = i.next(); - final Property property = itemDatasource.getItemProperty(id); - if (id != null && property != null) { - final LegacyField f = fieldFactory.createField( - itemDatasource, id, - this); - if (f != null) { - bindPropertyToField(id, property, f); - addField(id, f); - } - } - } - } - - /** - * Binds an item property to a field. The default behavior is to bind - * property straight to LegacyField. If Property.Viewer type property (e.g. - * PropertyFormatter) is already set for field, the property is bound to - * that Property.Viewer. - * - * @param propertyId - * @param property - * @param field - * @since 6.7.3 - */ - protected void bindPropertyToField(final Object propertyId, - final Property property, final LegacyField field) { - // check if field has a property that is Viewer set. In that case we - // expect developer has e.g. PropertyFormatter that he wishes to use and - // assign the property to the Viewer instead. - boolean hasFilterProperty = field.getPropertyDataSource() != null - && (field.getPropertyDataSource() instanceof Property.Viewer); - if (hasFilterProperty) { - ((Property.Viewer) field.getPropertyDataSource()) - .setPropertyDataSource(property); - } else { - field.setPropertyDataSource(property); - } - } - - /** - * Gets the layout of the form. - * - *

- * By default form uses OrderedLayout with form - * -style. - *

- * - * @return the Layout of the form. - */ - public Layout getLayout() { - return (Layout) getState(false).layout; - } - - /** - * Sets the layout of the form. - * - *

- * If set to null then Form uses a FormLayout by default. - *

- * - * @param layout - * the layout of the form. - */ - public void setLayout(Layout layout) { - - // Use orderedlayout by default - if (layout == null) { - layout = new FormLayout(); - } - - // reset cursor memory - gridlayoutCursorX = -1; - gridlayoutCursorY = -1; - - // Move fields from previous layout - if (getLayout() != null) { - final Object[] properties = propertyIds.toArray(); - for (int i = 0; i < properties.length; i++) { - LegacyField f = getField(properties[i]); - detachField(f); - if (layout instanceof CustomLayout) { - ((CustomLayout) layout).addComponent(f, - properties[i].toString()); - } else { - layout.addComponent(f); - } - } - - getLayout().setParent(null); - } - - // Replace the previous layout - layout.setParent(this); - getState().layout = layout; - } - - /** - * Sets the form field to be selectable from static list of changes. - * - *

- * The list values and descriptions are given as array. The value-array must - * contain the current value of the field and the lengths of the arrays must - * match. Null values are not supported. - *

- * - * Note: since Vaadin 7.0, returns an {@link AbstractSelect} instead of a - * {@link Select}. - * - * @param propertyId - * the id of the property. - * @param values - * @param descriptions - * @return the select property generated - */ - public AbstractSelect replaceWithSelect(Object propertyId, Object[] values, - Object[] descriptions) { - - // Checks the parameters - if (propertyId == null || values == null || descriptions == null) { - throw new NullPointerException("All parameters must be non-null"); - } - if (values.length != descriptions.length) { - throw new IllegalArgumentException( - "Value and description list are of different size"); - } - - // Gets the old field - final LegacyField oldField = fields.get(propertyId); - if (oldField == null) { - throw new IllegalArgumentException( - "Field with given propertyid '" - + propertyId.toString() + "' can not be found."); - } - final Object value = oldField.getPropertyDataSource() == null ? oldField - .getValue() : oldField.getPropertyDataSource().getValue(); - - // Checks that the value exists and check if the select should - // be forced in multiselect mode - boolean found = false; - boolean isMultiselect = false; - for (int i = 0; i < values.length && !found; i++) { - if (values[i] == value - || (value != null && value.equals(values[i]))) { - found = true; - } - } - if (value != null && !found) { - if (value instanceof Collection) { - for (final Iterator it = ((Collection) value) - .iterator(); it - .hasNext();) { - final Object val = it.next(); - found = false; - for (int i = 0; i < values.length && !found; i++) { - if (values[i] == val - || (val != null && val.equals(values[i]))) { - found = true; - } - } - if (!found) { - throw new IllegalArgumentException( - "Currently selected value '" + val - + "' of property '" - + propertyId.toString() - + "' was not found"); - } - } - isMultiselect = true; - } else { - throw new IllegalArgumentException("Current value '" + value - + "' of property '" + propertyId.toString() - + "' was not found"); - } - } - - // Creates the new field matching to old field parameters - final AbstractSelect newField = isMultiselect ? new ListSelect() - : new Select(); - newField.setCaption(oldField.getCaption()); - newField.setReadOnly(oldField.isReadOnly()); - newField.setBuffered(oldField.isBuffered()); - - // Creates the options list - newField.addContainerProperty("desc", String.class, ""); - newField.setItemCaptionPropertyId("desc"); - for (int i = 0; i < values.length; i++) { - Object id = values[i]; - final Item item; - if (id == null) { - id = newField.addItem(); - item = newField.getItem(id); - newField.setNullSelectionItemId(id); - } else { - item = newField.addItem(id); - } - - if (item != null) { - item.getItemProperty("desc").setValue( - descriptions[i].toString()); - } - } - - // Sets the property data source - final Property property = oldField.getPropertyDataSource(); - oldField.setPropertyDataSource(null); - newField.setPropertyDataSource(property); - - // Replaces the old field with new one - getLayout().replaceComponent(oldField, newField); - fields.put(propertyId, newField); - newField.addListener(fieldValueChangeListener); - oldField.removeListener(fieldValueChangeListener); - - return newField; - } - - /** - * Checks the validity of the Form and all of its fields. - * - * @see com.vaadin.legacy.data.Validatable#validate() - */ - @Override - public void validate() throws InvalidValueException { - super.validate(); - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - (fields.get(i.next())).validate(); - } - } - - /** - * Checks the validabtable object accept invalid values. - * - * @see com.vaadin.legacy.data.Validatable#isInvalidAllowed() - */ - @Override - public boolean isInvalidAllowed() { - return true; - } - - /** - * Should the validabtable object accept invalid values. - * - * @see com.vaadin.legacy.data.Validatable#setInvalidAllowed(boolean) - */ - @Override - public void setInvalidAllowed(boolean invalidValueAllowed) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - - /** - * Sets the component's to read-only mode to the specified state. - * - * @see com.vaadin.ui.Component#setReadOnly(boolean) - */ - @Override - public void setReadOnly(boolean readOnly) { - super.setReadOnly(readOnly); - for (final Iterator i = propertyIds.iterator(); i.hasNext();) { - (fields.get(i.next())).setReadOnly(readOnly); - } - } - - /** - * Sets the field factory used by this Form to genarate Fields for - * properties. - * - * {@link FormFieldFactory} is used to create fields for form properties. - * {@link DefaultFieldFactory} is used by default. - * - * @param fieldFactory - * the new factory used to create the fields. - * @see LegacyField - * @see FormFieldFactory - */ - public void setFormFieldFactory(FormFieldFactory fieldFactory) { - this.fieldFactory = fieldFactory; - } - - /** - * Get the field factory of the form. - * - * @return the FormFieldFactory Factory used to create the fields. - */ - public FormFieldFactory getFormFieldFactory() { - return fieldFactory; - } - - /** - * Gets the field type. - * - * @see com.vaadin.legacy.ui.LegacyAbstractField#getType() - */ - @Override - public Class getType() { - if (getPropertyDataSource() != null) { - return getPropertyDataSource().getType(); - } - return Object.class; - } - - /** - * Sets the internal value. - * - * This is relevant when the Form is used as LegacyField. - * - * @see com.vaadin.legacy.ui.LegacyAbstractField#setInternalValue(java.lang.Object) - */ - @Override - protected void setInternalValue(Object newValue) { - // Stores the old value - final Object oldValue = propertyValue; - - // Sets the current Value - super.setInternalValue(newValue); - propertyValue = newValue; - - // Ignores form updating if data object has not changed. - if (oldValue != newValue) { - setFormDataSource(newValue, getVisibleItemProperties()); - } - } - - /** - * Gets the first focusable field in form. If there are enabled, - * non-read-only fields, the first one of them is returned. Otherwise, the - * field for the first property (or null if none) is returned. - * - * @return the LegacyField. - */ - private LegacyField getFirstFocusableField() { - Collection itemPropertyIds = getItemPropertyIds(); - if (itemPropertyIds != null && itemPropertyIds.size() > 0) { - for (Object id : itemPropertyIds) { - if (id != null) { - LegacyField field = getField(id); - if (field.isConnectorEnabled() && !field.isReadOnly()) { - return field; - } - } - } - // fallback: first field if none of the fields is enabled and - // writable - Object id = itemPropertyIds.iterator().next(); - if (id != null) { - return getField(id); - } - } - return null; - } - - /** - * Updates the internal form datasource. - * - * Method setFormDataSource. - * - * @param data - * @param properties - */ - protected void setFormDataSource(Object data, Collection properties) { - - // If data is an item use it. - Item item = null; - if (data instanceof Item) { - item = (Item) data; - } else if (data != null) { - item = new BeanItem<>(data); - } - - // Sets the datasource to form - if (item != null && properties != null) { - // Shows only given properties - this.setItemDataSource(item, properties); - } else { - // Shows all properties - this.setItemDataSource(item); - } - } - - /** - * Returns the visibleProperties. - * - * @return the Collection of visible Item properites. - */ - public Collection getVisibleItemProperties() { - return visibleItemProperties; - } - - /** - * Sets the visibleProperties. - * - * @param visibleProperties - * the visibleProperties to set. - */ - public void setVisibleItemProperties(Collection visibleProperties) { - visibleItemProperties = visibleProperties; - Object value = getValue(); - if (value == null) { - value = itemDatasource; - } - setFormDataSource(value, getVisibleItemProperties()); - } - - /** - * Sets the visibleProperties. - * - * @param visibleProperties - * the visibleProperties to set. - */ - public void setVisibleItemProperties(Object... visibleProperties) { - LinkedList v = new LinkedList<>(); - for (int i = 0; i < visibleProperties.length; i++) { - v.add(visibleProperties[i]); - } - setVisibleItemProperties(v); - } - - /** - * Focuses the first field in the form. - * - * @see com.vaadin.ui.Component.Focusable#focus() - */ - @Override - public void focus() { - final LegacyField f = getFirstFocusableField(); - if (f != null) { - f.focus(); - } - } - - /** - * Sets the Tabulator index of this Focusable component. - * - * @see com.vaadin.ui.Component.Focusable#setTabIndex(int) - */ - @Override - public void setTabIndex(int tabIndex) { - super.setTabIndex(tabIndex); - for (final Iterator i = getItemPropertyIds().iterator(); i - .hasNext();) { - (getField(i.next())).setTabIndex(tabIndex); - } - } - - /** - * Setting the form to be immediate also sets all the fields of the form to - * the same state. - */ - @Override - public void setImmediate(boolean immediate) { - super.setImmediate(immediate); - for (Iterator> i = fields.values().iterator(); i - .hasNext();) { - LegacyField f = i.next(); - if (f instanceof AbstractComponent) { - ((AbstractComponent) f).setImmediate(immediate); - } - } - } - - /** - * {@inheritDoc} - *

- * A Form is empty if all of its fields are empty. - * - */ - @Override - public boolean isEmpty() { - - for (Iterator> i = fields.values().iterator(); i - .hasNext();) { - LegacyField f = i.next(); - if (f instanceof LegacyAbstractField) { - if (!((LegacyAbstractField) f).isEmpty()) { - return false; - } - } - } - - return true; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.AbstractField#clear() - */ - @Override - public void clear() { - for (Iterator> i = fields.values().iterator(); i - .hasNext();) { - LegacyField f = i.next(); - if (f instanceof LegacyAbstractField) { - ((LegacyAbstractField) f).clear(); - } - } - } - - /** - * Adding validators directly to form is not supported. - * - * Add the validators to form fields instead. - */ - @Override - public void addValidator(Validator validator) { - throw new UnsupportedOperationException(); - } - - /** - * Returns a layout that is rendered below normal form contents. This area - * can be used for example to include buttons related to form contents. - * - * @return layout rendered below normal form contents or null if no footer - * is used - */ - public Layout getFooter() { - return (Layout) getState(false).footer; - } - - /** - * Sets the layout that is rendered below normal form contents. No footer is - * rendered if this is set to null, . - * - * @param footer - * the new footer layout - */ - public void setFooter(Layout footer) { - if (getFooter() != null) { - getFooter().setParent(null); - } - getState().footer = footer; - if (footer != null) { - footer.setParent(this); - } - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - if (getParent() != null && !getParent().isEnabled()) { - // some ancestor still disabled, don't update children - return; - } else { - getLayout().markAsDirtyRecursive(); - } - } - - /* - * ACTIONS - */ - - /** - * Gets the {@link ActionManager} responsible for handling {@link Action}s - * added to this Form.
- * Note that Form has another ActionManager inherited from - * {@link LegacyAbstractField}. The ownActionManager handles Actions - * attached to this Form specifically, while the ActionManager in - * LegacyAbstractField delegates to the containing Window (i.e global - * Actions). - * - * @return - */ - protected ActionManager getOwnActionManager() { - if (ownActionManager == null) { - ownActionManager = new ActionManager(this); - } - return ownActionManager; - } - - @Override - public void addActionHandler(Handler actionHandler) { - getOwnActionManager().addActionHandler(actionHandler); - } - - @Override - public void removeActionHandler(Handler actionHandler) { - if (ownActionManager != null) { - ownActionManager.removeActionHandler(actionHandler); - } - } - - /** - * Removes all action handlers - */ - public void removeAllActionHandlers() { - if (ownActionManager != null) { - ownActionManager.removeAllActionHandlers(); - } - } - - @Override - public void addAction( - T action) { - getOwnActionManager().addAction(action); - } - - @Override - public void removeAction( - T action) { - if (ownActionManager != null) { - ownActionManager.removeAction(action); - } - } - - @Override - public Iterator iterator() { - return new ComponentIterator(); - } - - /** - * Modifiable and Serializable Iterator for the components, used by - * {@link Form#getComponentIterator()}. - */ - private class ComponentIterator implements Iterator, - Serializable { - - int i = 0; - - @Override - public boolean hasNext() { - if (i < getComponentCount()) { - return true; - } - return false; - } - - @Override - public Component next() { - if (!hasNext()) { - return null; - } - i++; - if (i == 1) { - if (getLayout() != null) { - return getLayout(); - } - if (getFooter() != null) { - return getFooter(); - } - } else if (i == 2) { - if (getFooter() != null) { - return getFooter(); - } - } - return null; - } - - @Override - public void remove() { - if (i == 1) { - if (getLayout() != null) { - setLayout(null); - i = 0; - } else { - setFooter(null); - } - } else if (i == 2) { - setFooter(null); - } - } - } - - /** - * @deprecated As of 7.0, use {@link #iterator()} instead. - */ - @Deprecated - public Iterator getComponentIterator() { - return iterator(); - } - - public int getComponentCount() { - int count = 0; - if (getLayout() != null) { - count++; - } - if (getFooter() != null) { - count++; - } - - return count; - } - -} diff --git a/server/src/main/java/com/vaadin/ui/FormFieldFactory.java b/server/src/main/java/com/vaadin/ui/FormFieldFactory.java deleted file mode 100644 index 5483b7a904..0000000000 --- a/server/src/main/java/com/vaadin/ui/FormFieldFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2000-2014 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.ui; - -import java.io.Serializable; - -import com.vaadin.data.Item; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.legacy.ui.LegacyField; - -/** - * Factory interface for creating new Field-instances based on {@link Item}, - * property id and uiContext (the component responsible for displaying fields). - * Currently this interface is used by {@link Form}, but might later be used by - * some other components for {@link Field} generation. - * - *

- * - * @author Vaadin Ltd. - * @since 6.0 - * @see TableFieldFactory - * @deprecated As of 7.0, use {@link FieldGroup} instead of {@link Form} for - * more flexibility. - */ -@Deprecated -public interface FormFieldFactory extends Serializable { - /** - * Creates a field based on the item, property id and the component (most - * commonly {@link Form}) where the Field will be presented. - * - * @param item - * the item where the property belongs to. - * @param propertyId - * the Id of the property. - * @param uiContext - * the component where the field is presented, most commonly this - * is {@link Form}. uiContext will not necessary be the parent - * component of the field, but the one that is responsible for - * creating it. - * @return the field suitable for editing the specified data. - */ - LegacyField createField(Item item, Object propertyId, - Component uiContext); -} diff --git a/server/src/test/java/com/vaadin/tests/server/SerializationTest.java b/server/src/test/java/com/vaadin/tests/server/SerializationTest.java index 995781f9bc..6a7c0f1755 100644 --- a/server/src/test/java/com/vaadin/tests/server/SerializationTest.java +++ b/server/src/test/java/com/vaadin/tests/server/SerializationTest.java @@ -17,31 +17,18 @@ import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.MethodProperty; import com.vaadin.legacy.data.validator.LegacyRegexpValidator; import com.vaadin.server.VaadinSession; -import com.vaadin.ui.Form; public class SerializationTest { @Test public void testValidators() throws Exception { - LegacyRegexpValidator validator = new LegacyRegexpValidator(".*", "Error"); + LegacyRegexpValidator validator = new LegacyRegexpValidator(".*", + "Error"); validator.validate("aaa"); LegacyRegexpValidator validator2 = serializeAndDeserialize(validator); validator2.validate("aaa"); } - @Test - public void testForm() throws Exception { - Form f = new Form(); - String propertyId = "My property"; - f.addItemProperty(propertyId, new MethodProperty(new Data(), - "dummyGetterAndSetter")); - f.replaceWithSelect(propertyId, new Object[] { "a", "b", null }, - new String[] { "Item a", "ITem b", "Null item" }); - - serializeAndDeserialize(f); - - } - @Test public void testIndedexContainerItemIds() throws Exception { IndexedContainer ic = new IndexedContainer(); @@ -95,8 +82,8 @@ public class SerializationTest { ObjectOutputStream out = new ObjectOutputStream(bs); out.writeObject(s); byte[] data = bs.toByteArray(); - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( - data)); + ObjectInputStream in = new ObjectInputStream( + new ByteArrayInputStream(data)); @SuppressWarnings("unchecked") S s2 = (S) in.readObject(); diff --git a/server/src/test/java/com/vaadin/tests/server/component/form/FormTest.java b/server/src/test/java/com/vaadin/tests/server/component/form/FormTest.java deleted file mode 100644 index e68679262f..0000000000 --- a/server/src/test/java/com/vaadin/tests/server/component/form/FormTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2000-2014 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.tests.server.component.form; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.ui.Form; - -/** - * Test for {@link Form}. - * - * @author Vaadin Ltd - */ -public class FormTest { - - @Test - public void testFocus() { - Form form = new Form(); - final boolean firstFieldIsFocused[] = new boolean[1]; - LegacyTextField field1 = new LegacyTextField() { - @Override - public boolean isConnectorEnabled() { - return false; - } - - @Override - public void focus() { - firstFieldIsFocused[0] = true; - } - }; - - final boolean secondFieldIsFocused[] = new boolean[1]; - LegacyTextField field2 = new LegacyTextField() { - @Override - public boolean isConnectorEnabled() { - return true; - } - - @Override - public void focus() { - secondFieldIsFocused[0] = true; - } - }; - form.addField("a", field1); - form.addField("b", field2); - form.focus(); - - Assert.assertTrue("Field with enabled connector is not focused", - secondFieldIsFocused[0]); - Assert.assertFalse("Field with disabled connector is focused", - firstFieldIsFocused[0]); - } -} diff --git a/shared/src/main/java/com/vaadin/shared/ui/form/FormState.java b/shared/src/main/java/com/vaadin/shared/ui/form/FormState.java deleted file mode 100644 index 99ed11f8df..0000000000 --- a/shared/src/main/java/com/vaadin/shared/ui/form/FormState.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2014 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.shared.ui.form; - -import com.vaadin.shared.AbstractFieldState; -import com.vaadin.shared.Connector; - -public class FormState extends AbstractFieldState { - { - primaryStyleName = "v-form"; - } - public Connector layout; - public Connector footer; -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/button/ButtonWithShortcutNotRendered.java b/uitest/src/main/java/com/vaadin/tests/components/button/ButtonWithShortcutNotRendered.java deleted file mode 100644 index 6da8ef8fe5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/button/ButtonWithShortcutNotRendered.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.vaadin.tests.components.button; - -import com.vaadin.annotations.PreserveOnRefresh; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.util.HierarchicalContainer; -import com.vaadin.event.ShortcutAction.KeyCode; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalSplitPanel; - -@PreserveOnRefresh -@SuppressWarnings("deprecation") -public class ButtonWithShortcutNotRendered extends AbstractTestUI { - - @Override - protected String getTestDescription() { - return "Button with shortcut broken if the shortcut is rendered before the button"; - } - - @Override - protected Integer getTicketNumber() { - return 9825; - } - - Button defaultButton; - Button otherButton; - - @SuppressWarnings("unchecked") - @Override - protected void setup(VaadinRequest request) { - getLayout().setWidth(100, Unit.PERCENTAGE); - getLayout().setHeight(null); - getLayout().setMargin(new MarginInfo(true, false, false, false)); - - HierarchicalContainer container = new HierarchicalContainer(); - container.addContainerProperty("t1", String.class, ""); - container.addContainerProperty("t2", String.class, ""); - - Item item = container.addItem("r1"); - item.getItemProperty("t1").setValue("Row1 t1"); - item.getItemProperty("t2").setValue("Row1 t2"); - - item = container.addItem("r2"); - item.getItemProperty("t1").setValue("Row2 t1"); - item.getItemProperty("t2").setValue("Row2 t2"); - - MyForm form = new MyForm(); - MyTable table = new MyTable(form, container); - - VerticalSplitPanel splitPanel = new VerticalSplitPanel(); - splitPanel.setWidth(100, Unit.PERCENTAGE); - splitPanel.setHeight(400, Unit.PIXELS); - splitPanel.setFirstComponent(table); - splitPanel.setSecondComponent(form); - splitPanel.setSplitPosition(50, Unit.PERCENTAGE); - - addComponent(splitPanel); - } - - public class MyTable extends Table { - final MyForm form; - - public MyTable(MyForm pform, HierarchicalContainer container) { - form = pform; - setContainerDataSource(container); - setSelectable(true); - setImmediate(true); - setWidth(100, Unit.PERCENTAGE); - setHeight(null); - - addValueChangeListener(new Property.ValueChangeListener() { - - @Override - public void valueChange( - com.vaadin.data.Property.ValueChangeEvent event) { - final Item item = getItem(getValue()); - form.setItemDataSource(item); - } - - }); - } - } - - public class MyForm extends Form implements ClickListener { - final GridLayout layout; - - @SuppressWarnings("unchecked") - public MyForm() { - setWidth(100, Unit.PERCENTAGE); - setHeight(null); - setImmediate(true); - - setFormFieldFactory(new DefaultFieldFactory() { - - @Override - public LegacyTextField createField(Item item, Object propertyId, - Component uiContext) { - LegacyTextField t = new LegacyTextField(); - t.setWidth(100, Unit.PERCENTAGE); - t.setHeight(null); - t.setCaption((String) propertyId); - t.setImmediate(false); - return t; - } - }); - - layout = new GridLayout(2, 1); - layout.setWidth(100, Unit.PERCENTAGE); - layout.setHeight(null); - layout.setColumnExpandRatio(0, 0.5f); - layout.setColumnExpandRatio(1, 0.5f); - layout.setMargin(true); - layout.setSpacing(true); - setLayout(layout); - - HorizontalLayout footer = new HorizontalLayout(); - footer.setSpacing(true); - footer.setMargin(false); - footer.setVisible(false); - setFooter(footer); - - defaultButton = new Button("Default Button", this); - defaultButton.setClickShortcut(KeyCode.ENTER); - footer.addComponent(defaultButton); - - otherButton = new Button("Other button", this); - footer.addComponent(otherButton); - } - - @Override - public void setItemDataSource(Item newDataSource) { - if (newDataSource != null) { - super.setItemDataSource(newDataSource); - layout.setVisible(true); - getFooter().setVisible(true); - } else { - super.setItemDataSource(null); - layout.setVisible(false); - getFooter().setVisible(false); - } - } - - @Override - @SuppressWarnings("rawtypes") - protected void attachField(Object propertyId, LegacyField field) { - if (propertyId.equals("t1")) { - layout.addComponent(field, 0, 0); - } else if (propertyId.equals("t2")) { - layout.addComponent(field, 1, 0); - } - } - - @Override - public void buttonClick(ClickEvent event) { - // NOP - } - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/AbstractNestedFormExample.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/AbstractNestedFormExample.java deleted file mode 100644 index 07c740a96d..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/AbstractNestedFormExample.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Person; -import com.vaadin.ui.Table; - -/** - * Demonstrate the use of a form as a custom field within another form. - */ -public abstract class AbstractNestedFormExample extends TestBase { - private NestedPersonForm personForm; - private boolean embeddedAddress; - - public void setup(boolean embeddedAddress) { - this.embeddedAddress = embeddedAddress; - - addComponent(getPersonTable()); - } - - /** - * Creates a table with two person objects - */ - public Table getPersonTable() { - Table table = new Table(); - table.setPageLength(5); - table.setSelectable(true); - table.setImmediate(true); - table.setNullSelectionAllowed(true); - table.addContainerProperty("Name", String.class, null); - table.addListener(getTableValueChangeListener()); - Person person = new Person("Teppo", "Testaaja", - "teppo.testaaja@example.com", "", "Ruukinkatu 2–4", 20540, - "Turku"); - Person person2 = new Person("Taina", "Testaaja", - "taina.testaaja@example.com", "", "Ruukinkatu 2–4", 20540, - "Turku"); - Item item = table.addItem(person); - item.getItemProperty("Name").setValue( - person.getFirstName() + " " + person.getLastName()); - item = table.addItem(person2); - item.getItemProperty("Name").setValue( - person2.getFirstName() + " " + person2.getLastName()); - return table; - } - - /** - * Creates value change listener for the table - */ - private Property.ValueChangeListener getTableValueChangeListener() { - return new Property.ValueChangeListener() { - - @Override - public void valueChange(ValueChangeEvent event) { - if (personForm != null) { - removeComponent(personForm); - } - if (event.getProperty().getValue() != null) { - personForm = new NestedPersonForm((Person) event - .getProperty().getValue(), embeddedAddress); - personForm.setWidth("350px"); - addComponent(personForm); - } - } - - }; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressField.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressField.java deleted file mode 100644 index 9d68ad3800..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressField.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import java.util.Arrays; -import java.util.List; - -import com.vaadin.data.Buffered; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.data.Validator.InvalidValueException; -import com.vaadin.tests.util.Address; -import com.vaadin.ui.Component; -import com.vaadin.ui.CustomField; -import com.vaadin.ui.Form; - -/** - * Nested form for the Address object of the Person object - */ -public class AddressField extends CustomField
{ - private Form addressForm; - private final Form parentForm; - - public AddressField() { - this(null); - } - - public AddressField(Form parentForm) { - this.parentForm = parentForm; - } - - @Override - protected Component initContent() { - if (parentForm != null) { - addressForm = new EmbeddedForm(parentForm); - } else { - addressForm = new Form(); - } - addressForm.setCaption("Address"); - addressForm.setBuffered(true); - - // make sure field changes are sent early - addressForm.setImmediate(true); - addressForm.setFooter(null); - return addressForm; - } - - @Override - protected Form getContent() { - return (Form) super.getContent(); - } - - @Override - public void setInternalValue(Address address) throws ReadOnlyException { - // create the address if not given - if (null == address) { - address = new Address(); - } - - super.setInternalValue(address); - - // set item data source and visible properties in a single operation to - // avoid creating fields multiple times - List visibleProperties = Arrays.asList("streetAddress", - "postalCode", "city"); - getContent().setItemDataSource(new BeanItem
(address), - visibleProperties); - } - - /** - * commit changes of the address form - */ - @Override - public void commit() throws Buffered.SourceException, InvalidValueException { - addressForm.commit(); - super.commit(); - } - - /** - * discard changes of the address form - */ - @Override - public void discard() throws Buffered.SourceException { - // Do not discard the top-level value - // super.discard(); - addressForm.discard(); - } - - @Override - public boolean isReadOnly() { - // In this application, the address is modified implicitly by - // addressForm.commit(), not by setting the Address object for a Person. - return false; - } - - @Override - public Class
getType() { - return Address.class; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressFormExample.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressFormExample.java deleted file mode 100644 index e5ac67b32e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/AddressFormExample.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import java.util.Locale; - -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Address; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Notification; - -/** - * Demonstrate a custom field which is a form, and contains another custom field - * for the selection of a city. - */ -public class AddressFormExample extends TestBase { - - @Override - protected void setup() { - getMainWindow().setLocale(Locale.ENGLISH); - Address address = new Address("Ruukinkatu 2-4", 20540, "Turku"); - final AddressField field = new AddressField(); - field.setValue(address); - field.setRequired(true); - - addComponent(field); - - Button commitButton = new Button("Save", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - field.commit(); - Address address = field.getValue(); - Notification.show("Address saved: " - + address.getStreetAddress() + ", " - + address.getPostalCode() + ", " + address.getCity()); - } - }); - addComponent(commitButton); - } - - @Override - protected String getDescription() { - return "Custom field for editing an Address"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/BooleanFieldExample.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/BooleanFieldExample.java deleted file mode 100644 index 29fffbbf16..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/BooleanFieldExample.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.Notification; -import com.vaadin.ui.VerticalLayout; - -public class BooleanFieldExample extends TestBase { - - /** - * Data model class with two boolean fields. - */ - public static class TwoBooleans { - private boolean normal; - private boolean custom; - - public void setNormal(boolean normal) { - this.normal = normal; - } - - public boolean isNormal() { - return normal; - } - - public void setCustom(boolean custom) { - this.custom = custom; - } - - public boolean isCustom() { - return custom; - } - } - - @Override - protected void setup() { - final VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - - final Form form = new Form(); - form.setFooter(null); - form.setFormFieldFactory(new DefaultFieldFactory() { - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - if ("custom".equals(propertyId)) { - return new BooleanField(); - } - return super.createField(item, propertyId, uiContext); - } - }); - final TwoBooleans data = new TwoBooleans(); - form.setItemDataSource(new BeanItem(data)); - - layout.addComponent(form); - - Button submit = new Button("Submit", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.commit(); - Notification.show("The custom boolean field value is " - + data.isCustom() + ".\n" - + "The checkbox (default boolean field) value is " - + data.isNormal() + "."); - } - }); - layout.addComponent(submit); - - addComponent(layout); - } - - @Override - protected String getDescription() { - return "A customized field (a two-state button) for editing a boolean value."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedForm.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedForm.java deleted file mode 100644 index 764949b7a3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedForm.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.ui.CustomLayout; -import com.vaadin.ui.Form; -import com.vaadin.ui.Layout; - -/** - * Form that displays its fields in the layout of another form. - * - * The fields are still logically part of this form even though they are in the - * layout of the parent form. The embedded form itself is automatically hidden. - * - * TODO Known issue: any field factory creating an {@link EmbeddedForm} - * (directly or indirectly) should re-use the field once it has been created to - * avoid the creation of duplicate fields when e.g. setting the visible item - * properties. - */ -public class EmbeddedForm extends Form { - private Form parentForm; - private Map fields = new HashMap(); - - /** - * Create a form that places its fields in another {@link Form}. - * - * @param parentForm - * form to which to embed the fields, not null - */ - public EmbeddedForm(Form parentForm) { - this.parentForm = parentForm; - setVisible(false); - } - - @Override - protected void attachField(Object propertyId, LegacyField field) { - if (propertyId == null || field == null) { - return; - } - - Layout layout = parentForm.getLayout(); - - LegacyField oldField = fields.get(propertyId); - if (oldField != null) { - layout.removeComponent(oldField); - } - - fields.put(propertyId, field); - - if (layout instanceof CustomLayout) { - ((CustomLayout) layout).addComponent(field, propertyId.toString()); - } else { - layout.addComponent(field); - } - } - - @Override - public boolean removeItemProperty(Object id) { - // remove the field from the parent layout if already added there - parentForm.getLayout().removeComponent(fields.get(id)); - fields.remove(id); - - return super.removeItemProperty(id); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedFormExample.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedFormExample.java deleted file mode 100644 index aeb1984937..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/EmbeddedFormExample.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vaadin.tests.components.customfield; - -public class EmbeddedFormExample extends AbstractNestedFormExample { - - @Override - protected void setup() { - super.setup(true); - } - - @Override - protected String getDescription() { - return "An address form embedded in a person form.\n" - + "The address fields are placed in the layout of the parent (person) form.\n" - + "Note that in many cases the same result can be achieved with a property that maps subfields to the top level."; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedFormExample.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedFormExample.java deleted file mode 100644 index 91fb43f4e2..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedFormExample.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.vaadin.tests.components.customfield; - -public class NestedFormExample extends AbstractNestedFormExample { - - @Override - protected void setup() { - super.setup(false); - } - - @Override - protected String getDescription() { - return "An address form nested in a person form."; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedPersonForm.java b/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedPersonForm.java deleted file mode 100644 index 5ecd75d34e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/customfield/NestedPersonForm.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.vaadin.tests.components.customfield; - -import java.util.Arrays; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.tests.util.Person; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Layout.MarginHandler; - -/** - * Example of nested forms - */ -public class NestedPersonForm extends Form { - private BeanItem beanItem; - private final boolean embeddedAddress; - - /** - * Creates a person form which contains nested form for the persons address - */ - public NestedPersonForm(Person person, boolean embeddedAddress) { - this.embeddedAddress = embeddedAddress; - - beanItem = new BeanItem(person); - setCaption("Update person details"); - setBuffered(true); - setFormFieldFactory(new PersonFieldFactory()); - // set the data source and the visible fields - // Note that if the nested form is the first or last field in the parent - // form, styles from the parent (padding, ...) may leak to its contents. - setItemDataSource(beanItem, Arrays.asList("firstName", "lastName", - "address", "email", "phoneNumber")); - getFooter().addComponent(getButtonsLayout()); - ((MarginHandler) getFooter()).setMargin(new MarginInfo(false, false, - true, true)); - } - - /** - * Get apply and discard button in the layout - */ - private Component getButtonsLayout() { - HorizontalLayout buttons = new HorizontalLayout(); - buttons.setSpacing(true); - Button discardChanges = new Button("Discard changes", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - NestedPersonForm.this.discard(); - } - }); - buttons.addComponent(discardChanges); - buttons.setComponentAlignment(discardChanges, Alignment.MIDDLE_LEFT); - - Button apply = new Button("Apply", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - try { - NestedPersonForm.this.commit(); - } catch (Exception e) { - // Ignored, we'll let the Form handle the errors - } - } - }); - buttons.addComponent(apply); - return buttons; - } - - /** - * LegacyField factory for person form - */ - private class PersonFieldFactory extends DefaultFieldFactory { - // reuse the address field - required by EmbeddedForm - private AddressField addressField; - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - LegacyField f = super.createField(item, propertyId, uiContext); - if ("address".equals(propertyId)) { - // create a custom field for the Address object - if (addressField == null) { - Form form = (embeddedAddress && uiContext instanceof Form) ? (Form) uiContext - : null; - addressField = new AddressField(form); - } - f = addressField; - } - return f; - } - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CommitInvalid.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CommitInvalid.java deleted file mode 100644 index dd5da9c526..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/CommitInvalid.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.legacy.data.Validator.InvalidValueException; -import com.vaadin.legacy.ui.LegacyDateField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; - -public class CommitInvalid extends TestBase { - - @Override - protected String getDescription() { - return "DateField with parsing error is committed regardless " - + "of the invalidity. Parsing error should be handled" - + " as a builtin validator, similar to isRequired()" - + " in LegacyAbstractField."; - } - - @Override - protected Integer getTicketNumber() { - return 5927; - } - - ObjectProperty dateProperty; - private LegacyDateField dateField; - private ObjectProperty integerProperty; - private LegacyTextField integerField; - private Log log; - - @Override - protected void setup() { - /* - * Create and configure form. - */ - final Form form = new Form(); - form.setBuffered(true); // set write buffering on - form.setImmediate(true); // make form (and especially its fields - // immediate) - - /* - * Create and configure Date LegacyField, the actual component to be - * tested. - */ - dateProperty = new ObjectProperty( - new Date(2009 - 1900, 4 - 1, 1)); - - dateField = new LegacyDateField("Year", dateProperty); - dateField.setLocale(new Locale("fi", "FI")); - dateField.setResolution(LegacyDateField.RESOLUTION_DAY); - dateField.setId("_DF"); - form.addField("date", dateField); - - /* - * Create a TextField with integer property (and integer validator, - * preventing invalid typed values to be pushded to property) as a - * reference component. - */ - integerProperty = new ObjectProperty(42); - integerField = new LegacyTextField("Another LegacyField", - integerProperty); - integerField.setId("_IF"); - form.addField("text", integerField); - - /* - * Action buttons. - */ - Button validate = new Button("Validate"); - validate.setId("_validate"); - validate.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - try { - form.validate(); - log.log("Form is valid"); - } catch (InvalidValueException e) { - log.log("Validation failed:" + e.getLocalizedMessage()); - } finally { - printState(); - } - } - }); - form.getFooter().addComponent(validate); - - Button commit = new Button("Commit"); - commit.setId("_commit"); - commit.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - try { - form.commit(); - log.log("Commit succeeded"); - } catch (InvalidValueException e) { - log.log("Commit failed : " + e.getLocalizedMessage()); - } finally { - printState(); - } - } - }); - - form.getFooter().addComponent(commit); - Button printState = new Button("printState"); - printState.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - printState(); - } - - }); - form.getFooter().addComponent(printState); - - log = new Log(7); - log.log("Test app started"); - printState(); - - addComponent(form); - addComponent(log); - - } - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - private String f(Date date) { - if (date == null) { - return "null"; - } - return dateFormat.format(date); - } - - private void printState() { - log.log("Date. LegacyField: " + f(dateField.getValue()) + " Property: " - + f(dateProperty.getValue())); - log.log("Integer: LegacyField: " + integerField.getValue() - + " Property: " + integerProperty.getValue()); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldInSubWindow.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldInSubWindow.java deleted file mode 100644 index f993b4558b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldInSubWindow.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.util.Date; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.AbstractTestCase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.DateField; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; - -public class DateFieldInSubWindow extends AbstractTestCase { - - @SuppressWarnings("serial") - public class TestCaseWindow extends Window { - - public class MyBean { - private Date myDate; - private String myString; - - public Date getMyDate() { - return myDate; - } - - public void setMyDate(Date myDate) { - this.myDate = myDate; - } - - public String getMyString() { - return myString; - } - - public void setMyString(String myString) { - this.myString = myString; - } - - } - - private MyBean myBean; - - public TestCaseWindow() { - super("Test Case Window"); - setModal(true); - setWidth("400px"); - myBean = new MyBean(); - - initWindow(); - } - - protected class CustomerFieldFactory extends DefaultFieldFactory { - - public static final String COMMON_FIELD_WIDTH = "12em"; - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - LegacyField f = super.createField(item, propertyId, - uiContext); - - if ("myDate".equals(propertyId)) { - ((DateField) f).setResolution(Resolution.MINUTE); - ((DateField) f).setCaption("This is my date"); - - } - - return f; - } - } - - protected void initWindow() { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - layout.setSpacing(true); - setContent(layout); - - /** - * This causes the window to add the .v-readonly style! - */ - setClosable(false); - - CustomerFieldFactory fieldFactory = new CustomerFieldFactory(); - final Form generalForm = new Form(); - { - generalForm.setFooter(null); - generalForm.setCaption("My form"); - generalForm.setBuffered(false); - generalForm.setFormFieldFactory(fieldFactory); - - BeanItem myBeanItem = new BeanItem(myBean); - generalForm.setItemDataSource(myBeanItem); - - generalForm.setVisibleItemProperties( - new String[] { "myDate", "myString" }); - generalForm.setValidationVisible(true); - layout.addComponent(generalForm); - } - - HorizontalLayout buttons = new HorizontalLayout(); - { - buttons.setSpacing(true); - - Button b = new Button("Close", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - TestCaseWindow.this.close(); - } - }); - buttons.addComponent(b); - layout.addComponent(buttons); - - } - } - } - - @Override - public void init() { - LegacyWindow mainWindow = new LegacyWindow(); - setMainWindow(mainWindow); - Button open = new Button("Open window", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - getMainWindow().addWindow(new TestCaseWindow()); - } - }); - - mainWindow.addComponent(open); - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - return 4582; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/ShowSelectedDateAfterInvalid.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/ShowSelectedDateAfterInvalid.java deleted file mode 100644 index 3fad7767f5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/ShowSelectedDateAfterInvalid.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import com.vaadin.legacy.ui.LegacyPopupDateField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.Label; - -/** - * First entering an invalid date, forcing a server roundtrip and then selecting - * a valid date from the popup in a non-immediate {@link LegacyPopupDateField} caused - * the invalid date string to continue to show. - */ -public class ShowSelectedDateAfterInvalid extends TestBase { - - @Override - protected void setup() { - final Label result = new Label(); - - final Form form = new Form(); - - LegacyPopupDateField datefield = new LegacyPopupDateField(); - datefield.setResolution(LegacyPopupDateField.RESOLUTION_DAY); - datefield.setDateFormat("dd/MM/yyyy"); - - form.addField("datefield", datefield); - - Button button = new Button("Validate"); - - button.addListener(new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - form.setValidationVisible(true); - if (form.isValid()) { - result.setValue("Valid!"); - } else { - result.setValue("Invalid"); - } - } - - }); - - addComponent(form); - addComponent(button); - addComponent(result); - } - - @Override - protected String getDescription() { - return "DateField doesn't show selected value after invalid and then selecting a value"; - } - - @Override - protected Integer getTicketNumber() { - return 5369; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormCaptionClickFocusing.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormCaptionClickFocusing.java deleted file mode 100644 index ec44f42ba0..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormCaptionClickFocusing.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.FormLayout; - -public class FormCaptionClickFocusing extends TestBase { - - @Override - protected void setup() { - FormLayout layout = new FormLayout(); - - LegacyTextField field = new LegacyTextField("Field 1"); - layout.addComponent(field); - - addComponent(layout); - } - - @Override - protected String getDescription() { - return "Formlayout should focus the field if the layout is clicked and the field is focusable."; - } - - @Override - protected Integer getTicketNumber() { - return 4567; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormClearDatasourceRepaint.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormClearDatasourceRepaint.java deleted file mode 100644 index df403ceb78..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormClearDatasourceRepaint.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; - -public class FormClearDatasourceRepaint extends TestBase { - - public static class MyBean { - - private String value; - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - } - - public static class MySecondBean extends MyBean { - - private String value2; - - public String getValue2() { - return value2; - } - - public void setValue2(String value) { - value2 = value; - } - } - - @Override - protected void setup() { - - final Form form = new Form(); - form.setFooter(null); - form.setItemDataSource(new BeanItem(new MySecondBean())); - addComponent(form); - - addComponent(new Button("Clear datasource", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setItemDataSource(null); - } - })); - - addComponent(new Button("Change data source", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setItemDataSource(new BeanItem( - new MyBean())); - } - })); - - } - - @Override - protected String getDescription() { - return "The form should adjust its size when clearing and setting data sources"; - } - - @Override - protected Integer getTicketNumber() { - return 7626; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormCommitWithInvalidValues.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormCommitWithInvalidValues.java deleted file mode 100644 index 7b09c7c484..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormCommitWithInvalidValues.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.data.validator.LegacyStringLengthValidator; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Form; -import com.vaadin.ui.Notification; - -public class FormCommitWithInvalidValues extends TestBase { - - private Form form; - - @Override - protected String getDescription() { - return "Commiting a form with invalid values should throw an exception"; - } - - @Override - protected Integer getTicketNumber() { - return 2466; - } - - @Override - protected void setup() { - form = new Form(); - form.setFooter(null); - LegacyTextField tf = new LegacyTextField( - "A field, must contain 1-2 chars"); - tf.addValidator( - new LegacyStringLengthValidator("Invalid length", 1, 2, false)); - tf.setRequired(true); - - form.addField("a", tf); - - Button b = new Button("Commit", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - try { - form.commit(); - if (form.isValid()) { - getMainWindow().showNotification( - "OK! Form validated and no error was thrown", - Notification.TYPE_HUMANIZED_MESSAGE); - } else { - getMainWindow().showNotification( - "Form is invalid but no exception was thrown", - Notification.TYPE_ERROR_MESSAGE); - } - } catch (Exception e) { - if (form.isValid()) { - getMainWindow().showNotification( - "Form is valid but an exception was thrown", - Notification.TYPE_ERROR_MESSAGE); - } else { - getMainWindow().showNotification( - "OK! Error was thrown for an invalid input", - Notification.TYPE_HUMANIZED_MESSAGE); - - } - } - } - - }); - - addComponent(form); - addComponent(b); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormDescription.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormDescription.java deleted file mode 100644 index 00c5ed9d65..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormDescription.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; - -public class FormDescription extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - form.setDescription("Some description"); - form.addField("AAAA", new LegacyTextField()); - addComponent(form); - - addComponent(new Button("Toggle description", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - if (form.getDescription() == null) { - form.setDescription("Form description"); - } else { - form.setDescription(null); - } - } - })); - - } - - @Override - protected String getDescription() { - return "Description element should be removed from DOM when not used"; - } - - @Override - protected Integer getTicketNumber() { - return 3725; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormErrorVisible.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormErrorVisible.java deleted file mode 100644 index f9a8c35300..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormErrorVisible.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012 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.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.UserError; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.Label; - -public class FormErrorVisible extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - addComponent(buildForm("With footer and error", true, true)); - addComponent(buildForm("With footer", false, true)); - addComponent(buildForm("With error", true, false)); - addComponent(buildForm("With nothing", false, false)); - addComponent(new Label("The end to see where the last form ends")); - } - - private Form buildForm(String caption, boolean withError, boolean withFooter) { - Form form = new Form(); - form.setCaption(caption); - form.addField("value", new LegacyTextField("MyField")); - - if (withError) { - form.setComponentError(new UserError("Has error")); - } - - if (withFooter) { - form.getFooter().addComponent(new Button("Footer button")); - } else { - form.setFooter(null); - } - - return form; - } - - @Override - protected String getTestDescription() { - return "Footer and error should be taken into account when rendering Form"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(10460); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptions.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptions.java deleted file mode 100644 index 25487fba7c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptions.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; - -public class FormFieldCaptions extends TestBase { - - @Override - protected void setup() { - // Method 1 - Form form1 = new Form(); - Item item1 = createItem(); - for (Object propertyId : item1.getItemPropertyIds()) { - form1.addItemProperty(propertyId, item1.getItemProperty(propertyId)); - } - - // Method 2 - - Form form2 = new Form(); - Item item2 = createItem(); - form2.setItemDataSource(item2); - - // Layout - HorizontalLayout hl = new HorizontalLayout(); - hl.addComponent(form1); - hl.addComponent(form2); - - addComponent(hl); - } - - private Item createItem() { - return new BeanItem(new Person("John", "Doe", 38)); - } - - public class Person { - private String firstName; - private String lastName; - - public Person(String firstName, String lastName, int age) { - super(); - this.firstName = firstName; - this.lastName = lastName; - this.age = age; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - private int age; - } - - @Override - protected String getDescription() { - return "The two forms generated using different methods should have the same captions for all fields"; - } - - @Override - protected Integer getTicketNumber() { - return 3554; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptionsStyles.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptionsStyles.java deleted file mode 100644 index 4018ac3115..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormFieldCaptionsStyles.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.FormLayout; - -public class FormFieldCaptionsStyles extends TestBase { - - @Override - protected void setup() { - - setTheme("tests-tickets"); - - FormLayout layout = new FormLayout(); - - LegacyTextField field1 = new LegacyTextField("Red style"); - field1.setStyleName("ticket4997-red"); - layout.addComponent(field1); - - LegacyTextField field2 = new LegacyTextField("Blue style"); - field2.setStyleName("ticket4997-blue"); - layout.addComponent(field2); - - LegacyTextField field3 = new LegacyTextField("Red-Blue style"); - field3.addStyleName("ticket4997-red"); - field3.addStyleName("ticket4997-blue"); - layout.addComponent(field3); - - LegacyTextField field4 = new LegacyTextField("Disabled"); - field4.setEnabled(false); - field4.addStyleName("foobar"); // no visible change, but points out - // a regression #5377 - layout.addComponent(field4); - - addComponent(layout); - } - - @Override - protected String getDescription() { - return "The field captions should have the same style names as the field"; - } - - @Override - protected Integer getTicketNumber() { - return 4997; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormNotGettingSmaller.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormNotGettingSmaller.java deleted file mode 100644 index a47ab944a2..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormNotGettingSmaller.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.data.Item; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.PropertysetItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; - -public class FormNotGettingSmaller extends TestBase { - - @Override - protected void setup() { - Item item = new PropertysetItem(); - item.addItemProperty("name", new ObjectProperty( - "Charles Anthony")); - item.addItemProperty("city", new ObjectProperty("London")); - item.addItemProperty("isTallPerson", new ObjectProperty( - Boolean.FALSE)); - - Label spacer = new Label(); - HorizontalLayout buttons = new HorizontalLayout(); - buttons.setSpacing(true); - buttons.setWidth("100%"); - buttons.addComponent(spacer); - buttons.addComponent(new Button("OK")); - buttons.addComponent(new Button("Cancel")); - buttons.setExpandRatio(spacer, 1f); - - Form form = new Form(); - form.setDescription("Ooh. Just a demonstration of things, really. Some long lorem ipsum dolor sit amet.Some very long lorem ipsum dolor sit amet.Some very long lorem ipsum dolor sit amet.Some very long lorem ipsum dolor sit amet."); - - form.setItemDataSource(item); - form.setFooter(buttons); - - getLayout().addComponent(form); - } - - @Override - protected String getDescription() { - return "When resizing window buttons should stay on " - + "right edge of the screent. Form should also get narrower."; - } - - @Override - protected Integer getTicketNumber() { - return 3365; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormPrimaryStyleName.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormPrimaryStyleName.java deleted file mode 100644 index d20412b5c6..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormPrimaryStyleName.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; - -public class FormPrimaryStyleName extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - form.addField("aaa", new LegacyTextField()); - form.setDescription("This is a form description"); - form.setCaption("This is a form caption"); - form.setPrimaryStyleName("my-form"); - - HorizontalLayout formFooter = new HorizontalLayout(); - formFooter.addComponent(new Label("Form footer")); - form.setFooter(formFooter); - - addComponent(form); - - addComponent(new Button("Set primary stylename", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setPrimaryStyleName("my-second-form"); - } - })); - - } - - @Override - protected String getDescription() { - return "Form should handle primary stylenames both initially and dynamically"; - } - - @Override - protected Integer getTicketNumber() { - return 9904; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormRenderingFlicker.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormRenderingFlicker.java deleted file mode 100644 index 41e1a91781..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormRenderingFlicker.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.data.Item; -import com.vaadin.event.ItemClickEvent; -import com.vaadin.event.ItemClickEvent.ItemClickListener; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Form; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalLayout; - -public class FormRenderingFlicker extends TestBase { - - private VerticalLayout tableLayout; - private Table table; - private Panel tablePanel; - private Form form; - - @Override - protected String getDescription() { - return "Clicking on an item in the table will replace the panel (surrounding the table) with a form. This should not cause the table rows to move downwards or cause any other visible flicker"; - } - - @Override - protected Integer getTicketNumber() { - return 2816; - } - - @Override - protected void setup() { - createTableLayout(); - form = new Form(); - - tablePanel = new Panel(); - tablePanel.setContent(tableLayout); - - addComponent(tablePanel); - } - - private void createTableLayout() { - tableLayout = new VerticalLayout(); - table = new Table(); - table.addContainerProperty("name", String.class, ""); - table.addContainerProperty("age", String.class, ""); - for (int i = 0; i < 100; i++) { - table.addItem(new Object[] { "Name " + i, String.valueOf(i) }, - new Object()); - } - table.setImmediate(true); - table.addListener(new ItemClickListener() { - - @Override - public void itemClick(ItemClickEvent event) { - clicked(event.getItem()); - } - - }); - - tableLayout.addComponent(table); - } - - protected void clicked(Item item) { - getLayout().replaceComponent(tablePanel, form); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormTest.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormTest.java deleted file mode 100644 index f6cb84289f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormTest.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.vaadin.tests.components.form; - -import java.util.LinkedHashMap; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.shared.ui.AlignmentInfo; -import com.vaadin.tests.components.abstractfield.LegacyAbstractFieldTest; -import com.vaadin.tests.components.select.AbstractSelectTestCase; -import com.vaadin.tests.util.Person; -import com.vaadin.tests.util.Product; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormFieldFactory; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Layout; -import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.VerticalLayout; - -public class FormTest extends LegacyAbstractFieldTest
{ - - private Command footerWidthCommand = new Command() { - - @Override - public void execute(Form c, String value, Object data) { - Layout footer = c.getFooter(); - if (footer != null) { - footer.setWidth(value); - } - - } - }; - private Command footerHeightCommand = new Command() { - - @Override - public void execute(Form c, String value, Object data) { - Layout footer = c.getFooter(); - if (footer != null) { - footer.setHeight(value); - } - - } - }; - - private Command> formLayoutCommand = new Command>() { - - @Override - public void execute(Form c, Class value, Object data) { - if (value == null) { - c.setLayout(null); - } else { - try { - Layout l = value.newInstance(); - l.setSizeUndefined(); - if (l instanceof GridLayout) { - ((GridLayout) l).setColumns(2); - } - c.setLayout(l); - } catch (Exception e) { - log("Error creating footer of type " + value.getName() - + ": " + e.getMessage()); - e.printStackTrace(); - } - } - } - - }; - private Command> formFooterCommand = new Command>() { - - @Override - public void execute(Form c, Class value, Object data) { - if (value == null) { - c.setFooter(null); - } else { - try { - c.setFooter(value.newInstance()); - Button b = new Button("Just a button"); - c.getFooter().addComponent(b); - } catch (Exception e) { - log("Error creating footer of type " + value.getName() - + ": " + e.getMessage()); - e.printStackTrace(); - } - } - - } - }; - private Command formItemDataSourceCommand = new Command() { - - @Override - public void execute(Form c, Item value, Object data) { - c.setItemDataSource(value); - } - }; - private LinkedHashMap> layoutOptions = new LinkedHashMap>(); - { - layoutOptions.put("VerticalLayout", VerticalLayout.class); - layoutOptions.put("HorizontalLayout", HorizontalLayout.class); - layoutOptions.put("GridLayout", GridLayout.class); - layoutOptions.put("CSSLayout", CssLayout.class); - layoutOptions.put("FormLayout", FormLayout.class); - } - - @Override - protected void createActions() { - super.createActions(); - - createFormLayoutSelect(CATEGORY_FEATURES); - createFooterSelect(CATEGORY_FEATURES); - createFooterPropertySelect(CATEGORY_FEATURES); - createFormFactorySelect(CATEGORY_FEATURES); - createDataSourceSelect(AbstractSelectTestCase.CATEGORY_DATA_SOURCE); - } - - private void createDataSourceSelect(String category) { - LinkedHashMap options = new LinkedHashMap(); - - options.put("Person", createPersonItem()); - options.put("Product", createProductItem()); - - createSelectAction("Form data source", category, options, "Person", - formItemDataSourceCommand); - - } - - private BeanItem createProductItem() { - return new BeanItem(new Product("Computer Monitor", 399.99f, - "A monitor that can display both color and black and white.")); - } - - private BeanItem createPersonItem() { - Person person = new Person("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem personItem = new BeanItem(person); - // add nested properties from address - personItem.expandProperty("address"); - - return personItem; - } - - private void createFormFactorySelect(String category) { - LinkedHashMap options = new LinkedHashMap(); - options.put("Default", DefaultFieldFactory.get()); - options.put("Custom FieldFactory", new FormFieldFactory() { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - Class type = item.getItemProperty(propertyId).getType(); - LegacyField c = null; - if (Number.class.isAssignableFrom(type)) { - LegacyTextField tf = new LegacyTextField(); - tf.setCaption(DefaultFieldFactory - .createCaptionByPropertyId(propertyId)); - tf.setWidth("3em"); - c = tf; - } else if ("city".equals(propertyId)) { - ComboBox cb = new ComboBox(); - cb.setNullSelectionAllowed(false); - cb.addItem("Turku"); - cb.addItem("New York"); - cb.addItem("Moscow"); - cb.setCaption(DefaultFieldFactory - .createCaptionByPropertyId(propertyId)); - c = cb; - c.setWidth("200px"); - } - - if (c == null) { - c = DefaultFieldFactory.get().createField(item, propertyId, - uiContext); - c.setWidth("200px"); - } - return c; - } - - @Override - public String toString() { - return "Custom FieldFactory"; - } - }); - - Command formFactoryCommand = new Command() { - - @Override - public void execute(Form c, FormFieldFactory value, Object data) { - c.setFormFieldFactory(value); - c.setItemDataSource(c.getItemDataSource()); - - } - }; - createSelectAction("FormFieldFactory", category, options, "Default", - formFactoryCommand); - } - - private void createFooterPropertySelect(String category) { - String propertyCategory = "Footer properties"; - createCategory(propertyCategory, category); - - LinkedHashMap options = new LinkedHashMap(); - options.put("auto", ""); - options.put("200px", "200px"); - options.put("100%", "100%"); - - createSelectAction("width", propertyCategory, options, "auto", - footerWidthCommand); - createSelectAction("height", propertyCategory, options, "auto", - footerHeightCommand); - - LinkedHashMap alignmentOptions = new LinkedHashMap(); - for (AlignmentInfo horizontal : new AlignmentInfo[] { - AlignmentInfo.LEFT, AlignmentInfo.CENTER, AlignmentInfo.RIGHT }) { - for (AlignmentInfo vertical : new AlignmentInfo[] { - AlignmentInfo.TOP, AlignmentInfo.MIDDLE, - AlignmentInfo.BOTTOM }) { - Alignment a = new Alignment(horizontal.getBitMask() - + vertical.getBitMask()); - alignmentOptions.put( - a.getHorizontalAlignment() + " " - + a.getVerticalAlignment(), a); - - } - - } - Command footerComponentAlignmentCommand = new Command() { - - @Override - public void execute(Form c, Alignment value, Object data) { - Layout l = c.getFooter(); - if (l instanceof AlignmentHandler) { - ((AlignmentHandler) l).setComponentAlignment(l - .getComponentIterator().next(), value); - } - - } - }; - createSelectAction("Component alignment", propertyCategory, - alignmentOptions, "left", footerComponentAlignmentCommand); - } - - private void createFooterSelect(String category) { - createSelectAction("Footer", category, layoutOptions, "-", - formFooterCommand); - - } - - private void createFormLayoutSelect(String category) { - - createSelectAction("Layout", category, layoutOptions, "-", - formLayoutCommand); - - } - - @Override - protected Class getTestClass() { - return Form.class; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormTooltips.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormTooltips.java deleted file mode 100644 index 06a1cc3cc6..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormTooltips.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012 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.tests.components.form; - -import java.util.Arrays; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.UserError; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.data.bean.Sex; -import com.vaadin.ui.Form; - -public class FormTooltips extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Form form = new Form(); - form.setId("tooltipForm"); - form.setDescription("Some description"); - form.setItemDataSource( - new BeanItem( - new Person("foo", "bar", "baz", 12, Sex.MALE, null)), - Arrays.asList(new String[] { "firstName", "lastName", "age" })); - ((LegacyTextField) form.getField("firstName")) - .setDescription("Fields own tooltip"); - - form.setComponentError(new UserError("Form error")); - addComponent(form); - - } - - @Override - protected String getTestDescription() { - return "The 'first name' should show its own tooltip, the other fields should show no tooltip"; - } - - @Override - protected Integer getTicketNumber() { - return 9173; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithEnterShortCut.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormWithEnterShortCut.java deleted file mode 100644 index 6f08a979c1..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithEnterShortCut.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.event.ShortcutAction.KeyCode; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; - -public class FormWithEnterShortCut extends TestBase { - private Log log = new Log(2); - - @Override - protected void setup() { - - final Form form = new Form(); - final LegacyTextField tf = new LegacyTextField("Search"); - form.addField("searchfield", tf); - - Button button = new Button("Go"); - button.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - log.log("search: " + tf.getValue()); - } - }); - button.setClickShortcut(KeyCode.ENTER); - button.setStyleName("primary"); - - form.getFooter().addComponent(button); - - addComponent(log); - addComponent(form); - - } - - @Override - protected String getDescription() { - return "Focusing a button and pressing enter (which is a shortcut for button click) should only produce one click event"; - } - - @Override - protected Integer getTicketNumber() { - return 5433; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPaddingsAndBorders.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPaddingsAndBorders.java deleted file mode 100644 index a6ca0ba06e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPaddingsAndBorders.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.TestUtils; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; - -public class FormWithPaddingsAndBorders extends TestBase { - - @Override - protected void setup() { - getLayout().setSizeFull(); - - TestUtils.injectCSS(getMainWindow(), - ".v-form{ border: 10px solid red; padding:10px;}"); - - final Form f = new Form(); - addComponent(f); - f.setSizeUndefined(); - f.getLayout().setSizeUndefined(); - - f.addField("foo", new LegacyTextField("Foo")); - f.addField("bar", new LegacyTextField("A bit longer field caption")); - - HorizontalLayout hl = new HorizontalLayout(); - hl.setWidth("100%"); - Button b = new Button("right aligned"); - hl.addComponent(b); - hl.setComponentAlignment(b, Alignment.TOP_RIGHT); - f.setFooter(hl); - } - - @Override - protected String getDescription() { - return "Ensure that paddings set on form is considered in width calculations"; - } - - @Override - protected Integer getTicketNumber() { - return 3710; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java deleted file mode 100644 index 4d858780c9..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithPropertyFormatterConnected.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.PropertyFormatter; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyAbstractField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormFieldFactory; - -public class FormWithPropertyFormatterConnected extends TestBase { - @Override - protected void setup() { - Form form2 = new Form(); - form2.setFormFieldFactory(new FormFieldFactory() { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - LegacyAbstractField f = (LegacyAbstractField) DefaultFieldFactory.get() - .createField(item, propertyId, uiContext); - if (propertyId.equals("age")) { - f.setPropertyDataSource(new PropertyFormatter() { - - @Override - public Object parse(String formattedValue) - throws Exception { - String str = formattedValue.replaceAll("[^0-9.]", - ""); - if (formattedValue.toLowerCase().contains("months")) { - return Double.parseDouble(str) / 12; - } - return Double.parseDouble(str); - } - - @Override - public String format(Object value) { - Double dValue = (Double) value; - if (dValue < 1) { - return ((int) (dValue * 12)) + " months"; - } - return dValue + " years"; - } - }); - f.setImmediate(true); - } - return f; - } - }); - form2.setItemDataSource(createItem()); - - addComponent(form2); - addComponent(new Button("B")); - } - - private Item createItem() { - return new BeanItem(new Person(0.5)); - } - - public class Person { - public Person(double age) { - super(); - this.age = age; - } - - public double getAge() { - return age; - } - - public void setAge(double age) { - this.age = age; - } - - private double age; - } - - @Override - protected String getDescription() { - return "It should be possible to inject PropertyFormatter and similar classses to fields in form. The test app hooks formatter that displays age in years or months and also accepts value in both (years by default, months if mentioned in the field)"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java b/uitest/src/main/java/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java deleted file mode 100644 index 17fe4477c3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.Form; -import com.vaadin.ui.Label; - -public class FormWithRelativelySizedLayout extends TestBase { - - @Override - protected String getDescription() { - return "Forms mainlayouts relative height should be everyting left out from footer and possible borders/paddings. "; - } - - @Override - protected Integer getTicketNumber() { - return 3488; - } - - @Override - protected void setup() { - - Form f = new Form(); - f.setCaption("Form, full size"); - - f.setWidth("100%"); - f.setHeight("100%"); - - Label l = new Label( - "This green label should consume all available space, pushing ok button to bottom of the view"); - l.setSizeFull(); - - CssLayout lo = new CssLayout() { - @Override - protected String getCss(Component c) { - return "background: green;color:red;"; - } - }; - lo.setSizeFull(); - - f.setLayout(lo); - lo.addComponent(l); - - f.getFooter().addComponent(new Button("OK button")); - - getLayout().setSizeFull(); - getLayout().addComponent(f); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/form/UndefinedWideFormWithRelativeWideFooter.java b/uitest/src/main/java/com/vaadin/tests/components/form/UndefinedWideFormWithRelativeWideFooter.java deleted file mode 100644 index 25bb0253c5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/form/UndefinedWideFormWithRelativeWideFooter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.vaadin.tests.components.form; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.LegacyApplication; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.LegacyWindow; - -@SuppressWarnings("serial") -public class UndefinedWideFormWithRelativeWideFooter extends LegacyApplication { - - @Override - public void init() { - - LegacyWindow w = new LegacyWindow("Test"); - setMainWindow(w); - - final Form f = new Form(); - w.addComponent(f); - f.setSizeUndefined(); - f.getLayout().setSizeUndefined(); - - f.setCaption("Test form with a really long caption"); - f.addField("foo", new LegacyTextField("Foo")); - f.addField("bar", new LegacyTextField("A bit longer field caption")); - - HorizontalLayout hl = new HorizontalLayout(); - hl.setWidth("100%"); - Button b = new Button("right aligned"); - hl.addComponent(b); - hl.setComponentAlignment(b, Alignment.TOP_RIGHT); - f.setFooter(hl); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutInForm.java b/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutInForm.java deleted file mode 100644 index e8261ec183..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/gridlayout/GridLayoutInForm.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.vaadin.tests.components.gridlayout; - -import java.util.ArrayList; -import java.util.List; - -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.PropertysetItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; - -public class GridLayoutInForm extends TestBase { - - @Override - protected void setup() { - final List propertyIds = new ArrayList(); - for (int i = 0; i < 50; i++) { - propertyIds.add("property " + i); - } - - GridLayout gridLayout = new GridLayout(); - gridLayout.setSizeUndefined(); - gridLayout.setColumns(2); - gridLayout.setSpacing(true); - - PropertysetItem item = new PropertysetItem(); - for (String propertyId : propertyIds) { - item.addItemProperty(propertyId, new ObjectProperty( - propertyId)); - } - - final Form form = new Form(gridLayout); - form.setItemDataSource(item); - - form.setSizeUndefined(); - - VerticalLayout panelLayout = new VerticalLayout(); - panelLayout.setMargin(true); - Panel panel = new Panel(panelLayout); - panelLayout.addComponent(form); - panel.setHeight("500px"); - - addComponent(panel); - - addComponent(new Button("Use 15 first fields", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setVisibleItemProperties(propertyIds - .subList(0, 15)); - } - })); - addComponent(new Button("Use 15 last fields", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setVisibleItemProperties(propertyIds.subList(35, - 50)); - } - })); - - addComponent(new Button("Use all fields", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.setVisibleItemProperties(propertyIds); - } - })); - } - - @Override - protected String getDescription() { - return "Changing the number of visible fields in a Form using a GridLayout with spacing should not cause additional empty space in the end of the GridLayout"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(8855); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/table/KeyboardNavigationDatasourceChange.java b/uitest/src/main/java/com/vaadin/tests/components/table/KeyboardNavigationDatasourceChange.java deleted file mode 100644 index 8db437f0c3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/table/KeyboardNavigationDatasourceChange.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.vaadin.tests.components.table; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import com.vaadin.data.util.BeanItemContainer; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Form; -import com.vaadin.ui.Table; - -public class KeyboardNavigationDatasourceChange extends TestBase { - - @Override - protected void setup() { - List items = new ArrayList(); - for (int i = 0; i < 110; i++) { - items.add(new MyItem("item" + i, i, null)); - } - BeanItemContainer c = new BeanItemContainer( - MyItem.class, items); - Table t = new Table("Test", c); - t.setVisibleColumns(new String[] { "nome", "index", "parent" }); - t.setSelectable(true); - t.setSizeFull(); - t.setImmediate(true); - LegacyTextField f = new LegacyTextField("Name"); - final Form form = new Form(); - // Property p = new ObjectProperty("", String.class); - // t.setPropertyDataSource(p); // UNCOMMENT THIS LINE TO SEE BUG - // HAPPENING - // f.setPropertyDataSource(p); - // f.setImmediate(true); - t.setPropertyDataSource(f); - form.addField("table", t); - form.addField("name", f); - addComponent(form); - - } - - @Override - protected String getDescription() { - return "When calling setPropertyDataSource on a regular table the keyboard navigation becomes unstable"; - } - - @Override - protected Integer getTicketNumber() { - return 7446; - } - - public class MyItem implements Serializable { - - private String nome; - private Integer index; - protected List children = new ArrayList(); - private MyItem parent; - - public MyItem(String nome, Integer index, List children) { - this.nome = nome; - this.index = index; - if (children != null) { - this.children = children; - if (children != null) { - for (MyItem child : children) { - child.setParent(this); - } - } - } - } - - /** - * @return the nome - */ - public String getNome() { - return nome; - } - - /** - * @param nome - * the nome to set - */ - public void setNome(String nome) { - this.nome = nome; - } - - /** - * @return the idade - */ - public Integer getIndex() { - return index; - } - - /** - * @param idade - * the idade to set - */ - public void setIndex(Integer idade) { - index = idade; - } - - /** - * @return the children - */ - public List getChildren() { - return children; - } - - /** - * @param children - * the children to set - */ - public void setChildren(List children) { - this.children = children; - } - - /** - * @return the parent - */ - public MyItem getParent() { - return parent; - } - - /** - * @param parent - * the parent to set - */ - public void setParent(MyItem parent) { - this.parent = parent; - } - - @Override - public String toString() { - return nome; - } - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/textfield/OutOfSyncIssueWithKeyboardShortcut.java b/uitest/src/main/java/com/vaadin/tests/components/textfield/OutOfSyncIssueWithKeyboardShortcut.java deleted file mode 100644 index 955a9c2772..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/textfield/OutOfSyncIssueWithKeyboardShortcut.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.vaadin.tests.components.textfield; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.data.Item; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.data.util.BeanContainer; -import com.vaadin.data.util.BeanItem; -import com.vaadin.event.ShortcutAction.KeyCode; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalSplitPanel; - -public class OutOfSyncIssueWithKeyboardShortcut extends TestBase { - - public static class TestToppingsView extends CustomComponent { - - public static class Topping { - private Long id; - private String name = "ham"; - - public void setId(Long id) { - this.id = id; - } - - public Long getId() { - return id; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - - private Table table = new Table(); - - private Form form = new Form(); - - private Map toppings = new HashMap(); - private long index = 1; - - private String previousFragment = null; - - public TestToppingsView() { - setSizeFull(); - - VerticalSplitPanel mainLayout = new VerticalSplitPanel(); - mainLayout.setSplitPosition(30); - setCompositionRoot(mainLayout); - - table.setSizeFull(); - table.setImmediate(true); - table.setSelectable(true); - - mainLayout.setFirstComponent(table); - mainLayout.setSecondComponent(form); - - form.setImmediate(true); - // this is critical for the problem to occur - form.setBuffered(true); - - HorizontalLayout footer = new HorizontalLayout(); - footer.setSpacing(true); - form.setFooter(footer); - Button saveButton = new Button("Save"); - footer.addComponent(saveButton); - - // make saving the form the default action on Enter keypress - saveButton.setClickShortcut(KeyCode.ENTER); - - table.addListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - if (value != null) { - String fragment = "edit/" - + String.valueOf(value) - .replaceAll("[^0-9]", ""); - if (!fragment.equals(previousFragment)) { - navigateTo(fragment); - } - } - } - }); - - saveButton.addListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.commit(); - Topping entity = getEntityForItem(form.getItemDataSource()); - if (entity != null && entity.getId() == null) { - entity.setId(index++); - toppings.put(entity.getId(), entity); - } - refreshTable(); - navigateTo(null); - } - }); - - // create new entity at the beginning - refreshTable(); - navigateTo("new"); - } - - public void navigateTo(String requestedDataId) { - previousFragment = requestedDataId; - - if ("new".equals(requestedDataId)) { - table.setValue(null); - form.setVisible(true); - setCurrentEntity(new Topping()); - form.focus(); - } else if (requestedDataId != null - && requestedDataId.startsWith("edit/")) { - try { - Long id = Long.valueOf(requestedDataId.substring(5)); - setCurrentEntity(getEntityForItem(table.getItem(id))); - form.focus(); - } catch (NumberFormatException e) { - setCurrentEntity(null); - } - } else { - setCurrentEntity(null); - } - } - - private void refreshTable() { - // refresh table - BeanContainer container = new BeanContainer( - Topping.class); - container.setBeanIdProperty("id"); - for (Topping entity : toppings.values()) { - container.addBean(entity); - } - table.setContainerDataSource(container); - } - - protected void setCurrentEntity(Topping entity) { - form.setVisible(entity != null); - if (entity != null) { - Item item = table.getItem(entity.getId()); - if (item == null) { - item = new BeanItem(entity); - } - form.setItemDataSource(item, Collections.singleton("name")); - } else { - form.setItemDataSource(null); - } - } - - public Topping getEntityForItem(Item item) { - if (item != null) { - return ((BeanItem) item).getBean(); - } else { - return null; - } - } - - } - - @Override - protected void setup() { - TestToppingsView testToppingsView = new TestToppingsView(); - addComponent(testToppingsView); - getLayout().setSizeFull(); - getLayout().setExpandRatio(testToppingsView, 1); - } - - @Override - protected String getDescription() { - return "Focus the text field and press ENTER.\n" - + "Click on the table row to edit it, change the text to \"ahm\" using the keyboard and press ENTER again.\n" - + "Then select the table row again.\n" - + "This causes an Out of Sync error if the cursor position for the text field is sent too late to a component that is no longer in the layout."; - } - - @Override - protected Integer getTicketNumber() { - return 6834; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContent.java b/uitest/src/main/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContent.java deleted file mode 100644 index 6742a08274..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContent.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.vaadin.tests.components.window; - -import com.vaadin.legacy.data.Validator; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Form; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; - -public class UndefinedHeightSubWindowAndContent extends TestBase { - - @Override - protected void setup() { - Window subWindow = new Window("No scrollbars!"); - subWindow.setWidth("300px"); - subWindow.center(); - subWindow.setModal(true); - VerticalLayout layout = new VerticalLayout(); - layout.setWidth("100%"); - subWindow.setContent(layout); - - final Form form = new Form(); - form.setFooter(null); - form.setImmediate(true); - form.setValidationVisible(true); - form.setCaption("This is a form"); - form.setDescription("How do you do?"); - final LegacyTextField field1 = new LegacyTextField("Write here"); - field1.setImmediate(true); - field1.addValidator(new Validator() { - - @Override - public void validate(Object value) throws InvalidValueException { - if (!isValid(value)) { - throw new InvalidValueException("FAIL!"); - } - } - - public boolean isValid(Object value) { - return field1.getValue().equals("valid"); - } - }); - form.addField("Field 1", field1); - layout.addComponent(form); - - getMainWindow().addWindow(subWindow); - subWindow.bringToFront(); - } - - @Override - protected String getDescription() { - return "When both window and its content have undefined height, window must not reserve space for a scroll bar when it is not needed."; - } - - @Override - protected Integer getTicketNumber() { - return 8852; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java b/uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java deleted file mode 100644 index 49416a73e5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.vaadin.tests.containers.sqlcontainer; - -import java.sql.SQLException; - -import com.vaadin.data.Container.ItemSetChangeEvent; -import com.vaadin.data.Container.ItemSetChangeListener; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.server.LegacyApplication; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Table; - -public class CheckboxUpdateProblem extends LegacyApplication implements - Property.ValueChangeListener { - private final DatabaseHelper databaseHelper = new DatabaseHelper(); - private Table testList; - private final HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel(); - - private TestForm testForm = new TestForm(); - - @Override - public void init() { - setMainWindow(new LegacyWindow("Test window")); - horizontalSplit.setSizeFull(); - testList = new Table(); - - horizontalSplit.setFirstComponent(testList); - testList.setSizeFull(); - testList.setContainerDataSource(databaseHelper.getTestContainer()); - testList.setSelectable(true); - testList.setImmediate(true); - testList.addListener(this); - - databaseHelper.getTestContainer().addListener( - new ItemSetChangeListener() { - @Override - public void containerItemSetChange(ItemSetChangeEvent event) { - Object selected = testList.getValue(); - if (selected != null) { - testForm.setItemDataSource(testList - .getItem(selected)); - } - } - }); - - testForm = new TestForm(); - testForm.setItemDataSource(null); - - horizontalSplit.setSecondComponent(testForm); - - getMainWindow().setContent(horizontalSplit); - } - - @Override - public void valueChange(ValueChangeEvent event) { - - Property property = event.getProperty(); - if (property == testList) { - Item item = testList.getItem(testList.getValue()); - - if (item != testForm.getItemDataSource()) { - testForm.setItemDataSource(item); - } - } - - } - - private class TestForm extends Form implements Button.ClickListener { - - private final Button save; - - private TestForm() { - setSizeFull(); - setBuffered(true); - setInvalidCommitted(false); - - save = new Button("Save", this); - getFooter().addComponent(save); - getFooter().setVisible(false); - } - - @Override - public void buttonClick(ClickEvent event) { - if (event.getSource() == save) { - super.commit(); - - try { - databaseHelper.getTestContainer().commit(); - getMainWindow().showNotification("Saved"); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setItemDataSource(Item newDataSource) { - super.setItemDataSource(newDataSource); - - if (newDataSource != null) { - getFooter().setVisible(true); - } else { - getFooter().setVisible(false); - } - } - - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormManyToMany.java b/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormManyToMany.java deleted file mode 100644 index f4f612503c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormManyToMany.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vaadin.tests.fieldgroup; - -import com.vaadin.tests.components.TestBase; - -public class FormManyToMany extends TestBase { - - @Override - protected void setup() { - // TODO implement - - // TODO note that in one direction, a setter is used and automatically - // updates the other direction (setting the Roles of a User updates - // Roles), whereas in the other direction (updating the list of Users - // for a Role), manual updates are needed at commit time to keep the - // Users consistent with Roles - } - - @Override - protected String getDescription() { - return "Forms which allow editing of a many-to-many mapping between users and roles"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToMany.java b/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToMany.java deleted file mode 100644 index e269a39441..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToMany.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.vaadin.tests.fieldgroup; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Millionaire; -import com.vaadin.ui.Form; - -public class FormOneToMany extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - addComponent(form); - form.setItemDataSource(createMillionaireItem()); - - // TODO support adding, editing and removing secondary addresses - } - - protected BeanItem createMillionaireItem() { - Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(person); - // add nested properties from address - item.expandProperty("address"); - - // TODO for now, hide secondary residences - item.removeItemProperty("secondaryResidences"); - - return item; - } - - @Override - protected String getDescription() { - return "Form with an editable list of sub-objects."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToOne.java b/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToOne.java deleted file mode 100644 index b16cb29a8a..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fieldgroup/FormOneToOne.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.vaadin.tests.fieldgroup; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Person; -import com.vaadin.ui.Form; - -public class FormOneToOne extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - addComponent(form); - form.setItemDataSource(createPersonItem()); - } - - protected BeanItem createPersonItem() { - Person person = new Person("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(person); - // add nested properties from address - item.expandProperty("address"); - - return item; - } - - @Override - protected String getDescription() { - return "Form where some properties come from a sub-object of the bean."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fields/FormManyToMany.java b/uitest/src/main/java/com/vaadin/tests/fields/FormManyToMany.java deleted file mode 100644 index 43fba20f33..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fields/FormManyToMany.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vaadin.tests.fields; - -import com.vaadin.tests.components.TestBase; - -public class FormManyToMany extends TestBase { - - @Override - protected void setup() { - // TODO implement - - // TODO note that in one direction, a setter is used and automatically - // updates the other direction (setting the Roles of a User updates - // Roles), whereas in the other direction (updating the list of Users - // for a Role), manual updates are needed at commit time to keep the - // Users consistent with Roles - } - - @Override - protected String getDescription() { - return "Forms which allow editing of a many-to-many mapping between users and roles"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fields/FormOneToMany.java b/uitest/src/main/java/com/vaadin/tests/fields/FormOneToMany.java deleted file mode 100644 index a010e935ab..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fields/FormOneToMany.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.vaadin.tests.fields; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Millionaire; -import com.vaadin.ui.Form; - -public class FormOneToMany extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - addComponent(form); - form.setItemDataSource(createMillionaireItem()); - - // TODO support adding, editing and removing secondary addresses - } - - protected BeanItem createMillionaireItem() { - Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(person); - // add nested properties from address - item.expandProperty("address"); - - // TODO for now, hide secondary residences - item.removeItemProperty("secondaryResidences"); - - return item; - } - - @Override - protected String getDescription() { - return "Form with an editable list of sub-objects."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/fields/FormOneToOne.java b/uitest/src/main/java/com/vaadin/tests/fields/FormOneToOne.java deleted file mode 100644 index 36f4dfe0ea..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/fields/FormOneToOne.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.vaadin.tests.fields; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Person; -import com.vaadin.ui.Form; - -public class FormOneToOne extends TestBase { - - @Override - protected void setup() { - final Form form = new Form(); - addComponent(form); - form.setItemDataSource(createPersonItem()); - } - - protected BeanItem createPersonItem() { - Person person = new Person("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(person); - // add nested properties from address - item.expandProperty("address"); - - return item; - } - - @Override - protected String getDescription() { - return "Form where some properties come from a sub-object of the bean."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/GridLayoutCaptions.java b/uitest/src/main/java/com/vaadin/tests/layouts/GridLayoutCaptions.java deleted file mode 100644 index 380aa1027b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/layouts/GridLayoutCaptions.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.vaadin.tests.layouts; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.data.Validator; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.AbstractErrorMessage; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormFieldFactory; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.VerticalLayout; - -public class GridLayoutCaptions extends TestBase { - - class CustomForm extends Form { - private com.vaadin.ui.GridLayout layout; - - private VerticalLayout wrapper = new VerticalLayout(); - private CssLayout wrapper2 = new CssLayout(); - - private FormFieldFactory fff = new FormFieldFactory() { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - - if (propertyId.equals(DataPOJO.Fields.name.name())) { - LegacyField f = DefaultFieldFactory.get().createField(item, - propertyId, uiContext); - f.setCaption("This is a long caption for the name field"); - return f; - - } else if (propertyId.equals(DataPOJO.Fields.hp.name())) { - LegacyField f = DefaultFieldFactory.get().createField(item, - propertyId, uiContext); - f.setCaption("This is a long caption for the HP field, but it has a VL as a wrapper"); - - return f; - - } else if (propertyId.equals(DataPOJO.Fields.place.name())) { - LegacyField f = DefaultFieldFactory.get().createField(item, - propertyId, uiContext); - f.setCaption("This is a long caption for the Place field, but it has a CSSLo as a wrapper"); - - return f; - - } else if (propertyId.equals(DataPOJO.Fields.price.name())) { - LegacyField f = DefaultFieldFactory.get().createField(item, - propertyId, uiContext); - f.setCaption("With size undefined the caption behaves like this..."); - f.setSizeFull(); - - return f; - - } else { - return DefaultFieldFactory.get().createField(item, - propertyId, uiContext); - } - } - }; - - public CustomForm() { - super(); - layout = new GridLayout(3, 3); - layout.addComponent(wrapper, 1, 0); - layout.addComponent(wrapper2, 2, 0); - layout.setSpacing(true); - - setLayout(layout); - setFormFieldFactory(fff); - - Label l = new Label("A label with caption"); - l.setCaption("A really long caption that is clipped"); - - layout.addComponent(l, 0, 2); - - Label l2 = new Label("A wrapped label with caption"); - l2.setCaption("A really long caption that is not clipped"); - - VerticalLayout vl = new VerticalLayout(); - vl.addComponent(l2); - - layout.addComponent(vl, 1, 2); - - } - - public void createErrors() { - Validator.InvalidValueException ive = new Validator.InvalidValueException( - "Ipsum lipsum laarum lop... "); - - for (Object propIDs : getItemDataSource().getItemPropertyIds()) { - ((LegacyTextField) getField(propIDs)) - .setComponentError(AbstractErrorMessage - .getErrorMessageForException(ive)); - - } - - } - - public void clearErrors() { - for (Object propIDs : getItemDataSource().getItemPropertyIds()) { - ((LegacyTextField) getField(propIDs)).setComponentError(null); - - } - } - - @Override - protected void attachField(Object propertyId, LegacyField field) { - - if (propertyId.equals(DataPOJO.Fields.name.name())) { - layout.addComponent(field, 0, 0); - - } else if (propertyId.equals(DataPOJO.Fields.hp.name())) { - wrapper.removeAllComponents(); - wrapper.addComponent(field); - } else if (propertyId.equals(DataPOJO.Fields.place.name())) { - wrapper2.removeAllComponents(); - wrapper2.addComponent(field); - } else if (propertyId.equals(DataPOJO.Fields.price.name())) { - layout.addComponent(field, 0, 1); - } - - } - } - - public static class DataPOJO { - - public enum Fields { - name, price, hp, place; - } - - private String name; - private int price; - private String hp; - private String place; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getPrice() { - return price; - } - - public void setPrice(int price) { - this.price = price; - } - - public String getHp() { - return hp; - } - - public void setHp(String hp) { - this.hp = hp; - } - - public String getPlace() { - return place; - } - - public void setPlace(String place) { - this.place = place; - } - - } - - @Override - protected void setup() { - LegacyWindow mainWindow = getMainWindow(); - - Label label = new Label("Hello Vaadin user"); - mainWindow.addComponent(label); - - DataPOJO forDemo = new DataPOJO(); - - BeanItem bi = new BeanItem(forDemo); - - final CustomForm aFormWithGl = new CustomForm(); - - aFormWithGl.setItemDataSource(bi); - - mainWindow.addComponent(aFormWithGl); - - Button b = new Button("Give me an error!", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - aFormWithGl.createErrors(); - - } - }); - mainWindow.addComponent(b); - - Button b2 = new Button("Get rid of an error!", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - aFormWithGl.clearErrors(); - - } - }); - mainWindow.addComponent(b2); - - } - - @Override - protected String getDescription() { - return "Captions in Gridlayout behaves differently than in other layouts"; - } - - @Override - protected Integer getTicketNumber() { - return 5424; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/HtmlInCaption.java b/uitest/src/main/java/com/vaadin/tests/layouts/HtmlInCaption.java index 0a805a8818..51f2bc33f1 100644 --- a/uitest/src/main/java/com/vaadin/tests/layouts/HtmlInCaption.java +++ b/uitest/src/main/java/com/vaadin/tests/layouts/HtmlInCaption.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -26,7 +26,6 @@ import com.vaadin.ui.ColorPicker; import com.vaadin.ui.ColorPickerArea; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; -import com.vaadin.ui.Form; import com.vaadin.ui.GridLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Link; @@ -36,7 +35,7 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; /** - * + * * @since * @author Vaadin Ltd */ @@ -106,7 +105,6 @@ public class HtmlInCaption extends AbstractTestUI { createComponent(components, Panel.class); createComponent(components, ColorPicker.class); createComponent(components, ColorPickerArea.class); - createComponent(components, Form.class); } diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/TestAbsoluteLayout.java b/uitest/src/main/java/com/vaadin/tests/layouts/TestAbsoluteLayout.java deleted file mode 100644 index d26002c290..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/layouts/TestAbsoluteLayout.java +++ /dev/null @@ -1,326 +0,0 @@ -package com.vaadin.tests.layouts; - -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; - -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.IndexedContainer; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.AbsoluteLayout; -import com.vaadin.ui.AbsoluteLayout.ComponentPosition; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; - -public class TestAbsoluteLayout extends TestBase { - - private static class MFieldFactory extends DefaultFieldFactory { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - if (propertyId.equals("CSSString")) { - TextArea f = new TextArea(); - f.setRows(5); - f.setHeight("8em"); - f.setCaption("CSS string"); - return f; - } else if (((String) propertyId).contains("Units")) { - NativeSelect s = new NativeSelect() { - }; - s.addContainerProperty("caption", String.class, ""); - s.setItemCaptionPropertyId("caption"); - s.setNullSelectionAllowed(false); - for (int i = 0; i < Layout.Unit.values().length; i++) { - Item unitItem = s.addItem(i); - unitItem.getItemProperty("caption").setValue( - Layout.Unit.values()[i]); - } - return s; - } - - return super.createField(item, propertyId, uiContext); - } - - private static MFieldFactory instance; - - public static DefaultFieldFactory get() { - if (instance == null) { - instance = new MFieldFactory(); - } - return instance; - } - } - - @Override - protected String getDescription() { - return "This is absolute layout tester."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - - @Override - protected void setup() { - AbsoluteLayout layout = new AbsoluteLayout(); - setTheme("tests-tickets"); - layout.setStyleName("cyan"); - layout.setWidth("1000px"); - layout.setHeight("500px"); - - layout.addComponent(new Label("Hello World")); - - Button button = new Button("Centered button,z-index:10;"); - button.setSizeFull(); - layout.addComponent(button, - "top:40%;bottom:40%;right:20%;left:20%;z-index:10;"); - - Label label = new Label( - "Exotic positioned label. Fullsize, top:100px; left:2cm; right: 3.5in; bottom:12.12mm "); - label.setStyleName("yellow"); - label.setSizeFull(); - layout.addComponent(label, - "top:100px; left:2cm; right: 3.5in; bottom:12.12mm"); - - label = new Label("fullize, bottom:80%;left:80%;"); - label.setStyleName("green"); - label.setSizeFull(); - layout.addComponent(label, "bottom:80%;left:80%;"); - - label = new Label("bottomright"); - label.setSizeUndefined(); - label.setStyleName("green"); - layout.addComponent(label, "bottom:0px; right:0px;"); - - getLayout().setSizeFull(); - getLayout().addComponent(layout); - - getMainWindow().addWindow(new EditorWindow(layout)); - - } - - public class EditorWindow extends Window { - private final AbsoluteLayout l; - private Form componentEditor; - private Form positionEditor; - - public EditorWindow(AbsoluteLayout lo) { - super("AbsoluteLayout editor aka köyhän miehen wysiwyg"); - l = lo; - - setHeight("600px"); - - Button componentChooser = new Button("choose component to edit"); - componentChooser.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - final Window chooser = new Window("Choose component", - layout); - layout.setSizeUndefined(); - chooser.setModal(true); - - NativeSelect select = new NativeSelect( - "Choose component to edit"); - - select.setNullSelectionAllowed(false); - - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty("caption", String.class, ""); - Iterator componentIterator = l - .getComponentIterator(); - while (componentIterator.hasNext()) { - AbstractComponent next = (AbstractComponent) componentIterator - .next(); - Item item = container.addItem(next); - - String caption = next.getClass().getSimpleName(); - - caption += "; cap: " + next.getCaption() + "; debugid" - + getId(); - - if (next instanceof Property) { - caption += " value:" - + ((Property) next).getValue(); - } - - item.getItemProperty("caption").setValue(caption); - } - select.setContainerDataSource(container); - select.setItemCaptionPropertyId("caption"); - select.setImmediate(true); - - select.addListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - editcomponent((Component) event.getProperty() - .getValue()); - getMainWindow().removeWindow(chooser); - } - - }); - - layout.addComponent(select); - - getMainWindow().addWindow(chooser); - - } - }); - - addComponent(componentChooser); - - Button addComp = new Button("add component"); - addComp.addListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - final Window chooser = new Window( - "Choose component type to add", layout); - layout.setSizeUndefined(); - chooser.setModal(true); - - NativeSelect select = new NativeSelect( - "Choose component to edit"); - - select.setNullSelectionAllowed(false); - - IndexedContainer container = new IndexedContainer(); - - URL resource = AbstractComponent.class.getResource("."); - File directory = new File(resource.getFile()); - if (directory.exists()) { - // Get the list of the files contained in the - // package - final String[] files = directory.list(); - for (int j = 0; j < files.length; j++) { - // we are only interested in .class files - if (files[j].endsWith(".class")) { - // removes the .class extension - String p = resource.toString() - + files[j].substring(0, - files[j].length() - 6); - p = p.replaceAll(".*classes/", ""); - p = p.replaceAll("/", "."); - Class c; - try { - c = Class.forName(p); - if (AbstractComponent.class - .isAssignableFrom(c) - && !p.toLowerCase().contains( - "layout") - && !p.toLowerCase().contains( - "abstract")) { - container.addItem(c); - } - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - select.setContainerDataSource(container); - select.setImmediate(true); - - select.addListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Class c = (Class) event.getProperty() - .getValue(); - - try { - Component newInstance = (Component) c - .newInstance(); - l.addComponent(newInstance); - editcomponent(newInstance); - getMainWindow().removeWindow(chooser); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - }); - - layout.addComponent(select); - - getMainWindow().addWindow(chooser); - - } - }); - - addComponent(addComp); - - componentEditor = new Form(); - componentEditor.setBuffered(true); - componentEditor.setCaption("Component properties:"); - componentEditor.setFormFieldFactory(MFieldFactory.get()); - addComponent(componentEditor); - - positionEditor = new Form(); - positionEditor.setCaption("Component position"); - positionEditor.setBuffered(true); - positionEditor.setFormFieldFactory(MFieldFactory.get()); - addComponent(positionEditor); - - Button b = new Button("Commit changes", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - positionEditor.commit(); - componentEditor.commit(); - } - }); - addComponent(b); - - } - - private void editcomponent(Component value) { - - BeanItem beanItem = new BeanItem(value); - String c = "Component properties for " - + value.getClass().getSimpleName(); - ArrayList fields = new ArrayList( - Arrays.asList(new String[] { "width", "widthUnits", - "height", "heightUnits", "caption", "styleName" })); - if (value instanceof Label) { - c += "(" + ((Label) value).getValue() + ")"; - fields.add("value"); - } - - componentEditor.setItemDataSource(beanItem, fields); - - BeanItem positionItem = new BeanItem( - l.getPosition(value)); - componentEditor.setCaption(c); - - positionEditor.setItemDataSource(positionItem); - - } - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1710.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1710.java deleted file mode 100644 index 01545975ba..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1710.java +++ /dev/null @@ -1,414 +0,0 @@ -package com.vaadin.tests.tickets; - -import java.util.Iterator; - -import com.vaadin.data.HasValue; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.util.MethodProperty; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.SystemError; -import com.vaadin.server.ThemeResource; -import com.vaadin.shared.ui.AlignmentInfo.Bits; -import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.DateField; -import com.vaadin.ui.Form; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; -import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; - -public class Ticket1710 extends com.vaadin.server.LegacyApplication { - - @Override - public void init() { - - setTheme("tests-tickets"); - - VerticalLayout lo = new VerticalLayout(); - setMainWindow(new LegacyWindow("#1710", lo)); - lo.setMargin(true); - lo.setSpacing(true); - lo.setWidth("100%"); - - // Hiding controls - HorizontalLayout hidingControls = new HorizontalLayout(); - lo.addComponent(hidingControls); - - // OrderedLayout - final VerticalLayout orderedLayout = new VerticalLayout(); - LayoutTestingPanel oltp = new LayoutTestingPanel("OrderedLayout", - orderedLayout); - CheckBox cb = new CheckBox("OrderedLayout"); - cb.setValue(oltp.isVisible()); - cb.addValueChangeListener(event -> oltp.setVisible(event.getValue())); - cb.setImmediate(true); - hidingControls.addComponent(cb); - lo.addComponent(oltp); - orderedLayout.setSpacing(false); - addFields(orderedLayout); - - // GridLayout - GridLayout grid = new GridLayout(1, 1); - Panel g1tp = new LayoutTestingPanel("Gridlayout with 1 column", grid); - cb = new CheckBox("GridLayout (1col)"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - g1tp.setVisible(false); - cb.setValue(g1tp.isVisible()); - cb.addValueChangeListener(event -> g1tp.setVisible(event.getValue())); - lo.addComponent(g1tp); - grid.setSpacing(true); - addFields(grid); - GridLayout grid2 = new GridLayout(2, 1); - Panel g2tp = new LayoutTestingPanel("Gridlayout with 2 columns", grid2); - cb = new CheckBox("GridLayout (2cols)"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - g2tp.setVisible(false); - cb.setValue(g2tp.isVisible()); - cb.addValueChangeListener(event -> g2tp.setVisible(event.getValue())); - lo.addComponent(g2tp); - grid2.setSpacing(true); - addFields(grid2); - - // ExpandLayout - VerticalLayout el = new VerticalLayout(); - Panel elp = new LayoutTestingPanel( - "ExpandLayout width first component expanded", el); - cb = new CheckBox("ExpandLayout (vertical)"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - elp.setVisible(false); - cb.setValue(elp.isVisible()); - cb.addValueChangeListener(event -> elp.setVisible(event.getValue())); - el.setHeight("700px"); - addFields(el); - Component firstComponent = el.getComponentIterator().next(); - firstComponent.setSizeFull(); - el.setExpandRatio(firstComponent, 1); - lo.addComponent(elp); - HorizontalLayout elh = new HorizontalLayout(); - Panel elhp = new LayoutTestingPanel( - "ExpandLayout width first component expanded; horizontal", elh); - cb = new CheckBox("ExpandLayout (horizontal)"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - elhp.setVisible(false); - cb.setValue(elhp.isVisible()); - cb.addValueChangeListener(event -> elhp.setVisible(event.getValue())); - elh.setWidth("2000px"); - elh.setHeight("100px"); - addFields(elh); - Component firstComponentElh = elh.getComponentIterator().next(); - firstComponentElh.setSizeFull(); - elh.setExpandRatio(firstComponentElh, 1); - lo.addComponent(elhp); - - // CustomLayout - VerticalLayout cl = new VerticalLayout(); - Panel clp = new LayoutTestingPanel("CustomLayout", cl); - cb = new CheckBox("CustomLayout"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - clp.setVisible(false); - cb.setValue(clp.isVisible()); - cb.addValueChangeListener(event -> clp.setVisible(event.getValue())); - lo.addComponent(clp); - cl.addComponent(new Label("<<< Add customlayout testcase here >>>")); - - // Form - VerticalLayout formPanelLayout = new VerticalLayout(); - formPanelLayout.setMargin(true); - Panel formPanel = new Panel("Form", formPanelLayout); - cb = new CheckBox("Form"); - cb.setImmediate(true); - hidingControls.addComponent(cb); - formPanel.setVisible(false); - cb.setValue(formPanel.isVisible()); - cb.addValueChangeListener( - event -> formPanel.setVisible(event.getValue())); - formPanelLayout.addComponent(getFormPanelExample()); - lo.addComponent(formPanel); - - for (Iterator i = hidingControls.getComponentIterator(); i - .hasNext();) { - ((AbstractComponent) i.next()).setImmediate(true); - } - - } - - private Form getFormPanelExample() { - Form f = new Form(); - f.setCaption("Test form"); - CheckBox fb2 = new CheckBox("Test button", true); - fb2.setComponentError(new SystemError("Test error")); - f.getLayout().addComponent(fb2); - LegacyTextField ft1 = new LegacyTextField("With caption"); - ft1.setComponentError(new SystemError("Error")); - f.addField("ft1", ft1); - LegacyTextField ft2 = new LegacyTextField(); - ft2.setComponentError(new SystemError("Error")); - ft2.setValue("Without caption"); - f.addField("ft2", ft2); - LegacyTextField ft3 = new LegacyTextField("With caption and required"); - ft3.setComponentError(new SystemError("Error")); - ft3.setRequired(true); - f.addField("ft3", ft3); - return f; - } - - private void addFields(ComponentContainer lo) { - Button button = new Button("Test button"); - button.setComponentError(new SystemError("Test error")); - lo.addComponent(button); - - CheckBox b2 = new CheckBox("Test button"); - b2.setComponentError(new SystemError("Test error")); - lo.addComponent(b2); - - LegacyTextField t1 = new LegacyTextField("With caption"); - t1.setComponentError(new SystemError("Error")); - lo.addComponent(t1); - - LegacyTextField t2 = new LegacyTextField("With caption and required"); - t2.setComponentError(new SystemError("Error")); - t2.setRequired(true); - lo.addComponent(t2); - - LegacyTextField t3 = new LegacyTextField(); - t3.setValue("Without caption"); - t3.setComponentError(new SystemError("Error")); - lo.addComponent(t3); - - lo.addComponent(new LegacyTextField("Textfield with no error in it")); - - LegacyTextField tt1 = new LegacyTextField( - "100% wide Textfield with no error in it"); - tt1.setWidth("100%"); - lo.addComponent(tt1); - - LegacyTextField tt2 = new LegacyTextField(); - tt2.setWidth("100%"); - tt2.setValue("100% wide Textfield with no error in it and no caption"); - lo.addComponent(tt2); - - LegacyTextField t4 = new LegacyTextField(); - t4.setValue("Without caption, With required"); - t4.setComponentError(new SystemError("Error")); - t4.setRequired(true); - lo.addComponent(t4); - - LegacyTextField t5 = new LegacyTextField(); - t5.setValue("Without caption, WIDE"); - t5.setComponentError(new SystemError("Error")); - t5.setWidth("100%"); - lo.addComponent(t5); - - LegacyTextField t6 = new LegacyTextField(); - t6.setValue("Without caption, With required, WIDE"); - t6.setComponentError(new SystemError("Error")); - t6.setRequired(true); - t6.setWidth("100%"); - lo.addComponent(t6); - - LegacyTextField t7 = new LegacyTextField(); - t7.setValue("With icon and required and icon"); - t7.setComponentError(new SystemError("Error")); - t7.setRequired(true); - t7.setIcon(new ThemeResource("../runo/icons/16/ok.png")); - lo.addComponent(t7); - - DateField d1 = new DateField( - "Datefield with caption and icon, next one without caption"); - d1.setComponentError(new SystemError("Error")); - d1.setRequired(true); - d1.setIcon(new ThemeResource("../runo/icons/16/ok.png")); - lo.addComponent(d1); - - DateField d2 = new DateField(); - d2.setComponentError(new SystemError("Error")); - d2.setRequired(true); - lo.addComponent(d2); - } - - public class LayoutTestingPanel extends Panel { - - Layout testedLayout; - - HorizontalLayout controls = new HorizontalLayout(); - CheckBox marginLeft = new CheckBox("m-left", false); - CheckBox marginRight = new CheckBox("m-right", false); - CheckBox marginTop = new CheckBox("m-top", false); - CheckBox marginBottom = new CheckBox("m-bottom", false); - CheckBox spacing = new CheckBox("spacing", false); - VerticalLayout testPanelLayout = new VerticalLayout(); - - LayoutTestingPanel(String caption, Layout layout) { - super(caption); - VerticalLayout internalLayout = new VerticalLayout(); - internalLayout.setWidth("100%"); - setContent(internalLayout); - testedLayout = layout; - testPanelLayout.setWidth("100%"); - VerticalLayout controlWrapperLayout = new VerticalLayout(); - controlWrapperLayout.setMargin(true); - Panel controlWrapper = new Panel(controlWrapperLayout); - controlWrapperLayout.addComponent(controls); - controlWrapper.setWidth("100%"); - controlWrapper.setStyleName("controls"); - internalLayout.addComponent(controlWrapper); - Panel testPanel = new Panel(testPanelLayout); - testPanel.setStyleName("testarea"); - testPanelLayout.addComponent(testedLayout); - internalLayout.addComponent(testPanel); - internalLayout.setMargin(true); - internalLayout.setSpacing(true); - controls.setSpacing(true); - controls.setMargin(false); - controls.addComponent(new Label("width")); - controls.addComponent(new LegacyTextField( - new MethodProperty(testedLayout, "width"))); - CheckBox widthPercentsCheckBox = new CheckBox("%"); - widthPercentsCheckBox.setImmediate(true); - controls.addComponent(widthPercentsCheckBox); - controls.addComponent(new Label("height")); - controls.addComponent(new LegacyTextField( - new MethodProperty(testedLayout, "height"))); - CheckBox heightPercentsCheckBox = new CheckBox("%"); - heightPercentsCheckBox.setImmediate(true); - controls.addComponent(heightPercentsCheckBox); - controls.addComponent(marginLeft); - controls.addComponent(marginRight); - controls.addComponent(marginTop); - controls.addComponent(marginBottom); - if (testedLayout instanceof Layout.SpacingHandler) { - controls.addComponent(spacing); - } - - HasValue.ValueChangeListener marginSpacingListener = event -> updateMarginsAndSpacing(); - - marginBottom.addValueChangeListener(marginSpacingListener); - marginTop.addValueChangeListener(marginSpacingListener); - marginLeft.addValueChangeListener(marginSpacingListener); - marginRight.addValueChangeListener(marginSpacingListener); - spacing.addValueChangeListener(marginSpacingListener); - updateMarginsAndSpacing(); - - addAlignmentControls(); - - testedLayout.setStyleName("tested-layout"); - setStyleName("layout-testing-panel"); - - for (Iterator i = controls.getComponentIterator(); i - .hasNext();) { - ((AbstractComponent) i.next()).setImmediate(true); - } - } - - @SuppressWarnings("deprecation") - private void addAlignmentControls() { - if (!(testedLayout instanceof Layout.AlignmentHandler)) { - return; - } - @SuppressWarnings("unused") - final Layout.AlignmentHandler ah = (AlignmentHandler) testedLayout; - - final NativeSelect vAlign = new NativeSelect(); - final NativeSelect hAlign = new NativeSelect(); - controls.addComponent(new Label("component alignment")); - controls.addComponent(hAlign); - controls.addComponent(vAlign); - hAlign.setNullSelectionAllowed(false); - vAlign.setNullSelectionAllowed(false); - - vAlign.addItem(new Integer(Bits.ALIGNMENT_TOP)); - vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_TOP), "top"); - vAlign.addItem(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER)); - vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER), - "center"); - vAlign.addItem(new Integer(Bits.ALIGNMENT_BOTTOM)); - vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_BOTTOM), "bottom"); - - hAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT)); - hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left"); - hAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER)); - hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), - "center"); - hAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT)); - hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right"); - - Property.ValueChangeListener alignmentChangeListener = new Property.ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Integer h = ((Integer) hAlign.getValue()).intValue(); - int v = ((Integer) vAlign.getValue()).intValue(); - - updateAlignments(new Alignment(h + v)); - } - - }; - - hAlign.setValue(new Integer(Bits.ALIGNMENT_LEFT)); - vAlign.addListener(alignmentChangeListener); - hAlign.addListener(alignmentChangeListener); - vAlign.setValue(new Integer(Bits.ALIGNMENT_TOP)); - - controls.addComponent(new Label("layout alignment")); - final NativeSelect lAlign = new NativeSelect(); - controls.addComponent(lAlign); - lAlign.setNullSelectionAllowed(false); - lAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT)); - lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left"); - lAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER)); - lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), - "center"); - lAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT)); - lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right"); - - lAlign.addListener(new Property.ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - testPanelLayout.setComponentAlignment(testedLayout, - new Alignment( - ((Integer) lAlign.getValue()).intValue() - + Bits.ALIGNMENT_TOP)); - } - }); - } - - private void updateAlignments(Alignment a) { - for (Iterator i = testedLayout.getComponentIterator(); i - .hasNext();) { - ((Layout.AlignmentHandler) testedLayout) - .setComponentAlignment(i.next(), a); - } - } - - private void updateMarginsAndSpacing() { - if (testedLayout instanceof Layout.MarginHandler) { - ((Layout.MarginHandler) testedLayout).setMargin( - new MarginInfo(marginTop.getValue().booleanValue(), - marginRight.getValue().booleanValue(), - marginBottom.getValue().booleanValue(), - marginLeft.getValue().booleanValue())); - } - if (testedLayout instanceof Layout.SpacingHandler) { - ((Layout.SpacingHandler) testedLayout) - .setSpacing(spacing.getValue().booleanValue()); - } - } - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1878.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1878.java deleted file mode 100644 index fffb86bd69..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket1878.java +++ /dev/null @@ -1,391 +0,0 @@ -package com.vaadin.tests.tickets; - -import java.util.Date; -import java.util.Iterator; -import java.util.Random; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.data.validator.LegacyStringLengthValidator; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.LegacyApplication; -import com.vaadin.server.Resource; -import com.vaadin.server.ThemeResource; -import com.vaadin.server.UserError; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Layout; -import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; - -public class Ticket1878 extends LegacyApplication { - - private Layout orderedLayout; - private Layout gridLayout; - private Layout formLayout; - private GridLayout mainLayout; - private Button switchToGridButton; - private Button switchToOrderedButton; - private Button switchToFormsButton; - - @Override - public void init() { - LegacyWindow w = new LegacyWindow(getClass().getSimpleName()); - setMainWindow(w); - // setTheme("tests-tickets"); - - mainLayout = new GridLayout(1, 2); - w.setContent(mainLayout); - orderedLayout = createOL(); - gridLayout = createGL(); - formLayout = createForms(); - - switchToGridButton = new Button("Switch to GridLayout", - new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - changeLayout(switchToGridButton, gridLayout); - } - - }); - switchToOrderedButton = new Button("Switch to OrderedLayout", - new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - changeLayout(switchToOrderedButton, orderedLayout); - } - - }); - switchToOrderedButton.setEnabled(false); - - switchToFormsButton = new Button("Switch to Form", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - changeLayout(switchToFormsButton, formLayout); - } - - }); - - HorizontalLayout buttonLayout = new HorizontalLayout(); - buttonLayout.addComponent(switchToOrderedButton); - buttonLayout.addComponent(switchToGridButton); - buttonLayout.addComponent(switchToFormsButton); - - mainLayout.addComponent(buttonLayout); - mainLayout.addComponent(orderedLayout); - // w.setContent(orderedLayout); - } - - private static Layout createOL() { - GridLayout layout = new GridLayout(1, 5); - - GridLayout l1 = new GridLayout(1, 3); - createLayout(l1, new HorizontalLayout(), "1000px", "150px", "100%", - null, true); - createLayout(l1, new HorizontalLayout(), "1000px", "150px", "50px", - null, false); - GridLayout l2 = new GridLayout(6, 1); - createLayout(l2, new VerticalLayout(), "200px", "500px", true); - createLayout(l2, new VerticalLayout(), "200px", "500px", "100%", null, - true); - createLayout(l2, new VerticalLayout(), "150px", "500px", true); - createLayout(l2, new VerticalLayout(), "150px", "500px", "100%", null, - true); - createLayout(l2, new VerticalLayout(), "100px", "500px", true); - createLayout(l2, new VerticalLayout(), "100px", "500px", "100%", null, - true); - layout.addComponent(l1); - layout.addComponent(l2); - - return layout; - } - - private static Layout createGL() { - GridLayout layout = new GridLayout(1, 5); - - GridLayout l1 = new GridLayout(1, 3); - createLayout(l1, new GridLayout(8, 1), "1000px", "150px", "100%", null, - true); - createLayout(l1, new GridLayout(8, 1), "1000px", "150px", "50px", null, - false); - GridLayout l2 = new GridLayout(6, 1); - createLayout(l2, new GridLayout(1, 8), "200px", "500px", true); - createLayout(l2, new GridLayout(1, 8), "200px", "500px", "100%", null, - true); - createLayout(l2, new GridLayout(1, 8), "150px", "500px", true); - createLayout(l2, new GridLayout(1, 8), "150px", "500px", "100%", null, - true); - createLayout(l2, new GridLayout(1, 8), "100px", "500px", true); - createLayout(l2, new GridLayout(1, 8), "100px", "500px", "100%", null, - true); - layout.addComponent(l1); - layout.addComponent(l2); - - return layout; - } - - public class FormObject { - private String stringValue = "abc"; - private int intValue = 1; - private long longValue = 2L; - private Date dateValue = new Date(34587034750L); - - public String getStringValue() { - return stringValue; - } - - public void setStringValue(String stringValue) { - this.stringValue = stringValue; - } - - public int getIntValue() { - return intValue; - } - - public void setIntValue(int intValue) { - this.intValue = intValue; - } - - public long getLongValue() { - return longValue; - } - - public void setLongValue(long longValue) { - this.longValue = longValue; - } - - public Date getDateValue() { - return dateValue; - } - - public void setDateValue(Date dateValue) { - this.dateValue = dateValue; - } - - } - - private Layout createForms() { - GridLayout layout = new GridLayout(1, 5); - Form form; - - Random r = new Random(); - GridLayout l1 = new GridLayout(1, 3); - form = createForm(l1, "200px", "500px"); - BeanItem item = new BeanItem(new FormObject()); - form.setItemDataSource(item); - for (Iterator i = item.getItemPropertyIds().iterator(); i - .hasNext();) { - Object property = i.next(); - LegacyField f = form.getField(property); - - f.setRequired(r.nextBoolean()); - if (r.nextBoolean()) { - f.setIcon(new ThemeResource("icons/16/document-add.png")); - } - if (r.nextBoolean()) { - f.setCaption(null); - } - - f.addValidator( - new LegacyStringLengthValidator("Error", 10, 8, false)); - } - // createLayout(l1, new - // ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL), - // "1000px", "150px", "50px", null, false); - - // GridLayout l2 = new GridLayout(6, 1); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "200px", "500px", true); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "200px", "500px", "100%", null, true); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "150px", "500px", true); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "150px", "500px", "100%", null, true); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "100px", "500px", true); - // createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL), - // "100px", "500px", "100%", null, true); - layout.addComponent(l1); - // layout.addComponent(l2); - - return layout; - } - - private Form createForm(GridLayout parentLayout, String w, String h) { - FormLayout formLayout = new FormLayout(); - Form form = new Form(formLayout); - - VerticalLayout vl = new VerticalLayout(); - vl.setMargin(true); - vl.setSizeFull(); - Panel p = new Panel("Form " + w + "x" + h, vl); - - p.setWidth(w); - p.setHeight(h); - - parentLayout.addComponent(p); - vl.addComponent(form); - formLayout.setSizeFull(); - - return form; - } - - protected void changeLayout(Button b, Layout newLayout) { - switchToOrderedButton.setEnabled(true); - switchToGridButton.setEnabled(true); - switchToFormsButton.setEnabled(true); - - b.setEnabled(false); - Iterator i = mainLayout.getComponentIterator(); - i.next(); - Layout l = (Layout) i.next(); - - mainLayout.replaceComponent(l, newLayout); - } - - private static void createLayout(GridLayout parentLayout, Layout newLayout, - String w, String h, boolean align) { - createLayout(parentLayout, newLayout, w, h, null, null, align); - } - - private static void createLayout(GridLayout parentLayout, - final Layout newLayout, String w, String h, String componentWidth, - String componentHeight, boolean align) { - String dirText = "V"; - String type; - if (newLayout instanceof VerticalLayout) { - type = "OL"; - } else if (newLayout instanceof HorizontalLayout) { - dirText = "H"; - type = "OL"; - } else { - if (((GridLayout) newLayout).getColumns() != 1) { - dirText = "H"; - } - type = "GL"; - } - String alignText = align ? "-A" : ""; - String cWidth = componentWidth == null ? "" : " - " + componentWidth; - Panel p = new Panel( - type + "/" + dirText + alignText + " " + w + "x" + h + cWidth, - newLayout); - - p.setWidth(w); - p.setHeight(h); - - newLayout.setSizeFull(); - - String captions[] = new String[] { "TextField with caption", null }; - Resource icons[] = new Resource[] { - new ThemeResource("icons/16/document-delete.png"), null }; - boolean required[] = new boolean[] { true, false }; - LegacyTextField fields[][] = new LegacyTextField[captions.length][icons.length]; - for (int caption = 0; caption < captions.length; caption++) { - for (int icon = 0; icon < icons.length; icon++) { - for (int req = 0; req < required.length; req++) { - LegacyTextField tf = createTextFieldWithError(captions[caption], - icons[icon], required[req]); - - fields[caption][icon] = tf; - if (componentWidth != null) { - tf.setWidth(componentWidth); - tf.setValue(tf.getValue() + " w:" + componentWidth); - } - - if (componentHeight != null) { - tf.setHeight(componentWidth); - tf.setValue(tf.getValue() + " h:" + componentHeight); - } - - newLayout.addComponent(tf); - - if (align) { - ((AlignmentHandler) newLayout).setComponentAlignment(tf, - Alignment.BOTTOM_RIGHT); - } - } - } - } - - parentLayout.addComponent(p); - - } - - // private static void createGridLayout(GridLayout parentLayout, int dir, - // String w, String h) { - // createGridLayout(parentLayout, dir, w, h, null, null); - // } - - // private static void createGridLayout(GridLayout parentLayout, int dir, - // String w, String h, String componentWidth, String componentHeight) { - // GridLayout gl; - // if (dir == OrderedLayout.ORIENTATION_HORIZONTAL) { - // gl = new GridLayout(8, 1); - // } else { - // gl = new GridLayout(1, 8); - // } - // - // String dirText = (dir == OrderedLayout.ORIENTATION_HORIZONTAL ? "H" - // : "V"); - // String cWidth = componentWidth == null ? "" : " - " + componentWidth; - // Panel p = new Panel("GL/" + dirText + " " + w + "x" + h + cWidth, gl); - // - // p.setWidth(w); - // p.setHeight(h); - // - // gl.setSizeFull(); - // - // String captions[] = new String[] { "TextField with caption", null }; - // Resource icons[] = new Resource[] { - // new ThemeResource("icons/16/document-delete.png"), null }; - // boolean required[] = new boolean[] { true, false }; - // TextField fields[][] = new TextField[captions.length][icons.length]; - // for (int caption = 0; caption < captions.length; caption++) { - // for (int icon = 0; icon < icons.length; icon++) { - // for (int req = 0; req < required.length; req++) { - // TextField tf = createTextFieldWithError(captions[caption], - // icons[icon], required[req]); - // - // fields[caption][icon] = tf; - // if (componentWidth != null) { - // tf.setWidth(componentWidth); - // } - // - // if (componentHeight != null) { - // tf.setHeight(componentWidth); - // } - // - // p.addComponent(tf); - // gl.setComponentAlignment(tf, OrderedLayout.ALIGNMENT_LEFT, - // OrderedLayout.ALIGNMENT_BOTTOM); - // } - // } - // } - // - // parentLayout.addComponent(p); - // - // } - - private static LegacyTextField createTextFieldWithError(String caption, - Resource icon, boolean required) { - LegacyTextField tf = new LegacyTextField(); - tf.setCaption(caption); - tf.setIcon(icon); - tf.setRequired(required); - tf.setComponentError(new UserError("Test error message")); - return tf; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2204.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2204.java deleted file mode 100644 index 532bf9a1ba..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2204.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.vaadin.tests.tickets; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.server.LegacyApplication; -import com.vaadin.ui.AbstractOrderedLayout; -import com.vaadin.ui.AbstractSplitPanel; -import com.vaadin.ui.Accordion; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormFieldFactory; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.Label; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Panel; -import com.vaadin.ui.RichTextArea; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.VerticalSplitPanel; - -public class Ticket2204 extends LegacyApplication { - - private final List textAreas = new ArrayList(); - private TabSheet ts; - private final Map containerToComponent = new HashMap(); - private RichTextArea rta; - private final List> classes = new ArrayList>(); - protected RichTextArea formTextArea; - - @Override - public void init() { - classes.add(VerticalLayout.class); - classes.add(HorizontalLayout.class); - classes.add(GridLayout.class); - classes.add(Accordion.class); - classes.add(TabSheet.class); - classes.add(Panel.class); - classes.add(VerticalSplitPanel.class); - classes.add(HorizontalSplitPanel.class); - classes.add(Form.class); - - LegacyWindow w = new LegacyWindow(getClass().getSimpleName()); - setMainWindow(w); - // setTheme("tests-tickets"); - createUI((AbstractOrderedLayout) w.getContent()); - } - - private void createUI(AbstractOrderedLayout layout) { - ts = new TabSheet(); - layout.addComponent(ts); - - for (Class c : classes) { - ts.addTab(createComponent(c), c.getSimpleName(), null); - } - rta = new RichTextArea(); - rta.setVisible(false); - ts.addTab(rta, "Hidden rta", null); - - Button b = new Button("Show area", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - showHide(); - } - }); - - layout.addComponent(b); - - b = new Button("Show tab", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - showTab(); - } - }); - - layout.addComponent(b); - - } - - protected void showTab() { - rta.setVisible(!rta.isVisible()); - - } - - protected void showHide() { - Component c = containerToComponent.get(ts.getSelectedTab()); - c.setVisible(!c.isVisible()); - } - - private Component createComponent(Class c) { - RichTextArea textArea = new RichTextArea(); - textArea.setVisible(false); - textArea.setCaption("This is the textArea"); - textArea.setWidth("200px"); - textArea.setHeight("100px"); - textAreas.add(textArea); - Component cc = null; - - try { - cc = c.newInstance(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } - // if (c == OrderedLayout.class) { - // cc = new VerticalLayout(); - // } else - if (c == Accordion.class) { - // Label l = new Label("Filler"); - // l.setCaption("Filler label"); - // cc.addComponent(l); - } - - if (c == Form.class) { - Form f = (Form) cc; - f.setFormFieldFactory(new FormFieldFactory() { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - formTextArea = new RichTextArea(); - formTextArea.setVisible(false); - return formTextArea; - } - - }); - f.setItemDataSource(new BeanItem(new Object() { - private int a; - - @SuppressWarnings("unused") - public int getA() { - return a; - } - - @SuppressWarnings("unused") - public void setA(int a) { - this.a = a; - } - })); - containerToComponent.put(f, formTextArea); - return f; - } - containerToComponent.put(cc, textArea); - if (cc instanceof ComponentContainer) { - ((ComponentContainer) cc).addComponent(textArea); - } - - if (AbstractSplitPanel.class.isAssignableFrom(c)) { - AbstractSplitPanel sp = (AbstractSplitPanel) cc; - sp.setWidth("300px"); - sp.setHeight("300px"); - sp.addComponent(new Label("Label")); - textArea.setSizeFull(); - } - if (c == Panel.class) { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - ((Panel) cc).setContent(layout); - containerToComponent.put(cc, layout); - layout.setVisible(false); - textArea.setVisible(true); - return cc; - } - - return cc; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2244.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2244.java deleted file mode 100644 index fcb1c55f33..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2244.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.vaadin.tests.tickets; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.server.LegacyApplication; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Form; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.LegacyWindow; - -public class Ticket2244 extends LegacyApplication { - - Form form; - - @Override - public void init() { - LegacyWindow w = new LegacyWindow(getClass().getSimpleName()); - setMainWindow(w); - - GridLayout gl = new GridLayout(3, 3); - gl.setSpacing(true); - gl.addComponent(new Label("Before form")); - gl.newLine(); - - form = new Form(gl); - form.setItemDataSource(new BeanItem(new MyBean())); - - gl.addComponent(new Label("After form")); - - w.addComponent(form); - - w.addComponent(new Button("new item", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - form.setItemDataSource(new BeanItem(new MyBean())); - - } - - })); - w.addComponent(new Button("new bigger item", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - form.setItemDataSource(new BeanItem( - new MyBiggerBean())); - - } - - })); - w.addComponent(new Button("new grid layout", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - form.setLayout(new GridLayout()); - - } - - })); - w.addComponent(new Button("new form layout", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - form.setLayout(new FormLayout()); - - } - - })); - - } - - public class MyBean { - String firstname; - String lastname; - String password; - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } - - public String getLastname() { - return lastname; - } - - public void setLastname(String lastname) { - this.lastname = lastname; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - } - - public class MyBiggerBean extends MyBean { - String address; - String phone; - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2364.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2364.java deleted file mode 100644 index 50a2a4329f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2364.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.vaadin.tests.tickets; - -import com.vaadin.server.LegacyApplication; -import com.vaadin.ui.Form; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Select; -import com.vaadin.ui.VerticalLayout; - -public class Ticket2364 extends LegacyApplication { - - @Override - public void init() { - - LegacyWindow main = new LegacyWindow("The Main Window!!!"); - setMainWindow(main); - Form form = new Form(); - VerticalLayout formLayout = new VerticalLayout(); - form.setLayout(formLayout); - Select formSelect = new Select("hello"); - Select select = new Select("hello"); - form.setEnabled(false); - select.setEnabled(false); - formLayout.addComponent(formSelect); - - VerticalLayout l2 = new VerticalLayout(); - l2.addComponent(new Select("hello")); - l2.setEnabled(false); - - form.setCaption("Form"); - main.addComponent(form); - l2.setCaption("VerticalLayout"); - main.addComponent(l2); - main.addComponent(select); - main.addComponent(new Select("Enabled=true select")); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2407.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2407.java deleted file mode 100644 index 492e16bed5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket2407.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.vaadin.tests.tickets; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.ui.Form; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.VerticalLayout; - -public class Ticket2407 extends com.vaadin.server.LegacyApplication { - - @Override - public void init() { - final LegacyWindow main = new LegacyWindow("Ticket2407"); - setMainWindow(main); - - Form form = new Form(new VerticalLayout()); - LegacyTextField text = new LegacyTextField("This caption shall be visible"); - text.setRequired(true); - form.addField("test", text); - main.addComponent(form); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket677.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket677.java deleted file mode 100644 index b5d5e88d58..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket677.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.vaadin.tests.tickets; - -import com.vaadin.data.Container; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.util.BeanItem; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.server.LegacyApplication; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Form; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalLayout; - -public class Ticket677 extends LegacyApplication { - - private static final Label info = new Label( - "
  • keep debug window open to see variable changes" - + "
  • disable root panel w/ toggle button" - + "
  • toggle one of the subpanels" - + "
  • we attempt to focus the subpanels first textfield" - + "
  • focusing should fail (try tabbing as well) [worked previousy]" - + "
  • no variable changes should be sent from disabled fields [changed sent previously]" - + "
  • try further toggling and tabbing around", - ContentMode.RAW); - - Panel root = new Panel("Enabled"); - Panel one = new Panel("Enabled"); - Panel two = new Panel("Enabled"); - Form form; - Table table; - - @Override - public void init() { - LegacyWindow main = new LegacyWindow(); - setMainWindow(main); - - main.addComponent(info); - - HorizontalLayout l = new HorizontalLayout(); - main.addComponent(l); - - l.addComponent(new Button("Toggle root panel", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(root); - } - })); - l.addComponent(new Button("Toggle panel one", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(one); - } - })); - l.addComponent(new Button("Toggle panel two", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(two); - } - })); - l.addComponent(new Button("Toggle form", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(form); - } - })); - l.addComponent(new Button("Toggle table", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(table); - } - })); - - GridLayout content = new GridLayout(2, 3); - root.setContent(content); - main.addComponent(root); - - LegacyTextField tf = new LegacyTextField("Enabled"); - tf.setImmediate(true); - content.addComponent(tf); - tf = new LegacyTextField("Disabled"); - tf.setImmediate(true); - tf.setEnabled(false); - content.addComponent(tf); - - VerticalLayout oneLayout = new VerticalLayout(); - oneLayout.setMargin(true); - one.setContent(oneLayout); - - content.addComponent(one); - tf = new LegacyTextField("Enabled"); - tf.setImmediate(true); - oneLayout.addComponent(tf); - tf = new LegacyTextField("Disabled"); - tf.setImmediate(true); - tf.setEnabled(false); - oneLayout.addComponent(tf); - - VerticalLayout twoLayout = new VerticalLayout(); - twoLayout.setMargin(true); - two.setContent(twoLayout); - - content.addComponent(two); - tf = new LegacyTextField("Enabled"); - tf.setImmediate(true); - twoLayout.addComponent(tf); - tf = new LegacyTextField("Disabled"); - tf.setImmediate(true); - tf.setEnabled(false); - twoLayout.addComponent(tf); - - form = new Form(); - form.setCaption("Enabled"); - form.setFormFieldFactory(new DefaultFieldFactory() { - - @Override - public LegacyField createField(Item item, Object propertyId, - Component uiContext) { - LegacyField f = super.createField(item, propertyId, uiContext); - f.setEnabled(!"disabled".equals(propertyId)); - return f; - } - - }); - form.setItemDataSource(new BeanItem(new MyBean())); - content.addComponent(form); - - table = new Table("Enabled"); - table.setPageLength(7); - table.addContainerProperty("Text", String.class, null); - for (int i = 0; i < 150; i++) { - Item item = table.addItem("Item" + i); - Property p = item.getItemProperty("Text"); - p.setValue(i % 5 == 0 ? "enabled" : "disabled"); - } - - table.setTableFieldFactory(new DefaultFieldFactory() { - - @Override - public LegacyField createField(Container container, Object itemId, - Object propertyId, Component uiContext) { - LegacyField f = super.createField(container, itemId, propertyId, - uiContext); - Item item = container.getItem(itemId); - Property p = item.getItemProperty(propertyId); - if ("disabled".equals(p.getValue())) { - f.setEnabled(false); - } - return f; - } - - }); - table.setEditable(true); - content.addComponent(table); - - } - - private void toggle(Component c) { - boolean enable = "Disabled".equals(c.getCaption()); - c.setEnabled(enable); - c.setCaption((enable ? "Enabled" : "Disabled")); - if (c instanceof ComponentContainer) { - LegacyTextField tf = (LegacyTextField) ((ComponentContainer) c) - .getComponentIterator().next(); - tf.focus(); - } - } - - class MyBean { - boolean on = false; - int number = 1; - String rw = "read/write"; - String r = "read"; - String disabled = "disabled"; - - public boolean isOn() { - return on; - } - - public void setOn(boolean on) { - this.on = on; - } - - public int getNumber() { - return number; - } - - public void setNumber(int number) { - this.number = number; - } - - public String getRw() { - return rw; - } - - public void setRw(String rw) { - this.rw = rw; - } - - public String getDisabled() { - return disabled; - } - - public void setDisabled(String disabled) { - this.disabled = disabled; - } - - public String getR() { - return r; - } - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket736.java b/uitest/src/main/java/com/vaadin/tests/tickets/Ticket736.java deleted file mode 100644 index 6efde37648..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/tickets/Ticket736.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.vaadin.tests.tickets; - -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.MethodProperty; -import com.vaadin.legacy.data.Validator; -import com.vaadin.legacy.data.validator.LegacyIntegerValidator; -import com.vaadin.server.LegacyApplication; -import com.vaadin.server.ThemeResource; -import com.vaadin.tests.util.CheckBoxWithPropertyDataSource; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.Panel; -import com.vaadin.ui.VerticalLayout; - -public class Ticket736 extends LegacyApplication { - - Address address = new Address(); - - @Override - public void init() { - - final LegacyWindow mainWin = new LegacyWindow("Test app for #736"); - setMainWindow(mainWin); - - setTheme("runo"); - - // Create form for editing address - final Form f = new Form(); - f.setItemDataSource(new BeanItem
    (address, new String[] { - "name", "street", "zip", "city", "state", "country" })); - f.setCaption("Office address"); - f.setIcon(new ThemeResource("../runo/icons/16/document.png")); - f.setDescription("Jep jpe, this is form description."); - mainWin.addComponent(f); - - // Select to use buffered mode for editing to enable commit and discard - f.setBuffered(true); - Button commit = new Button("Commit", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - f.commit(); - } - }); - Button discard = new Button("Discard", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - f.discard(); - } - - }); - HorizontalLayout ol = new HorizontalLayout(); - ol.setHeight("3em"); - ol.addComponent(commit); - ol.setComponentAlignment(commit, Alignment.TOP_RIGHT); - ol.addComponent(discard); - f.setFooter(ol); - - // Add some validators for the form - f.getField("zip").addValidator( - new LegacyIntegerValidator("'{0}' is not a number")); - ((AbstractComponent) f.getField("zip")).setDescription("Jepjep"); - ((AbstractComponent) f.getField("zip")) - .setIcon(new ThemeResource("../runo/icons/16/folder.png")); - f.getField("state").addValidator(new IsValidState()); - f.getField("name").setRequired(true); - f.getField("street").setRequired(true); - f.getField("city").setRequired(true); - f.getField("zip").setRequired(true); - - // Debug form properties - final VerticalLayout formPropertiesLayout = new VerticalLayout(); - formPropertiesLayout.setMargin(true); - final Panel formProperties = new Panel("Form properties", - formPropertiesLayout); - formProperties.setWidth("200px"); - final String[] visibleProps = { "required", "invalidAllowed", - "readOnly", "readThrough", "writeThrough", "invalidCommitted", - "validationVisible", "immediate" }; - for (int i = 0; i < visibleProps.length; i++) { - CheckBox b = new CheckBoxWithPropertyDataSource(visibleProps[i], - new MethodProperty(f, visibleProps[i])); - b.setImmediate(true); - formPropertiesLayout.addComponent(b); - } - mainWin.addComponent(formProperties); - - // Debug the internal state of the address-object - mainWin.addComponent(new Button("Show state of the address object", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - mainWin.showNotification(address.toString()); - } - })); - } - - /** Address pojo. */ - public static class Address { - String name = ""; - String street = ""; - String zip = ""; - String city = ""; - String state = ""; - String country = ""; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - public String getZip() { - return zip; - } - - public void setZip(String zip) { - this.zip = zip; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - @Override - public String toString() { - return name + "; " + street + "; " + city + " " + zip - + (state != null ? " " + state : "") + " " + country; - } - - } - - /** Simple state validator */ - static class IsValidState implements Validator { - - @Override - public void validate(Object value) throws InvalidValueException { - // Empty and null are accepted values - if (value == null || "".equals("" + value)) { - return; - } - - // Otherwise state must be two capital letter combo - if (value.toString().length() != 2 - || !value.toString().equals(("" + value).toUpperCase())) { - throw new InvalidValueException( - "State must be either two capital letter abreviation or left empty"); - } - } - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java b/uitest/src/main/java/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java deleted file mode 100644 index f7f7d222a7..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.vaadin.tests.validation; - -import java.util.Date; - -import com.vaadin.legacy.data.Validator.InvalidValueException; -import com.vaadin.legacy.ui.LegacyDateField; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.AlwaysFailValidator; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Form; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.OptionGroup; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Select; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.themes.Reindeer; - -public class EmptyFieldErrorIndicators extends TestBase { - - @Override - protected void setup() { - getLayout().setSizeFull(); - - HorizontalLayout hl = new HorizontalLayout(); - hl.setSizeFull(); - hl.setSpacing(true); - - Panel part1 = createPart("Empty required fields validation", true, - false); - part1.setId("emptyFieldPart"); - hl.addComponent(part1); - - Panel part2 = createPart("Empty required fields with failing validator", - true, true); - part1.setId("validatedFieldPart"); - hl.addComponent(part2); - - VerticalLayout panelLayout = new VerticalLayout(); - panelLayout.setMargin(true); - Panel panel = new Panel(panelLayout); - panel.setSizeFull(); - panel.setStyleName(Reindeer.PANEL_LIGHT); - panelLayout.addComponent(hl); - addComponent(panel); - } - - private Panel createPart(String caption, boolean required, - boolean failValidator) { - VerticalLayout part = new VerticalLayout(); - part.setMargin(true); - - final Form form = createForm(required, failValidator); - form.setFooter(null); - part.addComponent(form); - - Button validate = new Button("Validate fields"); - validate.addListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - try { - form.validate(); - } catch (InvalidValueException e) { - } - } - }); - part.addComponent(validate); - - Panel panel = new Panel(caption, part); - panel.setHeight("100%"); - return panel; - } - - private Form createForm(final boolean required, - final boolean failValidator) { - // hand-crafted form, not using form field factory - final Form form = new Form() { - @Override - public void addField(Object propertyId, LegacyField field) { - super.addField(propertyId, field); - field.setRequired(required); - field.setRequiredError("Missing required value!"); - if (failValidator && !(field instanceof Button)) { - field.addValidator(new AlwaysFailValidator()); - } - } - }; - - form.addField("Field", new LegacyTextField("Text")); - form.addField("Date", new LegacyDateField("Date")); - // not good for automated testing with screenshots when null - // form.addField("Inline Date", new InlineDateField("Date")); - // same as basic DateField - // form.addField("Popup Date", new PopupDateField("Date")); - Button setDateButton = new Button("Set date"); - form.getLayout().addComponent(setDateButton); - // form.addField("Set Date", setDateButton); - setDateButton.addListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - form.getField("Date").setValue(new Date(0)); - } - }); - - NativeSelect nativeSelect = new NativeSelect("NativeSelect"); - form.addField("Native Select", nativeSelect); - nativeSelect.addItem("Value 1"); - - // in #4103, the Select component was behaving differently from others - form.addField("Select", new Select("Select")); - - Select select2 = new Select("Select 2"); - select2.addItem("Value 1"); - form.addField("Select 2", select2); - - OptionGroup optionGroup = new OptionGroup("OptionGroup"); - optionGroup.setMultiSelect(false); - optionGroup.addItem("Option 1"); - optionGroup.addItem("Option 2"); - form.addField("Option Group 1", optionGroup); - - OptionGroup optionGroup2 = new OptionGroup("OptionGroup"); - optionGroup2.setMultiSelect(true); - optionGroup2.addItem("Option 1"); - optionGroup2.addItem("Option 2"); - form.addField("Option Group 2", optionGroup2); - - // TODO could add more different fields - - return form; - } - - @Override - protected String getDescription() { - return "Fields on a form should not show the error indicator if required and empty"; - } - - @Override - protected Integer getTicketNumber() { - return 4013; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/validation/RequiredErrorMessage.java b/uitest/src/main/java/com/vaadin/tests/validation/RequiredErrorMessage.java deleted file mode 100644 index d96ba4b774..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/validation/RequiredErrorMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.vaadin.tests.validation; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.AbstractTestCase; -import com.vaadin.ui.Form; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.VerticalLayout; - -public class RequiredErrorMessage extends AbstractTestCase { - - @Override - protected Integer getTicketNumber() { - return 2442; - } - - @Override - protected String getDescription() { - return "This test verifies that the tooltip for a required field contains the requiredError message if such has been given. The tooltip for the first field should contain a message, the second field has no required error message set"; - } - - @Override - public void init() { - - final LegacyWindow main = new LegacyWindow(getClass().getName()); - setMainWindow(main); - - final Form form = new Form(new VerticalLayout()); - final LegacyTextField requiredFieldWithError = new LegacyTextField( - "Field with requiredError"); - requiredFieldWithError.setRequired(true); - requiredFieldWithError - .setRequiredError("Error message for required field"); - form.addField("field1", requiredFieldWithError); - - final LegacyTextField requiredFieldNoError = new LegacyTextField( - "Field without requiredError"); - requiredFieldNoError.setRequired(true); - form.addField("field2", requiredFieldNoError); - - final LegacyTextField requiredFieldDescriptionAndError = new LegacyTextField( - "Field with requiredError and description"); - requiredFieldDescriptionAndError.setRequired(true); - requiredFieldDescriptionAndError - .setRequiredError("Error message for required field"); - requiredFieldDescriptionAndError - .setDescription("Description message for the field"); - form.addField("field3", requiredFieldDescriptionAndError); - - main.addComponent(form); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/validation/RequiredIndicatorForReadOnly.java b/uitest/src/main/java/com/vaadin/tests/validation/RequiredIndicatorForReadOnly.java deleted file mode 100644 index ec844f004c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/validation/RequiredIndicatorForReadOnly.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.vaadin.tests.validation; - -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Form; - -public class RequiredIndicatorForReadOnly extends TestBase { - - @Override - protected String getDescription() { - return "Required flags should not be visible when a component is in read-only mode or inside a read-only form"; - } - - @Override - protected Integer getTicketNumber() { - return 2465; - } - - @Override - protected void setup() { - LegacyTextField tf = new LegacyTextField("A read only field"); - tf.setReadOnly(true); - tf.setRequired(true); - addComponent(tf); - - Form f = new Form(); - LegacyTextField tf2 = new LegacyTextField("A field in a read only form"); - tf2.setRequired(true); - f.addField("Field-1", tf2); - f.setReadOnly(true); - addComponent(f); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/validation/TestValidators.java b/uitest/src/main/java/com/vaadin/tests/validation/TestValidators.java deleted file mode 100644 index 6f16efeba8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/validation/TestValidators.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.vaadin.tests.validation; - -import com.vaadin.legacy.data.Validator; -import com.vaadin.legacy.data.validator.LegacyAbstractStringValidator; -import com.vaadin.legacy.data.validator.LegacyCompositeValidator; -import com.vaadin.legacy.data.validator.LegacyCompositeValidator.CombinationMode; -import com.vaadin.legacy.data.validator.LegacyDoubleValidator; -import com.vaadin.legacy.data.validator.LegacyEmailValidator; -import com.vaadin.legacy.data.validator.LegacyIntegerValidator; -import com.vaadin.legacy.data.validator.LegacyRegexpValidator; -import com.vaadin.legacy.data.validator.LegacyStringLengthValidator; -import com.vaadin.legacy.ui.LegacyTextField; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Form; -import com.vaadin.ui.Notification; -import com.vaadin.ui.VerticalLayout; - -public class TestValidators extends TestBase { - - @Override - protected Integer getTicketNumber() { - return 680; - } - - @Override - protected String getDescription() { - return "This test verifies that various validators work correctly"; - } - - @Override - public void setup() { - final Form form = new Form(new VerticalLayout()); - - // simple validators - - LegacyTextField tf = new LegacyTextField( - "A field, must contain 1-2 chars"); - tf.addValidator( - new LegacyStringLengthValidator("Invalid length", 1, 2, false)); - tf.setRequired(true); - tf.setValue("ab"); - form.addField("a", tf); - - tf = new LegacyTextField("A field, must contain an integer"); - tf.addValidator(new LegacyIntegerValidator("Invalid integer {0}")); - tf.setRequired(true); - tf.setValue("123"); - form.addField("b", tf); - - tf = new LegacyTextField( - "A field, must contain an integer or be empty"); - tf.addValidator(new LegacyIntegerValidator("Invalid integer {0}")); - tf.setValue("-321"); - form.addField("c", tf); - - tf = new LegacyTextField( - "A field, must contain a floating point number or be empty"); - tf.addValidator(new LegacyDoubleValidator("Invalid double {0}")); - tf.setValue("-123.45e6"); - form.addField("d", tf); - - tf = new LegacyTextField( - "A field, must contain an e-mail address or be empty"); - tf.addValidator(new LegacyEmailValidator("Invalid e-mail address {0}")); - tf.setValue("a.b@example.com"); - form.addField("e", tf); - - // regular expressions - - tf = new LegacyTextField( - "A field, must match the regular expression a.*b.*c"); - tf.addValidator(new LegacyRegexpValidator("a.*b.*c", - "{0} does not match the regular expression")); - tf.setValue("aagsabeqgc"); - form.addField("f", tf); - - tf = new LegacyTextField( - "A field, must contain the regular expression a.*b.*c"); - tf.addValidator(new LegacyRegexpValidator("a.*b.*c", false, - "{0} does not contain the regular expression")); - tf.setValue("aagsabeqgc"); - form.addField("g", tf); - - tf = new LegacyTextField( - "A field, must match the regular expression ^a.*b.*c$"); - tf.addValidator(new LegacyRegexpValidator("^a.*b.*c$", false, - "{0} does not match the regular expression with ^ and $")); - tf.setValue("aagsabeqgc"); - form.addField("h", tf); - - tf = new LegacyTextField( - "A field, must contain the regular expression ^a.*b.*c$"); - tf.addValidator(new LegacyRegexpValidator("^a.*b.*c$", false, - "{0} does not contain the regular expression with ^ and $")); - tf.setValue("aagsabeqgc"); - form.addField("i", tf); - - // TODO CompositeValidator - tf = new LegacyTextField( - "A field, must be a floating point number with 4-5 chars"); - LegacyCompositeValidator cv = new LegacyCompositeValidator( - CombinationMode.AND, - "The field must contain a floating point number with 4-5 characters"); - cv.addValidator(new LegacyStringLengthValidator( - "String length of '{0}' should be 4-5 characters", 4, 5, - false)); - cv.addValidator(new LegacyDoubleValidator( - "{0} must be a floating point number")); - tf.addValidator(cv); - tf.setValue("12.34"); - form.addField("j", tf); - - tf = new LegacyTextField( - "A field, must be a floating point number or 4-5 chars"); - cv = new LegacyCompositeValidator(CombinationMode.OR, - "The field must contain a floating point or with 4-5 characters"); - cv.addValidator(new LegacyStringLengthValidator( - "String length of '{0}' should be 4-5 characters", 4, 5, - false)); - cv.addValidator(new LegacyDoubleValidator( - "{0} must be a floating point number")); - tf.addValidator(cv); - tf.setValue("12.34g"); - form.addField("jb", tf); - - // Postal code that must be 5 digits (10000-99999). - tf = new LegacyTextField("Postal Code"); - tf.setColumns(5); - - // Create the validator - this would be even easier with RegexpValidator - Validator postalCodeValidator = new LegacyAbstractStringValidator( - "Postal code must be a number 10000-99999.") { - @Override - protected boolean isValidValue(String value) { - return value.matches("[1-9][0-9]{4}"); - } - }; - tf.addValidator(postalCodeValidator); - tf.setValue("12345"); - form.addField("k", tf); - - Button b = new Button("Commit", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - try { - form.commit(); - if (form.isValid()) { - getMainWindow().showNotification( - "OK! Form validated and no error was thrown", - Notification.TYPE_HUMANIZED_MESSAGE); - } else { - getMainWindow().showNotification( - "Form is invalid but no exception was thrown", - Notification.TYPE_ERROR_MESSAGE); - } - } catch (Exception e) { - if (form.isValid()) { - getMainWindow().showNotification( - "Form is valid but an exception was thrown", - Notification.TYPE_ERROR_MESSAGE); - } else { - getMainWindow().showNotification( - "OK! Error was thrown for an invalid input", - Notification.TYPE_HUMANIZED_MESSAGE); - - } - } - } - - }); - - addComponent(form); - addComponent(b); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/form/FormTooltipsTest.java b/uitest/src/test/java/com/vaadin/tests/components/form/FormTooltipsTest.java deleted file mode 100644 index 346005c0a4..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/form/FormTooltipsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2013 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.tests.components.form; - -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.FormElement; -import com.vaadin.tests.legacyelements.LegacyTextFieldElement; -import com.vaadin.tests.tb3.TooltipTest; - -public class FormTooltipsTest extends TooltipTest { - - @Test - public void testTooltipConfiguration() throws Exception { - openTestURL(); - // first name tooltip - - WebElement fieldElement = $(FormElement.class).first() - .$(LegacyTextFieldElement.class).first(); - checkTooltip(fieldElement, "Fields own tooltip"); - clearTooltip(); - checkTooltipNotPresent(); - - // first name caption tooltip - checkTooltip($(FormElement.class).first() - .findElement(By.className("v-caption")), "Fields own tooltip"); - - clearTooltip(); - checkTooltipNotPresent(); - - // Form should not have a description tooltip - checkTooltip($(FormElement.class).first(), null); - - // Form error message should not have a tooltip - checkTooltip(By.className("v-form-errormessage"), null); - - // last name should have no tooltip - checkTooltip($(LegacyTextFieldElement.class).get(1), null); - - // last name caption should have no tooltip - checkTooltip($(FormElement.class).first() - .findElements(By.className("v-caption")).get(1), null); - } - -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContentTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContentTest.java deleted file mode 100644 index f28351c8c0..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/window/UndefinedHeightSubWindowAndContentTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.vaadin.tests.components.window; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.Keys; - -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.tests.legacyelements.LegacyTextFieldElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.WindowElement; - -public class UndefinedHeightSubWindowAndContentTest extends MultiBrowserTest { - - @Test - public void testUndefinedHeight() { - openTestURL(); - - TextFieldElement textField = $(LegacyTextFieldElement.class).first(); - - textField.click(); - textField.sendKeys("invalid", Keys.ENTER); - - WindowElement window = $(WindowElement.class).first(); - int height = window.getSize().getHeight(); - Assert.assertTrue("Window height with validation failure", - 161 <= height && height <= 164); - - textField.setValue("valid"); - textField.sendKeys(Keys.ENTER); - height = window.getSize().getHeight(); - Assert.assertTrue("Window height with validation success", - 136 <= height && height <= 139); - } - -} -- 2.39.5