diff options
author | Henri Sara <hesara@vaadin.com> | 2012-01-31 16:42:09 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-01-31 16:42:09 +0200 |
commit | dc0268c218c9de44df30f816d541de279e529ef4 (patch) | |
tree | 606d37feaf88e33c65c7b667b175ecff745c1061 | |
parent | c763891bc1535f62e524b4d4ba5837ab53817dd9 (diff) | |
parent | 1d01f9204bd760789592238be039acef57616109 (diff) | |
download | vaadin-framework-dc0268c218c9de44df30f816d541de279e529ef4.tar.gz vaadin-framework-dc0268c218c9de44df30f816d541de279e529ef4.zip |
Merge branch 'master' into rpc
Conflicts:
build/build.xml
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/Container.java
src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VButton.java
src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java
src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java
src/com/vaadin/terminal/gwt/client/ui/VSlider.java
src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
src/com/vaadin/terminal/gwt/client/ui/VUpload.java
src/com/vaadin/terminal/gwt/client/ui/VWindow.java
src/com/vaadin/ui/Button.java
tests/server-side/com/vaadin/tests/VaadinClasses.java
161 files changed, 5611 insertions, 4790 deletions
diff --git a/build/build.xml b/build/build.xml index 0fe17a5b73..7ef9693f19 100644 --- a/build/build.xml +++ b/build/build.xml @@ -157,8 +157,7 @@ <include name="${vaadin-package}/launcher/**" /> </fileset> <fileset dir="${result-classes-junit}"> - <!-- VaadinClasses is used by both JUnit and TestBench tests --> - <include name="**/VaadinClasses*.class" /> + <!-- VaadinClasses and data classes are used by TestBench tests also --> </fileset> <!-- test resources --> <fileset dir="tests/testbench"> diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index 169934024b..f9be8bf019 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -17,7 +17,7 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Timer; -import com.vaadin.terminal.gwt.client.ui.VUnknownComponent; +import com.vaadin.terminal.gwt.client.ui.VUnknownComponentPaintable; public class ApplicationConfiguration implements EntryPoint { @@ -381,13 +381,14 @@ public class ApplicationConfiguration implements EntryPoint { return useDebugIdInDom; } - public Class<? extends VPaintableWidget> getWidgetClassByEncodedTag(String tag) { + public Class<? extends VPaintableWidget> getWidgetClassByEncodedTag( + String tag) { try { int parseInt = Integer.parseInt(tag); return classes[parseInt]; } catch (Exception e) { // component was not present in mappings - return VUnknownComponent.class; + return VUnknownComponentPaintable.class; } } @@ -397,7 +398,7 @@ public class ApplicationConfiguration implements EntryPoint { String key = keyArray.get(i).intern(); int value = valueMap.getInt(key); classes[value] = widgetSet.getImplementationByClassName(key); - if (classes[value] == VUnknownComponent.class) { + if (classes[value] == VUnknownComponentPaintable.class) { if (unknownComponents == null) { unknownComponents = new HashMap<String, String>(); } diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 68ec1b5434..630f9bf99b 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -50,6 +50,7 @@ import com.vaadin.terminal.gwt.client.ui.VContextMenu; import com.vaadin.terminal.gwt.client.ui.VNotification; import com.vaadin.terminal.gwt.client.ui.VNotification.HideEvent; import com.vaadin.terminal.gwt.client.ui.VView; +import com.vaadin.terminal.gwt.client.ui.VViewPaintable; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; import com.vaadin.terminal.gwt.server.AbstractCommunicationManager; @@ -144,7 +145,7 @@ public class ApplicationConnection { private Timer loadTimer3; private Element loadElement; - private final VView view; + private final VViewPaintable view; protected boolean applicationRunning = false; @@ -831,7 +832,8 @@ public class ApplicationConnection { if (loadElement == null) { loadElement = DOM.createDiv(); DOM.setStyleAttribute(loadElement, "position", "absolute"); - DOM.appendChild(view.getElement(), loadElement); + DOM.appendChild(view.getWidgetForPaintable().getElement(), + loadElement); VConsole.log("inserting load indicator"); } DOM.setElementProperty(loadElement, "className", "v-loading-indicator"); @@ -972,7 +974,7 @@ public class ApplicationConnection { meta = json.getValueMap("meta"); if (meta.containsKey("repaintAll")) { repaintAll = true; - view.clear(); + view.getWidgetForPaintable().clear(); getPaintableMap().clear(); if (meta.containsKey("invalidLayouts")) { validatingLayouts = true; @@ -1640,11 +1642,7 @@ public class ApplicationConnection { // Changed invisibile <-> visible if (wasVisible && manageCaption) { // Must hide caption when component is hidden - final Container parent = Util.getLayout(component); - if (parent != null) { - parent.updateCaption(paintable, uidl); - } - + updateCaption(paintable, uidl); } } @@ -1689,10 +1687,7 @@ public class ApplicationConnection { // Set captions if (manageCaption) { - final Container parent = Util.getLayout(component); - if (parent != null) { - parent.updateCaption(paintable, uidl); - } + updateCaption(paintable, uidl); } // add error classname to components w/ error @@ -1702,13 +1697,6 @@ public class ApplicationConnection { tooltipInfo.setErrorUidl(null); } - // Set captions - if (manageCaption) { - final Container parent = Util.getLayout(component); - if (parent != null) { - parent.updateCaption(paintable, uidl); - } - } /* * updateComponentSize need to be after caption update so caption can be * taken into account @@ -1719,6 +1707,12 @@ public class ApplicationConnection { return false; } + @Deprecated + private void updateCaption(VPaintableWidget paintable, UIDL uidl) { + VPaintableWidgetContainer parent = paintable.getParentPaintable(); + parent.updateCaption(paintable, uidl); + } + /** * Generates the style name for the widget based on the given primary style * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL. @@ -1919,7 +1913,8 @@ public class ApplicationConnection { boolean horizontalScrollBar = false; boolean verticalScrollBar = false; - Container parentPaintable = Util.getLayout(widget); + VPaintableWidgetContainer parentPaintable = paintable + .getParentPaintable(); RenderSpace renderSpace; // Parent-less components (like sub-windows) are relative to browser @@ -1928,7 +1923,8 @@ public class ApplicationConnection { renderSpace = new RenderSpace(Window.getClientWidth(), Window.getClientHeight()); } else { - renderSpace = parentPaintable.getAllocatedSpace(widget); + renderSpace = ((Container) parentPaintable.getWidgetForPaintable()) + .getAllocatedSpace(widget); } if (relativeSize.getHeight() >= 0) { @@ -2245,7 +2241,7 @@ public class ApplicationConnection { @Override public void run() { VConsole.log("Running re-layout of " + view.getClass().getName()); - runDescendentsLayout(view); + runDescendentsLayout(view.getWidgetForPaintable()); isPending = false; } }; @@ -2280,7 +2276,7 @@ public class ApplicationConnection { * * @return the main view */ - public VView getView() { + public VViewPaintable getView() { return view; } diff --git a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index b03bc708e2..f49f99a477 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -375,7 +375,7 @@ public class ComponentLocator { } else if (w instanceof VWindow) { VWindow win = (VWindow) w; ArrayList<VWindow> subWindowList = client.getView() - .getSubWindowList(); + .getWidgetForPaintable().getSubWindowList(); int indexOfSubWindow = subWindowList.indexOf(win); return PARENTCHILD_SEPARATOR + "VWindow[" + indexOfSubWindow + "]"; } else if (w instanceof RootPanel) { @@ -435,7 +435,7 @@ public class ComponentLocator { if (part.equals(ROOT_ID)) { w = RootPanel.get(); } else if (part.equals("")) { - w = client.getView(); + w = client.getView().getWidgetForPaintable(); } else if (w == null) { // Must be static pid (PID_S*) w = ((VPaintableWidget) VPaintableMap.get(client).getPaintable( @@ -465,7 +465,8 @@ public class ComponentLocator { * compatibility */ if (widgetClassName.equals("VWindow")) { - iterator = client.getView().getSubWindowList().iterator(); + iterator = client.getView().getWidgetForPaintable() + .getSubWindowList().iterator(); } else if (widgetClassName.equals("VContextMenu")) { return client.getContextMenu(); } else { diff --git a/src/com/vaadin/terminal/gwt/client/Container.java b/src/com/vaadin/terminal/gwt/client/Container.java index db6bbf0ee4..b573fd934e 100644 --- a/src/com/vaadin/terminal/gwt/client/Container.java +++ b/src/com/vaadin/terminal/gwt/client/Container.java @@ -8,7 +8,11 @@ import java.util.Set; import com.google.gwt.user.client.ui.Widget; -public interface Container extends VPaintableWidget { +/** + * @deprecated To be removed before 7.0.0 + */ +@Deprecated +public interface Container { /** * Replace child of this layout with another component. @@ -33,23 +37,6 @@ public interface Container extends VPaintableWidget { boolean hasChildComponent(Widget component); /** - * Update child components caption, description and error message. - * - * <p> - * Each component is responsible for maintaining its caption, description - * and error message. In most cases components doesn't want to do that and - * those elements reside outside of the component. Because of this layouts - * must provide service for it's childen to show those elements for them. - * </p> - * - * @param paintable - * Child component for which service is requested. - * @param uidl - * UIDL of the child component. - */ - void updateCaption(VPaintableWidget paintable, UIDL uidl); - - /** * Called when a child components size has been updated in the rendering * phase. * diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java index 4487341bd7..a3b1074fc4 100644 --- a/src/com/vaadin/terminal/gwt/client/Util.java +++ b/src/com/vaadin/terminal/gwt/client/Util.java @@ -155,7 +155,7 @@ public class Util { Set<Widget> parentChanges = new HashSet<Widget>(); for (Container parent : childWidgets.keySet()) { if (!parent.requestLayout(childWidgets.get(parent))) { - parentChanges.add(parent.getWidgetForPaintable()); + parentChanges.add((Widget) parent); } } @@ -740,7 +740,7 @@ public class Util { */ public static VPaintableWidget getChildPaintableForElement( ApplicationConnection client, Container parent, Element element) { - Element rootElement = parent.getWidgetForPaintable().getElement(); + Element rootElement = ((Widget) parent).getElement(); while (element != null && element != rootElement) { VPaintableWidget paintable = VPaintableMap.get(client) .getPaintable(element); diff --git a/src/com/vaadin/terminal/gwt/client/VDebugConsole.java b/src/com/vaadin/terminal/gwt/client/VDebugConsole.java index fdaf944b9f..76c312676a 100644 --- a/src/com/vaadin/terminal/gwt/client/VDebugConsole.java +++ b/src/com/vaadin/terminal/gwt/client/VDebugConsole.java @@ -91,7 +91,7 @@ public class VDebugConsole extends VOverlay implements Console { for (ApplicationConnection a : ApplicationConfiguration .getRunningApplications()) { VPaintableWidget paintable = Util.getPaintableForElement(a, - a.getView(), eventTarget); + a.getView().getWidgetForPaintable(), eventTarget); if (paintable == null) { paintable = Util.getPaintableForElement(a, RootPanel.get(), eventTarget); @@ -120,7 +120,7 @@ public class VDebugConsole extends VOverlay implements Console { for (ApplicationConnection a : ApplicationConfiguration .getRunningApplications()) { VPaintableWidget paintable = Util.getPaintableForElement(a, - a.getView(), eventTarget); + a.getView().getWidgetForPaintable(), eventTarget); if (paintable == null) { paintable = Util.getPaintableForElement(a, RootPanel.get(), eventTarget); @@ -534,8 +534,7 @@ public class VDebugConsole extends VOverlay implements Console { emphasisInUi.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (paintable != null) { - Element element2 = layout.getWidgetForPaintable() - .getElement(); + Element element2 = ((Widget) layout).getElement(); Widget.setStyleName(element2, "invalidlayout", emphasisInUi.getValue()); } diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java index 2f0cae1cc1..11b6c9d0f6 100644 --- a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java +++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java @@ -21,4 +21,11 @@ public interface VPaintableWidget extends VPaintable { */ public Widget getWidgetForPaintable(); + /** + * Returns the parent {@link VPaintableWidgetContainer} + * + * @return + */ + // FIXME: Rename to getParent() + public VPaintableWidgetContainer getParentPaintable(); } diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java new file mode 100644 index 0000000000..baf266546d --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java @@ -0,0 +1,45 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client; + +import com.google.gwt.user.client.ui.HasWidgets; + +/** + * An interface used by client-side paintables whose widget is a component + * container (implements {@link HasWidgets}). + */ +public interface VPaintableWidgetContainer extends VPaintableWidget { + + /** + * Update child components caption, description and error message. + * + * <p> + * Each component is responsible for maintaining its caption, description + * and error message. In most cases components doesn't want to do that and + * those elements reside outside of the component. Because of this layouts + * must provide service for it's childen to show those elements for them. + * </p> + * + * @param paintable + * Child component for which service is requested. + * @param uidl + * UIDL of the child component. + */ + void updateCaption(VPaintableWidget paintable, UIDL uidl); + + /** + * Returns the children for this paintable. + * <p> + * The children for this paintable are defined as all + * {@link VPaintableWidget}s whose parent is this + * {@link VPaintableWidgetContainer}. + * </p> + * + * @return A collection of children for this paintable. An empty collection + * if there are no children. + */ + // public Collection<VPaintableWidget> getChildren(); + +} diff --git a/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java b/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java index bcf7f14a9d..e63bcf98d9 100644 --- a/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java +++ b/src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java @@ -24,7 +24,7 @@ import com.google.gwt.event.dom.client.MouseOutEvent; import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ui.VUnknownComponent; +import com.vaadin.terminal.gwt.client.ui.VUnknownComponentPaintable; import com.vaadin.terminal.gwt.client.ui.VWindow; public class VUIDLBrowser extends SimpleTree { @@ -99,7 +99,7 @@ public class VUIDLBrowser extends SimpleTree { String name) { Class<? extends VPaintableWidget> widgetClassByDecodedTag = conf .getWidgetClassByEncodedTag(name); - if (widgetClassByDecodedTag == VUnknownComponent.class) { + if (widgetClassByDecodedTag == VUnknownComponentPaintable.class) { return conf.getUnknownServerClassNameByEncodedTagName(name) + "(NO CLIENT IMPLEMENTATION FOUND)"; } else { diff --git a/src/com/vaadin/terminal/gwt/client/WidgetSet.java b/src/com/vaadin/terminal/gwt/client/WidgetSet.java index b78091950b..390d79ce17 100644 --- a/src/com/vaadin/terminal/gwt/client/WidgetSet.java +++ b/src/com/vaadin/terminal/gwt/client/WidgetSet.java @@ -6,13 +6,9 @@ package com.vaadin.terminal.gwt.client; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ui.VFilterSelect; -import com.vaadin.terminal.gwt.client.ui.VListSelect; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical; -import com.vaadin.terminal.gwt.client.ui.VUnknownComponent; -import com.vaadin.terminal.gwt.client.ui.VView; -import com.vaadin.terminal.gwt.client.ui.VWindow; +import com.vaadin.terminal.gwt.client.ui.VFilterSelectPaintable; +import com.vaadin.terminal.gwt.client.ui.VListSelectPaintable; +import com.vaadin.terminal.gwt.client.ui.VUnknownComponentPaintable; public class WidgetSet { @@ -25,7 +21,8 @@ public class WidgetSet { /** * Create an uninitialized component that best matches given UIDL. The - * component must be a {@link Widget} that implements {@link VPaintableWidget}. + * component must be a {@link Widget} that implements + * {@link VPaintableWidget}. * * @param uidl * UIDL to be painted with returned component. @@ -35,7 +32,8 @@ public class WidgetSet { * @return New uninitialized and unregistered component that can paint given * UIDL. */ - public VPaintableWidget createWidget(UIDL uidl, ApplicationConfiguration conf) { + public VPaintableWidget createWidget(UIDL uidl, + ApplicationConfiguration conf) { /* * Yes, this (including the generated code in WidgetMap) may look very * odd code, but due the nature of GWT, we cannot do this any cleaner. @@ -46,16 +44,15 @@ public class WidgetSet { * TODO should try to get rid of these exceptions here */ - final Class<? extends VPaintableWidget> classType = resolveWidgetType(uidl, - conf); - if (classType == null || classType == VUnknownComponent.class) { + final Class<? extends VPaintableWidget> classType = resolveWidgetType( + uidl, conf); + if (classType == null || classType == VUnknownComponentPaintable.class) { String serverSideName = conf .getUnknownServerClassNameByEncodedTagName(uidl.getTag()); - VUnknownComponent c = GWT.create(VUnknownComponent.class); + VUnknownComponentPaintable c = GWT + .create(VUnknownComponentPaintable.class); c.setServerSideClassName(serverSideName); return c; - } else if (VWindow.class == classType) { - return GWT.create(VWindow.class); } else { /* * let the auto generated code instantiate this type @@ -74,20 +71,14 @@ public class WidgetSet { // add our historical quirks - if (widgetClass == VView.class && uidl.hasAttribute("sub")) { - return VWindow.class; - } else if (widgetClass == VFilterSelect.class) { + if (widgetClass == VFilterSelectPaintable.class) { if (uidl.hasAttribute("type")) { final String type = uidl.getStringAttribute("type").intern(); if ("legacy-multi" == type) { - return VListSelect.class; + return VListSelectPaintable.class; } } - } else if (widgetClass == VSplitPanelHorizontal.class - && uidl.hasAttribute("vertical")) { - return VSplitPanelVertical.class; } - return widgetClass; } @@ -119,7 +110,7 @@ public class WidgetSet { public Class<? extends VPaintableWidget> getImplementationByClassName( String fullyqualifiedName) { if (fullyqualifiedName == null) { - return VUnknownComponent.class; + return VUnknownComponentPaintable.class; } Class<? extends VPaintableWidget> implementationByServerSideClassName = widgetMap .getImplementationByServerSideClassName(fullyqualifiedName); @@ -131,9 +122,7 @@ public class WidgetSet { * *actually* be VListSelect, when the annotation says VFilterSelect */ if (fullyqualifiedName.equals("com.vaadin.ui.Select")) { - loadImplementation(VListSelect.class); - } else if (fullyqualifiedName.equals("com.vaadin.ui.SplitPanel")) { - loadImplementation(VSplitPanelVertical.class); + loadImplementation(VListSelectPaintable.class); } return implementationByServerSideClassName; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java index e5982b1078..f95acfc43c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java @@ -4,7 +4,6 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -13,9 +12,6 @@ import java.util.Set; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Style; -import com.google.gwt.event.dom.client.DomEvent.Type; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; @@ -23,7 +19,6 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Container; -import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; @@ -49,26 +44,11 @@ public class VAbsoluteLayout extends ComplexPanel implements Container { private Object previousStyleName; - private Map<String, AbsoluteWrapper> pidToComponentWrappper = new HashMap<String, AbsoluteWrapper>(); + Map<String, AbsoluteWrapper> pidToComponentWrappper = new HashMap<String, AbsoluteWrapper>(); protected ApplicationConnection client; - private boolean rendering; - - private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( - this, EventId.LAYOUT_CLICK) { - - @Override - protected VPaintableWidget getChildComponent(Element element) { - return getComponent(element); - } - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; + boolean rendering; public VAbsoluteLayout() { setElement(Document.get().createDivElement()); @@ -137,46 +117,7 @@ public class VAbsoluteLayout extends ComplexPanel implements Container { return true; } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - AbsoluteWrapper parent2 = (AbsoluteWrapper) (component - .getWidgetForPaintable()).getParent(); - parent2.updateCaption(uidl); - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - this.client = client; - // TODO margin handling - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - - clickEventHandler.handleEventHandlerRegistration(client); - - HashSet<String> unrenderedPids = new HashSet<String>( - pidToComponentWrappper.keySet()); - - for (Iterator<Object> childIterator = uidl.getChildIterator(); childIterator - .hasNext();) { - UIDL cc = (UIDL) childIterator.next(); - if (cc.getTag().equals("cc")) { - UIDL componentUIDL = cc.getChildUIDL(0); - unrenderedPids.remove(componentUIDL.getId()); - getWrapper(client, componentUIDL).updateFromUIDL(cc); - } - } - - for (String pid : unrenderedPids) { - AbsoluteWrapper absoluteWrapper = pidToComponentWrappper.get(pid); - pidToComponentWrappper.remove(pid); - absoluteWrapper.destroy(); - } - rendering = false; - } - - private AbsoluteWrapper getWrapper(ApplicationConnection client, - UIDL componentUIDL) { + AbsoluteWrapper getWrapper(ApplicationConnection client, UIDL componentUIDL) { AbsoluteWrapper wrapper = pidToComponentWrappper.get(componentUIDL .getId()); if (wrapper == null) { @@ -364,7 +305,7 @@ public class VAbsoluteLayout extends ComplexPanel implements Container { * @return The Paintable which the element is a part of. Null if the element * belongs to the layout and not to a child. */ - private VPaintableWidget getComponent(Element element) { + VPaintableWidget getComponent(Element element) { return Util.getPaintableForElement(client, this, element); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java new file mode 100644 index 0000000000..27535806c1 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java @@ -0,0 +1,84 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper;
+
+public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer {
+
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
+ this, EventId.LAYOUT_CLICK) {
+
+ @Override
+ protected VPaintableWidget getChildComponent(Element element) {
+ return getWidgetForPaintable().getComponent(element);
+ }
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ getWidgetForPaintable().client = client;
+ // TODO margin handling
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ HashSet<String> unrenderedPids = new HashSet<String>(
+ getWidgetForPaintable().pidToComponentWrappper.keySet());
+
+ for (Iterator<Object> childIterator = uidl.getChildIterator(); childIterator
+ .hasNext();) {
+ UIDL cc = (UIDL) childIterator.next();
+ if (cc.getTag().equals("cc")) {
+ UIDL componentUIDL = cc.getChildUIDL(0);
+ unrenderedPids.remove(componentUIDL.getId());
+ getWidgetForPaintable().getWrapper(client, componentUIDL)
+ .updateFromUIDL(cc);
+ }
+ }
+
+ for (String pid : unrenderedPids) {
+ AbsoluteWrapper absoluteWrapper = getWidgetForPaintable().pidToComponentWrappper
+ .get(pid);
+ getWidgetForPaintable().pidToComponentWrappper.remove(pid);
+ absoluteWrapper.destroy();
+ }
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ AbsoluteWrapper parent2 = (AbsoluteWrapper) (component
+ .getWidgetForPaintable()).getParent();
+ parent2.updateCaption(uidl);
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VAbsoluteLayout.class);
+ }
+
+ @Override
+ public VAbsoluteLayout getWidgetForPaintable() {
+ return (VAbsoluteLayout) super.getWidgetForPaintable();
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java index 9a2e728454..90da0ef4ac 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java @@ -5,15 +5,18 @@ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer;
public abstract class VAbstractPaintableWidget implements VPaintableWidget {
private Widget widget;
private ApplicationConnection connection;
+ private String id;
/* State variables */
- // private boolean enabled = true;
+ private boolean enabled = true;
/**
* Default constructor
@@ -69,7 +72,32 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget { this.connection = connection;
}
- // public boolean isEnabled() {
- // return enabled;
- // }
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public VPaintableWidgetContainer getParentPaintable() {
+ // FIXME: Return VPaintableWidgetContainer
+ // FIXME: Store hierarchy instead of doing lookup every time
+
+ VPaintableMap paintableMap = VPaintableMap.get(getConnection());
+
+ Widget w = getWidgetForPaintable();
+ while (w != null) {
+ w = w.getParent();
+ if (paintableMap.isPaintable(w)) {
+ return (VPaintableWidgetContainer) paintableMap.getPaintable(w);
+ }
+ }
+
+ return null;
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java new file mode 100644 index 0000000000..b3e19f037a --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java @@ -0,0 +1,17 @@ +/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer;
+
+public abstract class VAbstractPaintableWidgetContainer extends
+ VAbstractPaintableWidget implements VPaintableWidgetContainer {
+
+ /**
+ * Default constructor
+ */
+ public VAbstractPaintableWidgetContainer() {
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java index 0d44609bb0..1aa9d92770 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java @@ -6,9 +6,7 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Set; -import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; -import com.google.gwt.event.dom.client.DomEvent.Type; import com.google.gwt.event.dom.client.TouchCancelEvent; import com.google.gwt.event.dom.client.TouchCancelHandler; import com.google.gwt.event.dom.client.TouchEndEvent; @@ -17,8 +15,6 @@ import com.google.gwt.event.dom.client.TouchMoveEvent; import com.google.gwt.event.dom.client.TouchMoveHandler; import com.google.gwt.event.dom.client.TouchStartEvent; import com.google.gwt.event.dom.client.TouchStartHandler; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; @@ -30,61 +26,16 @@ import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderSpace; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VPaintableMap; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -public class VSplitPanel extends ComplexPanel implements Container, +public class VAbstractSplitPanel extends ComplexPanel implements Container, ContainerResizedListener { private boolean enabled = false; public static final String CLASSNAME = "v-splitpanel"; - public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click"; - - private ClickEventHandler clickEventHandler = new ClickEventHandler(this, - SPLITTER_CLICK_EVENT_IDENTIFIER) { - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - if ((Event.getEventsSunk(splitter) & Event.getTypeInt(type - .getName())) != 0) { - // If we are already sinking the event for the splitter we do - // not want to additionally sink it for the root element - return addHandler(handler, type); - } else { - return addDomHandler(handler, type); - } - } - - @Override - public void onContextMenu( - com.google.gwt.event.dom.client.ContextMenuEvent event) { - Element target = event.getNativeEvent().getEventTarget().cast(); - if (splitter.isOrHasChild(target)) { - super.onContextMenu(event); - } - }; - - @Override - protected void fireClick(NativeEvent event) { - Element target = event.getEventTarget().cast(); - if (splitter.isOrHasChild(target)) { - super.fireClick(event); - } - } - - @Override - protected Element getRelativeToElement() { - return null; - } - - }; - public static final int ORIENTATION_HORIZONTAL = 0; public static final int ORIENTATION_VERTICAL = 1; @@ -93,9 +44,9 @@ public class VSplitPanel extends ComplexPanel implements Container, private int orientation = ORIENTATION_HORIZONTAL; - private Widget firstChild; + Widget firstChild; - private Widget secondChild; + Widget secondChild; private final Element wrapper = DOM.createDiv(); @@ -103,7 +54,7 @@ public class VSplitPanel extends ComplexPanel implements Container, private final Element secondContainer = DOM.createDiv(); - private final Element splitter = DOM.createDiv(); + final Element splitter = DOM.createDiv(); private boolean resizing; @@ -121,11 +72,11 @@ public class VSplitPanel extends ComplexPanel implements Container, private boolean positionReversed = false; - private String[] componentStyleNames; + String[] componentStyleNames; private Element draggingCurtain; - private ApplicationConnection client; + ApplicationConnection client; private String width = ""; @@ -136,14 +87,14 @@ public class VSplitPanel extends ComplexPanel implements Container, RenderInformation renderInformation = new RenderInformation(); - private String id; + String id; - private boolean immediate; + boolean immediate; - private boolean rendering = false; + boolean rendering = false; /* The current position of the split handle in either percentages or pixels */ - private String position; + String position; protected Element scrolledContainer; @@ -151,11 +102,11 @@ public class VSplitPanel extends ComplexPanel implements Container, private TouchScrollDelegate touchScrollDelegate; - public VSplitPanel() { + public VAbstractSplitPanel() { this(ORIENTATION_HORIZONTAL); } - public VSplitPanel(int orientation) { + public VAbstractSplitPanel(int orientation) { setElement(DOM.createDiv()); switch (orientation) { case ORIENTATION_HORIZONTAL: @@ -255,69 +206,6 @@ public class VSplitPanel extends ComplexPanel implements Container, + "-second-container"); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - id = uidl.getId(); - rendering = true; - - immediate = uidl.hasAttribute("immediate"); - - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - setEnabled(!uidl.getBooleanAttribute("disabled")); - - clickEventHandler.handleEventHandlerRegistration(client); - if (uidl.hasAttribute("style")) { - componentStyleNames = uidl.getStringAttribute("style").split(" "); - } else { - componentStyleNames = new String[0]; - } - - setLocked(uidl.getBooleanAttribute("locked")); - - setPositionReversed(uidl.getBooleanAttribute("reversed")); - - setStylenames(); - - position = uidl.getStringAttribute("position"); - setSplitPosition(position); - - final VPaintableWidget newFirstChildPaintable = client - .getPaintable(uidl.getChildUIDL(0)); - final VPaintableWidget newSecondChildPaintable = client - .getPaintable(uidl.getChildUIDL(1)); - Widget newFirstChild = newFirstChildPaintable.getWidgetForPaintable(); - Widget newSecondChild = newSecondChildPaintable.getWidgetForPaintable(); - - if (firstChild != newFirstChild) { - if (firstChild != null) { - client.unregisterPaintable(VPaintableMap.get(client) - .getPaintable(firstChild)); - } - setFirstWidget(newFirstChild); - } - if (secondChild != newSecondChild) { - if (secondChild != null) { - client.unregisterPaintable(VPaintableMap.get(client) - .getPaintable(secondChild)); - } - setSecondWidget(newSecondChild); - } - newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client); - newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client); - - renderInformation.updateSize(getElement()); - - // This is needed at least for cases like #3458 to take - // appearing/disappearing scrollbars into account. - client.runDescendentsLayout(this); - - rendering = false; - - } - @Override public boolean remove(Widget w) { boolean removed = super.remove(w); @@ -331,7 +219,7 @@ public class VSplitPanel extends ComplexPanel implements Container, return removed; } - private void setLocked(boolean newValue) { + void setLocked(boolean newValue) { if (locked != newValue) { locked = newValue; splitterSize = -1; @@ -339,7 +227,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } } - private void setPositionReversed(boolean reversed) { + void setPositionReversed(boolean reversed) { if (positionReversed != reversed) { if (orientation == ORIENTATION_HORIZONTAL) { DOM.setStyleAttribute(splitter, "right", ""); @@ -353,7 +241,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } } - private void setSplitPosition(String pos) { + void setSplitPosition(String pos) { if (pos == null) { return; } @@ -473,7 +361,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } - private void setFirstWidget(Widget w) { + void setFirstWidget(Widget w) { if (firstChild != null) { firstChild.removeFromParent(); } @@ -481,7 +369,7 @@ public class VSplitPanel extends ComplexPanel implements Container, firstChild = w; } - private void setSecondWidget(Widget w) { + void setSecondWidget(Widget w) { if (secondChild != null) { secondChild.removeFromParent(); } @@ -791,10 +679,6 @@ public class VSplitPanel extends ComplexPanel implements Container, } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // TODO Implement caption handling - } - /** * Updates the new split position back to server. */ @@ -810,7 +694,7 @@ public class VSplitPanel extends ComplexPanel implements Container, client.updateVariable(id, "position", pos, immediate); } - private void setStylenames() { + void setStylenames() { final String splitterSuffix = (orientation == ORIENTATION_HORIZONTAL ? "-hsplitter" : "-vsplitter"); final String firstContainerSuffix = "-first-container"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java new file mode 100644 index 0000000000..1ff066d004 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java @@ -0,0 +1,140 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public abstract class VAbstractSplitPanelPaintable extends
+ VAbstractPaintableWidgetContainer {
+
+ public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click";
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // TODO Implement caption handling
+ }
+
+ ClickEventHandler clickEventHandler = new ClickEventHandler(this,
+ SPLITTER_CLICK_EVENT_IDENTIFIER) {
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ if ((Event.getEventsSunk(getWidgetForPaintable().splitter) & Event
+ .getTypeInt(type.getName())) != 0) {
+ // If we are already sinking the event for the splitter we do
+ // not want to additionally sink it for the root element
+ return getWidgetForPaintable().addHandler(handler, type);
+ } else {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ }
+
+ @Override
+ public void onContextMenu(
+ com.google.gwt.event.dom.client.ContextMenuEvent event) {
+ Element target = event.getNativeEvent().getEventTarget().cast();
+ if (getWidgetForPaintable().splitter.isOrHasChild(target)) {
+ super.onContextMenu(event);
+ }
+ };
+
+ @Override
+ protected void fireClick(NativeEvent event) {
+ Element target = event.getEventTarget().cast();
+ if (getWidgetForPaintable().splitter.isOrHasChild(target)) {
+ super.fireClick(event);
+ }
+ }
+
+ @Override
+ protected Element getRelativeToElement() {
+ return null;
+ }
+
+ };
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+ getWidgetForPaintable().rendering = true;
+
+ getWidgetForPaintable().immediate = uidl.hasAttribute("immediate");
+
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+ getWidgetForPaintable().setEnabled(
+ !uidl.getBooleanAttribute("disabled"));
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+ if (uidl.hasAttribute("style")) {
+ getWidgetForPaintable().componentStyleNames = uidl
+ .getStringAttribute("style").split(" ");
+ } else {
+ getWidgetForPaintable().componentStyleNames = new String[0];
+ }
+
+ getWidgetForPaintable().setLocked(uidl.getBooleanAttribute("locked"));
+
+ getWidgetForPaintable().setPositionReversed(
+ uidl.getBooleanAttribute("reversed"));
+
+ getWidgetForPaintable().setStylenames();
+
+ getWidgetForPaintable().position = uidl.getStringAttribute("position");
+ getWidgetForPaintable().setSplitPosition(
+ getWidgetForPaintable().position);
+
+ final VPaintableWidget newFirstChildPaintable = client
+ .getPaintable(uidl.getChildUIDL(0));
+ final VPaintableWidget newSecondChildPaintable = client
+ .getPaintable(uidl.getChildUIDL(1));
+ Widget newFirstChild = newFirstChildPaintable.getWidgetForPaintable();
+ Widget newSecondChild = newSecondChildPaintable.getWidgetForPaintable();
+
+ if (getWidgetForPaintable().firstChild != newFirstChild) {
+ if (getWidgetForPaintable().firstChild != null) {
+ client.unregisterPaintable(VPaintableMap.get(client)
+ .getPaintable(getWidgetForPaintable().firstChild));
+ }
+ getWidgetForPaintable().setFirstWidget(newFirstChild);
+ }
+ if (getWidgetForPaintable().secondChild != newSecondChild) {
+ if (getWidgetForPaintable().secondChild != null) {
+ client.unregisterPaintable(VPaintableMap.get(client)
+ .getPaintable(getWidgetForPaintable().secondChild));
+ }
+ getWidgetForPaintable().setSecondWidget(newSecondChild);
+ }
+ newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client);
+ newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client);
+
+ getWidgetForPaintable().renderInformation
+ .updateSize(getWidgetForPaintable().getElement());
+
+ // This is needed at least for cases like #3458 to take
+ // appearing/disappearing scrollbars into account.
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ getWidgetForPaintable().rendering = false;
+
+ }
+
+ @Override
+ public VAbstractSplitPanel getWidgetForPaintable() {
+ return (VAbstractSplitPanel) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected abstract VAbstractSplitPanel createWidget();
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java index 7fe87713c3..3e4f21477b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java @@ -15,7 +15,6 @@ import com.google.gwt.user.client.Element; 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.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderSpace; @@ -36,58 +35,23 @@ public class VAccordion extends VTabsheetBase implements private String width = ""; - private HashMap<StackItem, UIDL> lazyUpdateMap = new HashMap<StackItem, UIDL>(); + HashMap<StackItem, UIDL> lazyUpdateMap = new HashMap<StackItem, UIDL>(); private RenderSpace renderSpace = new RenderSpace(0, 0, true); - private StackItem openTab = null; + StackItem openTab = null; - private boolean rendering = false; + boolean rendering = false; - private int selectedUIDLItemIndex = -1; + int selectedUIDLItemIndex = -1; - private RenderInformation renderInformation = new RenderInformation(); + RenderInformation renderInformation = new RenderInformation(); public VAccordion() { super(CLASSNAME); } @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - selectedUIDLItemIndex = -1; - super.updateFromUIDL(uidl, client); - /* - * Render content after all tabs have been created and we know how large - * the content area is - */ - if (selectedUIDLItemIndex >= 0) { - StackItem selectedItem = getStackItem(selectedUIDLItemIndex); - UIDL selectedTabUIDL = lazyUpdateMap.remove(selectedItem); - open(selectedUIDLItemIndex); - - selectedItem.setContent(selectedTabUIDL); - } else if (!uidl.getBooleanAttribute("cached") && openTab != null) { - close(openTab); - } - - iLayout(); - // finally render possible hidden tabs - if (lazyUpdateMap.size() > 0) { - for (Iterator iterator = lazyUpdateMap.keySet().iterator(); iterator - .hasNext();) { - StackItem item = (StackItem) iterator.next(); - item.setContent(lazyUpdateMap.get(item)); - } - lazyUpdateMap.clear(); - } - - renderInformation.updateSize(getElement()); - - rendering = false; - } - - @Override protected void renderTab(UIDL tabUidl, int index, boolean selected, boolean hidden) { StackItem item; @@ -182,7 +146,7 @@ public class VAccordion extends VTabsheetBase implements return item; } - private void open(int itemIndex) { + void open(int itemIndex) { StackItem item = (StackItem) getWidget(itemIndex); boolean alreadyOpen = false; if (openTab != null) { @@ -205,7 +169,7 @@ public class VAccordion extends VTabsheetBase implements updateOpenTabSize(); } - private void close(StackItem item) { + void close(StackItem item) { if (!item.isOpen()) { return; } @@ -581,10 +545,6 @@ public class VAccordion extends VTabsheetBase implements } } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - /* Accordion does not render its children's captions */ - } - public boolean requestLayout(Set<Widget> children) { if (!isDynamicHeight() && !isDynamicWidth()) { /* @@ -646,12 +606,8 @@ public class VAccordion extends VTabsheetBase implements return null; } - private StackItem getStackItem(int index) { + StackItem getStackItem(int index) { return (StackItem) getWidget(index); } - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java new file mode 100644 index 0000000000..3f28818073 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java @@ -0,0 +1,68 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.Iterator;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.VAccordion.StackItem;
+
+public class VAccordionPaintable extends VTabsheetBasePaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ getWidgetForPaintable().selectedUIDLItemIndex = -1;
+ super.updateFromUIDL(uidl, client);
+ /*
+ * Render content after all tabs have been created and we know how large
+ * the content area is
+ */
+ if (getWidgetForPaintable().selectedUIDLItemIndex >= 0) {
+ StackItem selectedItem = getWidgetForPaintable().getStackItem(
+ getWidgetForPaintable().selectedUIDLItemIndex);
+ UIDL selectedTabUIDL = getWidgetForPaintable().lazyUpdateMap
+ .remove(selectedItem);
+ getWidgetForPaintable().open(
+ getWidgetForPaintable().selectedUIDLItemIndex);
+
+ selectedItem.setContent(selectedTabUIDL);
+ } else if (!uidl.getBooleanAttribute("cached")
+ && getWidgetForPaintable().openTab != null) {
+ getWidgetForPaintable().close(getWidgetForPaintable().openTab);
+ }
+
+ getWidgetForPaintable().iLayout();
+ // finally render possible hidden tabs
+ if (getWidgetForPaintable().lazyUpdateMap.size() > 0) {
+ for (Iterator iterator = getWidgetForPaintable().lazyUpdateMap
+ .keySet().iterator(); iterator.hasNext();) {
+ StackItem item = (StackItem) iterator.next();
+ item.setContent(getWidgetForPaintable().lazyUpdateMap.get(item));
+ }
+ getWidgetForPaintable().lazyUpdateMap.clear();
+ }
+
+ getWidgetForPaintable().renderInformation
+ .updateSize(getWidgetForPaintable().getElement());
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ @Override
+ public VAccordion getWidgetForPaintable() {
+ return (VAccordion) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VAccordion.class);
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ /* Accordion does not render its children's captions */
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAudio.java b/src/com/vaadin/terminal/gwt/client/ui/VAudio.java index 7fc061184d..f6df827237 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAudio.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAudio.java @@ -6,12 +6,6 @@ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.dom.client.AudioElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Style; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.UIDL; public class VAudio extends VMediaBase { private static String CLASSNAME = "v-audio"; @@ -25,31 +19,8 @@ public class VAudio extends VMediaBase { } @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - super.updateFromUIDL(uidl, client); - Style style = audio.getStyle(); - - // Make sure that the controls are not clipped if visible. - if (shouldShowControls(uidl) - && (style.getHeight() == null || "".equals(style.getHeight()))) { - if (BrowserInfo.get().isChrome()) { - style.setHeight(32, Unit.PX); - } else { - style.setHeight(25, Unit.PX); - } - } - } - - @Override protected String getDefaultAltHtml() { return "Your browser does not support the <code>audio</code> element."; } - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java new file mode 100644 index 0000000000..e949d95104 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAudioPaintable.java @@ -0,0 +1,37 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VAudioPaintable extends VMediaBasePaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ super.updateFromUIDL(uidl, client);
+ Style style = getWidgetForPaintable().getElement().getStyle();
+
+ // Make sure that the controls are not clipped if visible.
+ if (shouldShowControls(uidl)
+ && (style.getHeight() == null || "".equals(style.getHeight()))) {
+ if (BrowserInfo.get().isChrome()) {
+ style.setHeight(32, Unit.PX);
+ } else {
+ style.setHeight(25, Unit.PX);
+ }
+ }
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VAudio.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java index 6872d5f640..e04403d00e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java @@ -20,7 +20,6 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Accessibility; import com.google.gwt.user.client.ui.FocusWidget; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; @@ -481,9 +480,4 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler, public void onBlur(BlurEvent arg0) { client.updateVariable(paintableId, EventId.BLUR, "", true); } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java index 1367d412a8..98f2888700 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java @@ -1,3 +1,7 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.core.client.GWT; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java index d306bab39e..d92d7e37ed 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java @@ -16,16 +16,13 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements - VPaintableWidget, Field, FocusHandler, BlurHandler { + Field, FocusHandler, BlurHandler { public static final String VARIABLE_STATE = "state"; @@ -37,12 +34,12 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements ApplicationConnection client; - private Element errorIndicatorElement; + Element errorIndicatorElement; - private Icon icon; + Icon icon; - private HandlerRegistration focusHandlerRegistration; - private HandlerRegistration blurHandlerRegistration; + HandlerRegistration focusHandlerRegistration; + HandlerRegistration blurHandlerRegistration; public VCheckBox() { setStyleName(CLASSNAME); @@ -71,61 +68,6 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements } } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // Save details - this.client = client; - id = uidl.getId(); - - // Ensure correct implementation - if (client.updateComponent(this, uidl, false)) { - return; - } - - focusHandlerRegistration = EventHelper.updateFocusHandler(this, client, - focusHandlerRegistration); - blurHandlerRegistration = EventHelper.updateBlurHandler(this, client, - blurHandlerRegistration); - - if (uidl.hasAttribute("error")) { - if (errorIndicatorElement == null) { - errorIndicatorElement = DOM.createSpan(); - errorIndicatorElement.setInnerHTML(" "); - DOM.setElementProperty(errorIndicatorElement, "className", - "v-errorindicator"); - DOM.appendChild(getElement(), errorIndicatorElement); - DOM.sinkEvents(errorIndicatorElement, VTooltip.TOOLTIP_EVENTS - | Event.ONCLICK); - } else { - DOM.setStyleAttribute(errorIndicatorElement, "display", ""); - } - } else if (errorIndicatorElement != null) { - DOM.setStyleAttribute(errorIndicatorElement, "display", "none"); - } - - if (uidl.hasAttribute("readonly")) { - setEnabled(false); - } - - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - DOM.insertChild(getElement(), icon.getElement(), 1); - icon.sinkEvents(VTooltip.TOOLTIP_EVENTS); - icon.sinkEvents(Event.ONCLICK); - } - icon.setUri(uidl.getStringAttribute("icon")); - } else if (icon != null) { - // detach icon - DOM.removeChild(getElement(), icon.getElement()); - icon = null; - } - - // Set text - setText(uidl.getStringAttribute("caption")); - setValue(uidl.getBooleanVariable(VARIABLE_STATE)); - immediate = uidl.getBooleanAttribute("immediate"); - } - @Override public void onBrowserEvent(Event event) { if (icon != null && (event.getTypeInt() == Event.ONCLICK) @@ -137,7 +79,7 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements Util.notifyParentOfSizeChange(this, true); } if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java new file mode 100644 index 0000000000..03233c6e27 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java @@ -0,0 +1,96 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.EventHelper;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VTooltip;
+
+public class VCheckBoxPaintable extends VAbstractPaintableWidget {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ // Save details
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ // Ensure correct implementation
+ if (client.updateComponent(this, uidl, false)) {
+ return;
+ }
+
+ getWidgetForPaintable().focusHandlerRegistration = EventHelper
+ .updateFocusHandler(this, client,
+ getWidgetForPaintable().focusHandlerRegistration);
+ getWidgetForPaintable().blurHandlerRegistration = EventHelper
+ .updateBlurHandler(this, client,
+ getWidgetForPaintable().blurHandlerRegistration);
+
+ if (uidl.hasAttribute("error")) {
+ if (getWidgetForPaintable().errorIndicatorElement == null) {
+ getWidgetForPaintable().errorIndicatorElement = DOM
+ .createSpan();
+ getWidgetForPaintable().errorIndicatorElement
+ .setInnerHTML(" ");
+ DOM.setElementProperty(
+ getWidgetForPaintable().errorIndicatorElement,
+ "className", "v-errorindicator");
+ DOM.appendChild(getWidgetForPaintable().getElement(),
+ getWidgetForPaintable().errorIndicatorElement);
+ DOM.sinkEvents(getWidgetForPaintable().errorIndicatorElement,
+ VTooltip.TOOLTIP_EVENTS | Event.ONCLICK);
+ } else {
+ DOM.setStyleAttribute(
+ getWidgetForPaintable().errorIndicatorElement,
+ "display", "");
+ }
+ } else if (getWidgetForPaintable().errorIndicatorElement != null) {
+ DOM.setStyleAttribute(
+ getWidgetForPaintable().errorIndicatorElement, "display",
+ "none");
+ }
+
+ if (uidl.hasAttribute("readonly")) {
+ getWidgetForPaintable().setEnabled(false);
+ }
+
+ if (uidl.hasAttribute("icon")) {
+ if (getWidgetForPaintable().icon == null) {
+ getWidgetForPaintable().icon = new Icon(client);
+ DOM.insertChild(getWidgetForPaintable().getElement(),
+ getWidgetForPaintable().icon.getElement(), 1);
+ getWidgetForPaintable().icon
+ .sinkEvents(VTooltip.TOOLTIP_EVENTS);
+ getWidgetForPaintable().icon.sinkEvents(Event.ONCLICK);
+ }
+ getWidgetForPaintable().icon
+ .setUri(uidl.getStringAttribute("icon"));
+ } else if (getWidgetForPaintable().icon != null) {
+ // detach icon
+ DOM.removeChild(getWidgetForPaintable().getElement(),
+ getWidgetForPaintable().icon.getElement());
+ getWidgetForPaintable().icon = null;
+ }
+
+ // Set text
+ getWidgetForPaintable().setText(uidl.getStringAttribute("caption"));
+ getWidgetForPaintable()
+ .setValue(
+ uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE));
+ getWidgetForPaintable().immediate = uidl
+ .getBooleanAttribute("immediate");
+ }
+
+ @Override
+ public VCheckBox getWidgetForPaintable() {
+ return (VCheckBox) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VCheckBox.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java index ffd7fc49b2..e56d333dad 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java @@ -11,9 +11,6 @@ import java.util.Iterator; import java.util.Set; import com.google.gwt.dom.client.Style; -import com.google.gwt.event.dom.client.DomEvent.Type; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlowPanel; @@ -22,7 +19,6 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.Container; -import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.StyleConstants; import com.vaadin.terminal.gwt.client.UIDL; @@ -33,33 +29,17 @@ import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.ValueMap; -public class VCssLayout extends SimplePanel implements VPaintableWidget, - Container { +public class VCssLayout extends SimplePanel implements Container { public static final String TAGNAME = "csslayout"; public static final String CLASSNAME = "v-" + TAGNAME; - private FlowPane panel = new FlowPane(); + FlowPane panel = new FlowPane(); - private Element margin = DOM.createDiv(); - - private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( - this, EventId.LAYOUT_CLICK) { - - @Override - protected VPaintableWidget getChildComponent(Element element) { - return panel.getComponent(element); - } - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; + Element margin = DOM.createDiv(); private boolean hasHeight; private boolean hasWidth; - private boolean rendering; + boolean rendering; public VCssLayout() { super(); @@ -94,32 +74,6 @@ public class VCssLayout extends SimplePanel implements VPaintableWidget, } } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - clickEventHandler.handleEventHandlerRegistration(client); - - final VMarginInfo margins = new VMarginInfo( - uidl.getIntAttribute("margins")); - setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, - margins.hasTop()); - setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT, - margins.hasRight()); - setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_BOTTOM, - margins.hasBottom()); - setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_LEFT, - margins.hasLeft()); - - setStyleName(margin, CLASSNAME + "-" + "spacing", - uidl.hasAttribute("spacing")); - panel.updateFromUIDL(uidl, client); - rendering = false; - } - public boolean hasChildComponent(Widget component) { return panel.hasChildComponent(component); } @@ -128,10 +82,6 @@ public class VCssLayout extends SimplePanel implements VPaintableWidget, panel.replaceChildComponent(oldComponent, newComponent); } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - panel.updateCaption(component, uidl); - } - public class FlowPane extends FlowPanel { private final HashMap<Widget, VCaption> widgetToCaption = new HashMap<Widget, VCaption>(); @@ -275,7 +225,7 @@ public class VCssLayout extends SimplePanel implements VPaintableWidget, } } - private VPaintableWidget getComponent(Element element) { + VPaintableWidget getComponent(Element element) { return Util .getPaintableForElement(client, VCssLayout.this, element); } @@ -347,4 +297,28 @@ public class VCssLayout extends SimplePanel implements VPaintableWidget, public Widget getWidgetForPaintable() { return this; } + + /** + * Sets CSS classes for margin and spacing based on the given parameters. + * + * @param margins + * A {@link VMarginInfo} object that provides info on + * top/left/bottom/right margins + * @param spacing + * true to enable spacing, false otherwise + */ + protected void setMarginAndSpacingStyles(VMarginInfo margins, + boolean spacing) { + setStyleName(margin, VCssLayout.CLASSNAME + "-" + + StyleConstants.MARGIN_TOP, margins.hasTop()); + setStyleName(margin, VCssLayout.CLASSNAME + "-" + + StyleConstants.MARGIN_RIGHT, margins.hasRight()); + setStyleName(margin, VCssLayout.CLASSNAME + "-" + + StyleConstants.MARGIN_BOTTOM, margins.hasBottom()); + setStyleName(margin, VCssLayout.CLASSNAME + "-" + + StyleConstants.MARGIN_LEFT, margins.hasLeft()); + + setStyleName(margin, VCssLayout.CLASSNAME + "-" + "spacing", spacing); + + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayoutPaintable.java new file mode 100644 index 0000000000..d8640e3fe5 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayoutPaintable.java @@ -0,0 +1,61 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VCssLayoutPaintable extends VAbstractPaintableWidgetContainer {
+
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
+ this, EventId.LAYOUT_CLICK) {
+
+ @Override
+ protected VPaintableWidget getChildComponent(Element element) {
+ return getWidgetForPaintable().panel.getComponent(element);
+ }
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ getWidgetForPaintable().setMarginAndSpacingStyles(
+ new VMarginInfo(uidl.getIntAttribute("margins")),
+ uidl.hasAttribute("spacing"));
+ getWidgetForPaintable().panel.updateFromUIDL(uidl, client);
+ getWidgetForPaintable().rendering = false;
+ }
+
+ @Override
+ public VCssLayout getWidgetForPaintable() {
+ return (VCssLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VCssLayout.class);
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ getWidgetForPaintable().panel.updateCaption(component, uidl);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java index 39d1ee462c..ca18104c86 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java @@ -6,81 +6,28 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Set; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.RenderSpace; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VPaintableMap; -import com.vaadin.terminal.gwt.client.VPaintableWidget; public class VCustomComponent extends SimplePanel implements Container { private static final String CLASSNAME = "v-customcomponent"; private String height; - private ApplicationConnection client; - private boolean rendering; + ApplicationConnection client; + boolean rendering; private String width; - private RenderSpace renderSpace = new RenderSpace(); + RenderSpace renderSpace = new RenderSpace(); public VCustomComponent() { super(); setStyleName(CLASSNAME); } - public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) { - rendering = true; - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - this.client = client; - - final UIDL child = uidl.getChildUIDL(0); - if (child != null) { - final VPaintableWidget paintable = client.getPaintable(child); - Widget widget = paintable.getWidgetForPaintable(); - if (widget != getWidget()) { - if (getWidget() != null) { - client.unregisterPaintable(VPaintableMap.get(client) - .getPaintable(getWidget())); - clear(); - } - setWidget(widget); - } - paintable.updateFromUIDL(child, client); - } - - boolean updateDynamicSize = updateDynamicSize(); - if (updateDynamicSize) { - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - // FIXME deferred relative size update needed to fix some - // scrollbar issues in sampler. This must be the wrong way - // to do it. Might be that some other component is broken. - client.handleComponentRelativeSize(VCustomComponent.this); - - } - }); - } - - renderSpace.setWidth(getElement().getOffsetWidth()); - renderSpace.setHeight(getElement().getOffsetHeight()); - - /* - * Needed to update client size if the size of this component has - * changed and the child uses relative size(s). - */ - client.runDescendentsLayout(this); - - rendering = false; - } - - private boolean updateDynamicSize() { + boolean updateDynamicSize() { boolean updated = false; if (isDynamicWidth()) { int childWidth = Util.getRequiredWidth(getWidget()); @@ -121,10 +68,6 @@ public class VCustomComponent extends SimplePanel implements Container { } } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // NOP, custom component dont render composition roots caption - } - public boolean requestLayout(Set<Widget> children) { // If a child grows in size, it will not necessarily be calculated // correctly unless we remove previous size definitions diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java new file mode 100644 index 0000000000..3abcd9cd75 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java @@ -0,0 +1,79 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VCustomComponentPaintable extends
+ VAbstractPaintableWidgetContainer {
+
+ public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+ getWidgetForPaintable().client = client;
+
+ final UIDL child = uidl.getChildUIDL(0);
+ if (child != null) {
+ final VPaintableWidget paintable = client.getPaintable(child);
+ Widget widget = paintable.getWidgetForPaintable();
+ if (widget != getWidgetForPaintable().getWidget()) {
+ if (getWidgetForPaintable().getWidget() != null) {
+ client.unregisterPaintable(VPaintableMap.get(client)
+ .getPaintable(getWidgetForPaintable().getWidget()));
+ getWidgetForPaintable().clear();
+ }
+ getWidgetForPaintable().setWidget(widget);
+ }
+ paintable.updateFromUIDL(child, client);
+ }
+
+ boolean updateDynamicSize = getWidgetForPaintable().updateDynamicSize();
+ if (updateDynamicSize) {
+ Scheduler.get().scheduleDeferred(new Command() {
+ public void execute() {
+ // FIXME deferred relative size update needed to fix some
+ // scrollbar issues in sampler. This must be the wrong way
+ // to do it. Might be that some other component is broken.
+ client.handleComponentRelativeSize(getWidgetForPaintable());
+
+ }
+ });
+ }
+
+ getWidgetForPaintable().renderSpace.setWidth(getWidgetForPaintable()
+ .getElement().getOffsetWidth());
+ getWidgetForPaintable().renderSpace.setHeight(getWidgetForPaintable()
+ .getElement().getOffsetHeight());
+
+ /*
+ * Needed to update client size if the size of this component has
+ * changed and the child uses relative size(s).
+ */
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VCustomComponent.class);
+ }
+
+ @Override
+ public VCustomComponent getWidgetForPaintable() {
+ return (VCustomComponent) super.getWidgetForPaintable();
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP, custom component dont render composition roots caption
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java index 787be254f6..7a5f630587 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java @@ -35,8 +35,8 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget; * @author Vaadin Ltd * */ -public class VCustomLayout extends ComplexPanel implements VPaintableWidget, - Container, ContainerResizedListener { +public class VCustomLayout extends ComplexPanel implements Container, + ContainerResizedListener { public static final String CLASSNAME = "v-customlayout"; @@ -44,7 +44,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget, private final HashMap<String, Element> locationToElement = new HashMap<String, Element>(); /** Location-name to contained widget map */ - private final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>(); + final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>(); /** Widget to captionwrapper map */ private final HashMap<VPaintableWidget, VCaptionWrapper> paintableToCaptionWrapper = new HashMap<VPaintableWidget, VCaptionWrapper>(); @@ -53,12 +53,12 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget, String currentTemplateName; /** Unexecuted scripts loaded from the template */ - private String scripts = ""; + String scripts = ""; /** Paintable ID of this paintable */ - private String pid; + String pid; - private ApplicationConnection client; + ApplicationConnection client; /** Has the template been loaded from contents passed in UIDL **/ private boolean hasTemplateContents = false; @@ -132,66 +132,8 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget, locationToWidget.put(location, widget); } - /** Update the layout from UIDL */ - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - // ApplicationConnection manages generic component features - if (client.updateComponent(this, uidl, true)) { - return; - } - - pid = uidl.getId(); - if (!hasTemplate()) { - // Update HTML template only once - initializeHTML(uidl, client); - } - - // Evaluate scripts - eval(scripts); - scripts = null; - - iLayout(); - // TODO Check if this is needed - client.runDescendentsLayout(this); - - Set<Widget> oldWidgets = new HashSet<Widget>(); - oldWidgets.addAll(locationToWidget.values()); - - // For all contained widgets - for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { - final UIDL uidlForChild = (UIDL) i.next(); - if (uidlForChild.getTag().equals("location")) { - final String location = uidlForChild.getStringAttribute("name"); - UIDL childUIDL = uidlForChild.getChildUIDL(0); - final VPaintableWidget childPaintable = client - .getPaintable(childUIDL); - Widget childWidget = childPaintable.getWidgetForPaintable(); - try { - setWidget(childWidget, location); - childPaintable.updateFromUIDL(childUIDL, client); - } catch (final IllegalArgumentException e) { - // If no location is found, this component is not visible - } - oldWidgets.remove(childWidget); - } - } - for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator - .hasNext();) { - Widget oldWidget = iterator.next(); - if (oldWidget.isAttached()) { - // slot of this widget is emptied, remove it - remove(oldWidget); - } - } - - iLayout(); - // TODO Check if this is needed - client.runDescendentsLayout(this); - - } - /** Initialize HTML-layout. */ - private void initializeHTML(UIDL uidl, ApplicationConnection client) { + void initializeHTML(UIDL uidl, ApplicationConnection client) { final String newTemplateContents = uidl .getStringAttribute("templateContents"); @@ -264,7 +206,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget, return false; }-*/; - private boolean hasTemplate() { + boolean hasTemplate() { if (currentTemplateName == null && !hasTemplateContents) { return false; } else { @@ -295,7 +237,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget, } /** Evaluate given script in browser document */ - private static native void eval(String script) + static native void eval(String script) /*-{ try { if (script != null) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java new file mode 100644 index 0000000000..7997355136 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java @@ -0,0 +1,87 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VCustomLayoutPaintable extends VAbstractPaintableWidgetContainer {
+
+ /** Update the layout from UIDL */
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+ // ApplicationConnection manages generic component features
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().pid = uidl.getId();
+ if (!getWidgetForPaintable().hasTemplate()) {
+ // Update HTML template only once
+ getWidgetForPaintable().initializeHTML(uidl, client);
+ }
+
+ // Evaluate scripts
+ VCustomLayout.eval(getWidgetForPaintable().scripts);
+ getWidgetForPaintable().scripts = null;
+
+ getWidgetForPaintable().iLayout();
+ // TODO Check if this is needed
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ Set<Widget> oldWidgets = new HashSet<Widget>();
+ oldWidgets.addAll(getWidgetForPaintable().locationToWidget.values());
+
+ // For all contained widgets
+ for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
+ final UIDL uidlForChild = (UIDL) i.next();
+ if (uidlForChild.getTag().equals("location")) {
+ final String location = uidlForChild.getStringAttribute("name");
+ UIDL childUIDL = uidlForChild.getChildUIDL(0);
+ final VPaintableWidget childPaintable = client
+ .getPaintable(childUIDL);
+ Widget childWidget = childPaintable.getWidgetForPaintable();
+ try {
+ getWidgetForPaintable().setWidget(childWidget, location);
+ childPaintable.updateFromUIDL(childUIDL, client);
+ } catch (final IllegalArgumentException e) {
+ // If no location is found, this component is not visible
+ }
+ oldWidgets.remove(childWidget);
+ }
+ }
+ for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
+ .hasNext();) {
+ Widget oldWidget = iterator.next();
+ if (oldWidget.isAttached()) {
+ // slot of this widget is emptied, remove it
+ getWidgetForPaintable().remove(oldWidget);
+ }
+ }
+
+ getWidgetForPaintable().iLayout();
+ // TODO Check if this is needed
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ }
+
+ @Override
+ public VCustomLayout getWidgetForPaintable() {
+ return (VCustomLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VCustomLayout.class);
+ }
+
+ public void updateCaption(VPaintableWidget paintable, UIDL uidl) {
+ getWidgetForPaintable().updateCaption(paintable, uidl);
+
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateField.java b/src/com/vaadin/terminal/gwt/client/ui/VDateField.java index d21a20229e..14c3b99210 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VDateField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VDateField.java @@ -8,22 +8,17 @@ import java.util.Date; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.DateTimeService; -import com.vaadin.terminal.gwt.client.LocaleNotLoadedException; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.VTooltip; -public class VDateField extends FlowPanel implements VPaintableWidget, Field { +public class VDateField extends FlowPanel implements Field { public static final String CLASSNAME = "v-datefield"; - private String id; + protected String paintableId; - private ApplicationConnection client; + protected ApplicationConnection client; protected boolean immediate; @@ -65,7 +60,7 @@ public class VDateField extends FlowPanel implements VPaintableWidget, Field { protected DateTimeService dts; - private boolean showISOWeekNumbers = false; + protected boolean showISOWeekNumbers = false; public VDateField() { setStyleName(CLASSNAME); @@ -77,80 +72,7 @@ public class VDateField extends FlowPanel implements VPaintableWidget, Field { public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, this); - } - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // Ensure correct implementation and let layout manage caption - if (client.updateComponent(this, uidl, true)) { - return; - } - - // Save details - this.client = client; - id = uidl.getId(); - immediate = uidl.getBooleanAttribute("immediate"); - - readonly = uidl.getBooleanAttribute("readonly"); - enabled = !uidl.getBooleanAttribute("disabled"); - - if (uidl.hasAttribute("locale")) { - final String locale = uidl.getStringAttribute("locale"); - try { - dts.setLocale(locale); - currentLocale = locale; - } catch (final LocaleNotLoadedException e) { - currentLocale = dts.getLocale(); - VConsole.error("Tried to use an unloaded locale \"" + locale - + "\". Using default locale (" + currentLocale + ")."); - VConsole.error(e); - } - } - - // We show week numbers only if the week starts with Monday, as ISO 8601 - // specifies - showISOWeekNumbers = uidl.getBooleanAttribute(WEEK_NUMBERS) - && dts.getFirstDayOfWeek() == 1; - - int newResolution; - if (uidl.hasVariable("sec")) { - newResolution = RESOLUTION_SEC; - } else if (uidl.hasVariable("min")) { - newResolution = RESOLUTION_MIN; - } else if (uidl.hasVariable("hour")) { - newResolution = RESOLUTION_HOUR; - } else if (uidl.hasVariable("day")) { - newResolution = RESOLUTION_DAY; - } else if (uidl.hasVariable("month")) { - newResolution = RESOLUTION_MONTH; - } else { - newResolution = RESOLUTION_YEAR; - } - - currentResolution = newResolution; - - // Add stylename that indicates current resolution - addStyleName(CLASSNAME + "-" + resolutionToString(currentResolution)); - - final int year = uidl.getIntVariable("year"); - final int month = (currentResolution >= RESOLUTION_MONTH) ? uidl - .getIntVariable("month") : -1; - final int day = (currentResolution >= RESOLUTION_DAY) ? uidl - .getIntVariable("day") : -1; - final int hour = (currentResolution >= RESOLUTION_HOUR) ? uidl - .getIntVariable("hour") : 0; - final int min = (currentResolution >= RESOLUTION_MIN) ? uidl - .getIntVariable("min") : 0; - final int sec = (currentResolution >= RESOLUTION_SEC) ? uidl - .getIntVariable("sec") : 0; - - // Construct new date for this datefield (only if not null) - if (year > -1) { - setCurrentDate(new Date((long) getTime(year, month, day, hour, min, - sec, 0))); - } else { - setCurrentDate(null); + client.handleWidgetTooltipEvent(event, this); } } @@ -158,7 +80,7 @@ public class VDateField extends FlowPanel implements VPaintableWidget, Field { * We need this redundant native function because Java's Date object doesn't * have a setMilliseconds method. */ - private static native double getTime(int y, int m, int d, int h, int mi, + protected static native double getTime(int y, int m, int d, int h, int mi, int s, int ms) /*-{ try { @@ -227,7 +149,7 @@ public class VDateField extends FlowPanel implements VPaintableWidget, Field { } public String getId() { - return id; + return paintableId; } public ApplicationConnection getClient() { @@ -270,8 +192,4 @@ public class VDateField extends FlowPanel implements VPaintableWidget, Field { protected void setDate(Date date) { this.date = date; } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java index 73bfe27700..6fb8456258 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java @@ -7,20 +7,16 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Date;
import com.google.gwt.event.dom.client.DomEvent;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.DateTimeService;
-import com.vaadin.terminal.gwt.client.UIDL;
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener;
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;
/**
* A client side implementation for InlineDateField
*/
public class VDateFieldCalendar extends VDateField {
- private final VCalendarPanel calendarPanel;
+ protected final VCalendarPanel calendarPanel;
public VDateFieldCalendar() {
super();
@@ -44,73 +40,11 @@ public class VDateFieldCalendar extends VDateField { });
}
- @Override
- @SuppressWarnings("deprecation")
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- super.updateFromUIDL(uidl, client);
- calendarPanel.setShowISOWeekNumbers(isShowISOWeekNumbers());
- calendarPanel.setDateTimeService(getDateTimeService());
- calendarPanel.setResolution(getCurrentResolution());
- Date currentDate = getCurrentDate();
- if (currentDate != null) {
- calendarPanel.setDate(new Date(currentDate.getTime()));
- } else {
- calendarPanel.setDate(null);
- }
-
- if (currentResolution > RESOLUTION_DAY) {
- calendarPanel.setTimeChangeListener(new TimeChangeListener() {
- public void changed(int hour, int min, int sec, int msec) {
- Date d = getDate();
- if (d == null) {
- // date currently null, use the value from calendarPanel
- // (~ client time at the init of the widget)
- d = (Date) calendarPanel.getDate().clone();
- }
- d.setHours(hour);
- d.setMinutes(min);
- d.setSeconds(sec);
- DateTimeService.setMilliseconds(d, msec);
-
- // Always update time changes to the server
- calendarPanel.setDate(d);
- updateValueFromPanel();
- }
- });
- }
-
- if (currentResolution <= RESOLUTION_MONTH) {
- calendarPanel.setFocusChangeListener(new FocusChangeListener() {
- public void focusChanged(Date date) {
- Date date2 = new Date();
- if (calendarPanel.getDate() != null) {
- date2.setTime(calendarPanel.getDate().getTime());
- }
- /*
- * Update the value of calendarPanel
- */
- date2.setYear(date.getYear());
- date2.setMonth(date.getMonth());
- calendarPanel.setDate(date2);
- /*
- * Then update the value from panel to server
- */
- updateValueFromPanel();
- }
- });
- } else {
- calendarPanel.setFocusChangeListener(null);
- }
-
- // Update possible changes
- calendarPanel.renderCalendar();
- }
-
/**
* TODO refactor: almost same method as in VPopupCalendar.updateValue
*/
@SuppressWarnings("deprecation")
- private void updateValueFromPanel() {
+ protected void updateValueFromPanel() {
Date date2 = calendarPanel.getDate();
Date currentDate = getCurrentDate();
if (currentDate == null || date2.getTime() != currentDate.getTime()) {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendarPaintable.java new file mode 100644 index 0000000000..8dced06235 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendarPaintable.java @@ -0,0 +1,101 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.terminal.gwt.client.ui; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.DateTimeService; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener; +import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; + +public class VDateFieldCalendarPaintable extends VDateFieldPaintable { + + @Override + @SuppressWarnings("deprecation") + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + getWidgetForPaintable().calendarPanel + .setShowISOWeekNumbers(getWidgetForPaintable() + .isShowISOWeekNumbers()); + getWidgetForPaintable().calendarPanel + .setDateTimeService(getWidgetForPaintable() + .getDateTimeService()); + getWidgetForPaintable().calendarPanel + .setResolution(getWidgetForPaintable().getCurrentResolution()); + Date currentDate = getWidgetForPaintable().getCurrentDate(); + if (currentDate != null) { + getWidgetForPaintable().calendarPanel.setDate(new Date(currentDate + .getTime())); + } else { + getWidgetForPaintable().calendarPanel.setDate(null); + } + + if (getWidgetForPaintable().currentResolution > VDateField.RESOLUTION_DAY) { + getWidgetForPaintable().calendarPanel + .setTimeChangeListener(new TimeChangeListener() { + public void changed(int hour, int min, int sec, int msec) { + Date d = getWidgetForPaintable().getDate(); + if (d == null) { + // date currently null, use the value from + // calendarPanel + // (~ client time at the init of the widget) + d = (Date) getWidgetForPaintable().calendarPanel + .getDate().clone(); + } + d.setHours(hour); + d.setMinutes(min); + d.setSeconds(sec); + DateTimeService.setMilliseconds(d, msec); + + // Always update time changes to the server + getWidgetForPaintable().calendarPanel.setDate(d); + getWidgetForPaintable().updateValueFromPanel(); + } + }); + } + + if (getWidgetForPaintable().currentResolution <= VDateField.RESOLUTION_MONTH) { + getWidgetForPaintable().calendarPanel + .setFocusChangeListener(new FocusChangeListener() { + public void focusChanged(Date date) { + Date date2 = new Date(); + if (getWidgetForPaintable().calendarPanel.getDate() != null) { + date2.setTime(getWidgetForPaintable().calendarPanel + .getDate().getTime()); + } + /* + * Update the value of calendarPanel + */ + date2.setYear(date.getYear()); + date2.setMonth(date.getMonth()); + getWidgetForPaintable().calendarPanel + .setDate(date2); + /* + * Then update the value from panel to server + */ + getWidgetForPaintable().updateValueFromPanel(); + } + }); + } else { + getWidgetForPaintable().calendarPanel.setFocusChangeListener(null); + } + + // Update possible changes + getWidgetForPaintable().calendarPanel.renderCalendar(); + } + + @Override + protected Widget createWidget() { + return GWT.create(VDateFieldCalendar.class); + } + + @Override + public VDateFieldCalendar getWidgetForPaintable() { + return (VDateFieldCalendar) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldPaintable.java new file mode 100644 index 0000000000..4aaf1c2dd3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldPaintable.java @@ -0,0 +1,106 @@ +package com.vaadin.terminal.gwt.client.ui; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.LocaleNotLoadedException; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VConsole; + +public class VDateFieldPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Ensure correct implementation and let layout manage caption + if (client.updateComponent(this, uidl, true)) { + return; + } + + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + getWidgetForPaintable().immediate = uidl + .getBooleanAttribute("immediate"); + + getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly"); + getWidgetForPaintable().enabled = !uidl.getBooleanAttribute("disabled"); + + if (uidl.hasAttribute("locale")) { + final String locale = uidl.getStringAttribute("locale"); + try { + getWidgetForPaintable().dts.setLocale(locale); + getWidgetForPaintable().currentLocale = locale; + } catch (final LocaleNotLoadedException e) { + getWidgetForPaintable().currentLocale = getWidgetForPaintable().dts + .getLocale(); + VConsole.error("Tried to use an unloaded locale \"" + locale + + "\". Using default locale (" + + getWidgetForPaintable().currentLocale + ")."); + VConsole.error(e); + } + } + + // We show week numbers only if the week starts with Monday, as ISO 8601 + // specifies + getWidgetForPaintable().showISOWeekNumbers = uidl + .getBooleanAttribute(VDateField.WEEK_NUMBERS) + && getWidgetForPaintable().dts.getFirstDayOfWeek() == 1; + + int newResolution; + if (uidl.hasVariable("sec")) { + newResolution = VDateField.RESOLUTION_SEC; + } else if (uidl.hasVariable("min")) { + newResolution = VDateField.RESOLUTION_MIN; + } else if (uidl.hasVariable("hour")) { + newResolution = VDateField.RESOLUTION_HOUR; + } else if (uidl.hasVariable("day")) { + newResolution = VDateField.RESOLUTION_DAY; + } else if (uidl.hasVariable("month")) { + newResolution = VDateField.RESOLUTION_MONTH; + } else { + newResolution = VDateField.RESOLUTION_YEAR; + } + + getWidgetForPaintable().currentResolution = newResolution; + + // Add stylename that indicates current resolution + getWidgetForPaintable() + .addStyleName( + VDateField.CLASSNAME + + "-" + + VDateField + .resolutionToString(getWidgetForPaintable().currentResolution)); + + final int year = uidl.getIntVariable("year"); + final int month = (getWidgetForPaintable().currentResolution >= VDateField.RESOLUTION_MONTH) ? uidl + .getIntVariable("month") : -1; + final int day = (getWidgetForPaintable().currentResolution >= VDateField.RESOLUTION_DAY) ? uidl + .getIntVariable("day") : -1; + final int hour = (getWidgetForPaintable().currentResolution >= VDateField.RESOLUTION_HOUR) ? uidl + .getIntVariable("hour") : 0; + final int min = (getWidgetForPaintable().currentResolution >= VDateField.RESOLUTION_MIN) ? uidl + .getIntVariable("min") : 0; + final int sec = (getWidgetForPaintable().currentResolution >= VDateField.RESOLUTION_SEC) ? uidl + .getIntVariable("sec") : 0; + + // Construct new date for this datefield (only if not null) + if (year > -1) { + getWidgetForPaintable().setCurrentDate( + new Date((long) getWidgetForPaintable().getTime(year, + month, day, hour, min, sec, 0))); + } else { + getWidgetForPaintable().setCurrentDate(null); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VDateField.class); + } + + @Override + public VDateField getWidgetForPaintable() { + return (VDateField) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java index 3251a03d6a..0297e8df3f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java @@ -4,10 +4,8 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JsArrayString; @@ -28,7 +26,6 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderInformation.Size; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.VPaintable; @@ -97,7 +94,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } @@ -111,7 +108,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements private boolean startDrag(NativeEvent event) { if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) { VTransferable transferable = new VTransferable(); - transferable.setDragSource(VDragAndDropWrapper.this); + transferable.setDragSource(VPaintableMap.get(client).getPaintable( + VDragAndDropWrapper.this)); VPaintableWidget paintable = Util.findPaintable(client, (Element) event.getEventTarget().cast()); @@ -140,58 +138,15 @@ public class VDragAndDropWrapper extends VCustomComponent implements protected int dragStartMode; - private ApplicationConnection client; - private VAbstractDropHandler dropHandler; + ApplicationConnection client; + VAbstractDropHandler dropHandler; private VDragEvent vaadinDragEvent; - private int filecounter = 0; - private Map<String, String> fileIdToReceiver; - private ValueMap html5DataFlavors; + int filecounter = 0; + Map<String, String> fileIdToReceiver; + ValueMap html5DataFlavors; private Element dragStartElement; - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - super.updateFromUIDL(uidl, client); - if (!uidl.hasAttribute("cached") && !uidl.hasAttribute("hidden")) { - UIDL acceptCrit = uidl.getChildByTagName("-ac"); - if (acceptCrit == null) { - dropHandler = null; - } else { - if (dropHandler == null) { - dropHandler = new CustomDropHandler(); - } - dropHandler.updateAcceptRules(acceptCrit); - } - - Set<String> variableNames = uidl.getVariableNames(); - for (String fileId : variableNames) { - if (fileId.startsWith("rec-")) { - String receiverUrl = uidl.getStringVariable(fileId); - fileId = fileId.substring(4); - if (fileIdToReceiver == null) { - fileIdToReceiver = new HashMap<String, String>(); - } - if ("".equals(receiverUrl)) { - Integer id = Integer.parseInt(fileId); - int indexOf = fileIds.indexOf(id); - if (indexOf != -1) { - files.remove(indexOf); - fileIds.remove(indexOf); - } - } else { - fileIdToReceiver.put(fileId, receiverUrl); - } - } - } - startNextUpload(); - - dragStartMode = uidl.getIntAttribute(DRAG_START_MODE); - initDragStartMode(); - html5DataFlavors = uidl.getMapAttribute(HTML5_DATA_FLAVORS); - } - } - protected void initDragStartMode() { Element div = getElement(); if (dragStartMode == HTML5) { @@ -231,7 +186,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements }; private Timer dragleavetimer; - private void startNextUpload() { + void startNextUpload() { Scheduler.get().scheduleDeferred(new Command() { public void execute() { @@ -287,7 +242,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements } if (VDragAndDropManager.get().getCurrentDropHandler() != getDropHandler()) { VTransferable transferable = new VTransferable(); - transferable.setDragSource(this); + transferable.setDragSource(VPaintableMap.get(client) + .getPaintable(this)); vaadinDragEvent = VDragAndDropManager.get().startDrag( transferable, event, false); @@ -455,8 +411,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements * @param fileId * @param data */ - private List<Integer> fileIds = new ArrayList<Integer>(); - private List<VHtml5File> files = new ArrayList<VHtml5File>(); + List<Integer> fileIds = new ArrayList<Integer>(); + List<VHtml5File> files = new ArrayList<VHtml5File>(); private void queueFilePost(final int fileId, final VHtml5File file) { fileIds.add(fileId); @@ -544,7 +500,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public VPaintableWidget getPaintable() { - return VDragAndDropWrapper.this; + return VPaintableMap.get(client).getPaintable( + VDragAndDropWrapper.this); } public ApplicationConnection getApplicationConnection() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java new file mode 100644 index 0000000000..1deb155001 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java @@ -0,0 +1,71 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashMap;
+import java.util.Set;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VDragAndDropWrapperPaintable extends VCustomComponentPaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+ super.updateFromUIDL(uidl, client);
+ if (!uidl.hasAttribute("cached") && !uidl.hasAttribute("hidden")) {
+ UIDL acceptCrit = uidl.getChildByTagName("-ac");
+ if (acceptCrit == null) {
+ getWidgetForPaintable().dropHandler = null;
+ } else {
+ if (getWidgetForPaintable().dropHandler == null) {
+ getWidgetForPaintable().dropHandler = getWidgetForPaintable().new CustomDropHandler();
+ }
+ getWidgetForPaintable().dropHandler
+ .updateAcceptRules(acceptCrit);
+ }
+
+ Set<String> variableNames = uidl.getVariableNames();
+ for (String fileId : variableNames) {
+ if (fileId.startsWith("rec-")) {
+ String receiverUrl = uidl.getStringVariable(fileId);
+ fileId = fileId.substring(4);
+ if (getWidgetForPaintable().fileIdToReceiver == null) {
+ getWidgetForPaintable().fileIdToReceiver = new HashMap<String, String>();
+ }
+ if ("".equals(receiverUrl)) {
+ Integer id = Integer.parseInt(fileId);
+ int indexOf = getWidgetForPaintable().fileIds
+ .indexOf(id);
+ if (indexOf != -1) {
+ getWidgetForPaintable().files.remove(indexOf);
+ getWidgetForPaintable().fileIds.remove(indexOf);
+ }
+ } else {
+ getWidgetForPaintable().fileIdToReceiver.put(fileId,
+ receiverUrl);
+ }
+ }
+ }
+ getWidgetForPaintable().startNextUpload();
+
+ getWidgetForPaintable().dragStartMode = uidl
+ .getIntAttribute(VDragAndDropWrapper.DRAG_START_MODE);
+ getWidgetForPaintable().initDragStartMode();
+ getWidgetForPaintable().html5DataFlavors = uidl
+ .getMapAttribute(VDragAndDropWrapper.HTML5_DATA_FLAVORS);
+ }
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VDragAndDropWrapper.class);
+ }
+
+ @Override
+ public VDragAndDropWrapper getWidgetForPaintable() {
+ return (VDragAndDropWrapper) super.getWidgetForPaintable();
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java index 54385c665f..549a7b4549 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java @@ -8,190 +8,31 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Node; -import com.google.gwt.dom.client.NodeList; -import com.google.gwt.dom.client.ObjectElement; -import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.DomEvent.Type; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VTooltip; -public class VEmbedded extends HTML implements VPaintableWidget { - public static final String CLICK_EVENT_IDENTIFIER = "click"; +public class VEmbedded extends HTML { + public static String CLASSNAME = "v-embedded"; - private static String CLASSNAME = "v-embedded"; + protected String height; + protected String width; + protected Element browserElement; - private String height; - private String width; - private Element browserElement; + protected String type; - private String type; - - private ApplicationConnection client; - - private final ClickEventHandler clickEventHandler = new ClickEventHandler( - this, CLICK_EVENT_IDENTIFIER) { - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - - }; + protected ApplicationConnection client; public VEmbedded() { setStyleName(CLASSNAME); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - this.client = client; - - boolean clearBrowserElement = true; - - clickEventHandler.handleEventHandlerRegistration(client); - - if (uidl.hasAttribute("type")) { - type = uidl.getStringAttribute("type"); - if (type.equals("image")) { - addStyleName(CLASSNAME + "-image"); - Element el = null; - boolean created = false; - NodeList<Node> nodes = getElement().getChildNodes(); - if (nodes != null && nodes.getLength() == 1) { - Node n = nodes.getItem(0); - if (n.getNodeType() == Node.ELEMENT_NODE) { - Element e = (Element) n; - if (e.getTagName().equals("IMG")) { - el = e; - } - } - } - if (el == null) { - setHTML(""); - el = DOM.createImg(); - created = true; - DOM.sinkEvents(el, Event.ONLOAD); - } - - // Set attributes - Style style = el.getStyle(); - String w = uidl.getStringAttribute("width"); - if (w != null) { - style.setProperty("width", w); - } else { - style.setProperty("width", ""); - } - String h = uidl.getStringAttribute("height"); - if (h != null) { - style.setProperty("height", h); - } else { - style.setProperty("height", ""); - } - DOM.setElementProperty(el, "src", getSrc(uidl, client)); - - if (created) { - // insert in dom late - getElement().appendChild(el); - } - - /* - * Sink tooltip events so tooltip is displayed when hovering the - * image. - */ - sinkEvents(VTooltip.TOOLTIP_EVENTS); - - } else if (type.equals("browser")) { - addStyleName(CLASSNAME + "-browser"); - if (browserElement == null) { - setHTML("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\"" - + " allowTransparency=\"true\" src=\"\"" - + " name=\"" + uidl.getId() + "\"></iframe>"); - browserElement = DOM.getFirstChild(getElement()); - } - DOM.setElementAttribute(browserElement, "src", - getSrc(uidl, client)); - clearBrowserElement = false; - } else { - VConsole.log("Unknown Embedded type '" + type + "'"); - } - } else if (uidl.hasAttribute("mimetype")) { - final String mime = uidl.getStringAttribute("mimetype"); - if (mime.equals("application/x-shockwave-flash")) { - // Handle embedding of Flash - addStyleName(CLASSNAME + "-flash"); - setHTML(createFlashEmbed(uidl)); - - } else if (mime.equals("image/svg+xml")) { - addStyleName(CLASSNAME + "-svg"); - String data; - Map<String, String> parameters = getParameters(uidl); - if (parameters.get("data") == null) { - data = getSrc(uidl, client); - } else { - data = "data:image/svg+xml," + parameters.get("data"); - } - setHTML(""); - ObjectElement obj = Document.get().createObjectElement(); - obj.setType(mime); - obj.setData(data); - if (width != null) { - obj.getStyle().setProperty("width", "100%"); - } - if (height != null) { - obj.getStyle().setProperty("height", "100%"); - } - if (uidl.hasAttribute("classid")) { - obj.setAttribute("classid", - uidl.getStringAttribute("classid")); - } - if (uidl.hasAttribute("codebase")) { - obj.setAttribute("codebase", - uidl.getStringAttribute("codebase")); - } - if (uidl.hasAttribute("codetype")) { - obj.setAttribute("codetype", - uidl.getStringAttribute("codetype")); - } - if (uidl.hasAttribute("archive")) { - obj.setAttribute("archive", - uidl.getStringAttribute("archive")); - } - if (uidl.hasAttribute("standby")) { - obj.setAttribute("standby", - uidl.getStringAttribute("standby")); - } - getElement().appendChild(obj); - - } else { - VConsole.log("Unknown Embedded mimetype '" + mime + "'"); - } - } else { - VConsole.log("Unknown Embedded; no type or mimetype attribute"); - } - - if (clearBrowserElement) { - browserElement = null; - } - } - /** * Creates the Object and Embed tags for the Flash plugin so it works * cross-browser @@ -200,7 +41,7 @@ public class VEmbedded extends HTML implements VPaintableWidget { * The UIDL * @return Tags concatenated into a string */ - private String createFlashEmbed(UIDL uidl) { + protected String createFlashEmbed(UIDL uidl) { /* * To ensure cross-browser compatibility we are using the twice-cooked * method to embed flash i.e. we add a OBJECT tag for IE ActiveX and @@ -318,7 +159,7 @@ public class VEmbedded extends HTML implements VPaintableWidget { * @param uidl * @return */ - private static Map<String, String> getParameters(UIDL uidl) { + protected static Map<String, String> getParameters(UIDL uidl) { Map<String, String> parameters = new HashMap<String, String>(); Iterator<Object> childIterator = uidl.getChildIterator(); @@ -347,7 +188,7 @@ public class VEmbedded extends HTML implements VPaintableWidget { * @param client * @return */ - private String getSrc(UIDL uidl, ApplicationConnection client) { + protected String getSrc(UIDL uidl, ApplicationConnection client) { String url = client.translateVaadinUri(uidl.getStringAttribute("src")); if (url == null) { return ""; @@ -412,7 +253,7 @@ public class VEmbedded extends HTML implements VPaintableWidget { Util.notifyParentOfSizeChange(this, true); } - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } /** @@ -432,9 +273,4 @@ public class VEmbedded extends HTML implements VPaintableWidget { Unit.PX); } } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java new file mode 100644 index 0000000000..bdb34b6d14 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java @@ -0,0 +1,198 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import java.util.Map; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Node; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.ObjectElement; +import com.google.gwt.dom.client.Style; +import com.google.gwt.event.dom.client.DomEvent.Type; +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VConsole; +import com.vaadin.terminal.gwt.client.VTooltip; + +public class VEmbeddedPaintable extends VAbstractPaintableWidget { + + public static final String CLICK_EVENT_IDENTIFIER = "click"; + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + if (client.updateComponent(this, uidl, true)) { + return; + } + + // Save details + getWidgetForPaintable().client = client; + + boolean clearBrowserElement = true; + + clickEventHandler.handleEventHandlerRegistration(client); + + if (uidl.hasAttribute("type")) { + getWidgetForPaintable().type = uidl.getStringAttribute("type"); + if (getWidgetForPaintable().type.equals("image")) { + getWidgetForPaintable().addStyleName( + VEmbedded.CLASSNAME + "-image"); + Element el = null; + boolean created = false; + NodeList<Node> nodes = getWidgetForPaintable().getElement() + .getChildNodes(); + if (nodes != null && nodes.getLength() == 1) { + Node n = nodes.getItem(0); + if (n.getNodeType() == Node.ELEMENT_NODE) { + Element e = (Element) n; + if (e.getTagName().equals("IMG")) { + el = e; + } + } + } + if (el == null) { + getWidgetForPaintable().setHTML(""); + el = DOM.createImg(); + created = true; + DOM.sinkEvents(el, Event.ONLOAD); + } + + // Set attributes + Style style = el.getStyle(); + String w = uidl.getStringAttribute("width"); + if (w != null) { + style.setProperty("width", w); + } else { + style.setProperty("width", ""); + } + String h = uidl.getStringAttribute("height"); + if (h != null) { + style.setProperty("height", h); + } else { + style.setProperty("height", ""); + } + DOM.setElementProperty(el, "src", getWidgetForPaintable() + .getSrc(uidl, client)); + + if (created) { + // insert in dom late + getWidgetForPaintable().getElement().appendChild(el); + } + + /* + * Sink tooltip events so tooltip is displayed when hovering the + * image. + */ + getWidgetForPaintable().sinkEvents(VTooltip.TOOLTIP_EVENTS); + + } else if (getWidgetForPaintable().type.equals("browser")) { + getWidgetForPaintable().addStyleName( + VEmbedded.CLASSNAME + "-browser"); + if (getWidgetForPaintable().browserElement == null) { + getWidgetForPaintable().setHTML( + "<iframe width=\"100%\" height=\"100%\" frameborder=\"0\"" + + " allowTransparency=\"true\" src=\"\"" + + " name=\"" + uidl.getId() + + "\"></iframe>"); + getWidgetForPaintable().browserElement = DOM + .getFirstChild(getWidgetForPaintable().getElement()); + } + DOM.setElementAttribute(getWidgetForPaintable().browserElement, + "src", getWidgetForPaintable().getSrc(uidl, client)); + clearBrowserElement = false; + } else { + VConsole.log("Unknown Embedded type '" + + getWidgetForPaintable().type + "'"); + } + } else if (uidl.hasAttribute("mimetype")) { + final String mime = uidl.getStringAttribute("mimetype"); + if (mime.equals("application/x-shockwave-flash")) { + // Handle embedding of Flash + getWidgetForPaintable().addStyleName( + VEmbedded.CLASSNAME + "-flash"); + getWidgetForPaintable().setHTML( + getWidgetForPaintable().createFlashEmbed(uidl)); + + } else if (mime.equals("image/svg+xml")) { + getWidgetForPaintable().addStyleName( + VEmbedded.CLASSNAME + "-svg"); + String data; + Map<String, String> parameters = VEmbedded.getParameters(uidl); + if (parameters.get("data") == null) { + data = getWidgetForPaintable().getSrc(uidl, client); + } else { + data = "data:image/svg+xml," + parameters.get("data"); + } + getWidgetForPaintable().setHTML(""); + ObjectElement obj = Document.get().createObjectElement(); + obj.setType(mime); + obj.setData(data); + if (getWidgetForPaintable().width != null) { + obj.getStyle().setProperty("width", "100%"); + } + if (getWidgetForPaintable().height != null) { + obj.getStyle().setProperty("height", "100%"); + } + if (uidl.hasAttribute("classid")) { + obj.setAttribute("classid", + uidl.getStringAttribute("classid")); + } + if (uidl.hasAttribute("codebase")) { + obj.setAttribute("codebase", + uidl.getStringAttribute("codebase")); + } + if (uidl.hasAttribute("codetype")) { + obj.setAttribute("codetype", + uidl.getStringAttribute("codetype")); + } + if (uidl.hasAttribute("archive")) { + obj.setAttribute("archive", + uidl.getStringAttribute("archive")); + } + if (uidl.hasAttribute("standby")) { + obj.setAttribute("standby", + uidl.getStringAttribute("standby")); + } + getWidgetForPaintable().getElement().appendChild(obj); + + } else { + VConsole.log("Unknown Embedded mimetype '" + mime + "'"); + } + } else { + VConsole.log("Unknown Embedded; no type or mimetype attribute"); + } + + if (clearBrowserElement) { + getWidgetForPaintable().browserElement = null; + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VEmbedded.class); + } + + @Override + public VEmbedded getWidgetForPaintable() { + return (VEmbedded) super.getWidgetForPaintable(); + } + + protected final ClickEventHandler clickEventHandler = new ClickEventHandler( + this, CLICK_EVENT_IDENTIFIER) { + + @Override + protected <H extends EventHandler> HandlerRegistration registerHandler( + H handler, Type<H> type) { + return getWidgetForPaintable().addDomHandler(handler, type); + } + + }; +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index b6bbe5dd19..7006a82fd1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -42,12 +42,10 @@ import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.PopupPanel.PositionCallback; import com.google.gwt.user.client.ui.SuggestOracle.Suggestion; import com.google.gwt.user.client.ui.TextBox; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Focusable; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; @@ -59,9 +57,8 @@ import com.vaadin.terminal.gwt.client.VTooltip; * TODO needs major refactoring (to be extensible etc) */ @SuppressWarnings("deprecation") -public class VFilterSelect extends Composite implements VPaintableWidget, Field, - KeyDownHandler, KeyUpHandler, ClickHandler, FocusHandler, BlurHandler, - Focusable { +public class VFilterSelect extends Composite implements Field, KeyDownHandler, + KeyUpHandler, ClickHandler, FocusHandler, BlurHandler, Focusable { /** * Represents a suggestion in the suggestion popup box @@ -153,7 +150,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, private static final String Z_INDEX = "30000"; - private final SuggestionMenu menu; + protected final SuggestionMenu menu; private final Element up = DOM.createDiv(); private final Element down = DOM.createDiv(); @@ -776,7 +773,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, return keyboardSelectedItem; } - private void setKeyboardSelectedItem(MenuItem firstItem) { + protected void setKeyboardSelectedItem(MenuItem firstItem) { keyboardSelectedItem = firstItem; } @@ -803,7 +800,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, /** * The text box where the filter is written */ - private final TextBox tb = new TextBox() { + protected final TextBox tb = new TextBox() { /* * (non-Javadoc) * @@ -815,7 +812,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, VFilterSelect.this); + client.handleWidgetTooltipEvent(event, VFilterSelect.this); } } @@ -830,7 +827,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, }; }; - private final SuggestionPopup suggestionPopup = new SuggestionPopup(); + protected final SuggestionPopup suggestionPopup = new SuggestionPopup(); /** * Used when measuring the width of the popup @@ -848,7 +845,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, VFilterSelect.this); + client.handleWidgetTooltipEvent(event, VFilterSelect.this); } /* @@ -861,73 +858,73 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, private final Image selectedItemIcon = new Image(); - private ApplicationConnection client; + protected ApplicationConnection client; - private String paintableId; + protected String paintableId; - private int currentPage; + protected int currentPage; /** * A collection of available suggestions (options) as received from the * server. */ - private final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>(); + protected final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>(); - private boolean immediate; + protected boolean immediate; - private String selectedOptionKey; + protected String selectedOptionKey; - private boolean waitingForFilteringResponse = false; - private boolean updateSelectionWhenReponseIsReceived = false; + protected boolean waitingForFilteringResponse = false; + protected boolean updateSelectionWhenReponseIsReceived = false; private boolean tabPressedWhenPopupOpen = false; - private boolean initDone = false; + protected boolean initDone = false; - private String lastFilter = ""; + protected String lastFilter = ""; - private enum Select { + protected enum Select { NONE, FIRST, LAST }; - private Select selectPopupItemWhenResponseIsReceived = Select.NONE; + protected Select selectPopupItemWhenResponseIsReceived = Select.NONE; /** * The current suggestion selected from the dropdown. This is one of the * values in currentSuggestions except when filtering, in this case * currentSuggestion might not be in currentSuggestions. */ - private FilterSelectSuggestion currentSuggestion; + protected FilterSelectSuggestion currentSuggestion; - private int totalMatches; - private boolean allowNewItem; - private boolean nullSelectionAllowed; - private boolean nullSelectItem; - private boolean enabled; - private boolean readonly; + protected int totalMatches; + protected boolean allowNewItem; + protected boolean nullSelectionAllowed; + protected boolean nullSelectItem; + protected boolean enabled; + protected boolean readonly; - private int filteringmode = FILTERINGMODE_OFF; + protected int filteringmode = FILTERINGMODE_OFF; // shown in unfocused empty field, disappears on focus (e.g "Search here") private static final String CLASSNAME_PROMPT = "prompt"; - private static final String ATTR_INPUTPROMPT = "prompt"; + protected static final String ATTR_INPUTPROMPT = "prompt"; public static final String ATTR_NO_TEXT_INPUT = "noInput"; - private String inputPrompt = ""; - private boolean prompting = false; + protected String inputPrompt = ""; + protected boolean prompting = false; // Set true when popupopened has been clicked. Cleared on each UIDL-update. // This handles the special case where are not filtering yet and the // selected value has changed on the server-side. See #2119 - private boolean popupOpenerClicked; + protected boolean popupOpenerClicked; private String width = null; private int textboxPadding = -1; private int componentPadding = -1; - private int suggestionPopupMinWidth = 0; + protected int suggestionPopupMinWidth = 0; private int popupWidth = -1; /* * Stores the last new item string to avoid double submissions. Cleared on * uidl updates */ - private String lastNewItemString; - private boolean focused = false; + protected String lastNewItemString; + protected boolean focused = false; private int horizPaddingAndBorder = 2; /** @@ -1030,204 +1027,11 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, currentPage = page; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal - * .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection) - */ - @SuppressWarnings("deprecation") - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - paintableId = uidl.getId(); - this.client = client; - - readonly = uidl.hasAttribute("readonly"); - enabled = !uidl.hasAttribute("disabled"); - - tb.setEnabled(enabled); - updateReadOnly(); - - if (client.updateComponent(this, uidl, true)) { - return; - } - - // Inverse logic here to make the default case (text input enabled) - // work without additional UIDL messages - boolean noTextInput = uidl.hasAttribute(ATTR_NO_TEXT_INPUT) - && uidl.getBooleanAttribute(ATTR_NO_TEXT_INPUT); - setTextInputEnabled(!noTextInput); - - // not a FocusWidget -> needs own tabindex handling - if (uidl.hasAttribute("tabindex")) { - tb.setTabIndex(uidl.getIntAttribute("tabindex")); - } - - if (uidl.hasAttribute("filteringmode")) { - filteringmode = uidl.getIntAttribute("filteringmode"); - } - - immediate = uidl.hasAttribute("immediate"); - - nullSelectionAllowed = uidl.hasAttribute("nullselect"); - - nullSelectItem = uidl.hasAttribute("nullselectitem") - && uidl.getBooleanAttribute("nullselectitem"); - - currentPage = uidl.getIntVariable("page"); - - if (uidl.hasAttribute("pagelength")) { - pageLength = uidl.getIntAttribute("pagelength"); - } - - if (uidl.hasAttribute(ATTR_INPUTPROMPT)) { - // input prompt changed from server - inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT); - } else { - inputPrompt = ""; - } - - suggestionPopup.updateStyleNames(uidl); - - allowNewItem = uidl.hasAttribute("allownewitem"); - lastNewItemString = null; - - currentSuggestions.clear(); - if (!waitingForFilteringResponse) { - /* - * Clear the current suggestions as the server response always - * includes the new ones. Exception is when filtering, then we need - * to retain the value if the user does not select any of the - * options matching the filter. - */ - currentSuggestion = null; - /* - * Also ensure no old items in menu. Unless cleared the old values - * may cause odd effects on blur events. Suggestions in menu might - * not necessary exist in select at all anymore. - */ - suggestionPopup.menu.clearItems(); - - } - - final UIDL options = uidl.getChildUIDL(0); - if (uidl.hasAttribute("totalMatches")) { - totalMatches = uidl.getIntAttribute("totalMatches"); - } else { - totalMatches = 0; - } - - // used only to calculate minimum popup width - String captions = Util.escapeHTML(inputPrompt); - - for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) { - final UIDL optionUidl = (UIDL) i.next(); - final FilterSelectSuggestion suggestion = new FilterSelectSuggestion( - optionUidl); - currentSuggestions.add(suggestion); - if (optionUidl.hasAttribute("selected")) { - if (!waitingForFilteringResponse || popupOpenerClicked) { - String newSelectedOptionKey = Integer.toString(suggestion - .getOptionKey()); - if (!newSelectedOptionKey.equals(selectedOptionKey) - || suggestion.getReplacementString().equals( - tb.getText())) { - // Update text field if we've got a new selection - // Also update if we've got the same text to retain old - // text selection behavior - setPromptingOff(suggestion.getReplacementString()); - selectedOptionKey = newSelectedOptionKey; - } - } - currentSuggestion = suggestion; - setSelectedItemIcon(suggestion.getIconUri()); - } - - // Collect captions so we can calculate minimum width for textarea - if (captions.length() > 0) { - captions += "|"; - } - captions += Util.escapeHTML(suggestion.getReplacementString()); - } - - if ((!waitingForFilteringResponse || popupOpenerClicked) - && uidl.hasVariable("selected") - && uidl.getStringArrayVariable("selected").length == 0) { - // select nulled - if (!waitingForFilteringResponse || !popupOpenerClicked) { - if (!focused) { - /* - * client.updateComponent overwrites all styles so we must - * ALWAYS set the prompting style at this point, even though - * we think it has been set already... - */ - prompting = false; - setPromptingOn(); - } else { - // we have focus in field, prompting can't be set on, - // instead just clear the input - tb.setValue(""); - } - } - selectedOptionKey = null; - } - - if (waitingForFilteringResponse - && lastFilter.toLowerCase().equals( - uidl.getStringVariable("filter"))) { - suggestionPopup.showSuggestions(currentSuggestions, currentPage, - totalMatches); - waitingForFilteringResponse = false; - if (!popupOpenerClicked - && selectPopupItemWhenResponseIsReceived != Select.NONE) { - // we're paging w/ arrows - if (selectPopupItemWhenResponseIsReceived == Select.LAST) { - suggestionPopup.menu.selectLastItem(); - } else { - suggestionPopup.menu.selectFirstItem(); - } - - // This is used for paging so we update the keyboard selection - // variable as well. - MenuItem activeMenuItem = suggestionPopup.menu - .getSelectedItem(); - suggestionPopup.menu.setKeyboardSelectedItem(activeMenuItem); - - // Update text field to contain the correct text - setTextboxText(activeMenuItem.getText()); - tb.setSelectionRange(lastFilter.length(), activeMenuItem - .getText().length() - lastFilter.length()); - - selectPopupItemWhenResponseIsReceived = Select.NONE; // reset - } - if (updateSelectionWhenReponseIsReceived) { - suggestionPopup.menu.doPostFilterSelectedItemAction(); - } - } - - // Calculate minumum textarea width - suggestionPopupMinWidth = minWidth(captions); - - popupOpenerClicked = false; - - if (!initDone) { - updateRootWidth(); - } - - // Focus dependent style names are lost during the update, so we add - // them here back again - if (focused) { - addStyleDependentName("focus"); - } - - initDone = true; - } - - private void updateReadOnly() { + protected void updateReadOnly() { tb.setReadOnly(readonly || !textInputEnabled); } - private void setTextInputEnabled(boolean textInputEnabled) { + protected void setTextInputEnabled(boolean textInputEnabled) { // Always update styles as they might have been overwritten if (textInputEnabled) { removeStyleDependentName(STYLE_NO_INPUT); @@ -1249,7 +1053,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, * @param text * the text to set in the text box */ - private void setTextboxText(final String text) { + protected void setTextboxText(final String text) { tb.setText(text); } @@ -1273,7 +1077,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, * Turns prompting on. When prompting is turned on a command prompt is shown * in the text box if nothing has been entered. */ - private void setPromptingOn() { + protected void setPromptingOn() { if (!prompting) { prompting = true; addStyleDependentName(CLASSNAME_PROMPT); @@ -1288,7 +1092,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, * @param text * The text the text box should contain. */ - private void setPromptingOff(String text) { + protected void setPromptingOff(String text) { setTextboxText(text); if (prompting) { prompting = false; @@ -1338,7 +1142,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, * @param iconUri * The URI of the icon */ - private void setSelectedItemIcon(String iconUri) { + protected void setSelectedItemIcon(String iconUri) { if (iconUri == null || iconUri == "") { panel.remove(selectedItemIcon); updateRootWidth(); @@ -1613,7 +1417,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, /** * Calculate minimum width for FilterSelect textarea */ - private native int minWidth(String captions) + protected native int minWidth(String captions) /*-{ if(!captions || captions.length <= 0) return 0; @@ -1665,7 +1469,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, } addStyleDependentName("focus"); - if (client.hasEventListeners(this, EventId.FOCUS)) { + if (client.hasWidgetEventListeners(this, EventId.FOCUS)) { client.updateVariable(paintableId, EventId.FOCUS, "", true); } } @@ -1730,7 +1534,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, } removeStyleDependentName("focus"); - if (client.hasEventListeners(this, EventId.BLUR)) { + if (client.hasWidgetEventListeners(this, EventId.BLUR)) { client.updateVariable(paintableId, EventId.BLUR, "", true); } } @@ -1784,7 +1588,7 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, * Calculates the width of the select if the select has undefined width. * Should be called when the width changes or when the icon changes. */ - private void updateRootWidth() { + protected void updateRootWidth() { if (width == null) { /* * When the width is not specified we must specify width for root @@ -1934,8 +1738,4 @@ public class VFilterSelect extends Composite implements VPaintableWidget, Field, super.onDetach(); suggestionPopup.hide(); } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java new file mode 100644 index 0000000000..3249ea17d5 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java @@ -0,0 +1,244 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.terminal.gwt.client.ui; + +import java.util.Iterator; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.ui.VFilterSelect.FilterSelectSuggestion; + +public class VFilterSelectPaintable extends VAbstractPaintableWidget { + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.terminal.gwt.client.Paintable#updateFromUIDL(com.vaadin.terminal + * .gwt.client.UIDL, com.vaadin.terminal.gwt.client.ApplicationConnection) + */ + @SuppressWarnings("deprecation") + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + + getWidgetForPaintable().readonly = uidl.hasAttribute("readonly"); + getWidgetForPaintable().enabled = !uidl.hasAttribute("disabled"); + + getWidgetForPaintable().tb.setEnabled(getWidgetForPaintable().enabled); + getWidgetForPaintable().updateReadOnly(); + + if (client.updateComponent(this, uidl, true)) { + return; + } + + // Inverse logic here to make the default case (text input enabled) + // work without additional UIDL messages + boolean noTextInput = uidl + .hasAttribute(VFilterSelect.ATTR_NO_TEXT_INPUT) + && uidl.getBooleanAttribute(VFilterSelect.ATTR_NO_TEXT_INPUT); + getWidgetForPaintable().setTextInputEnabled(!noTextInput); + + // not a FocusWidget -> needs own tabindex handling + if (uidl.hasAttribute("tabindex")) { + getWidgetForPaintable().tb.setTabIndex(uidl + .getIntAttribute("tabindex")); + } + + if (uidl.hasAttribute("filteringmode")) { + getWidgetForPaintable().filteringmode = uidl + .getIntAttribute("filteringmode"); + } + + getWidgetForPaintable().immediate = uidl.hasAttribute("immediate"); + + getWidgetForPaintable().nullSelectionAllowed = uidl + .hasAttribute("nullselect"); + + getWidgetForPaintable().nullSelectItem = uidl + .hasAttribute("nullselectitem") + && uidl.getBooleanAttribute("nullselectitem"); + + getWidgetForPaintable().currentPage = uidl.getIntVariable("page"); + + if (uidl.hasAttribute("pagelength")) { + getWidgetForPaintable().pageLength = uidl + .getIntAttribute("pagelength"); + } + + if (uidl.hasAttribute(VFilterSelect.ATTR_INPUTPROMPT)) { + // input prompt changed from server + getWidgetForPaintable().inputPrompt = uidl + .getStringAttribute(VFilterSelect.ATTR_INPUTPROMPT); + } else { + getWidgetForPaintable().inputPrompt = ""; + } + + getWidgetForPaintable().suggestionPopup.updateStyleNames(uidl); + + getWidgetForPaintable().allowNewItem = uidl + .hasAttribute("allownewitem"); + getWidgetForPaintable().lastNewItemString = null; + + getWidgetForPaintable().currentSuggestions.clear(); + if (!getWidgetForPaintable().waitingForFilteringResponse) { + /* + * Clear the current suggestions as the server response always + * includes the new ones. Exception is when filtering, then we need + * to retain the value if the user does not select any of the + * options matching the filter. + */ + getWidgetForPaintable().currentSuggestion = null; + /* + * Also ensure no old items in menu. Unless cleared the old values + * may cause odd effects on blur events. Suggestions in menu might + * not necessary exist in select at all anymore. + */ + getWidgetForPaintable().suggestionPopup.menu.clearItems(); + + } + + final UIDL options = uidl.getChildUIDL(0); + if (uidl.hasAttribute("totalMatches")) { + getWidgetForPaintable().totalMatches = uidl + .getIntAttribute("totalMatches"); + } else { + getWidgetForPaintable().totalMatches = 0; + } + + // used only to calculate minimum popup width + String captions = Util.escapeHTML(getWidgetForPaintable().inputPrompt); + + for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) { + final UIDL optionUidl = (UIDL) i.next(); + final FilterSelectSuggestion suggestion = getWidgetForPaintable().new FilterSelectSuggestion( + optionUidl); + getWidgetForPaintable().currentSuggestions.add(suggestion); + if (optionUidl.hasAttribute("selected")) { + if (!getWidgetForPaintable().waitingForFilteringResponse + || getWidgetForPaintable().popupOpenerClicked) { + String newSelectedOptionKey = Integer.toString(suggestion + .getOptionKey()); + if (!newSelectedOptionKey + .equals(getWidgetForPaintable().selectedOptionKey) + || suggestion.getReplacementString().equals( + getWidgetForPaintable().tb.getText())) { + // Update text field if we've got a new selection + // Also update if we've got the same text to retain old + // text selection behavior + getWidgetForPaintable().setPromptingOff( + suggestion.getReplacementString()); + getWidgetForPaintable().selectedOptionKey = newSelectedOptionKey; + } + } + getWidgetForPaintable().currentSuggestion = suggestion; + getWidgetForPaintable().setSelectedItemIcon( + suggestion.getIconUri()); + } + + // Collect captions so we can calculate minimum width for textarea + if (captions.length() > 0) { + captions += "|"; + } + captions += Util.escapeHTML(suggestion.getReplacementString()); + } + + if ((!getWidgetForPaintable().waitingForFilteringResponse || getWidgetForPaintable().popupOpenerClicked) + && uidl.hasVariable("selected") + && uidl.getStringArrayVariable("selected").length == 0) { + // select nulled + if (!getWidgetForPaintable().waitingForFilteringResponse + || !getWidgetForPaintable().popupOpenerClicked) { + if (!getWidgetForPaintable().focused) { + /* + * client.updateComponent overwrites all styles so we must + * ALWAYS set the prompting style at this point, even though + * we think it has been set already... + */ + getWidgetForPaintable().prompting = false; + getWidgetForPaintable().setPromptingOn(); + } else { + // we have focus in field, prompting can't be set on, + // instead just clear the input + getWidgetForPaintable().tb.setValue(""); + } + } + getWidgetForPaintable().selectedOptionKey = null; + } + + if (getWidgetForPaintable().waitingForFilteringResponse + && getWidgetForPaintable().lastFilter.toLowerCase().equals( + uidl.getStringVariable("filter"))) { + getWidgetForPaintable().suggestionPopup.showSuggestions( + getWidgetForPaintable().currentSuggestions, + getWidgetForPaintable().currentPage, + getWidgetForPaintable().totalMatches); + getWidgetForPaintable().waitingForFilteringResponse = false; + if (!getWidgetForPaintable().popupOpenerClicked + && getWidgetForPaintable().selectPopupItemWhenResponseIsReceived != VFilterSelect.Select.NONE) { + // we're paging w/ arrows + if (getWidgetForPaintable().selectPopupItemWhenResponseIsReceived == VFilterSelect.Select.LAST) { + getWidgetForPaintable().suggestionPopup.menu + .selectLastItem(); + } else { + getWidgetForPaintable().suggestionPopup.menu + .selectFirstItem(); + } + + // This is used for paging so we update the keyboard selection + // variable as well. + MenuItem activeMenuItem = getWidgetForPaintable().suggestionPopup.menu + .getSelectedItem(); + getWidgetForPaintable().suggestionPopup.menu + .setKeyboardSelectedItem(activeMenuItem); + + // Update text field to contain the correct text + getWidgetForPaintable() + .setTextboxText(activeMenuItem.getText()); + getWidgetForPaintable().tb.setSelectionRange( + getWidgetForPaintable().lastFilter.length(), + activeMenuItem.getText().length() + - getWidgetForPaintable().lastFilter.length()); + + getWidgetForPaintable().selectPopupItemWhenResponseIsReceived = VFilterSelect.Select.NONE; // reset + } + if (getWidgetForPaintable().updateSelectionWhenReponseIsReceived) { + getWidgetForPaintable().suggestionPopup.menu + .doPostFilterSelectedItemAction(); + } + } + + // Calculate minumum textarea width + getWidgetForPaintable().suggestionPopupMinWidth = getWidgetForPaintable() + .minWidth(captions); + + getWidgetForPaintable().popupOpenerClicked = false; + + if (!getWidgetForPaintable().initDone) { + getWidgetForPaintable().updateRootWidth(); + } + + // Focus dependent style names are lost during the update, so we add + // them here back again + if (getWidgetForPaintable().focused) { + getWidgetForPaintable().addStyleDependentName("focus"); + } + + getWidgetForPaintable().initDone = true; + } + + @Override + protected Widget createWidget() { + return GWT.create(VFilterSelect.class); + } + + @Override + public VFilterSelect getWidgetForPaintable() { + return (VFilterSelect) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VForm.java b/src/com/vaadin/terminal/gwt/client/ui/VForm.java index a329e1eaef..d70d7ed0d8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VForm.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VForm.java @@ -19,12 +19,9 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderSpace; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.VErrorMessage; -import com.vaadin.terminal.gwt.client.VPaintableMap; -import com.vaadin.terminal.gwt.client.VPaintableWidget; public class VForm extends ComplexPanel implements Container, KeyDownHandler { @@ -36,33 +33,33 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler { public static final String CLASSNAME = "v-form"; - private Container lo; - private Element legend = DOM.createLegend(); - private Element caption = DOM.createSpan(); + Widget lo; + Element legend = DOM.createLegend(); + Element caption = DOM.createSpan(); private Element errorIndicatorElement = DOM.createDiv(); - private Element desc = DOM.createDiv(); - private Icon icon; - private VErrorMessage errorMessage = new VErrorMessage(); + Element desc = DOM.createDiv(); + Icon icon; + VErrorMessage errorMessage = new VErrorMessage(); - private Element fieldContainer = DOM.createDiv(); + Element fieldContainer = DOM.createDiv(); - private Element footerContainer = DOM.createDiv(); + Element footerContainer = DOM.createDiv(); - private Element fieldSet = DOM.createFieldSet(); + Element fieldSet = DOM.createFieldSet(); - private Container footer; + Widget footer; - private ApplicationConnection client; + ApplicationConnection client; private RenderInformation renderInformation = new RenderInformation(); private int borderPaddingHorizontal = -1; - private boolean rendering = false; + boolean rendering = false; ShortcutActionHandler shortcutHandler; - private HandlerRegistration keyDownRegistration; + HandlerRegistration keyDownRegistration; public VForm() { setElement(DOM.createDiv()); @@ -84,130 +81,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler { fieldSet.appendChild(footerContainer); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - this.client = client; - id = uidl.getId(); - - if (client.updateComponent(this, uidl, false)) { - rendering = false; - return; - } - - boolean legendEmpty = true; - if (uidl.hasAttribute("caption")) { - caption.setInnerText(uidl.getStringAttribute("caption")); - legendEmpty = false; - } else { - caption.setInnerText(""); - } - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - legend.insertFirst(icon.getElement()); - } - icon.setUri(uidl.getStringAttribute("icon")); - legendEmpty = false; - } else { - if (icon != null) { - legend.removeChild(icon.getElement()); - } - } - if (legendEmpty) { - addStyleDependentName("nocaption"); - } else { - removeStyleDependentName("nocaption"); - } - - if (uidl.hasAttribute("error")) { - final UIDL errorUidl = uidl.getErrors(); - errorMessage.updateFromUIDL(errorUidl); - errorMessage.setVisible(true); - - } else { - errorMessage.setVisible(false); - } - - if (uidl.hasAttribute("description")) { - desc.setInnerHTML(uidl.getStringAttribute("description")); - if (desc.getParentElement() == null) { - fieldSet.insertAfter(desc, legend); - } - } else { - desc.setInnerHTML(""); - if (desc.getParentElement() != null) { - fieldSet.removeChild(desc); - } - } - - updateSize(); - - // first render footer so it will be easier to handle relative height of - // main layout - if (uidl.getChildCount() > 1 - && !uidl.getChildUIDL(1).getTag().equals("actions")) { - // render footer - Container newFooter = (Container) client.getPaintable(uidl - .getChildUIDL(1)); - if (footer == null) { - add(newFooter.getWidgetForPaintable(), footerContainer); - footer = newFooter; - } else if (newFooter != footer) { - remove(footer.getWidgetForPaintable()); - client.unregisterPaintable(footer); - add(newFooter.getWidgetForPaintable(), footerContainer); - } - footer = newFooter; - footer.updateFromUIDL(uidl.getChildUIDL(1), client); - // needed for the main layout to know the space it has available - updateSize(); - } else { - if (footer != null) { - remove(footer.getWidgetForPaintable()); - client.unregisterPaintable(footer); - // needed for the main layout to know the space it has available - updateSize(); - } - } - - final UIDL layoutUidl = uidl.getChildUIDL(0); - Container newLo = (Container) client.getPaintable(layoutUidl); - if (lo == null) { - lo = newLo; - add(lo.getWidgetForPaintable(), fieldContainer); - } else if (lo != newLo) { - client.unregisterPaintable(lo); - remove(lo.getWidgetForPaintable()); - lo = newLo; - add(lo.getWidgetForPaintable(), fieldContainer); - } - lo.updateFromUIDL(layoutUidl, client); - - // also recalculates size of the footer if undefined size form - see - // #3710 - updateSize(); - client.runDescendentsLayout(this); - - // We may have actions attached - if (uidl.getChildCount() > 1) { - UIDL childUidl = uidl.getChildByTagName("actions"); - if (childUidl != null) { - if (shortcutHandler == null) { - shortcutHandler = new ShortcutActionHandler(id, client); - keyDownRegistration = addDomHandler(this, - KeyDownEvent.getType()); - } - shortcutHandler.updateActionMap(childUidl); - } - } else if (shortcutHandler != null) { - keyDownRegistration.removeHandler(); - shortcutHandler = null; - keyDownRegistration = null; - } - - rendering = false; - } - public void updateSize() { renderInformation.updateSize(getElement()); @@ -241,12 +114,10 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler { } remove(oldComponent); if (oldComponent == lo) { - lo = (Container) VPaintableMap.get(client).getPaintable( - newComponent); + lo = newComponent; add(newComponent, fieldContainer); } else { - footer = (Container) VPaintableMap.get(client).getPaintable( - newComponent); + footer = newComponent; add(newComponent, footerContainer); } @@ -272,11 +143,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler { } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // NOP form don't render caption for neither field layout nor footer - // layout - } - @Override public void setHeight(String height) { if (this.height.equals(height)) { @@ -332,4 +198,11 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler { public Widget getWidgetForPaintable() { return this; } + + @Override + protected void add(Widget child, Element container) { + // Overridden to allow VFormPaintable to call this. Should be removed + // once functionality from VFormPaintable is moved to VForm. + super.add(child, container); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index e6305b3c42..b2357f11e1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -38,13 +38,13 @@ public class VFormLayout extends SimplePanel implements Container { private final static String CLASSNAME = "v-formlayout"; - private ApplicationConnection client; - private VFormLayoutTable table; + ApplicationConnection client; + VFormLayoutTable table; private String width = ""; private String height = ""; - private boolean rendering = false; + boolean rendering = false; public VFormLayout() { super(); @@ -279,21 +279,6 @@ public class VFormLayout extends SimplePanel implements Container { } } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - - this.client = client; - - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - - table.updateFromUIDL(uidl, client); - - rendering = false; - } - public boolean isDynamicWidth() { return width.equals(""); } @@ -306,10 +291,6 @@ public class VFormLayout extends SimplePanel implements Container { table.replaceChildComponent(oldComponent, newComponent); } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - table.updateCaption(component, uidl); - } - public class Caption extends HTML { public static final String CLASSNAME = "v-caption"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java new file mode 100644 index 0000000000..c4590a71c9 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java @@ -0,0 +1,39 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VFormLayoutPaintable extends VAbstractPaintableWidgetContainer {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+
+ getWidgetForPaintable().client = client;
+
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ getWidgetForPaintable().table.updateFromUIDL(uidl, client);
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ getWidgetForPaintable().table.updateCaption(component, uidl);
+ }
+
+ @Override
+ public VFormLayout getWidgetForPaintable() {
+ return (VFormLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VFormLayout.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java new file mode 100644 index 0000000000..5f519c09d4 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java @@ -0,0 +1,173 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VFormPaintable extends VAbstractPaintableWidgetContainer {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ if (client.updateComponent(this, uidl, false)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ boolean legendEmpty = true;
+ if (uidl.hasAttribute("caption")) {
+ getWidgetForPaintable().caption.setInnerText(uidl
+ .getStringAttribute("caption"));
+ legendEmpty = false;
+ } else {
+ getWidgetForPaintable().caption.setInnerText("");
+ }
+ if (uidl.hasAttribute("icon")) {
+ if (getWidgetForPaintable().icon == null) {
+ getWidgetForPaintable().icon = new Icon(client);
+ getWidgetForPaintable().legend
+ .insertFirst(getWidgetForPaintable().icon.getElement());
+ }
+ getWidgetForPaintable().icon
+ .setUri(uidl.getStringAttribute("icon"));
+ legendEmpty = false;
+ } else {
+ if (getWidgetForPaintable().icon != null) {
+ getWidgetForPaintable().legend
+ .removeChild(getWidgetForPaintable().icon.getElement());
+ }
+ }
+ if (legendEmpty) {
+ getWidgetForPaintable().addStyleDependentName("nocaption");
+ } else {
+ getWidgetForPaintable().removeStyleDependentName("nocaption");
+ }
+
+ if (uidl.hasAttribute("error")) {
+ final UIDL errorUidl = uidl.getErrors();
+ getWidgetForPaintable().errorMessage.updateFromUIDL(errorUidl);
+ getWidgetForPaintable().errorMessage.setVisible(true);
+ } else {
+ getWidgetForPaintable().errorMessage.setVisible(false);
+ }
+
+ if (uidl.hasAttribute("description")) {
+ getWidgetForPaintable().desc.setInnerHTML(uidl
+ .getStringAttribute("description"));
+ if (getWidgetForPaintable().desc.getParentElement() == null) {
+ getWidgetForPaintable().fieldSet.insertAfter(
+ getWidgetForPaintable().desc,
+ getWidgetForPaintable().legend);
+ }
+ } else {
+ getWidgetForPaintable().desc.setInnerHTML("");
+ if (getWidgetForPaintable().desc.getParentElement() != null) {
+ getWidgetForPaintable().fieldSet
+ .removeChild(getWidgetForPaintable().desc);
+ }
+ }
+
+ getWidgetForPaintable().updateSize();
+
+ // first render footer so it will be easier to handle relative height of
+ // main layout
+ if (uidl.getChildCount() > 1
+ && !uidl.getChildUIDL(1).getTag().equals("actions")) {
+ // render footer
+ VPaintableWidget newFooter = client.getPaintable(uidl
+ .getChildUIDL(1));
+ Widget newFooterWidget = newFooter.getWidgetForPaintable();
+ if (getWidgetForPaintable().footer == null) {
+ getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
+ getWidgetForPaintable().footerContainer);
+ getWidgetForPaintable().footer = newFooterWidget;
+ } else if (newFooter != getWidgetForPaintable().footer) {
+ getWidgetForPaintable().remove(getWidgetForPaintable().footer);
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().footer));
+ getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
+ getWidgetForPaintable().footerContainer);
+ }
+ getWidgetForPaintable().footer = newFooterWidget;
+ newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);
+ // needed for the main layout to know the space it has available
+ getWidgetForPaintable().updateSize();
+ } else {
+ if (getWidgetForPaintable().footer != null) {
+ getWidgetForPaintable().remove(getWidgetForPaintable().footer);
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().footer));
+ // needed for the main layout to know the space it has available
+ getWidgetForPaintable().updateSize();
+ }
+ }
+
+ final UIDL layoutUidl = uidl.getChildUIDL(0);
+ VPaintableWidget newLayout = client.getPaintable(layoutUidl);
+ Widget newLayoutWidget = newLayout.getWidgetForPaintable();
+ if (getWidgetForPaintable().lo == null) {
+ // Layout not rendered before
+ getWidgetForPaintable().lo = newLayoutWidget;
+ getWidgetForPaintable().add(newLayoutWidget,
+ getWidgetForPaintable().fieldContainer);
+ } else if (getWidgetForPaintable().lo != newLayoutWidget) {
+ // Layout has changed
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().lo));
+ getWidgetForPaintable().remove(getWidgetForPaintable().lo);
+ getWidgetForPaintable().lo = newLayoutWidget;
+ getWidgetForPaintable().add(newLayoutWidget,
+ getWidgetForPaintable().fieldContainer);
+ }
+ newLayout.updateFromUIDL(layoutUidl, client);
+
+ // also recalculates size of the footer if undefined size form - see
+ // #3710
+ getWidgetForPaintable().updateSize();
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ // We may have actions attached
+ if (uidl.getChildCount() > 1) {
+ UIDL childUidl = uidl.getChildByTagName("actions");
+ if (childUidl != null) {
+ if (getWidgetForPaintable().shortcutHandler == null) {
+ getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(
+ getId(), client);
+ getWidgetForPaintable().keyDownRegistration = getWidgetForPaintable()
+ .addDomHandler(getWidgetForPaintable(),
+ KeyDownEvent.getType());
+ }
+ getWidgetForPaintable().shortcutHandler
+ .updateActionMap(childUidl);
+ }
+ } else if (getWidgetForPaintable().shortcutHandler != null) {
+ getWidgetForPaintable().keyDownRegistration.removeHandler();
+ getWidgetForPaintable().shortcutHandler = null;
+ getWidgetForPaintable().keyDownRegistration = null;
+ }
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP form don't render caption for neither field layout nor footer
+ // layout
+ }
+
+ @Override
+ public VForm getWidgetForPaintable() {
+ return (VForm) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VForm.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index b37032e987..e6e167f077 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -14,16 +14,12 @@ import java.util.Set; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.event.dom.client.DomEvent.Type; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.AbsolutePanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Container; -import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.StyleConstants; import com.vaadin.terminal.gwt.client.UIDL; @@ -33,59 +29,43 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout; import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer; -public class VGridLayout extends SimplePanel implements VPaintableWidget, - Container { +public class VGridLayout extends SimplePanel implements Container { public static final String CLASSNAME = "v-gridlayout"; private DivElement margin = Document.get().createDivElement(); - private final AbsolutePanel canvas = new AbsolutePanel(); + final AbsolutePanel canvas = new AbsolutePanel(); - private ApplicationConnection client; + ApplicationConnection client; protected HashMap<Widget, ChildComponentContainer> widgetToComponentContainer = new HashMap<Widget, ChildComponentContainer>(); - private HashMap<Widget, Cell> widgetToCell = new HashMap<Widget, Cell>(); + HashMap<Widget, Cell> widgetToCell = new HashMap<Widget, Cell>(); private int spacingPixelsHorizontal; private int spacingPixelsVertical; - private int[] columnWidths; - private int[] rowHeights; + int[] columnWidths; + int[] rowHeights; private String height; private String width; - private int[] colExpandRatioArray; + int[] colExpandRatioArray; - private int[] rowExpandRatioArray; + int[] rowExpandRatioArray; - private int[] minColumnWidths; + int[] minColumnWidths; private int[] minRowHeights; - private boolean rendering; + boolean rendering; - private HashMap<Widget, ChildComponentContainer> nonRenderedWidgets; + HashMap<Widget, ChildComponentContainer> nonRenderedWidgets; - private boolean sizeChangedDuringRendering = false; - - private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( - this, EventId.LAYOUT_CLICK) { - - @Override - protected VPaintableWidget getChildComponent(Element element) { - return getComponent(element); - } - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; + boolean sizeChangedDuringRendering = false; public VGridLayout() { super(); @@ -135,126 +115,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, return spacingPixelsVertical; } - @SuppressWarnings("unchecked") - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - this.client = client; - - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - clickEventHandler.handleEventHandlerRegistration(client); - - canvas.setWidth("0px"); - - handleMargins(uidl); - detectSpacing(uidl); - - int cols = uidl.getIntAttribute("w"); - int rows = uidl.getIntAttribute("h"); - - columnWidths = new int[cols]; - rowHeights = new int[rows]; - - if (cells == null) { - cells = new Cell[cols][rows]; - } else if (cells.length != cols || cells[0].length != rows) { - Cell[][] newCells = new Cell[cols][rows]; - for (int i = 0; i < cells.length; i++) { - for (int j = 0; j < cells[i].length; j++) { - if (i < cols && j < rows) { - newCells[i][j] = cells[i][j]; - } - } - } - cells = newCells; - } - - nonRenderedWidgets = (HashMap<Widget, ChildComponentContainer>) widgetToComponentContainer - .clone(); - - final int[] alignments = uidl.getIntArrayAttribute("alignments"); - int alignmentIndex = 0; - - LinkedList<Cell> pendingCells = new LinkedList<Cell>(); - - LinkedList<Cell> relativeHeighted = new LinkedList<Cell>(); - - for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { - final UIDL r = (UIDL) i.next(); - if ("gr".equals(r.getTag())) { - for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) { - final UIDL c = (UIDL) j.next(); - if ("gc".equals(c.getTag())) { - Cell cell = getCell(c); - if (cell.hasContent()) { - boolean rendered = cell.renderIfNoRelativeWidth(); - cell.alignment = alignments[alignmentIndex++]; - if (!rendered) { - pendingCells.add(cell); - } - - if (cell.colspan > 1) { - storeColSpannedCell(cell); - } else if (rendered) { - // strore non-colspanned widths to columnWidth - // array - if (columnWidths[cell.col] < cell.getWidth()) { - columnWidths[cell.col] = cell.getWidth(); - } - } - if (cell.hasRelativeHeight()) { - relativeHeighted.add(cell); - } - } - } - } - } - } - - colExpandRatioArray = uidl.getIntArrayAttribute("colExpand"); - rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand"); - distributeColSpanWidths(); - - minColumnWidths = cloneArray(columnWidths); - expandColumns(); - - renderRemainingComponentsWithNoRelativeHeight(pendingCells); - - detectRowHeights(); - - expandRows(); - - renderRemainingComponents(pendingCells); - - for (Cell cell : relativeHeighted) { - // rendering done above so cell.cc should not be null - Widget widget2 = cell.cc.getWidget(); - client.handleComponentRelativeSize(widget2); - cell.cc.updateWidgetSize(); - } - - layoutCells(); - - // clean non rendered components - for (Widget w : nonRenderedWidgets.keySet()) { - ChildComponentContainer childComponentContainer = widgetToComponentContainer - .get(w); - widgetToCell.remove(w); - widgetToComponentContainer.remove(w); - childComponentContainer.removeFromParent(); - VPaintableMap paintableMap = VPaintableMap.get(client); - paintableMap.unregisterPaintable(paintableMap.getPaintable(w)); - } - nonRenderedWidgets = null; - - rendering = false; - sizeChangedDuringRendering = false; - - } - - private static int[] cloneArray(int[] toBeCloned) { + static int[] cloneArray(int[] toBeCloned) { int[] clone = new int[toBeCloned.length]; for (int i = 0; i < clone.length; i++) { clone[i] = toBeCloned[i] * 1; @@ -262,7 +123,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, return clone; } - private void expandRows() { + void expandRows() { if (!"".equals(height)) { int usedSpace = minRowHeights[0]; for (int i = 1; i < minRowHeights.length; i++) { @@ -401,7 +262,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, } } - private void expandColumns() { + void expandColumns() { if (!"".equals(width)) { int usedSpace = minColumnWidths[0]; for (int i = 1; i < minColumnWidths.length; i++) { @@ -428,7 +289,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, } } - private void layoutCells() { + void layoutCells() { int x = 0; int y = 0; for (int i = 0; i < cells.length; i++) { @@ -470,13 +331,13 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, return "".equals(width); } - private void renderRemainingComponents(LinkedList<Cell> pendingCells) { + void renderRemainingComponents(LinkedList<Cell> pendingCells) { for (Cell cell : pendingCells) { cell.render(); } } - private void detectRowHeights() { + void detectRowHeights() { // collect min rowheight from non-rowspanned cells for (int i = 0; i < cells.length; i++) { @@ -531,7 +392,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, l.cells.add(cell); } - private void renderRemainingComponentsWithNoRelativeHeight( + void renderRemainingComponentsWithNoRelativeHeight( LinkedList<Cell> pendingCells) { for (Iterator<Cell> iterator = pendingCells.iterator(); iterator @@ -549,7 +410,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, * Iterates colspanned cells, ensures cols have enough space to accommodate * them */ - private void distributeColSpanWidths() { + void distributeColSpanWidths() { for (SpanList list : colSpans) { for (Cell cell : list.cells) { // cells with relative content may return non 0 here if on @@ -643,7 +504,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, } } - private void storeColSpannedCell(Cell cell) { + void storeColSpannedCell(Cell cell) { SpanList l = null; for (SpanList list : colSpans) { if (list.span < cell.colspan) { @@ -666,7 +527,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, l.cells.add(cell); } - private void detectSpacing(UIDL uidl) { + void detectSpacing(UIDL uidl) { DivElement spacingmeter = Document.get().createDivElement(); spacingmeter.setClassName(CLASSNAME + "-" + "spacing-" + (uidl.getBooleanAttribute("spacing") ? "on" : "off")); @@ -678,7 +539,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, canvas.getElement().removeChild(spacingmeter); } - private void handleMargins(UIDL uidl) { + void handleMargins(UIDL uidl) { final VMarginInfo margins = new VMarginInfo( uidl.getIntAttribute("margins")); @@ -719,23 +580,6 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, widgetToCell.put(newComponent, widgetToCell.get(oldComponent)); } - public void updateCaption(VPaintableWidget paintable, UIDL uidl) { - Widget widget = paintable.getWidgetForPaintable(); - ChildComponentContainer cc = widgetToComponentContainer.get(widget); - if (cc != null) { - cc.updateCaption(uidl, client); - } - if (!rendering) { - // ensure rel size details are updated - widgetToCell.get(widget).updateRelSizeStatus(uidl); - /* - * This was a component-only update and the possible size change - * must be propagated to the layout - */ - client.captionSizeUpdated(widget); - } - } - public boolean requestLayout(final Set<Widget> changedChildren) { boolean needsLayout = false; boolean reDistributeColSpanWidths = false; @@ -895,12 +739,12 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, return cell.getAllocatedSpace(); } - private Cell[][] cells; + Cell[][] cells; /** * Private helper class. */ - private class Cell { + class Cell { private boolean relHeight = false; private boolean relWidth = false; private boolean widthCanAffectHeight = false; @@ -1109,7 +953,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, } } - private Cell getCell(UIDL c) { + Cell getCell(UIDL c) { int row = c.getIntAttribute("y"); int col = c.getIntAttribute("x"); Cell cell = cells[col][row]; @@ -1132,7 +976,7 @@ public class VGridLayout extends SimplePanel implements VPaintableWidget, * @return The Paintable which the element is a part of. Null if the element * belongs to the layout and not to a child. */ - private VPaintableWidget getComponent(Element element) { + VPaintableWidget getComponent(Element element) { return Util.getPaintableForElement(client, this, element); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java new file mode 100644 index 0000000000..1ef958183b --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java @@ -0,0 +1,193 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell;
+import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;
+
+public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer {
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
+ this, EventId.LAYOUT_CLICK) {
+
+ @Override
+ protected VPaintableWidget getChildComponent(Element element) {
+ return getWidgetForPaintable().getComponent(element);
+ }
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ getWidgetForPaintable().client = client;
+
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ getWidgetForPaintable().canvas.setWidth("0px");
+
+ getWidgetForPaintable().handleMargins(uidl);
+ getWidgetForPaintable().detectSpacing(uidl);
+
+ int cols = uidl.getIntAttribute("w");
+ int rows = uidl.getIntAttribute("h");
+
+ getWidgetForPaintable().columnWidths = new int[cols];
+ getWidgetForPaintable().rowHeights = new int[rows];
+
+ if (getWidgetForPaintable().cells == null) {
+ getWidgetForPaintable().cells = new Cell[cols][rows];
+ } else if (getWidgetForPaintable().cells.length != cols
+ || getWidgetForPaintable().cells[0].length != rows) {
+ Cell[][] newCells = new Cell[cols][rows];
+ for (int i = 0; i < getWidgetForPaintable().cells.length; i++) {
+ for (int j = 0; j < getWidgetForPaintable().cells[i].length; j++) {
+ if (i < cols && j < rows) {
+ newCells[i][j] = getWidgetForPaintable().cells[i][j];
+ }
+ }
+ }
+ getWidgetForPaintable().cells = newCells;
+ }
+
+ getWidgetForPaintable().nonRenderedWidgets = (HashMap<Widget, ChildComponentContainer>) getWidgetForPaintable().widgetToComponentContainer
+ .clone();
+
+ final int[] alignments = uidl.getIntArrayAttribute("alignments");
+ int alignmentIndex = 0;
+
+ LinkedList<Cell> pendingCells = new LinkedList<Cell>();
+
+ LinkedList<Cell> relativeHeighted = new LinkedList<Cell>();
+
+ for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
+ final UIDL r = (UIDL) i.next();
+ if ("gr".equals(r.getTag())) {
+ for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) {
+ final UIDL c = (UIDL) j.next();
+ if ("gc".equals(c.getTag())) {
+ Cell cell = getWidgetForPaintable().getCell(c);
+ if (cell.hasContent()) {
+ boolean rendered = cell.renderIfNoRelativeWidth();
+ cell.alignment = alignments[alignmentIndex++];
+ if (!rendered) {
+ pendingCells.add(cell);
+ }
+
+ if (cell.colspan > 1) {
+ getWidgetForPaintable().storeColSpannedCell(
+ cell);
+ } else if (rendered) {
+ // strore non-colspanned widths to columnWidth
+ // array
+ if (getWidgetForPaintable().columnWidths[cell.col] < cell
+ .getWidth()) {
+ getWidgetForPaintable().columnWidths[cell.col] = cell
+ .getWidth();
+ }
+ }
+ if (cell.hasRelativeHeight()) {
+ relativeHeighted.add(cell);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ getWidgetForPaintable().colExpandRatioArray = uidl
+ .getIntArrayAttribute("colExpand");
+ getWidgetForPaintable().rowExpandRatioArray = uidl
+ .getIntArrayAttribute("rowExpand");
+ getWidgetForPaintable().distributeColSpanWidths();
+
+ getWidgetForPaintable().minColumnWidths = VGridLayout
+ .cloneArray(getWidgetForPaintable().columnWidths);
+ getWidgetForPaintable().expandColumns();
+
+ getWidgetForPaintable().renderRemainingComponentsWithNoRelativeHeight(
+ pendingCells);
+
+ getWidgetForPaintable().detectRowHeights();
+
+ getWidgetForPaintable().expandRows();
+
+ getWidgetForPaintable().renderRemainingComponents(pendingCells);
+
+ for (Cell cell : relativeHeighted) {
+ // rendering done above so cell.cc should not be null
+ Widget widget2 = cell.cc.getWidget();
+ client.handleComponentRelativeSize(widget2);
+ cell.cc.updateWidgetSize();
+ }
+
+ getWidgetForPaintable().layoutCells();
+
+ // clean non rendered components
+ for (Widget w : getWidgetForPaintable().nonRenderedWidgets.keySet()) {
+ ChildComponentContainer childComponentContainer = getWidgetForPaintable().widgetToComponentContainer
+ .get(w);
+ getWidgetForPaintable().widgetToCell.remove(w);
+ getWidgetForPaintable().widgetToComponentContainer.remove(w);
+ childComponentContainer.removeFromParent();
+ VPaintableMap paintableMap = VPaintableMap.get(client);
+ paintableMap.unregisterPaintable(paintableMap.getPaintable(w));
+ }
+ getWidgetForPaintable().nonRenderedWidgets = null;
+
+ getWidgetForPaintable().rendering = false;
+ getWidgetForPaintable().sizeChangedDuringRendering = false;
+
+ }
+
+ public void updateCaption(VPaintableWidget paintable, UIDL uidl) {
+ Widget widget = paintable.getWidgetForPaintable();
+ ChildComponentContainer cc = getWidgetForPaintable().widgetToComponentContainer
+ .get(widget);
+ if (cc != null) {
+ cc.updateCaption(uidl, getConnection());
+ }
+ if (!getWidgetForPaintable().rendering) {
+ // ensure rel size details are updated
+ getWidgetForPaintable().widgetToCell.get(widget)
+ .updateRelSizeStatus(uidl);
+ /*
+ * This was a component-only update and the possible size change
+ * must be propagated to the layout
+ */
+ getConnection().captionSizeUpdated(widget);
+ }
+ }
+
+ @Override
+ public VGridLayout getWidgetForPaintable() {
+ return (VGridLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VGridLayout.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java new file mode 100644 index 0000000000..b72f5222cc --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalLayoutPaintable.java @@ -0,0 +1,17 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+public class VHorizontalLayoutPaintable extends VOrderedLayoutPaintable {
+
+ @Override
+ public VHorizontalLayout getWidgetForPaintable() {
+ return (VHorizontalLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected VHorizontalLayout createWidget() {
+ return GWT.create(VHorizontalLayout.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java new file mode 100644 index 0000000000..2340ceb0b6 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java @@ -0,0 +1,13 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+public class VHorizontalSplitPanelPaintable extends
+ VAbstractSplitPanelPaintable {
+
+ @Override
+ protected VAbstractSplitPanel createWidget() {
+ return GWT.create(VSplitPanelHorizontal.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLink.java b/src/com/vaadin/terminal/gwt/client/ui/VLink.java index 0ade84aaf5..df651c0a4d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VLink.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VLink.java @@ -11,44 +11,41 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -public class VLink extends HTML implements VPaintableWidget, ClickHandler { +public class VLink extends HTML implements ClickHandler { public static final String CLASSNAME = "v-link"; - private static final int BORDER_STYLE_DEFAULT = 0; - private static final int BORDER_STYLE_MINIMAL = 1; - private static final int BORDER_STYLE_NONE = 2; + protected static final int BORDER_STYLE_DEFAULT = 0; + protected static final int BORDER_STYLE_MINIMAL = 1; + protected static final int BORDER_STYLE_NONE = 2; - private String src; + protected String src; - private String target; + protected String target; - private int borderStyle = BORDER_STYLE_DEFAULT; + protected int borderStyle = BORDER_STYLE_DEFAULT; - private boolean enabled; + protected boolean enabled; - private boolean readonly; + protected boolean readonly; - private int targetWidth; + protected int targetWidth; - private int targetHeight; + protected int targetHeight; - private Element errorIndicatorElement; + protected Element errorIndicatorElement; - private final Element anchor = DOM.createAnchor(); + protected final Element anchor = DOM.createAnchor(); - private final Element captionElement = DOM.createSpan(); + protected final Element captionElement = DOM.createSpan(); - private Icon icon; + protected Icon icon; - private ApplicationConnection client; + protected ApplicationConnection client; public VLink() { super(); @@ -59,68 +56,6 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler { setStyleName(CLASSNAME); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - // Ensure correct implementation, - // but don't let container manage caption etc. - if (client.updateComponent(this, uidl, false)) { - return; - } - - this.client = client; - - enabled = uidl.hasAttribute("disabled") ? false : true; - readonly = uidl.hasAttribute("readonly") ? true : false; - - if (uidl.hasAttribute("name")) { - target = uidl.getStringAttribute("name"); - anchor.setAttribute("target", target); - } - if (uidl.hasAttribute("src")) { - src = client.translateVaadinUri(uidl.getStringAttribute("src")); - anchor.setAttribute("href", src); - } - - if (uidl.hasAttribute("border")) { - if ("none".equals(uidl.getStringAttribute("border"))) { - borderStyle = BORDER_STYLE_NONE; - } else { - borderStyle = BORDER_STYLE_MINIMAL; - } - } else { - borderStyle = BORDER_STYLE_DEFAULT; - } - - targetHeight = uidl.hasAttribute("targetHeight") ? uidl - .getIntAttribute("targetHeight") : -1; - targetWidth = uidl.hasAttribute("targetWidth") ? uidl - .getIntAttribute("targetWidth") : -1; - - // Set link caption - captionElement.setInnerText(uidl.getStringAttribute("caption")); - - // handle error - if (uidl.hasAttribute("error")) { - if (errorIndicatorElement == null) { - errorIndicatorElement = DOM.createDiv(); - DOM.setElementProperty(errorIndicatorElement, "className", - "v-errorindicator"); - } - DOM.insertChild(getElement(), errorIndicatorElement, 0); - } else if (errorIndicatorElement != null) { - DOM.setStyleAttribute(errorIndicatorElement, "display", "none"); - } - - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - anchor.insertBefore(icon.getElement(), captionElement); - } - icon.setUri(uidl.getStringAttribute("icon")); - } - - } - public void onClick(ClickEvent event) { if (enabled && !readonly) { if (target == null) { @@ -168,7 +103,7 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler { Util.notifyParentOfSizeChange(this, true); } if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } if (target == captionElement || target == anchor || (icon != null && target == icon.getElement())) { @@ -180,8 +115,4 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler { } - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java new file mode 100644 index 0000000000..3fbd796c4b --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java @@ -0,0 +1,100 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VLinkPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + // Ensure correct implementation, + // but don't let container manage caption etc. + if (client.updateComponent(this, uidl, false)) { + return; + } + + getWidgetForPaintable().client = client; + + getWidgetForPaintable().enabled = uidl.hasAttribute("disabled") ? false + : true; + getWidgetForPaintable().readonly = uidl.hasAttribute("readonly") ? true + : false; + + if (uidl.hasAttribute("name")) { + getWidgetForPaintable().target = uidl.getStringAttribute("name"); + getWidgetForPaintable().anchor.setAttribute("target", + getWidgetForPaintable().target); + } + if (uidl.hasAttribute("src")) { + getWidgetForPaintable().src = client.translateVaadinUri(uidl + .getStringAttribute("src")); + getWidgetForPaintable().anchor.setAttribute("href", + getWidgetForPaintable().src); + } + + if (uidl.hasAttribute("border")) { + if ("none".equals(uidl.getStringAttribute("border"))) { + getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_NONE; + } else { + getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_MINIMAL; + } + } else { + getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_DEFAULT; + } + + getWidgetForPaintable().targetHeight = uidl + .hasAttribute("targetHeight") ? uidl + .getIntAttribute("targetHeight") : -1; + getWidgetForPaintable().targetWidth = uidl.hasAttribute("targetWidth") ? uidl + .getIntAttribute("targetWidth") : -1; + + // Set link caption + getWidgetForPaintable().captionElement.setInnerText(uidl + .getStringAttribute("caption")); + + // handle error + if (uidl.hasAttribute("error")) { + if (getWidgetForPaintable().errorIndicatorElement == null) { + getWidgetForPaintable().errorIndicatorElement = DOM.createDiv(); + DOM.setElementProperty( + getWidgetForPaintable().errorIndicatorElement, + "className", "v-errorindicator"); + } + DOM.insertChild(getWidgetForPaintable().getElement(), + getWidgetForPaintable().errorIndicatorElement, 0); + } else if (getWidgetForPaintable().errorIndicatorElement != null) { + DOM.setStyleAttribute( + getWidgetForPaintable().errorIndicatorElement, "display", + "none"); + } + + if (uidl.hasAttribute("icon")) { + if (getWidgetForPaintable().icon == null) { + getWidgetForPaintable().icon = new Icon(client); + getWidgetForPaintable().anchor.insertBefore( + getWidgetForPaintable().icon.getElement(), + getWidgetForPaintable().captionElement); + } + getWidgetForPaintable().icon + .setUri(uidl.getStringAttribute("icon")); + } + + } + + @Override + protected Widget createWidget() { + return GWT.create(VLink.class); + } + + @Override + public VLink getWidgetForPaintable() { + return (VLink) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VListSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VListSelect.java index 25bd6f35b2..1ea2f4f705 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VListSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VListSelect.java @@ -12,7 +12,6 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VTooltip; @@ -81,11 +80,11 @@ public class VListSelect extends VOptionGroupBase { } else { lastSelectedIndex = si; if (isMultiselect()) { - client.updateVariable(id, "selected", getSelectedItems(), - isImmediate()); + client.updateVariable(paintableId, "selected", + getSelectedItems(), isImmediate()); } else { - client.updateVariable(id, "selected", new String[] { "" - + getSelectedItem() }, isImmediate()); + client.updateVariable(paintableId, "selected", + new String[] { "" + getSelectedItem() }, isImmediate()); } } } @@ -110,11 +109,6 @@ public class VListSelect extends VOptionGroupBase { public void focus() { select.setFocus(true); } - - public Widget getWidgetForPaintable() { - return this; - } - } /** @@ -123,7 +117,7 @@ public class VListSelect extends VOptionGroupBase { */ class TooltipListBox extends ListBox { private ApplicationConnection client; - private VPaintableWidget pntbl; + private Widget widget; TooltipListBox(boolean isMultiselect) { super(isMultiselect); @@ -134,15 +128,15 @@ class TooltipListBox extends ListBox { this.client = client; } - public void setSelect(VPaintableWidget s) { - pntbl = s; + public void setSelect(Widget widget) { + this.widget = widget; } @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, pntbl); + client.handleWidgetTooltipEvent(event, widget); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VListSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VListSelectPaintable.java new file mode 100644 index 0000000000..b77bfa33e3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VListSelectPaintable.java @@ -0,0 +1,21 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; + +public class VListSelectPaintable extends VOptionGroupBasePaintable { + + @Override + protected Widget createWidget() { + return GWT.create(VListSelect.class); + } + + @Override + public VListSelect getWidgetForPaintable() { + return (VListSelect) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java b/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java index df76b6d878..6c5fbc2ef0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMediaBase.java @@ -8,25 +8,10 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.MediaElement; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.Util; -public abstract class VMediaBase extends Widget implements VPaintableWidget { - public static final String ATTR_PAUSE = "pause"; - public static final String ATTR_PLAY = "play"; - public static final String ATTR_MUTED = "muted"; - public static final String ATTR_CONTROLS = "ctrl"; - public static final String ATTR_AUTOPLAY = "auto"; - public static final String TAG_SOURCE = "src"; - public static final String ATTR_RESOURCE = "res"; - public static final String ATTR_RESOURCE_TYPE = "type"; - public static final String ATTR_HTML = "html"; - public static final String ATTR_ALT_TEXT = "alt"; +public abstract class VMediaBase extends Widget { private MediaElement media; - protected ApplicationConnection client; /** * Sets the MediaElement that is to receive all commands and properties. @@ -38,96 +23,40 @@ public abstract class VMediaBase extends Widget implements VPaintableWidget { media = element; } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - - this.client = client; - - media.setControls(shouldShowControls(uidl)); - media.setAutoplay(shouldAutoplay(uidl)); - media.setMuted(isMediaMuted(uidl)); - - // Add all sources - for (int ix = 0; ix < uidl.getChildCount(); ix++) { - UIDL child = uidl.getChildUIDL(ix); - if (TAG_SOURCE.equals(child.getTag())) { - Element src = Document.get().createElement("source").cast(); - src.setAttribute("src", getSourceUrl(child)); - src.setAttribute("type", getSourceType(child)); - media.appendChild(src); - } - } - setAltText(uidl); - - evalPauseCommand(uidl); - evalPlayCommand(uidl); - } - - protected boolean shouldShowControls(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_CONTROLS); - } - - private boolean shouldAutoplay(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_AUTOPLAY); - } - - private boolean isMediaMuted(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_MUTED); - } - /** - * @param uidl - * @return the URL of a resource to be used as a source for the media + * @return the default HTML to show users with browsers that do not support + * HTML5 media markup. */ - private String getSourceUrl(UIDL uidl) { - String url = client.translateVaadinUri(uidl - .getStringAttribute(ATTR_RESOURCE)); - if (url == null) { - return ""; - } - return url; - } + protected abstract String getDefaultAltHtml(); - /** - * @param uidl - * @return the mime type of the media - */ - private String getSourceType(UIDL uidl) { - return uidl.getStringAttribute(ATTR_RESOURCE_TYPE); + public void play() { + media.play(); } - private void setAltText(UIDL uidl) { - String alt = uidl.getStringAttribute(ATTR_ALT_TEXT); + public void pause() { + media.pause(); + } - if (alt == null || "".equals(alt)) { - alt = getDefaultAltHtml(); - } else if (!allowHtmlContent(uidl)) { - alt = Util.escapeHTML(alt); - } + public void setAltText(String alt) { media.appendChild(Document.get().createTextNode(alt)); } - private boolean allowHtmlContent(UIDL uidl) { - return uidl.getBooleanAttribute(ATTR_HTML); + public void setControls(boolean shouldShowControls) { + media.setControls(shouldShowControls); } - private void evalPlayCommand(UIDL uidl) { - if (uidl.hasAttribute(ATTR_PLAY)) { - media.play(); - } + public void setAutoplay(boolean shouldAutoplay) { + media.setAutoplay(shouldAutoplay); } - private void evalPauseCommand(UIDL uidl) { - if (uidl.hasAttribute(ATTR_PAUSE)) { - media.pause(); - } + public void setMuted(boolean mediaMuted) { + media.setMuted(mediaMuted); } - /** - * @return the default HTML to show users with browsers that do not support - * HTML5 media markup. - */ - protected abstract String getDefaultAltHtml(); + public void addSource(String sourceUrl, String sourceType) { + Element src = Document.get().createElement("source").cast(); + src.setAttribute("src", sourceUrl); + src.setAttribute("type", sourceType); + media.appendChild(src); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java new file mode 100644 index 0000000000..fc709d56b3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VMediaBasePaintable.java @@ -0,0 +1,109 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
+
+public abstract class VMediaBasePaintable extends VAbstractPaintableWidget {
+
+ public static final String TAG_SOURCE = "src";
+
+ public static final String ATTR_PAUSE = "pause";
+ public static final String ATTR_PLAY = "play";
+ public static final String ATTR_MUTED = "muted";
+ public static final String ATTR_CONTROLS = "ctrl";
+ public static final String ATTR_AUTOPLAY = "auto";
+ public static final String ATTR_RESOURCE = "res";
+ public static final String ATTR_RESOURCE_TYPE = "type";
+ public static final String ATTR_HTML = "html";
+ public static final String ATTR_ALT_TEXT = "alt";
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().setControls(shouldShowControls(uidl));
+ getWidgetForPaintable().setAutoplay(shouldAutoplay(uidl));
+ getWidgetForPaintable().setMuted(isMediaMuted(uidl));
+
+ // Add all sources
+ for (int ix = 0; ix < uidl.getChildCount(); ix++) {
+ UIDL child = uidl.getChildUIDL(ix);
+ if (TAG_SOURCE.equals(child.getTag())) {
+ getWidgetForPaintable().addSource(getSourceUrl(child),
+ getSourceType(child));
+ }
+ }
+ setAltText(uidl);
+
+ evalPauseCommand(uidl);
+ evalPlayCommand(uidl);
+ }
+
+ protected boolean shouldShowControls(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_CONTROLS);
+ }
+
+ private boolean shouldAutoplay(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_AUTOPLAY);
+ }
+
+ private boolean isMediaMuted(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_MUTED);
+ }
+
+ private boolean allowHtmlContent(UIDL uidl) {
+ return uidl.getBooleanAttribute(ATTR_HTML);
+ }
+
+ private void evalPlayCommand(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_PLAY)) {
+ getWidgetForPaintable().play();
+ }
+ }
+
+ private void evalPauseCommand(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_PAUSE)) {
+ getWidgetForPaintable().pause();
+ }
+ }
+
+ @Override
+ public VMediaBase getWidgetForPaintable() {
+ return (VMediaBase) super.getWidgetForPaintable();
+ }
+
+ /**
+ * @param uidl
+ * @return the URL of a resource to be used as a source for the media
+ */
+ private String getSourceUrl(UIDL uidl) {
+ String url = getConnection().translateVaadinUri(
+ uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE));
+ if (url == null) {
+ return "";
+ }
+ return url;
+ }
+
+ /**
+ * @param uidl
+ * @return the mime type of the media
+ */
+ private String getSourceType(UIDL uidl) {
+ return uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE_TYPE);
+ }
+
+ private void setAltText(UIDL uidl) {
+ String alt = uidl.getStringAttribute(VMediaBasePaintable.ATTR_ALT_TEXT);
+
+ if (alt == null || "".equals(alt)) {
+ alt = getWidgetForPaintable().getDefaultAltHtml();
+ } else if (!allowHtmlContent(uidl)) {
+ alt = Util.escapeHTML(alt);
+ }
+ getWidgetForPaintable().setAltText(alt);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java index a0b374c97e..3deb3d56b2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java @@ -16,7 +16,6 @@ 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.Button; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; @@ -157,8 +156,4 @@ public class VNativeButton extends Button implements ClickHandler, setStyleName(ApplicationConnection.DISABLED_CLASSNAME, !enabled); } } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java index 5e0dceea75..ebf9cad264 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java @@ -1,3 +1,6 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.core.client.GWT; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeSelect.java index 038b598555..ec2f6e42a1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeSelect.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Iterator; import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.UIDL; public class VNativeSelect extends VOptionGroupBase implements Field { @@ -74,10 +73,10 @@ public class VNativeSelect extends VOptionGroupBase implements Field { public void onChange(ChangeEvent event) { if (select.isMultipleSelect()) { - client.updateVariable(id, "selected", getSelectedItems(), + client.updateVariable(paintableId, "selected", getSelectedItems(), isImmediate()); } else { - client.updateVariable(id, "selected", new String[] { "" + client.updateVariable(paintableId, "selected", new String[] { "" + getSelectedItem() }, isImmediate()); } if (firstValueIsTemporaryNullItem) { @@ -107,8 +106,4 @@ public class VNativeSelect extends VOptionGroupBase implements Field { public void focus() { select.setFocus(true); } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeSelectPaintable.java new file mode 100644 index 0000000000..37defb605f --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeSelectPaintable.java @@ -0,0 +1,21 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; + +public class VNativeSelectPaintable extends VOptionGroupBasePaintable { + + @Override + protected Widget createWidget() { + return GWT.create(VNativeSelect.class); + } + + @Override + public VNativeSelect getWidgetForPaintable() { + return (VNativeSelect) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java index 0175134355..bf89a01a03 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java @@ -4,7 +4,6 @@ package com.vaadin.terminal.gwt.client.ui; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -38,14 +37,14 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, public static final String CLASSNAME = "v-select-optiongroup"; - private final Panel panel; + protected final Panel panel; private final Map<CheckBox, String> optionsToKeys; - private boolean sendFocusEvents = false; - private boolean sendBlurEvents = false; - private List<HandlerRegistration> focusHandlers = null; - private List<HandlerRegistration> blurHandlers = null; + protected boolean sendFocusEvents = false; + protected boolean sendBlurEvents = false; + protected List<HandlerRegistration> focusHandlers = null; + protected List<HandlerRegistration> blurHandlers = null; private final LoadHandler iconLoadHandler = new LoadHandler() { public void onLoad(LoadEvent event) { @@ -62,7 +61,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, */ private boolean blurOccured = false; - private boolean htmlContentAllowed = false; + protected boolean htmlContentAllowed = false; public VOptionGroup() { super(CLASSNAME); @@ -70,43 +69,6 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, optionsToKeys = new HashMap<CheckBox, String>(); } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - htmlContentAllowed = uidl.hasAttribute(HTML_CONTENT_ALLOWED); - - super.updateFromUIDL(uidl, client); - - sendFocusEvents = client.hasEventListeners(this, EventId.FOCUS); - sendBlurEvents = client.hasEventListeners(this, EventId.BLUR); - - if (focusHandlers != null) { - for (HandlerRegistration reg : focusHandlers) { - reg.removeHandler(); - } - focusHandlers.clear(); - focusHandlers = null; - - for (HandlerRegistration reg : blurHandlers) { - reg.removeHandler(); - } - blurHandlers.clear(); - blurHandlers = null; - } - - if (sendFocusEvents || sendBlurEvents) { - focusHandlers = new ArrayList<HandlerRegistration>(); - blurHandlers = new ArrayList<HandlerRegistration>(); - - // add focus and blur handlers to checkboxes / radio buttons - for (Widget wid : panel) { - if (wid instanceof CheckBox) { - focusHandlers.add(((CheckBox) wid).addFocusHandler(this)); - blurHandlers.add(((CheckBox) wid).addBlurHandler(this)); - } - } - } - } - /* * Return true if no elements were changed, false otherwise. */ @@ -133,7 +95,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, op = new VCheckBox(); op.setHTML(itemHtml); } else { - op = new RadioButton(id, itemHtml, true); + op = new RadioButton(paintableId, itemHtml, true); op.setStyleName("v-radiobutton"); } @@ -174,7 +136,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, } else { selectedKeys.remove(key); } - client.updateVariable(id, "selected", getSelectedItems(), + client.updateVariable(paintableId, "selected", getSelectedItems(), isImmediate()); } } @@ -200,7 +162,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, // panel was blurred => fire the event to the server side if // requested by server side if (sendFocusEvents) { - client.updateVariable(id, EventId.FOCUS, "", true); + client.updateVariable(paintableId, EventId.FOCUS, "", true); } } else { // blur occured before this focus event @@ -219,16 +181,12 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, // check whether blurOccured still is true and then send the // event out to the server if (blurOccured) { - client.updateVariable(id, EventId.BLUR, "", true); + client.updateVariable(paintableId, EventId.BLUR, "", + true); blurOccured = false; } } }); } } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBase.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBase.java index c4d92783c8..bcd5cc891f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBase.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBase.java @@ -19,35 +19,34 @@ import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Focusable; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.UIDL; -abstract class VOptionGroupBase extends Composite implements VPaintableWidget, - Field, ClickHandler, ChangeHandler, KeyPressHandler, Focusable { +abstract class VOptionGroupBase extends Composite implements Field, + ClickHandler, ChangeHandler, KeyPressHandler, Focusable { public static final String CLASSNAME_OPTION = "v-select-option"; protected ApplicationConnection client; - protected String id; + protected String paintableId; protected Set<String> selectedKeys; - private boolean immediate; + protected boolean immediate; - private boolean multiselect; + protected boolean multiselect; - private boolean disabled; + protected boolean disabled; - private boolean readonly; + protected boolean readonly; - private int cols = 0; + protected int cols = 0; - private int rows = 0; + protected int rows = 0; - private boolean nullSelectionAllowed = true; + protected boolean nullSelectionAllowed = true; - private boolean nullSelectionItemAvailable = false; + protected boolean nullSelectionItemAvailable = false; /** * Widget holding the different options (e.g. ListBox or Panel for radio @@ -58,11 +57,11 @@ abstract class VOptionGroupBase extends Composite implements VPaintableWidget, /** * Panel containing the component */ - private final Panel container; + protected final Panel container; - private VTextField newItemField; + protected VTextField newItemField; - private VNativeButton newItemButton; + protected VNativeButton newItemButton; public VOptionGroupBase(String classname) { container = new FlowPanel(); @@ -122,84 +121,23 @@ abstract class VOptionGroupBase extends Composite implements VPaintableWidget, return rows; } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - id = uidl.getId(); - - if (client.updateComponent(this, uidl, true)) { - return; - } - - selectedKeys = uidl.getStringArrayVariableAsSet("selected"); - - readonly = uidl.getBooleanAttribute("readonly"); - disabled = uidl.getBooleanAttribute("disabled"); - multiselect = "multi".equals(uidl.getStringAttribute("selectmode")); - immediate = uidl.getBooleanAttribute("immediate"); - nullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); - nullSelectionItemAvailable = uidl.getBooleanAttribute("nullselectitem"); - - if (uidl.hasAttribute("cols")) { - cols = uidl.getIntAttribute("cols"); - } - if (uidl.hasAttribute("rows")) { - rows = uidl.getIntAttribute("rows"); - } - - final UIDL ops = uidl.getChildUIDL(0); - - if (getColumns() > 0) { - container.setWidth(getColumns() + "em"); - if (container != optionsContainer) { - optionsContainer.setWidth("100%"); - } - } - - buildOptions(ops); - - if (uidl.getBooleanAttribute("allownewitem")) { - if (newItemField == null) { - newItemButton = new VNativeButton(); - newItemButton.setText("+"); - newItemButton.addClickHandler(this); - newItemField = new VTextField(); - newItemField.addKeyPressHandler(this); - } - newItemField.setEnabled(!disabled && !readonly); - newItemButton.setEnabled(!disabled && !readonly); - - if (newItemField == null || newItemField.getParent() != container) { - container.add(newItemField); - container.add(newItemButton); - final int w = container.getOffsetWidth() - - newItemButton.getOffsetWidth(); - newItemField.setWidth(Math.max(w, 0) + "px"); - } - } else if (newItemField != null) { - container.remove(newItemField); - container.remove(newItemButton); - } - - setTabIndex(uidl.hasAttribute("tabindex") ? uidl - .getIntAttribute("tabindex") : 0); - - } - abstract protected void setTabIndex(int tabIndex); public void onClick(ClickEvent event) { if (event.getSource() == newItemButton && !newItemField.getText().equals("")) { - client.updateVariable(id, "newitem", newItemField.getText(), true); + client.updateVariable(paintableId, "newitem", + newItemField.getText(), true); newItemField.setText(""); } } public void onChange(ChangeEvent event) { if (multiselect) { - client.updateVariable(id, "selected", getSelectedItems(), immediate); + client.updateVariable(paintableId, "selected", getSelectedItems(), + immediate); } else { - client.updateVariable(id, "selected", new String[] { "" + client.updateVariable(paintableId, "selected", new String[] { "" + getSelectedItem() }, immediate); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBasePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBasePaintable.java new file mode 100644 index 0000000000..76486ff8a3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBasePaintable.java @@ -0,0 +1,103 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public abstract class VOptionGroupBasePaintable extends + VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + + if (client.updateComponent(this, uidl, true)) { + return; + } + + getWidgetForPaintable().selectedKeys = uidl + .getStringArrayVariableAsSet("selected"); + + getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly"); + getWidgetForPaintable().disabled = uidl.getBooleanAttribute("disabled"); + getWidgetForPaintable().multiselect = "multi".equals(uidl + .getStringAttribute("selectmode")); + getWidgetForPaintable().immediate = uidl + .getBooleanAttribute("immediate"); + getWidgetForPaintable().nullSelectionAllowed = uidl + .getBooleanAttribute("nullselect"); + getWidgetForPaintable().nullSelectionItemAvailable = uidl + .getBooleanAttribute("nullselectitem"); + + if (uidl.hasAttribute("cols")) { + getWidgetForPaintable().cols = uidl.getIntAttribute("cols"); + } + if (uidl.hasAttribute("rows")) { + getWidgetForPaintable().rows = uidl.getIntAttribute("rows"); + } + + final UIDL ops = uidl.getChildUIDL(0); + + if (getWidgetForPaintable().getColumns() > 0) { + getWidgetForPaintable().container.setWidth(getWidgetForPaintable() + .getColumns() + "em"); + if (getWidgetForPaintable().container != getWidgetForPaintable().optionsContainer) { + getWidgetForPaintable().optionsContainer.setWidth("100%"); + } + } + + getWidgetForPaintable().buildOptions(ops); + + if (uidl.getBooleanAttribute("allownewitem")) { + if (getWidgetForPaintable().newItemField == null) { + getWidgetForPaintable().newItemButton = new VNativeButton(); + getWidgetForPaintable().newItemButton.setText("+"); + getWidgetForPaintable().newItemButton + .addClickHandler(getWidgetForPaintable()); + getWidgetForPaintable().newItemField = new VTextField(); + getWidgetForPaintable().newItemField + .addKeyPressHandler(getWidgetForPaintable()); + } + getWidgetForPaintable().newItemField + .setEnabled(!getWidgetForPaintable().disabled + && !getWidgetForPaintable().readonly); + getWidgetForPaintable().newItemButton + .setEnabled(!getWidgetForPaintable().disabled + && !getWidgetForPaintable().readonly); + + if (getWidgetForPaintable().newItemField == null + || getWidgetForPaintable().newItemField.getParent() != getWidgetForPaintable().container) { + getWidgetForPaintable().container + .add(getWidgetForPaintable().newItemField); + getWidgetForPaintable().container + .add(getWidgetForPaintable().newItemButton); + final int w = getWidgetForPaintable().container + .getOffsetWidth() + - getWidgetForPaintable().newItemButton + .getOffsetWidth(); + getWidgetForPaintable().newItemField.setWidth(Math.max(w, 0) + + "px"); + } + } else if (getWidgetForPaintable().newItemField != null) { + getWidgetForPaintable().container + .remove(getWidgetForPaintable().newItemField); + getWidgetForPaintable().container + .remove(getWidgetForPaintable().newItemButton); + } + + getWidgetForPaintable().setTabIndex( + uidl.hasAttribute("tabindex") ? uidl + .getIntAttribute("tabindex") : 0); + + } + + @Override + public VOptionGroupBase getWidgetForPaintable() { + return (VOptionGroupBase) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupPaintable.java new file mode 100644 index 0000000000..f4ffc4f0da --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroupPaintable.java @@ -0,0 +1,71 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import java.util.ArrayList; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.EventId; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VOptionGroupPaintable extends VOptionGroupBasePaintable { + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + getWidgetForPaintable().htmlContentAllowed = uidl + .hasAttribute(VOptionGroup.HTML_CONTENT_ALLOWED); + + super.updateFromUIDL(uidl, client); + + getWidgetForPaintable().sendFocusEvents = client.hasEventListeners( + this, EventId.FOCUS); + getWidgetForPaintable().sendBlurEvents = client.hasEventListeners(this, + EventId.BLUR); + + if (getWidgetForPaintable().focusHandlers != null) { + for (HandlerRegistration reg : getWidgetForPaintable().focusHandlers) { + reg.removeHandler(); + } + getWidgetForPaintable().focusHandlers.clear(); + getWidgetForPaintable().focusHandlers = null; + + for (HandlerRegistration reg : getWidgetForPaintable().blurHandlers) { + reg.removeHandler(); + } + getWidgetForPaintable().blurHandlers.clear(); + getWidgetForPaintable().blurHandlers = null; + } + + if (getWidgetForPaintable().sendFocusEvents + || getWidgetForPaintable().sendBlurEvents) { + getWidgetForPaintable().focusHandlers = new ArrayList<HandlerRegistration>(); + getWidgetForPaintable().blurHandlers = new ArrayList<HandlerRegistration>(); + + // add focus and blur handlers to checkboxes / radio buttons + for (Widget wid : getWidgetForPaintable().panel) { + if (wid instanceof CheckBox) { + getWidgetForPaintable().focusHandlers.add(((CheckBox) wid) + .addFocusHandler(getWidgetForPaintable())); + getWidgetForPaintable().blurHandlers.add(((CheckBox) wid) + .addBlurHandler(getWidgetForPaintable())); + } + } + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VOptionGroup.class); + } + + @Override + public VOptionGroup getWidgetForPaintable() { + return (VOptionGroup) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java index f490e5176d..9f5576dfaf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java @@ -9,15 +9,8 @@ import java.util.Set; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.DomEvent.Type; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.EventId; -import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize; import com.vaadin.terminal.gwt.client.RenderInformation.Size; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.UIDL; @@ -32,21 +25,18 @@ public class VOrderedLayout extends CellBasedLayout { public static final String CLASSNAME = "v-orderedlayout"; - private int orientation; - - // Can be removed once OrderedLayout is removed - private boolean allowOrientationUpdate = false; + int orientation; /** * Size of the layout excluding any margins. */ - private Size activeLayoutSize = new Size(0, 0); + Size activeLayoutSize = new Size(0, 0); - private boolean isRendering = false; + boolean isRendering = false; private String width = ""; - private boolean sizeHasChangedDuringRendering = false; + boolean sizeHasChangedDuringRendering = false; private ValueMap expandRatios; @@ -56,24 +46,8 @@ public class VOrderedLayout extends CellBasedLayout { private ValueMap alignments; - private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( - this, EventId.LAYOUT_CLICK) { - - @Override - protected VPaintableWidget getChildComponent(Element element) { - return getComponent(element); - } - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; - public VOrderedLayout() { this(CLASSNAME, ORIENTATION_VERTICAL); - allowOrientationUpdate = true; } protected VOrderedLayout(String className, int orientation) { @@ -87,195 +61,7 @@ public class VOrderedLayout extends CellBasedLayout { STYLENAME_MARGIN_LEFT = className + "-margin-left"; } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - isRendering = true; - super.updateFromUIDL(uidl, client); - - // Only non-cached, visible UIDL:s can introduce changes - if (uidl.getBooleanAttribute("cached") - || uidl.getBooleanAttribute("invisible")) { - isRendering = false; - return; - } - - clickEventHandler.handleEventHandlerRegistration(client); - - if (allowOrientationUpdate) { - handleOrientationUpdate(uidl); - } - - // IStopWatch w = new IStopWatch("OrderedLayout.updateFromUIDL"); - - ArrayList<Widget> uidlWidgets = new ArrayList<Widget>( - uidl.getChildCount()); - ArrayList<ChildComponentContainer> relativeSizeComponents = new ArrayList<ChildComponentContainer>(); - ArrayList<UIDL> relativeSizeComponentUIDL = new ArrayList<UIDL>(); - - int pos = 0; - for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) { - final UIDL childUIDL = (UIDL) it.next(); - final VPaintableWidget childPaintable = client - .getPaintable(childUIDL); - Widget widget = childPaintable.getWidgetForPaintable(); - - // Create container for component - ChildComponentContainer childComponentContainer = getComponentContainer(widget); - - if (childComponentContainer == null) { - // This is a new component - childComponentContainer = createChildContainer(childPaintable); - } else { - /* - * The widget may be null if the same paintable has been - * rendered in a different component container while this has - * been invisible. Ensure the childComponentContainer has the - * widget attached. See e.g. #5372 - */ - childComponentContainer.setPaintable(childPaintable); - } - - addOrMoveChild(childComponentContainer, pos++); - - /* - * Components which are to be expanded in the same orientation as - * the layout are rendered later when it is clear how much space - * they can use - */ - if (!Util.isCached(childUIDL)) { - FloatSize relativeSize = Util.parseRelativeSize(childUIDL); - childComponentContainer.setRelativeSize(relativeSize); - } - - if (childComponentContainer.isComponentRelativeSized(orientation)) { - relativeSizeComponents.add(childComponentContainer); - relativeSizeComponentUIDL.add(childUIDL); - } else { - if (isDynamicWidth()) { - childComponentContainer.renderChild(childUIDL, client, -1); - } else { - childComponentContainer.renderChild(childUIDL, client, - activeLayoutSize.getWidth()); - } - if (sizeHasChangedDuringRendering && Util.isCached(childUIDL)) { - // notify cached relative sized component about size - // chance - client.handleComponentRelativeSize(childComponentContainer - .getWidget()); - } - } - - uidlWidgets.add(widget); - - } - - // w.mark("Rendering of " - // + (uidlWidgets.size() - relativeSizeComponents.size()) - // + " absolute size components done"); - - /* - * Remove any children after pos. These are the ones that previously - * were in the layout but have now been removed - */ - removeChildrenAfter(pos); - - // w.mark("Old children removed"); - - /* Fetch alignments and expand ratio from UIDL */ - updateAlignmentsAndExpandRatios(uidl, uidlWidgets); - // w.mark("Alignments and expand ratios updated"); - - /* Fetch widget sizes from rendered components */ - updateWidgetSizes(); - // w.mark("Widget sizes updated"); - - recalculateLayout(); - // w.mark("Layout size calculated (" + activeLayoutSize + - // ") offsetSize: " - // + getOffsetWidth() + "," + getOffsetHeight()); - - /* Render relative size components */ - for (int i = 0; i < relativeSizeComponents.size(); i++) { - ChildComponentContainer childComponentContainer = relativeSizeComponents - .get(i); - UIDL childUIDL = relativeSizeComponentUIDL.get(i); - - if (isDynamicWidth()) { - childComponentContainer.renderChild(childUIDL, client, -1); - } else { - childComponentContainer.renderChild(childUIDL, client, - activeLayoutSize.getWidth()); - } - - if (Util.isCached(childUIDL)) { - /* - * We must update the size of the relative sized component if - * the expand ratio or something else in the layout changes - * which affects the size of a relative sized component - */ - client.handleComponentRelativeSize(childComponentContainer - .getWidget()); - } - - // childComponentContainer.updateWidgetSize(); - } - - // w.mark("Rendering of " + (relativeSizeComponents.size()) - // + " relative size components done"); - - /* Fetch widget sizes for relative size components */ - for (ChildComponentContainer childComponentContainer : widgetToComponentContainer - .values()) { - - /* Update widget size from DOM */ - childComponentContainer.updateWidgetSize(); - } - - // w.mark("Widget sizes updated"); - - /* - * Components with relative size in main direction may affect the layout - * size in the other direction - */ - if ((isHorizontal() && isDynamicHeight()) - || (isVertical() && isDynamicWidth())) { - layoutSizeMightHaveChanged(); - } - // w.mark("Layout dimensions updated"); - - /* Update component spacing */ - updateContainerMargins(); - - /* - * Update component sizes for components with relative size in non-main - * direction - */ - if (updateRelativeSizesInNonMainDirection()) { - // Sizes updated - might affect the other dimension so we need to - // recheck the widget sizes and recalculate layout dimensions - updateWidgetSizes(); - layoutSizeMightHaveChanged(); - } - calculateAlignments(); - // w.mark("recalculateComponentSizesAndAlignments done"); - - setRootSize(); - - if (BrowserInfo.get().isIE()) { - /* - * This should fix the issue with padding not always taken into - * account for the containers leading to no spacing between - * elements. - */ - root.getStyle().setProperty("zoom", "1"); - } - - // w.mark("runDescendentsLayout done"); - isRendering = false; - sizeHasChangedDuringRendering = false; - } - - private void layoutSizeMightHaveChanged() { + void layoutSizeMightHaveChanged() { Size oldSize = new Size(activeLayoutSize.getWidth(), activeLayoutSize.getHeight()); calculateLayoutDimensions(); @@ -288,7 +74,7 @@ public class VOrderedLayout extends CellBasedLayout { } } - private void updateWidgetSizes() { + void updateWidgetSizes() { for (ChildComponentContainer childComponentContainer : widgetToComponentContainer .values()) { @@ -299,7 +85,7 @@ public class VOrderedLayout extends CellBasedLayout { } } - private void recalculateLayout() { + void recalculateLayout() { /* Calculate space for relative size components */ int spaceForExpansion = calculateLayoutDimensions(); @@ -340,30 +126,13 @@ public class VOrderedLayout extends CellBasedLayout { } - private void handleOrientationUpdate(UIDL uidl) { - int newOrientation = ORIENTATION_VERTICAL; - if ("horizontal".equals(uidl.getStringAttribute("orientation"))) { - newOrientation = ORIENTATION_HORIZONTAL; - } - - if (orientation != newOrientation) { - orientation = newOrientation; - - for (ChildComponentContainer childComponentContainer : widgetToComponentContainer - .values()) { - childComponentContainer.setOrientation(orientation); - } - } - - } - /** * Updated components with relative height in horizontal layouts and * components with relative width in vertical layouts. This is only needed * if the height (horizontal layout) or width (vertical layout) has not been * specified. */ - private boolean updateRelativeSizesInNonMainDirection() { + boolean updateRelativeSizesInNonMainDirection() { int updateDirection = 1 - orientation; if ((updateDirection == ORIENTATION_HORIZONTAL && !isDynamicWidth()) || (updateDirection == ORIENTATION_VERTICAL && !isDynamicHeight())) { @@ -468,7 +237,7 @@ public class VOrderedLayout extends CellBasedLayout { return widgetWidth; } - private void calculateAlignments() { + void calculateAlignments() { int w = 0; int h = 0; @@ -676,7 +445,7 @@ public class VOrderedLayout extends CellBasedLayout { * Updates the spacing between components. Needs to be done only when * components are added/removed. */ - private void updateContainerMargins() { + void updateContainerMargins() { ChildComponentContainer firstChildComponent = getFirstChildComponentContainer(); if (firstChildComponent != null) { firstChildComponent.setMarginLeft(0); @@ -697,15 +466,15 @@ public class VOrderedLayout extends CellBasedLayout { } } - private boolean isHorizontal() { + boolean isHorizontal() { return orientation == ORIENTATION_HORIZONTAL; } - private boolean isVertical() { + boolean isVertical() { return orientation == ORIENTATION_VERTICAL; } - private ChildComponentContainer createChildContainer(VPaintableWidget child) { + ChildComponentContainer createChildContainer(VPaintableWidget child) { // Create a container DIV for the child ChildComponentContainer childComponent = new ChildComponentContainer( @@ -783,7 +552,7 @@ public class VOrderedLayout extends CellBasedLayout { setRootSize(); } - private void setRootSize() { + void setRootSize() { root.getStyle().setPropertyPx("width", activeLayoutSize.getWidth()); root.getStyle().setPropertyPx("height", activeLayoutSize.getHeight()); } @@ -942,19 +711,6 @@ public class VOrderedLayout extends CellBasedLayout { } } - public void updateCaption(VPaintableWidget paintable, UIDL uidl) { - Widget widget = paintable.getWidgetForPaintable(); - ChildComponentContainer componentContainer = getComponentContainer(widget); - componentContainer.updateCaption(uidl, client); - if (!isRendering) { - /* - * This was a component-only update and the possible size change - * must be propagated to the layout - */ - client.captionSizeUpdated(widget); - } - } - /** * Returns the deepest nested child component which contains "element". The * child component is also returned if "element" is part of its caption. @@ -965,7 +721,7 @@ public class VOrderedLayout extends CellBasedLayout { * @return The Paintable which the element is a part of. Null if the element * belongs to the layout and not to a child. */ - private VPaintableWidget getComponent(Element element) { + VPaintableWidget getComponent(Element element) { return Util.getPaintableForElement(client, this, element); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java new file mode 100644 index 0000000000..4720e07099 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java @@ -0,0 +1,254 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayoutPaintable;
+import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;
+
+public abstract class VOrderedLayoutPaintable extends CellBasedLayoutPaintable {
+
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
+ this, EventId.LAYOUT_CLICK) {
+
+ @Override
+ protected VPaintableWidget getChildComponent(Element element) {
+ return getWidgetForPaintable().getComponent(element);
+ }
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateCaption(VPaintableWidget paintable, UIDL uidl) {
+ Widget widget = paintable.getWidgetForPaintable();
+ ChildComponentContainer componentContainer = getWidgetForPaintable()
+ .getComponentContainer(widget);
+ componentContainer.updateCaption(uidl, getConnection());
+ if (!getWidgetForPaintable().isRendering) {
+ /*
+ * This was a component-only update and the possible size change
+ * must be propagated to the layout
+ */
+ getConnection().captionSizeUpdated(widget);
+ }
+ }
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().isRendering = true;
+ super.updateFromUIDL(uidl, client);
+
+ // Only non-cached, visible UIDL:s can introduce changes
+ if (uidl.getBooleanAttribute("cached")
+ || uidl.getBooleanAttribute("invisible")) {
+ getWidgetForPaintable().isRendering = false;
+ return;
+ }
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ // IStopWatch w = new IStopWatch("OrderedLayout.updateFromUIDL");
+
+ ArrayList<Widget> uidlWidgets = new ArrayList<Widget>(
+ uidl.getChildCount());
+ ArrayList<ChildComponentContainer> relativeSizeComponents = new ArrayList<ChildComponentContainer>();
+ ArrayList<UIDL> relativeSizeComponentUIDL = new ArrayList<UIDL>();
+
+ int pos = 0;
+ for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {
+ final UIDL childUIDL = (UIDL) it.next();
+ final VPaintableWidget childPaintable = client
+ .getPaintable(childUIDL);
+ Widget widget = childPaintable.getWidgetForPaintable();
+
+ // Create container for component
+ ChildComponentContainer childComponentContainer = getWidgetForPaintable()
+ .getComponentContainer(widget);
+
+ if (childComponentContainer == null) {
+ // This is a new component
+ childComponentContainer = getWidgetForPaintable()
+ .createChildContainer(childPaintable);
+ } else {
+ /*
+ * The widget may be null if the same paintable has been
+ * rendered in a different component container while this has
+ * been invisible. Ensure the childComponentContainer has the
+ * widget attached. See e.g. #5372
+ */
+ childComponentContainer.setPaintable(childPaintable);
+ }
+
+ getWidgetForPaintable().addOrMoveChild(childComponentContainer,
+ pos++);
+
+ /*
+ * Components which are to be expanded in the same orientation as
+ * the layout are rendered later when it is clear how much space
+ * they can use
+ */
+ if (!Util.isCached(childUIDL)) {
+ FloatSize relativeSize = Util.parseRelativeSize(childUIDL);
+ childComponentContainer.setRelativeSize(relativeSize);
+ }
+
+ if (childComponentContainer
+ .isComponentRelativeSized(getWidgetForPaintable().orientation)) {
+ relativeSizeComponents.add(childComponentContainer);
+ relativeSizeComponentUIDL.add(childUIDL);
+ } else {
+ if (getWidgetForPaintable().isDynamicWidth()) {
+ childComponentContainer.renderChild(childUIDL, client, -1);
+ } else {
+ childComponentContainer
+ .renderChild(childUIDL, client,
+ getWidgetForPaintable().activeLayoutSize
+ .getWidth());
+ }
+ if (getWidgetForPaintable().sizeHasChangedDuringRendering
+ && Util.isCached(childUIDL)) {
+ // notify cached relative sized component about size
+ // chance
+ client.handleComponentRelativeSize(childComponentContainer
+ .getWidget());
+ }
+ }
+
+ uidlWidgets.add(widget);
+
+ }
+
+ // w.mark("Rendering of "
+ // + (uidlWidgets.size() - relativeSizeComponents.size())
+ // + " absolute size components done");
+
+ /*
+ * Remove any children after pos. These are the ones that previously
+ * were in the layout but have now been removed
+ */
+ getWidgetForPaintable().removeChildrenAfter(pos);
+
+ // w.mark("Old children removed");
+
+ /* Fetch alignments and expand ratio from UIDL */
+ getWidgetForPaintable().updateAlignmentsAndExpandRatios(uidl,
+ uidlWidgets);
+ // w.mark("Alignments and expand ratios updated");
+
+ /* Fetch widget sizes from rendered components */
+ getWidgetForPaintable().updateWidgetSizes();
+ // w.mark("Widget sizes updated");
+
+ getWidgetForPaintable().recalculateLayout();
+ // w.mark("Layout size calculated (" + activeLayoutSize +
+ // ") offsetSize: "
+ // + getOffsetWidth() + "," + getOffsetHeight());
+
+ /* Render relative size components */
+ for (int i = 0; i < relativeSizeComponents.size(); i++) {
+ ChildComponentContainer childComponentContainer = relativeSizeComponents
+ .get(i);
+ UIDL childUIDL = relativeSizeComponentUIDL.get(i);
+
+ if (getWidgetForPaintable().isDynamicWidth()) {
+ childComponentContainer.renderChild(childUIDL, client, -1);
+ } else {
+ childComponentContainer.renderChild(childUIDL, client,
+ getWidgetForPaintable().activeLayoutSize.getWidth());
+ }
+
+ if (Util.isCached(childUIDL)) {
+ /*
+ * We must update the size of the relative sized component if
+ * the expand ratio or something else in the layout changes
+ * which affects the size of a relative sized component
+ */
+ client.handleComponentRelativeSize(childComponentContainer
+ .getWidget());
+ }
+
+ // childComponentContainer.updateWidgetSize();
+ }
+
+ // w.mark("Rendering of " + (relativeSizeComponents.size())
+ // + " relative size components done");
+
+ /* Fetch widget sizes for relative size components */
+ for (ChildComponentContainer childComponentContainer : getWidgetForPaintable()
+ .getComponentContainers()) {
+
+ /* Update widget size from DOM */
+ childComponentContainer.updateWidgetSize();
+ }
+
+ // w.mark("Widget sizes updated");
+
+ /*
+ * Components with relative size in main direction may affect the layout
+ * size in the other direction
+ */
+ if ((getWidgetForPaintable().isHorizontal() && getWidgetForPaintable()
+ .isDynamicHeight())
+ || (getWidgetForPaintable().isVertical() && getWidgetForPaintable()
+ .isDynamicWidth())) {
+ getWidgetForPaintable().layoutSizeMightHaveChanged();
+ }
+ // w.mark("Layout dimensions updated");
+
+ /* Update component spacing */
+ getWidgetForPaintable().updateContainerMargins();
+
+ /*
+ * Update component sizes for components with relative size in non-main
+ * direction
+ */
+ if (getWidgetForPaintable().updateRelativeSizesInNonMainDirection()) {
+ // Sizes updated - might affect the other dimension so we need to
+ // recheck the widget sizes and recalculate layout dimensions
+ getWidgetForPaintable().updateWidgetSizes();
+ getWidgetForPaintable().layoutSizeMightHaveChanged();
+ }
+ getWidgetForPaintable().calculateAlignments();
+ // w.mark("recalculateComponentSizesAndAlignments done");
+
+ getWidgetForPaintable().setRootSize();
+
+ if (BrowserInfo.get().isIE()) {
+ /*
+ * This should fix the issue with padding not always taken into
+ * account for the containers leading to no spacing between
+ * elements.
+ */
+ getWidgetForPaintable().root.getStyle().setProperty("zoom", "1");
+ }
+
+ // w.mark("runDescendentsLayout done");
+ getWidgetForPaintable().isRendering = false;
+ getWidgetForPaintable().sizeHasChangedDuringRendering = false;
+ }
+
+ @Override
+ protected abstract VOrderedLayout createWidget();
+
+ @Override
+ public VOrderedLayout getWidgetForPaintable() {
+ return (VOrderedLayout) super.getWidgetForPaintable();
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java index 9eec275b59..354a42c4d5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java @@ -8,11 +8,8 @@ import java.util.Set; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.event.dom.client.DomEvent.Type; import com.google.gwt.event.dom.client.TouchStartEvent; import com.google.gwt.event.dom.client.TouchStartHandler; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; @@ -33,28 +30,27 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan public class VPanel extends SimplePanel implements Container, ShortcutActionHandlerOwner, Focusable { - public static final String CLICK_EVENT_IDENTIFIER = "click"; public static final String CLASSNAME = "v-panel"; ApplicationConnection client; String id; - private final Element captionNode = DOM.createDiv(); + final Element captionNode = DOM.createDiv(); private final Element captionText = DOM.createSpan(); private Icon icon; - private final Element bottomDecoration = DOM.createDiv(); + final Element bottomDecoration = DOM.createDiv(); - private final Element contentNode = DOM.createDiv(); + final Element contentNode = DOM.createDiv(); private Element errorIndicatorElement; private String height; - private VPaintableWidget layout; + VPaintableWidget layout; ShortcutActionHandler shortcutHandler; @@ -62,9 +58,9 @@ public class VPanel extends SimplePanel implements Container, private Element geckoCaptionMeter; - private int scrollTop; + int scrollTop; - private int scrollLeft; + int scrollLeft; private RenderInformation renderInformation = new RenderInformation(); @@ -76,21 +72,12 @@ public class VPanel extends SimplePanel implements Container, private int captionMarginLeft = -1; - private boolean rendering; + boolean rendering; private int contentMarginLeft = -1; private String previousStyleName; - private ClickEventHandler clickEventHandler = new ClickEventHandler(this, - CLICK_EVENT_IDENTIFIER) { - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; private TouchScrollDelegate touchScrollDelegate; public VPanel() { @@ -157,129 +144,10 @@ public class VPanel extends SimplePanel implements Container, return contentNode; } - private void setCaption(String text) { + void setCaption(String text) { DOM.setInnerHTML(captionText, text); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - if (!uidl.hasAttribute("cached")) { - - // Handle caption displaying and style names, prior generics. - // Affects size - // calculations - - // Restore default stylenames - contentNode.setClassName(CLASSNAME + "-content"); - bottomDecoration.setClassName(CLASSNAME + "-deco"); - captionNode.setClassName(CLASSNAME + "-caption"); - boolean hasCaption = false; - if (uidl.hasAttribute("caption") - && !uidl.getStringAttribute("caption").equals("")) { - setCaption(uidl.getStringAttribute("caption")); - hasCaption = true; - } else { - setCaption(""); - captionNode.setClassName(CLASSNAME + "-nocaption"); - } - - // Add proper stylenames for all elements. This way we can prevent - // unwanted CSS selector inheritance. - if (uidl.hasAttribute("style")) { - final String[] styles = uidl.getStringAttribute("style").split( - " "); - final String captionBaseClass = CLASSNAME - + (hasCaption ? "-caption" : "-nocaption"); - final String contentBaseClass = CLASSNAME + "-content"; - final String decoBaseClass = CLASSNAME + "-deco"; - String captionClass = captionBaseClass; - String contentClass = contentBaseClass; - String decoClass = decoBaseClass; - for (int i = 0; i < styles.length; i++) { - captionClass += " " + captionBaseClass + "-" + styles[i]; - contentClass += " " + contentBaseClass + "-" + styles[i]; - decoClass += " " + decoBaseClass + "-" + styles[i]; - } - captionNode.setClassName(captionClass); - contentNode.setClassName(contentClass); - bottomDecoration.setClassName(decoClass); - - } - } - // Ensure correct implementation - if (client.updateComponent(this, uidl, false)) { - rendering = false; - return; - } - - clickEventHandler.handleEventHandlerRegistration(client); - - this.client = client; - id = uidl.getId(); - - setIconUri(uidl, client); - - handleError(uidl); - - // Render content - final UIDL layoutUidl = uidl.getChildUIDL(0); - final VPaintableWidget newLayout = client.getPaintable(layoutUidl); - if (newLayout != layout) { - if (layout != null) { - client.unregisterPaintable(layout); - } - setWidget(newLayout.getWidgetForPaintable()); - layout = newLayout; - } - layout.updateFromUIDL(layoutUidl, client); - - // We may have actions attached to this panel - if (uidl.getChildCount() > 1) { - final int cnt = uidl.getChildCount(); - for (int i = 1; i < cnt; i++) { - UIDL childUidl = uidl.getChildUIDL(i); - if (childUidl.getTag().equals("actions")) { - if (shortcutHandler == null) { - shortcutHandler = new ShortcutActionHandler(id, client); - } - shortcutHandler.updateActionMap(childUidl); - } - } - } - - if (uidl.hasVariable("scrollTop") - && uidl.getIntVariable("scrollTop") != scrollTop) { - scrollTop = uidl.getIntVariable("scrollTop"); - contentNode.setScrollTop(scrollTop); - // re-read the actual scrollTop in case invalid value was set - // (scrollTop != 0 when no scrollbar exists, other values would be - // caught by scroll listener), see #3784 - scrollTop = contentNode.getScrollTop(); - } - - if (uidl.hasVariable("scrollLeft") - && uidl.getIntVariable("scrollLeft") != scrollLeft) { - scrollLeft = uidl.getIntVariable("scrollLeft"); - contentNode.setScrollLeft(scrollLeft); - // re-read the actual scrollTop in case invalid value was set - // (scrollTop != 0 when no scrollbar exists, other values would be - // caught by scroll listener), see #3784 - scrollLeft = contentNode.getScrollLeft(); - } - - // Must be run after scrollTop is set as Webkit overflow fix re-sets the - // scrollTop - runHacks(false); - - // And apply tab index - if (uidl.hasVariable("tabindex")) { - contentNode.setTabIndex(uidl.getIntVariable("tabindex")); - } - - rendering = false; - - } - @Override public void setStyleName(String style) { if (!style.equals(previousStyleName)) { @@ -289,7 +157,7 @@ public class VPanel extends SimplePanel implements Container, } } - private void handleError(UIDL uidl) { + void handleError(UIDL uidl) { if (uidl.hasAttribute("error")) { if (errorIndicatorElement == null) { errorIndicatorElement = DOM.createSpan(); @@ -305,7 +173,7 @@ public class VPanel extends SimplePanel implements Container, } } - private void setIconUri(UIDL uidl, ApplicationConnection client) { + void setIconUri(UIDL uidl, ApplicationConnection client) { final String iconUri = uidl.hasAttribute("icon") ? uidl .getStringAttribute("icon") : null; if (iconUri == null) { @@ -394,7 +262,7 @@ public class VPanel extends SimplePanel implements Container, } } else if (captionNode.isOrHasChild(target)) { if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } } @@ -554,10 +422,6 @@ public class VPanel extends SimplePanel implements Container, return !renderInformation.updateSize(getElement()); } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // NOP: layouts caption, errors etc not rendered in Panel - } - @Override protected void onAttach() { super.onAttach(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java new file mode 100644 index 0000000000..198d7f4020 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java @@ -0,0 +1,175 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VPanelPaintable extends VAbstractPaintableWidgetContainer {
+
+ public static final String CLICK_EVENT_IDENTIFIER = "click";
+
+ private ClickEventHandler clickEventHandler = new ClickEventHandler(this,
+ CLICK_EVENT_IDENTIFIER) {
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ if (!uidl.hasAttribute("cached")) {
+
+ // Handle caption displaying and style names, prior generics.
+ // Affects size
+ // calculations
+
+ // Restore default stylenames
+ getWidgetForPaintable().contentNode.setClassName(VPanel.CLASSNAME
+ + "-content");
+ getWidgetForPaintable().bottomDecoration
+ .setClassName(VPanel.CLASSNAME + "-deco");
+ getWidgetForPaintable().captionNode.setClassName(VPanel.CLASSNAME
+ + "-caption");
+ boolean hasCaption = false;
+ if (uidl.hasAttribute("caption")
+ && !uidl.getStringAttribute("caption").equals("")) {
+ getWidgetForPaintable().setCaption(
+ uidl.getStringAttribute("caption"));
+ hasCaption = true;
+ } else {
+ getWidgetForPaintable().setCaption("");
+ getWidgetForPaintable().captionNode
+ .setClassName(VPanel.CLASSNAME + "-nocaption");
+ }
+
+ // Add proper stylenames for all elements. This way we can prevent
+ // unwanted CSS selector inheritance.
+ if (uidl.hasAttribute("style")) {
+ final String[] styles = uidl.getStringAttribute("style").split(
+ " ");
+ final String captionBaseClass = VPanel.CLASSNAME
+ + (hasCaption ? "-caption" : "-nocaption");
+ final String contentBaseClass = VPanel.CLASSNAME + "-content";
+ final String decoBaseClass = VPanel.CLASSNAME + "-deco";
+ String captionClass = captionBaseClass;
+ String contentClass = contentBaseClass;
+ String decoClass = decoBaseClass;
+ for (int i = 0; i < styles.length; i++) {
+ captionClass += " " + captionBaseClass + "-" + styles[i];
+ contentClass += " " + contentBaseClass + "-" + styles[i];
+ decoClass += " " + decoBaseClass + "-" + styles[i];
+ }
+ getWidgetForPaintable().captionNode.setClassName(captionClass);
+ getWidgetForPaintable().contentNode.setClassName(contentClass);
+ getWidgetForPaintable().bottomDecoration
+ .setClassName(decoClass);
+
+ }
+ }
+ // Ensure correct implementation
+ if (client.updateComponent(this, uidl, false)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ getWidgetForPaintable().setIconUri(uidl, client);
+
+ getWidgetForPaintable().handleError(uidl);
+
+ // Render content
+ final UIDL layoutUidl = uidl.getChildUIDL(0);
+ final VPaintableWidget newLayout = client.getPaintable(layoutUidl);
+ if (newLayout != getWidgetForPaintable().layout) {
+ if (getWidgetForPaintable().layout != null) {
+ client.unregisterPaintable(getWidgetForPaintable().layout);
+ }
+ getWidgetForPaintable()
+ .setWidget(newLayout.getWidgetForPaintable());
+ getWidgetForPaintable().layout = newLayout;
+ }
+ getWidgetForPaintable().layout.updateFromUIDL(layoutUidl, client);
+
+ // We may have actions attached to this panel
+ if (uidl.getChildCount() > 1) {
+ final int cnt = uidl.getChildCount();
+ for (int i = 1; i < cnt; i++) {
+ UIDL childUidl = uidl.getChildUIDL(i);
+ if (childUidl.getTag().equals("actions")) {
+ if (getWidgetForPaintable().shortcutHandler == null) {
+ getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(
+ getId(), client);
+ }
+ getWidgetForPaintable().shortcutHandler
+ .updateActionMap(childUidl);
+ }
+ }
+ }
+
+ if (uidl.hasVariable("scrollTop")
+ && uidl.getIntVariable("scrollTop") != getWidgetForPaintable().scrollTop) {
+ getWidgetForPaintable().scrollTop = uidl
+ .getIntVariable("scrollTop");
+ getWidgetForPaintable().contentNode
+ .setScrollTop(getWidgetForPaintable().scrollTop);
+ // re-read the actual scrollTop in case invalid value was set
+ // (scrollTop != 0 when no scrollbar exists, other values would be
+ // caught by scroll listener), see #3784
+ getWidgetForPaintable().scrollTop = getWidgetForPaintable().contentNode
+ .getScrollTop();
+ }
+
+ if (uidl.hasVariable("scrollLeft")
+ && uidl.getIntVariable("scrollLeft") != getWidgetForPaintable().scrollLeft) {
+ getWidgetForPaintable().scrollLeft = uidl
+ .getIntVariable("scrollLeft");
+ getWidgetForPaintable().contentNode
+ .setScrollLeft(getWidgetForPaintable().scrollLeft);
+ // re-read the actual scrollTop in case invalid value was set
+ // (scrollTop != 0 when no scrollbar exists, other values would be
+ // caught by scroll listener), see #3784
+ getWidgetForPaintable().scrollLeft = getWidgetForPaintable().contentNode
+ .getScrollLeft();
+ }
+
+ // Must be run after scrollTop is set as Webkit overflow fix re-sets the
+ // scrollTop
+ getWidgetForPaintable().runHacks(false);
+
+ // And apply tab index
+ if (uidl.hasVariable("tabindex")) {
+ getWidgetForPaintable().contentNode.setTabIndex(uidl
+ .getIntVariable("tabindex"));
+ }
+
+ getWidgetForPaintable().rendering = false;
+
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP: layouts caption, errors etc not rendered in Panel
+ }
+
+ @Override
+ public VPanel getWidgetForPaintable() {
+ return (VPanel) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VPanel.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPasswordFieldPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPasswordFieldPaintable.java new file mode 100644 index 0000000000..98be1250a3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPasswordFieldPaintable.java @@ -0,0 +1,28 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VPasswordFieldPaintable extends VTextFieldPaintable { + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + } + + @Override + protected Widget createWidget() { + return GWT.create(VPasswordField.class); + } + + @Override + public VPasswordField getWidgetForPaintable() { + return (VPasswordField) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 44fb9ac69c..223e13c8d7 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -21,16 +21,10 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.DateTimeService;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole;
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener;
-import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;
/**
* Represents a date selection component with a text field and a popup date
@@ -42,19 +36,19 @@ import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; * <code>setCalendarPanel(VCalendarPanel panel)</code> method.
*
*/
-public class VPopupCalendar extends VTextualDate implements VPaintableWidget,
- Field, ClickHandler, CloseHandler<PopupPanel>, SubPartAware {
+public class VPopupCalendar extends VTextualDate implements Field,
+ ClickHandler, CloseHandler<PopupPanel>, SubPartAware {
- private static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME
+ protected static final String POPUP_PRIMARY_STYLE_NAME = VDateField.CLASSNAME
+ "-popup";
- private final Button calendarToggle;
+ protected final Button calendarToggle;
- private VCalendarPanel calendar;
+ protected VCalendarPanel calendar;
- private final VOverlay popup;
+ protected final VOverlay popup;
private boolean open = false;
- private boolean parsable = true;
+ protected boolean parsable = true;
public VPopupCalendar() {
super();
@@ -105,7 +99,7 @@ public class VPopupCalendar extends VTextualDate implements VPaintableWidget, }
@SuppressWarnings("deprecation")
- private void updateValue(Date newDate) {
+ protected void updateValue(Date newDate) {
Date currentDate = getCurrentDate();
if (currentDate == null || newDate.getTime() != currentDate.getTime()) {
setCurrentDate((Date) newDate.clone());
@@ -141,96 +135,6 @@ public class VPopupCalendar extends VTextualDate implements VPaintableWidget, * (non-Javadoc)
*
* @see
- * com.vaadin.terminal.gwt.client.ui.VTextualDate#updateFromUIDL(com.vaadin
- * .terminal.gwt.client.UIDL,
- * com.vaadin.terminal.gwt.client.ApplicationConnection)
- */
- @Override
- @SuppressWarnings("deprecation")
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- boolean lastReadOnlyState = readonly;
- boolean lastEnabledState = isEnabled();
-
- parsable = uidl.getBooleanAttribute("parsable");
-
- super.updateFromUIDL(uidl, client);
-
- String popupStyleNames = ApplicationConnection.getStyleName(
- POPUP_PRIMARY_STYLE_NAME, uidl, false);
- popupStyleNames += " " + VDateField.CLASSNAME + "-"
- + resolutionToString(currentResolution);
- popup.setStyleName(popupStyleNames);
-
- calendar.setDateTimeService(getDateTimeService());
- calendar.setShowISOWeekNumbers(isShowISOWeekNumbers());
- if (calendar.getResolution() != currentResolution) {
- calendar.setResolution(currentResolution);
- if (calendar.getDate() != null) {
- calendar.setDate((Date) getCurrentDate().clone());
- // force re-render when changing resolution only
- calendar.renderCalendar();
- }
- }
- calendarToggle.setEnabled(enabled);
-
- if (currentResolution <= RESOLUTION_MONTH) {
- calendar.setFocusChangeListener(new FocusChangeListener() {
- public void focusChanged(Date date) {
- updateValue(date);
- buildDate();
- Date date2 = calendar.getDate();
- date2.setYear(date.getYear());
- date2.setMonth(date.getMonth());
- }
- });
- } else {
- calendar.setFocusChangeListener(null);
- }
-
- if (currentResolution > RESOLUTION_DAY) {
- calendar.setTimeChangeListener(new TimeChangeListener() {
- public void changed(int hour, int min, int sec, int msec) {
- Date d = getDate();
- if (d == null) {
- // date currently null, use the value from calendarPanel
- // (~ client time at the init of the widget)
- d = (Date) calendar.getDate().clone();
- }
- d.setHours(hour);
- d.setMinutes(min);
- d.setSeconds(sec);
- DateTimeService.setMilliseconds(d, msec);
-
- // Always update time changes to the server
- updateValue(d);
-
- // Update text field
- buildDate();
- }
- });
- }
-
- if (readonly) {
- calendarToggle.addStyleName(CLASSNAME + "-button-readonly");
- } else {
- calendarToggle.removeStyleName(CLASSNAME + "-button-readonly");
- }
-
- if (lastReadOnlyState != readonly || lastEnabledState != isEnabled()) {
- // Enabled or readonly state changed. Differences in theming might
- // affect the width (for instance if the popup button is hidden) so
- // we have to recalculate the width (IF the width of the field is
- // fixed)
- updateWidth();
- }
-
- calendarToggle.setEnabled(true);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
* com.google.gwt.user.client.ui.UIObject#setStyleName(java.lang.String)
*/
@Override
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java new file mode 100644 index 0000000000..96e966a993 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java @@ -0,0 +1,138 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import java.util.Date; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.DateTimeService; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener; +import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener; + +public class VPopupCalendarPaintable extends VTextualDatePaintable { + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.terminal.gwt.client.ui.VTextualDate#updateFromUIDL(com.vaadin + * .terminal.gwt.client.UIDL, + * com.vaadin.terminal.gwt.client.ApplicationConnection) + */ + @Override + @SuppressWarnings("deprecation") + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + boolean lastReadOnlyState = getWidgetForPaintable().readonly; + boolean lastEnabledState = getWidgetForPaintable().isEnabled(); + + getWidgetForPaintable().parsable = uidl.getBooleanAttribute("parsable"); + + super.updateFromUIDL(uidl, client); + + String popupStyleNames = ApplicationConnection.getStyleName( + VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false); + popupStyleNames += " " + + VDateField.CLASSNAME + + "-" + + VPopupCalendar + .resolutionToString(getWidgetForPaintable().currentResolution); + getWidgetForPaintable().popup.setStyleName(popupStyleNames); + + getWidgetForPaintable().calendar + .setDateTimeService(getWidgetForPaintable() + .getDateTimeService()); + getWidgetForPaintable().calendar + .setShowISOWeekNumbers(getWidgetForPaintable() + .isShowISOWeekNumbers()); + if (getWidgetForPaintable().calendar.getResolution() != getWidgetForPaintable().currentResolution) { + getWidgetForPaintable().calendar + .setResolution(getWidgetForPaintable().currentResolution); + if (getWidgetForPaintable().calendar.getDate() != null) { + getWidgetForPaintable().calendar + .setDate((Date) getWidgetForPaintable() + .getCurrentDate().clone()); + // force re-render when changing resolution only + getWidgetForPaintable().calendar.renderCalendar(); + } + } + getWidgetForPaintable().calendarToggle + .setEnabled(getWidgetForPaintable().enabled); + + if (getWidgetForPaintable().currentResolution <= VPopupCalendar.RESOLUTION_MONTH) { + getWidgetForPaintable().calendar + .setFocusChangeListener(new FocusChangeListener() { + public void focusChanged(Date date) { + getWidgetForPaintable().updateValue(date); + getWidgetForPaintable().buildDate(); + Date date2 = getWidgetForPaintable().calendar + .getDate(); + date2.setYear(date.getYear()); + date2.setMonth(date.getMonth()); + } + }); + } else { + getWidgetForPaintable().calendar.setFocusChangeListener(null); + } + + if (getWidgetForPaintable().currentResolution > VPopupCalendar.RESOLUTION_DAY) { + getWidgetForPaintable().calendar + .setTimeChangeListener(new TimeChangeListener() { + public void changed(int hour, int min, int sec, int msec) { + Date d = getWidgetForPaintable().getDate(); + if (d == null) { + // date currently null, use the value from + // calendarPanel + // (~ client time at the init of the widget) + d = (Date) getWidgetForPaintable().calendar + .getDate().clone(); + } + d.setHours(hour); + d.setMinutes(min); + d.setSeconds(sec); + DateTimeService.setMilliseconds(d, msec); + + // Always update time changes to the server + getWidgetForPaintable().updateValue(d); + + // Update text field + getWidgetForPaintable().buildDate(); + } + }); + } + + if (getWidgetForPaintable().readonly) { + getWidgetForPaintable().calendarToggle + .addStyleName(VPopupCalendar.CLASSNAME + "-button-readonly"); + } else { + getWidgetForPaintable().calendarToggle + .removeStyleName(VPopupCalendar.CLASSNAME + + "-button-readonly"); + } + + if (lastReadOnlyState != getWidgetForPaintable().readonly + || lastEnabledState != getWidgetForPaintable().isEnabled()) { + // Enabled or readonly state changed. Differences in theming might + // affect the width (for instance if the popup button is hidden) so + // we have to recalculate the width (IF the width of the field is + // fixed) + getWidgetForPaintable().updateWidth(); + } + + getWidgetForPaintable().calendarToggle.setEnabled(true); + } + + @Override + protected Widget createWidget() { + return GWT.create(VPopupCalendar.class); + } + + @Override + public VPopupCalendar getWidgetForPaintable() { + return (VPopupCalendar) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java index e667489dda..34bf0ca619 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java @@ -29,7 +29,6 @@ import com.vaadin.terminal.gwt.client.RenderInformation.Size; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.VCaptionWrapper; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; @@ -40,13 +39,13 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> { public static final String CLASSNAME = "v-popupview"; /** For server-client communication */ - private String uidlId; - private ApplicationConnection client; + String uidlId; + ApplicationConnection client; /** This variable helps to communicate popup visibility to the server */ - private boolean hostPopupVisible; + boolean hostPopupVisible; - private final CustomPopup popup; + final CustomPopup popup; private final Label loading = new Label(); /** @@ -82,61 +81,6 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> { } /** - * - * - * @see com.vaadin.terminal.gwt.client.VPaintableWidget#updateFromUIDL(com.vaadin.terminal.gwt.client.UIDL, - * com.vaadin.terminal.gwt.client.ApplicationConnection) - */ - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // This call should be made first. Ensure correct implementation, - // and don't let the containing layout manage caption. - if (client.updateComponent(this, uidl, false)) { - return; - } - // These are for future server connections - this.client = client; - uidlId = uidl.getId(); - - hostPopupVisible = uidl.getBooleanVariable("popupVisibility"); - - setHTML(uidl.getStringAttribute("html")); - - if (uidl.hasAttribute("hideOnMouseOut")) { - popup.setHideOnMouseOut(uidl.getBooleanAttribute("hideOnMouseOut")); - } - - // Render the popup if visible and show it. - if (hostPopupVisible) { - UIDL popupUIDL = uidl.getChildUIDL(0); - - // showPopupOnTop(popup, hostReference); - preparePopup(popup); - popup.updateFromUIDL(popupUIDL, client); - if (uidl.hasAttribute("style")) { - final String[] styles = uidl.getStringAttribute("style").split( - " "); - final StringBuffer styleBuf = new StringBuffer(); - final String primaryName = popup.getStylePrimaryName(); - styleBuf.append(primaryName); - for (int i = 0; i < styles.length; i++) { - styleBuf.append(" "); - styleBuf.append(primaryName); - styleBuf.append("-"); - styleBuf.append(styles[i]); - } - popup.setStyleName(styleBuf.toString()); - } else { - popup.setStyleName(popup.getStylePrimaryName()); - } - showPopup(popup); - - // The popup shouldn't be visible, try to hide it. - } else { - popup.hide(); - } - }// updateFromUIDL - - /** * Update popup visibility to server * * @param visibility @@ -149,7 +93,7 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> { } } - private void preparePopup(final CustomPopup popup) { + void preparePopup(final CustomPopup popup) { popup.setVisible(false); popup.show(); } @@ -231,8 +175,8 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> { protected class CustomPopup extends VOverlay { private VPaintableWidget popupComponentPaintable = null; - private Widget popupComponentWidget = null; - private VCaptionWrapper captionWrapper = null; + Widget popupComponentWidget = null; + VCaptionWrapper captionWrapper = null; private boolean hasHadMouseOver = false; private boolean hideOnMouseOut = true; @@ -446,27 +390,11 @@ public class VPopupView extends HTML implements Container, Iterable<Widget> { return true; } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - if (VCaption.isNeeded(uidl)) { - if (popup.captionWrapper != null) { - popup.captionWrapper.updateCaption(uidl); - } else { - popup.captionWrapper = new VCaptionWrapper(component, client); - popup.setWidget(popup.captionWrapper); - popup.captionWrapper.updateCaption(uidl); - } - } else { - if (popup.captionWrapper != null) { - popup.setWidget(popup.popupComponentWidget); - } - } - } - @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java new file mode 100644 index 0000000000..627f925d77 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java @@ -0,0 +1,104 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VCaption;
+import com.vaadin.terminal.gwt.client.VCaptionWrapper;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VPopupViewPaintable extends VAbstractPaintableWidgetContainer {
+
+ /**
+ *
+ *
+ * @see com.vaadin.terminal.gwt.client.VPaintableWidget#updateFromUIDL(com.vaadin.terminal.gwt.client.UIDL,
+ * com.vaadin.terminal.gwt.client.ApplicationConnection)
+ */
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ // This call should be made first. Ensure correct implementation,
+ // and don't let the containing layout manage caption.
+ if (client.updateComponent(this, uidl, false)) {
+ return;
+ }
+ // These are for future server connections
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().uidlId = uidl.getId();
+
+ getWidgetForPaintable().hostPopupVisible = uidl
+ .getBooleanVariable("popupVisibility");
+
+ getWidgetForPaintable().setHTML(uidl.getStringAttribute("html"));
+
+ if (uidl.hasAttribute("hideOnMouseOut")) {
+ getWidgetForPaintable().popup.setHideOnMouseOut(uidl
+ .getBooleanAttribute("hideOnMouseOut"));
+ }
+
+ // Render the popup if visible and show it.
+ if (getWidgetForPaintable().hostPopupVisible) {
+ UIDL popupUIDL = uidl.getChildUIDL(0);
+
+ // showPopupOnTop(popup, hostReference);
+ getWidgetForPaintable().preparePopup(getWidgetForPaintable().popup);
+ getWidgetForPaintable().popup.updateFromUIDL(popupUIDL, client);
+ if (uidl.hasAttribute("style")) {
+ final String[] styles = uidl.getStringAttribute("style").split(
+ " ");
+ final StringBuffer styleBuf = new StringBuffer();
+ final String primaryName = getWidgetForPaintable().popup
+ .getStylePrimaryName();
+ styleBuf.append(primaryName);
+ for (int i = 0; i < styles.length; i++) {
+ styleBuf.append(" ");
+ styleBuf.append(primaryName);
+ styleBuf.append("-");
+ styleBuf.append(styles[i]);
+ }
+ getWidgetForPaintable().popup.setStyleName(styleBuf.toString());
+ } else {
+ getWidgetForPaintable().popup
+ .setStyleName(getWidgetForPaintable().popup
+ .getStylePrimaryName());
+ }
+ getWidgetForPaintable().showPopup(getWidgetForPaintable().popup);
+
+ // The popup shouldn't be visible, try to hide it.
+ } else {
+ getWidgetForPaintable().popup.hide();
+ }
+ }// updateFromUIDL
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ if (VCaption.isNeeded(uidl)) {
+ if (getWidgetForPaintable().popup.captionWrapper != null) {
+ getWidgetForPaintable().popup.captionWrapper
+ .updateCaption(uidl);
+ } else {
+ getWidgetForPaintable().popup.captionWrapper = new VCaptionWrapper(
+ component, getConnection());
+ getWidgetForPaintable().popup
+ .setWidget(getWidgetForPaintable().popup.captionWrapper);
+ getWidgetForPaintable().popup.captionWrapper
+ .updateCaption(uidl);
+ }
+ } else {
+ if (getWidgetForPaintable().popup.captionWrapper != null) {
+ getWidgetForPaintable().popup
+ .setWidget(getWidgetForPaintable().popup.popupComponentWidget);
+ }
+ }
+ }
+
+ @Override
+ public VPopupView getWidgetForPaintable() {
+ return (VPopupView) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VPopupView.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicator.java b/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicator.java index f7cc4240b7..cff6bf89bd 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicator.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicator.java @@ -9,20 +9,18 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -public class VProgressIndicator extends Widget implements VPaintableWidget { +public class VProgressIndicator extends Widget { - private static final String CLASSNAME = "v-progressindicator"; + public static final String CLASSNAME = "v-progressindicator"; Element wrapper = DOM.createDiv(); Element indicator = DOM.createDiv(); - private ApplicationConnection client; - private final Poller poller; - private boolean indeterminate = false; + protected ApplicationConnection client; + protected final Poller poller; + protected boolean indeterminate = false; private boolean pollerSuspendedDueDetach; - private int interval; + protected int interval; public VProgressIndicator() { setElement(DOM.createDiv()); @@ -34,38 +32,6 @@ public class VProgressIndicator extends Widget implements VPaintableWidget { poller = new Poller(); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - if (!uidl.getBooleanAttribute("cached")) { - poller.cancel(); - } - if (client.updateComponent(this, uidl, true)) { - return; - } - - indeterminate = uidl.getBooleanAttribute("indeterminate"); - - if (indeterminate) { - String basename = CLASSNAME + "-indeterminate"; - VProgressIndicator.setStyleName(getElement(), basename, true); - VProgressIndicator.setStyleName(getElement(), basename - + "-disabled", uidl.getBooleanAttribute("disabled")); - } else { - try { - final float f = Float.parseFloat(uidl - .getStringAttribute("state")); - final int size = Math.round(100 * f); - DOM.setStyleAttribute(indicator, "width", size + "%"); - } catch (final Exception e) { - } - } - - if (!uidl.getBooleanAttribute("disabled")) { - interval = uidl.getIntAttribute("pollinginterval"); - poller.scheduleRepeating(interval); - } - } - @Override protected void onAttach() { super.onAttach(); @@ -102,9 +68,4 @@ public class VProgressIndicator extends Widget implements VPaintableWidget { } } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java new file mode 100644 index 0000000000..39ffe1ad96 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java @@ -0,0 +1,65 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VProgressIndicatorPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + // Ensure correct implementation, + // but don't let container manage caption etc. + if (client.updateComponent(this, uidl, false)) { + return; + } + + // Save details + getWidgetForPaintable().client = client; + + getWidgetForPaintable().indeterminate = uidl + .getBooleanAttribute("indeterminate"); + + if (getWidgetForPaintable().indeterminate) { + String basename = VProgressIndicator.CLASSNAME + "-indeterminate"; + getWidgetForPaintable().addStyleName(basename); + if (uidl.getBooleanAttribute("disabled")) { + getWidgetForPaintable().addStyleName(basename + "-disabled"); + } else { + getWidgetForPaintable().removeStyleName(basename + "-disabled"); + } + } else { + try { + final float f = Float.parseFloat(uidl + .getStringAttribute("state")); + final int size = Math.round(100 * f); + DOM.setStyleAttribute(getWidgetForPaintable().indicator, + "width", size + "%"); + } catch (final Exception e) { + } + } + + if (!uidl.getBooleanAttribute("disabled")) { + getWidgetForPaintable().interval = uidl + .getIntAttribute("pollinginterval"); + getWidgetForPaintable().poller + .scheduleRepeating(getWidgetForPaintable().interval); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VProgressIndicator.class); + } + + @Override + public VProgressIndicator getWidgetForPaintable() { + return (VProgressIndicator) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSlider.java b/src/com/vaadin/terminal/gwt/client/ui/VSlider.java index 3632e90956..9fbbeb7181 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSlider.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSlider.java @@ -17,13 +17,11 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ContainerResizedListener;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
-public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
- Field, ContainerResizedListener {
+public class VSlider extends SimpleFocusablePanel implements Field,
+ ContainerResizedListener {
public static final String CLASSNAME = "v-slider";
@@ -37,16 +35,16 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, String id;
- private boolean immediate;
- private boolean disabled;
- private boolean readonly;
+ boolean immediate;
+ boolean disabled;
+ boolean readonly;
private int acceleration = 1;
- private double min;
- private double max;
- private int resolution;
- private Double value;
- private boolean vertical;
+ double min;
+ double max;
+ int resolution;
+ Double value;
+ boolean vertical;
private final HTML feedback = new HTML("", false);
private final VOverlay feedbackPopup = new VOverlay(true, false, true) {
@@ -113,57 +111,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, feedbackPopup.setWidget(feedback);
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- this.client = client;
- id = uidl.getId();
-
- // Ensure correct implementation
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
-
- immediate = uidl.getBooleanAttribute("immediate");
- disabled = uidl.getBooleanAttribute("disabled");
- readonly = uidl.getBooleanAttribute("readonly");
-
- vertical = uidl.hasAttribute("vertical");
-
- String style = "";
- if (uidl.hasAttribute("style")) {
- style = uidl.getStringAttribute("style");
- }
-
- if (vertical) {
- addStyleName(CLASSNAME + "-vertical");
- } else {
- removeStyleName(CLASSNAME + "-vertical");
- }
-
- min = uidl.getDoubleAttribute("min");
- max = uidl.getDoubleAttribute("max");
- resolution = uidl.getIntAttribute("resolution");
- value = new Double(uidl.getDoubleVariable("value"));
-
- setFeedbackValue(value);
-
- buildBase();
-
- if (!vertical) {
- // Draw handle with a delay to allow base to gain maximum width
- Scheduler.get().scheduleDeferred(new Command() {
- public void execute() {
- buildHandle();
- setValue(value, false);
- }
- });
- } else {
- buildHandle();
- setValue(value, false);
- }
- }
-
- private void setFeedbackValue(double value) {
+ void setFeedbackValue(double value) {
String currentValue = "" + value;
if (resolution == 0) {
currentValue = "" + new Double(value).intValue();
@@ -186,7 +134,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, }
}
- private void buildBase() {
+ void buildBase() {
final String styleAttribute = vertical ? "height" : "width";
final String domProperty = vertical ? "offsetHeight" : "offsetWidth";
@@ -220,7 +168,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, // TODO attach listeners for focusing and arrow keys
}
- private void buildHandle() {
+ void buildHandle() {
final String handleAttribute = vertical ? "marginTop" : "marginLeft";
DOM.setStyleAttribute(handle, handleAttribute, "0");
@@ -230,7 +178,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, }
- private void setValue(Double value, boolean updateToServer) {
+ void setValue(Double value, boolean updateToServer) {
if (value == null) {
return;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java new file mode 100644 index 0000000000..f5b8c8a45e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java @@ -0,0 +1,78 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VSliderPaintable extends VAbstractPaintableWidget {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ // Ensure correct implementation
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().immediate = uidl
+ .getBooleanAttribute("immediate");
+ getWidgetForPaintable().disabled = uidl.getBooleanAttribute("disabled");
+ getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly");
+
+ getWidgetForPaintable().vertical = uidl.hasAttribute("vertical");
+
+ String style = "";
+ if (uidl.hasAttribute("style")) {
+ style = uidl.getStringAttribute("style");
+ }
+
+ if (getWidgetForPaintable().vertical) {
+ getWidgetForPaintable().addStyleName(
+ VSlider.CLASSNAME + "-vertical");
+ } else {
+ getWidgetForPaintable().removeStyleName(
+ VSlider.CLASSNAME + "-vertical");
+ }
+
+ getWidgetForPaintable().min = uidl.getDoubleAttribute("min");
+ getWidgetForPaintable().max = uidl.getDoubleAttribute("max");
+ getWidgetForPaintable().resolution = uidl.getIntAttribute("resolution");
+ getWidgetForPaintable().value = new Double(
+ uidl.getDoubleVariable("value"));
+
+ getWidgetForPaintable().setFeedbackValue(getWidgetForPaintable().value);
+
+ getWidgetForPaintable().buildBase();
+
+ if (!getWidgetForPaintable().vertical) {
+ // Draw handle with a delay to allow base to gain maximum width
+ Scheduler.get().scheduleDeferred(new Command() {
+ public void execute() {
+ getWidgetForPaintable().buildHandle();
+ getWidgetForPaintable().setValue(
+ getWidgetForPaintable().value, false);
+ }
+ });
+ } else {
+ getWidgetForPaintable().buildHandle();
+ getWidgetForPaintable().setValue(getWidgetForPaintable().value,
+ false);
+ }
+ }
+
+ @Override
+ public VSlider getWidgetForPaintable() {
+ return (VSlider) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VSlider.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java index ff1e2e6b78..3902f064a5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java @@ -4,9 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; -public class VSplitPanelHorizontal extends VSplitPanel { +public class VSplitPanelHorizontal extends VAbstractSplitPanel { public VSplitPanelHorizontal() { - super(VSplitPanel.ORIENTATION_HORIZONTAL); + super(VAbstractSplitPanel.ORIENTATION_HORIZONTAL); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java index dcf7622e50..e61f8cf5e5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java @@ -4,9 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; -public class VSplitPanelVertical extends VSplitPanel { +public class VSplitPanelVertical extends VAbstractSplitPanel { public VSplitPanelVertical() { - super(VSplitPanel.ORIENTATION_VERTICAL); + super(VAbstractSplitPanel.ORIENTATION_VERTICAL); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTablePaging.java b/src/com/vaadin/terminal/gwt/client/ui/VTablePaging.java deleted file mode 100644 index cf35dc8e88..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/VTablePaging.java +++ /dev/null @@ -1,450 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ - -package com.vaadin.terminal.gwt.client.ui; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; - -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.SimplePanel; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.VPaintableWidget; - -/** - * TODO make this work (just an early prototype). We may want to have paging - * style table which will be much lighter than VScrollTable is. - */ -public class VTablePaging extends Composite implements Table, VPaintableWidget, - ClickHandler { - - private final Grid tBody = new Grid(); - private final Button nextPage = new Button(">"); - private final Button prevPage = new Button("<"); - private final Button firstPage = new Button("<<"); - private final Button lastPage = new Button(">>"); - - private int pageLength = 15; - - private boolean rowHeaders = false; - - private ApplicationConnection client; - private String id; - - private boolean immediate = false; - - private int selectMode = Table.SELECT_MODE_NONE; - - private final ArrayList<String> selectedRowKeys = new ArrayList<String>(); - - private int totalRows; - - private final HashMap<?, ?> visibleColumns = new HashMap<Object, Object>(); - - private int rows; - - private int firstRow; - private boolean sortAscending = true; - private final HorizontalPanel pager; - - public HashMap<String, TableRow> rowKeysToTableRows = new HashMap<String, TableRow>(); - - public VTablePaging() { - - tBody.setStyleName("itable-tbody"); - - final VerticalPanel panel = new VerticalPanel(); - - pager = new HorizontalPanel(); - pager.add(firstPage); - firstPage.addClickHandler(this); - pager.add(prevPage); - prevPage.addClickHandler(this); - pager.add(nextPage); - nextPage.addClickHandler(this); - pager.add(lastPage); - lastPage.addClickHandler(this); - - panel.add(pager); - panel.add(tBody); - - initWidget(panel); - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - - this.client = client; - id = uidl.getStringAttribute("id"); - immediate = uidl.getBooleanAttribute("immediate"); - totalRows = uidl.getIntAttribute("totalrows"); - pageLength = uidl.getIntAttribute("pagelength"); - firstRow = uidl.getIntAttribute("firstrow"); - rows = uidl.getIntAttribute("rows"); - - if (uidl.hasAttribute("selectmode")) { - if (uidl.getStringAttribute("selectmode").equals("multi")) { - selectMode = Table.SELECT_MODE_MULTI; - } else { - selectMode = Table.SELECT_MODE_SINGLE; - } - - if (uidl.hasAttribute("selected")) { - final Set<String> selectedKeys = uidl - .getStringArrayVariableAsSet("selected"); - selectedRowKeys.clear(); - for (final Iterator<String> it = selectedKeys.iterator(); it - .hasNext();) { - selectedRowKeys.add(it.next()); - } - } - } - - if (uidl.hasVariable("sortascending")) { - sortAscending = uidl.getBooleanVariable("sortascending"); - } - - if (uidl.hasAttribute("rowheaders")) { - rowHeaders = true; - } - - UIDL rowData = null; - UIDL visibleColumns = null; - for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) { - final UIDL c = (UIDL) it.next(); - if (c.getTag().equals("rows")) { - rowData = c; - } else if (c.getTag().equals("actions")) { - updateActionMap(c); - } else if (c.getTag().equals("visiblecolumns")) { - visibleColumns = c; - } - } - tBody.resize(rows + 1, uidl.getIntAttribute("cols") - + (rowHeaders ? 1 : 0)); - updateHeader(visibleColumns); - updateBody(rowData); - - updatePager(); - } - - private void updateHeader(UIDL c) { - final Iterator<?> it = c.getChildIterator(); - visibleColumns.clear(); - int colIndex = (rowHeaders ? 1 : 0); - while (it.hasNext()) { - final UIDL col = (UIDL) it.next(); - final String cid = col.getStringAttribute("cid"); - if (!col.hasAttribute("collapsed")) { - tBody.setWidget(0, colIndex, - new HeaderCell(cid, col.getStringAttribute("caption"))); - - } - colIndex++; - } - } - - private void updateActionMap(UIDL c) { - // TODO Auto-generated method stub - - } - - /** - * Updates row data from uidl. UpdateFromUIDL delegates updating tBody to - * this method. - * - * Updates may be to different part of tBody, depending on update type. It - * can be initial row data, scroll up, scroll down... - * - * @param uidl - * which contains row data - */ - private void updateBody(UIDL uidl) { - final Iterator<?> it = uidl.getChildIterator(); - - int curRowIndex = 1; - while (it.hasNext()) { - final UIDL rowUidl = (UIDL) it.next(); - final TableRow row = new TableRow(curRowIndex, - String.valueOf(rowUidl.getIntAttribute("key")), - rowUidl.hasAttribute("selected")); - int colIndex = 0; - if (rowHeaders) { - tBody.setWidget(curRowIndex, colIndex, new BodyCell(row, - rowUidl.getStringAttribute("caption"))); - colIndex++; - } - final Iterator<?> cells = rowUidl.getChildIterator(); - while (cells.hasNext()) { - final Object cell = cells.next(); - if (cell instanceof String) { - tBody.setWidget(curRowIndex, colIndex, new BodyCell(row, - (String) cell)); - } else { - final VPaintableWidget cellContent = client - .getPaintable((UIDL) cell); - final BodyCell bodyCell = new BodyCell(row); - bodyCell.setWidget(cellContent.getWidgetForPaintable()); - tBody.setWidget(curRowIndex, colIndex, bodyCell); - } - colIndex++; - } - curRowIndex++; - } - } - - private void updatePager() { - if (pageLength == 0) { - pager.setVisible(false); - return; - } - if (isFirstPage()) { - firstPage.setEnabled(false); - prevPage.setEnabled(false); - } else { - firstPage.setEnabled(true); - prevPage.setEnabled(true); - } - if (hasNextPage()) { - nextPage.setEnabled(true); - lastPage.setEnabled(true); - } else { - nextPage.setEnabled(false); - lastPage.setEnabled(false); - - } - } - - private boolean hasNextPage() { - if (firstRow + rows + 1 > totalRows) { - return false; - } - return true; - } - - private boolean isFirstPage() { - if (firstRow == 0) { - return true; - } - return false; - } - - public void onClick(ClickEvent event) { - Object sender = event.getSource(); - if (sender instanceof Button) { - if (sender == firstPage) { - client.updateVariable(id, "firstvisible", 0, true); - } else if (sender == nextPage) { - client.updateVariable(id, "firstvisible", - firstRow + pageLength, true); - } else if (sender == prevPage) { - int newFirst = firstRow - pageLength; - if (newFirst < 0) { - newFirst = 0; - } - client.updateVariable(id, "firstvisible", newFirst, true); - } else if (sender == lastPage) { - client.updateVariable(id, "firstvisible", totalRows - - pageLength, true); - } - } - if (sender instanceof HeaderCell) { - final HeaderCell hCell = (HeaderCell) sender; - client.updateVariable(id, "sortcolumn", hCell.getCid(), false); - client.updateVariable(id, "sortascending", (sortAscending ? false - : true), true); - } - } - - private class HeaderCell extends HTML { - - private String cid; - - public String getCid() { - return cid; - } - - public void setCid(String pid) { - cid = pid; - } - - HeaderCell(String pid, String caption) { - super(); - cid = pid; - addClickHandler(VTablePaging.this); - setText(caption); - // TODO remove debug color - DOM.setStyleAttribute(getElement(), "color", "brown"); - DOM.setStyleAttribute(getElement(), "font-weight", "bold"); - } - } - - /** - * Abstraction of table cell content. In needs to know on which row it is in - * case of context click. - * - * @author mattitahvonen - */ - public class BodyCell extends SimplePanel { - private final TableRow row; - - public BodyCell(TableRow row) { - super(); - sinkEvents(Event.BUTTON_LEFT | Event.BUTTON_RIGHT); - this.row = row; - } - - public BodyCell(TableRow row2, String textContent) { - super(); - sinkEvents(Event.BUTTON_LEFT | Event.BUTTON_RIGHT); - row = row2; - setWidget(new Label(textContent)); - } - - @Override - public void onBrowserEvent(Event event) { - System.out.println("CEll event: " + event.toString()); - switch (DOM.eventGetType(event)) { - case Event.BUTTON_RIGHT: - row.showContextMenu(event); - Window.alert("context menu un-implemented"); - DOM.eventCancelBubble(event, true); - break; - case Event.BUTTON_LEFT: - if (selectMode > Table.SELECT_MODE_NONE) { - row.toggleSelected(); - } - break; - default: - break; - } - super.onBrowserEvent(event); - } - } - - private class TableRow { - - private final String key; - private final int rowIndex; - private boolean selected = false; - - public TableRow(int rowIndex, String rowKey, boolean selected) { - rowKeysToTableRows.put(rowKey, this); - this.rowIndex = rowIndex; - key = rowKey; - setSelected(selected); - } - - /** - * This method is used to set row status. Does not change value on - * server. - * - * @param selected - */ - public void setSelected(boolean sel) { - selected = sel; - if (selected) { - selectedRowKeys.add(key); - DOM.setStyleAttribute( - tBody.getRowFormatter().getElement(rowIndex), - "background", "yellow"); - - } else { - selectedRowKeys.remove(key); - DOM.setStyleAttribute( - tBody.getRowFormatter().getElement(rowIndex), - "background", "transparent"); - } - } - - public void setContextMenuOptions(HashMap<?, ?> options) { - - } - - /** - * Toggles rows select state. Also updates state to server according to - * tables immediate flag. - * - */ - public void toggleSelected() { - if (selected) { - setSelected(false); - } else { - if (selectMode == Table.SELECT_MODE_SINGLE) { - deselectAll(); - } - setSelected(true); - } - client.updateVariable( - id, - "selected", - selectedRowKeys.toArray(new String[selectedRowKeys.size()]), - immediate); - } - - /** - * Shows context menu for this row. - * - * @param event - * Event which triggered context menu. Correct place for - * context menu can be determined with it. - */ - public void showContextMenu(Event event) { - System.out.println("TODO: Show context menu"); - } - } - - public void deselectAll() { - final Object[] keys = selectedRowKeys.toArray(); - for (int i = 0; i < keys.length; i++) { - final TableRow tableRow = rowKeysToTableRows.get(keys[i]); - if (tableRow != null) { - tableRow.setSelected(false); - } - } - // still ensure all selects are removed from - selectedRowKeys.clear(); - } - - public void add(Widget w) { - // TODO Auto-generated method stub - - } - - public void clear() { - // TODO Auto-generated method stub - - } - - public Iterator<Widget> iterator() { - // TODO Auto-generated method stub - return null; - } - - public boolean remove(Widget w) { - // TODO Auto-generated method stub - return false; - } - - public Widget getWidgetForPaintable() { - return this; - } -} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java index 74ff328710..553a4d673e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java @@ -54,7 +54,7 @@ public class VTabsheet extends VTabsheetBase { /** * Representation of a single "tab" shown in the TabBar - * + * */ private static class Tab extends SimplePanel { private static final String TD_CLASSNAME = CLASSNAME + "-tabitemcell"; @@ -206,9 +206,10 @@ public class VTabsheet extends VTabsheetBase { if (uidl.hasAttribute(ATTRIBUTE_ERROR)) { tooltipInfo.setErrorUidl(uidl.getErrors()); } - client.registerTooltip(getTabsheet(), getElement(), tooltipInfo); + client.registerWidgetTooltip(getTabsheet(), getElement(), + tooltipInfo); } else { - client.registerTooltip(getTabsheet(), getElement(), null); + client.registerWidgetTooltip(getTabsheet(), getElement(), null); } boolean ret = super.updateCaption(uidl); @@ -236,7 +237,7 @@ public class VTabsheet extends VTabsheetBase { if (event.getTypeInt() == Event.ONLOAD) { getTabsheet().tabSizeMightHaveChanged(getTab()); } - client.handleTooltipEvent(event, getTabsheet(), getElement()); + client.handleWidgetTooltipEvent(event, getTabsheet(), getElement()); } public Tab getTab() { @@ -469,7 +470,7 @@ public class VTabsheet extends VTabsheetBase { // Can't use "style" as it's already in use public static final String TAB_STYLE_NAME = "tabstyle"; - private final Element tabs; // tabbar and 'scroller' container + final Element tabs; // tabbar and 'scroller' container private final Element scroller; // tab-scroller element private final Element scrollerNext; // tab-scroller next button element private final Element scrollerPrev; // tab-scroller prev button element @@ -480,15 +481,15 @@ public class VTabsheet extends VTabsheetBase { private int scrollerIndex = 0; private final TabBar tb = new TabBar(this); - private final VTabsheetPanel tp = new VTabsheetPanel(); + final VTabsheetPanel tp = new VTabsheetPanel(); private final Element contentNode, deco; private String height; private String width; - private boolean waitingForResponse; + boolean waitingForResponse; - private final RenderInformation renderInformation = new RenderInformation(); + final RenderInformation renderInformation = new RenderInformation(); /** * Previous visible widget is set invisible with CSS (not display: none, but @@ -497,7 +498,7 @@ public class VTabsheet extends VTabsheetBase { */ private Widget previousVisibleWidget; - private boolean rendering = false; + boolean rendering = false; private String currentStyle; @@ -545,11 +546,11 @@ public class VTabsheet extends VTabsheetBase { client.updateVariable(id, "close", tabKeys.get(tabIndex), true); } - private boolean isDynamicWidth() { + boolean isDynamicWidth() { return width == null || width.equals(""); } - private boolean isDynamicHeight() { + boolean isDynamicHeight() { return height == null || height.equals(""); } @@ -633,60 +634,7 @@ public class VTabsheet extends VTabsheetBase { return scrollerIndex > index; } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - rendering = true; - - if (!uidl.getBooleanAttribute("cached")) { - // Handle stylename changes before generics (might affect size - // calculations) - handleStyleNames(uidl); - } - - super.updateFromUIDL(uidl, client); - if (cachedUpdate) { - rendering = false; - return; - } - - // tabs; push or not - if (!isDynamicWidth()) { - // FIXME: This makes tab sheet tabs go to 1px width on every update - // and then back to original width - // update width later, in updateTabScroller(); - DOM.setStyleAttribute(tabs, "width", "1px"); - DOM.setStyleAttribute(tabs, "overflow", "hidden"); - } else { - showAllTabs(); - DOM.setStyleAttribute(tabs, "width", ""); - DOM.setStyleAttribute(tabs, "overflow", "visible"); - updateDynamicWidth(); - } - - if (!isDynamicHeight()) { - // Must update height after the styles have been set - updateContentNodeHeight(); - updateOpenTabSize(); - } - - iLayout(); - - // Re run relative size update to ensure optimal scrollbars - // TODO isolate to situation that visible tab has undefined height - try { - client.handleComponentRelativeSize(tp.getWidget(tp - .getVisibleWidget())); - } catch (Exception e) { - // Ignore, most likely empty tabsheet - } - - renderInformation.updateSize(getElement()); - - waitingForResponse = false; - rendering = false; - } - - private void handleStyleNames(UIDL uidl) { + void handleStyleNames(UIDL uidl) { // Add proper stylenames for all elements (easier to prevent unwanted // style inheritance) if (uidl.hasAttribute("style")) { @@ -728,7 +676,7 @@ public class VTabsheet extends VTabsheetBase { } } - private void updateDynamicWidth() { + void updateDynamicWidth() { // Find width consumed by tabs TableCellElement spacerCell = ((TableElement) tb.getElement().cast()) .getRows().getItem(0).getCells().getItem(tb.getTabCount()); @@ -923,7 +871,7 @@ public class VTabsheet extends VTabsheetBase { } } - private void updateContentNodeHeight() { + void updateContentNodeHeight() { if (height != null && !"".equals(height)) { int contentHeight = getOffsetHeight(); contentHeight -= DOM.getElementPropertyInt(deco, "offsetHeight"); @@ -990,7 +938,7 @@ public class VTabsheet extends VTabsheetBase { * position: absolute (to work around a firefox flickering bug) we must keep * this up-to-date by hand. */ - private void updateOpenTabSize() { + void updateOpenTabSize() { /* * The overflow=auto element must have a height specified, otherwise it * will be just as high as the contents and no scrollbars will appear @@ -1066,7 +1014,7 @@ public class VTabsheet extends VTabsheetBase { } - private void showAllTabs() { + void showAllTabs() { scrollerIndex = tb.getFirstVisibleTab(); for (int i = 0; i < tb.getTabCount(); i++) { Tab t = tb.getTab(i); @@ -1114,10 +1062,6 @@ public class VTabsheet extends VTabsheetBase { tp.replaceComponent(oldComponent, newComponent); } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - /* Tabsheet does not render its children's captions */ - } - public boolean requestLayout(Set<Widget> children) { if (!isDynamicHeight() && !isDynamicWidth()) { /* diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java index 9dd74474f3..271aed1859 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java @@ -14,7 +14,6 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; abstract class VTabsheetBase extends ComplexPanel implements Container { @@ -34,81 +33,6 @@ abstract class VTabsheetBase extends ComplexPanel implements Container { setStyleName(classname); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - - // Ensure correct implementation - cachedUpdate = client.updateComponent(this, uidl, true); - if (cachedUpdate) { - return; - } - - // Update member references - id = uidl.getId(); - disabled = uidl.hasAttribute("disabled"); - - // Render content - final UIDL tabs = uidl.getChildUIDL(0); - - // Paintables in the TabSheet before update - ArrayList<Widget> oldWidgets = new ArrayList<Widget>(); - for (Iterator<Widget> iterator = getWidgetIterator(); iterator - .hasNext();) { - oldWidgets.add(iterator.next()); - } - - // Clear previous values - tabKeys.clear(); - disabledTabKeys.clear(); - - int index = 0; - for (final Iterator<Object> it = tabs.getChildIterator(); it.hasNext();) { - final UIDL tab = (UIDL) it.next(); - final String key = tab.getStringAttribute("key"); - final boolean selected = tab.getBooleanAttribute("selected"); - final boolean hidden = tab.getBooleanAttribute("hidden"); - - if (tab.getBooleanAttribute("disabled")) { - disabledTabKeys.add(key); - } - - tabKeys.add(key); - - if (selected) { - activeTabIndex = index; - } - renderTab(tab, index, selected, hidden); - index++; - } - - int tabCount = getTabCount(); - while (tabCount-- > index) { - removeTab(index); - } - - for (int i = 0; i < getTabCount(); i++) { - VPaintableWidget p = getTab(i); - // During the initial rendering the paintable might be null (this is - // weird...) - if (p != null) { - oldWidgets.remove(p.getWidgetForPaintable()); - } - } - - // Perform unregister for any paintables removed during update - for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator - .hasNext();) { - Widget oldWidget = iterator.next(); - VPaintableWidget oldPaintable = VPaintableMap.get(client) - .getPaintable(oldWidget); - if (oldWidget.isAttached()) { - oldWidget.removeFromParent(); - } - VPaintableMap.get(client).unregisterPaintable(oldPaintable); - } - - } - /** * @return a list of currently shown Paintables * diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java new file mode 100644 index 0000000000..3fbc52c2ca --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java @@ -0,0 +1,96 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public abstract class VTabsheetBasePaintable extends
+ VAbstractPaintableWidgetContainer {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+
+ // Ensure correct implementation
+ getWidgetForPaintable().cachedUpdate = client.updateComponent(this,
+ uidl, true);
+ if (getWidgetForPaintable().cachedUpdate) {
+ return;
+ }
+
+ // Update member references
+ getWidgetForPaintable().id = uidl.getId();
+ getWidgetForPaintable().disabled = uidl.hasAttribute("disabled");
+
+ // Render content
+ final UIDL tabs = uidl.getChildUIDL(0);
+
+ // Paintables in the TabSheet before update
+ ArrayList<Widget> oldWidgets = new ArrayList<Widget>();
+ for (Iterator<Widget> iterator = getWidgetForPaintable()
+ .getWidgetIterator(); iterator.hasNext();) {
+ oldWidgets.add(iterator.next());
+ }
+
+ // Clear previous values
+ getWidgetForPaintable().tabKeys.clear();
+ getWidgetForPaintable().disabledTabKeys.clear();
+
+ int index = 0;
+ for (final Iterator<Object> it = tabs.getChildIterator(); it.hasNext();) {
+ final UIDL tab = (UIDL) it.next();
+ final String key = tab.getStringAttribute("key");
+ final boolean selected = tab.getBooleanAttribute("selected");
+ final boolean hidden = tab.getBooleanAttribute("hidden");
+
+ if (tab.getBooleanAttribute("disabled")) {
+ getWidgetForPaintable().disabledTabKeys.add(key);
+ }
+
+ getWidgetForPaintable().tabKeys.add(key);
+
+ if (selected) {
+ getWidgetForPaintable().activeTabIndex = index;
+ }
+ getWidgetForPaintable().renderTab(tab, index, selected, hidden);
+ index++;
+ }
+
+ int tabCount = getWidgetForPaintable().getTabCount();
+ while (tabCount-- > index) {
+ getWidgetForPaintable().removeTab(index);
+ }
+
+ for (int i = 0; i < getWidgetForPaintable().getTabCount(); i++) {
+ VPaintableWidget p = getWidgetForPaintable().getTab(i);
+ // During the initial rendering the paintable might be null (this is
+ // weird...)
+ if (p != null) {
+ oldWidgets.remove(p.getWidgetForPaintable());
+ }
+ }
+
+ // Perform unregister for any paintables removed during update
+ for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
+ .hasNext();) {
+ Widget oldWidget = iterator.next();
+ VPaintableWidget oldPaintable = VPaintableMap.get(client)
+ .getPaintable(oldWidget);
+ if (oldWidget.isAttached()) {
+ oldWidget.removeFromParent();
+ }
+ VPaintableMap.get(client).unregisterPaintable(oldPaintable);
+ }
+
+ }
+
+ @Override
+ public VTabsheetBase getWidgetForPaintable() {
+ return (VTabsheetBase) super.getWidgetForPaintable();
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java new file mode 100644 index 0000000000..e8d6da757e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java @@ -0,0 +1,82 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VTabsheetPaintable extends VTabsheetBasePaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+
+ if (!uidl.getBooleanAttribute("cached")) {
+ // Handle stylename changes before generics (might affect size
+ // calculations)
+ getWidgetForPaintable().handleStyleNames(uidl);
+ }
+
+ super.updateFromUIDL(uidl, client);
+ if (getWidgetForPaintable().cachedUpdate) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ // tabs; push or not
+ if (!getWidgetForPaintable().isDynamicWidth()) {
+ // FIXME: This makes tab sheet tabs go to 1px width on every update
+ // and then back to original width
+ // update width later, in updateTabScroller();
+ DOM.setStyleAttribute(getWidgetForPaintable().tabs, "width", "1px");
+ DOM.setStyleAttribute(getWidgetForPaintable().tabs, "overflow",
+ "hidden");
+ } else {
+ getWidgetForPaintable().showAllTabs();
+ DOM.setStyleAttribute(getWidgetForPaintable().tabs, "width", "");
+ DOM.setStyleAttribute(getWidgetForPaintable().tabs, "overflow",
+ "visible");
+ getWidgetForPaintable().updateDynamicWidth();
+ }
+
+ if (!getWidgetForPaintable().isDynamicHeight()) {
+ // Must update height after the styles have been set
+ getWidgetForPaintable().updateContentNodeHeight();
+ getWidgetForPaintable().updateOpenTabSize();
+ }
+
+ getWidgetForPaintable().iLayout();
+
+ // Re run relative size update to ensure optimal scrollbars
+ // TODO isolate to situation that visible tab has undefined height
+ try {
+ client.handleComponentRelativeSize(getWidgetForPaintable().tp
+ .getWidget(getWidgetForPaintable().tp.getVisibleWidget()));
+ } catch (Exception e) {
+ // Ignore, most likely empty tabsheet
+ }
+
+ getWidgetForPaintable().renderInformation
+ .updateSize(getWidgetForPaintable().getElement());
+
+ getWidgetForPaintable().waitingForResponse = false;
+ getWidgetForPaintable().rendering = false;
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VTabsheet.class);
+ }
+
+ @Override
+ public VTabsheet getWidgetForPaintable() {
+ return (VTabsheet) super.getWidgetForPaintable();
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ /* Tabsheet does not render its children's captions */
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java index cd09e24d67..bd58c38829 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java @@ -9,8 +9,6 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.UIDL;
/**
* This class represents a multiline textfield (textarea).
@@ -29,20 +27,6 @@ public class VTextArea extends VTextField { setStyleName(CLASSNAME);
}
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- // Call parent renderer explicitly
- super.updateFromUIDL(uidl, client);
-
- if (uidl.hasAttribute("rows")) {
- setRows(uidl.getIntAttribute("rows"));
- }
-
- if (getMaxLength() >= 0) {
- sinkEvents(Event.ONKEYUP);
- }
- }
-
public void setRows(int rows) {
setRows(getElement(), rows);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextAreaPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTextAreaPaintable.java new file mode 100644 index 0000000000..3c21a4ab2f --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextAreaPaintable.java @@ -0,0 +1,38 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VTextAreaPaintable extends VTextFieldPaintable { + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Call parent renderer explicitly + super.updateFromUIDL(uidl, client); + + if (uidl.hasAttribute("rows")) { + getWidgetForPaintable().setRows(uidl.getIntAttribute("rows")); + } + + if (getWidgetForPaintable().getMaxLength() >= 0) { + getWidgetForPaintable().sinkEvents(Event.ONKEYUP); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VTextArea.class); + } + + @Override + public VTextArea getWidgetForPaintable() { + return (VTextArea) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java index 80dad78e58..80b27e6c8c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java @@ -4,7 +4,6 @@ package com.vaadin.terminal.gwt.client.ui; -import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Style.Overflow; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; @@ -15,21 +14,16 @@ import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.TextBoxBase; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; /** * This class represents a basic text input field with one row. @@ -37,9 +31,8 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutAct * @author Vaadin Ltd. * */ -public class VTextField extends TextBoxBase implements VPaintableWidget, Field, - ChangeHandler, FocusHandler, BlurHandler, BeforeShortcutActionListener, - KeyDownHandler { +public class VTextField extends TextBoxBase implements Field, ChangeHandler, + FocusHandler, BlurHandler, KeyDownHandler { public static final String VAR_CUR_TEXT = "curText"; @@ -53,11 +46,11 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, */ public static final String CLASSNAME_FOCUS = "focus"; - protected String id; + protected String paintableId; protected ApplicationConnection client; - private String valueBeforeEdit = null; + protected String valueBeforeEdit = null; /** * Set to false if a text change event has been sent since the last value @@ -66,20 +59,20 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, */ private boolean valueBeforeEditIsSynced = true; - private boolean immediate = false; + protected boolean immediate = false; private int extraHorizontalPixels = -1; private int extraVerticalPixels = -1; private int maxLength = -1; private static final String CLASSNAME_PROMPT = "prompt"; - private static final String ATTR_INPUTPROMPT = "prompt"; + protected static final String ATTR_INPUTPROMPT = "prompt"; public static final String ATTR_TEXTCHANGE_TIMEOUT = "iet"; public static final String VAR_CURSOR = "c"; public static final String ATTR_TEXTCHANGE_EVENTMODE = "iem"; - private static final String TEXTCHANGE_MODE_EAGER = "EAGER"; + protected static final String TEXTCHANGE_MODE_EAGER = "EAGER"; private static final String TEXTCHANGE_MODE_TIMEOUT = "TIMEOUT"; - private String inputPrompt = null; + protected String inputPrompt = null; private boolean prompting = false; private int lastCursorPos = -1; private boolean wordwrap = true; @@ -112,14 +105,14 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, * Eager polling for a change is bit dum and heavy operation, so I guess we * should first try to survive without. */ - private static final int TEXTCHANGE_EVENTS = Event.ONPASTE + protected static final int TEXTCHANGE_EVENTS = Event.ONPASTE | Event.KEYEVENTS | Event.ONMOUSEUP; @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } if (listenTextChangeEvents @@ -158,7 +151,7 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, client.sendPendingVariableChanges(); } else { // Default case - just send an immediate text change message - client.updateVariable(id, VAR_CUR_TEXT, text, true); + client.updateVariable(paintableId, VAR_CUR_TEXT, text, true); // Shouldn't investigate valueBeforeEdit to avoid duplicate text // change events as the states are not in sync any more @@ -180,9 +173,9 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, } }; private boolean scheduled = false; - private boolean listenTextChangeEvents; - private String textChangeEventMode; - private int textChangeEventTimeout; + protected boolean listenTextChangeEvents; + protected String textChangeEventMode; + protected int textChangeEventTimeout; private void deferTextChangeEvent() { if (textChangeEventMode.equals(TEXTCHANGE_MODE_TIMEOUT) && scheduled) { @@ -215,88 +208,7 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, super.setReadOnly(readOnly); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - id = uidl.getId(); - - if (client.updateComponent(this, uidl, true)) { - return; - } - - if (uidl.getBooleanAttribute("readonly")) { - setReadOnly(true); - } else { - setReadOnly(false); - } - - inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT); - - setMaxLength(uidl.hasAttribute("maxLength") ? uidl - .getIntAttribute("maxLength") : -1); - - immediate = uidl.getBooleanAttribute("immediate"); - - listenTextChangeEvents = client.hasEventListeners(this, "ie"); - if (listenTextChangeEvents) { - textChangeEventMode = uidl - .getStringAttribute(ATTR_TEXTCHANGE_EVENTMODE); - if (textChangeEventMode.equals(TEXTCHANGE_MODE_EAGER)) { - textChangeEventTimeout = 1; - } else { - textChangeEventTimeout = uidl - .getIntAttribute(ATTR_TEXTCHANGE_TIMEOUT); - if (textChangeEventTimeout < 1) { - // Sanitize and allow lazy/timeout with timeout set to 0 to - // work as eager - textChangeEventTimeout = 1; - } - } - sinkEvents(TEXTCHANGE_EVENTS); - attachCutEventListener(getElement()); - } - - if (uidl.hasAttribute("cols")) { - setColumns(new Integer(uidl.getStringAttribute("cols")).intValue()); - } - - final String text = uidl.getStringVariable("text"); - - /* - * We skip the text content update if field has been repainted, but text - * has not been changed. Additional sanity check verifies there is no - * change in the que (in which case we count more on the server side - * value). - */ - if (!(uidl.getBooleanAttribute(ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) - && valueBeforeEdit != null && text.equals(valueBeforeEdit))) { - updateFieldContent(text); - } - - if (uidl.hasAttribute("selpos")) { - final int pos = uidl.getIntAttribute("selpos"); - final int length = uidl.getIntAttribute("sellen"); - /* - * Gecko defers setting the text so we need to defer the selection. - */ - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - setSelectionRange(pos, length); - } - }); - } - - // Here for backward compatibility; to be moved to TextArea. - // Optimization: server does not send attribute for the default 'true' - // state. - if (uidl.hasAttribute("wordwrap") - && uidl.getBooleanAttribute("wordwrap") == false) { - setWordwrap(false); - } else { - setWordwrap(true); - } - } - - private void updateFieldContent(final String text) { + protected void updateFieldContent(final String text) { setPrompting(inputPrompt != null && focusedTextField != this && (text.equals(""))); @@ -350,7 +262,7 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, } } - private void setMaxLength(int newMaxLength) { + protected void setMaxLength(int newMaxLength) { if (newMaxLength >= 0) { maxLength = newMaxLength; if (getElement().getTagName().toLowerCase().equals("textarea")) { @@ -386,20 +298,20 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, * true if the field was blurred */ public void valueChange(boolean blurred) { - if (client != null && id != null) { + if (client != null && paintableId != null) { boolean sendBlurEvent = false; boolean sendValueChange = false; - if (blurred && client.hasEventListeners(this, EventId.BLUR)) { + if (blurred && client.hasWidgetEventListeners(this, EventId.BLUR)) { sendBlurEvent = true; - client.updateVariable(id, EventId.BLUR, "", false); + client.updateVariable(paintableId, EventId.BLUR, "", false); } String newText = getText(); if (!prompting && newText != null && !newText.equals(valueBeforeEdit)) { sendValueChange = immediate; - client.updateVariable(id, "text", getText(), false); + client.updateVariable(paintableId, "text", getText(), false); valueBeforeEdit = newText; valueBeforeEditIsSynced = true; } @@ -432,7 +344,7 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, if (Util.isAttachedAndDisplayed(this)) { int cursorPos = getCursorPos(); if (lastCursorPos != cursorPos) { - client.updateVariable(id, VAR_CURSOR, cursorPos, false); + client.updateVariable(paintableId, VAR_CURSOR, cursorPos, false); lastCursorPos = cursorPos; return true; } @@ -456,8 +368,8 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, setPrompting(false); } focusedTextField = this; - if (client.hasEventListeners(this, EventId.FOCUS)) { - client.updateVariable(id, EventId.FOCUS, "", true); + if (client.hasWidgetEventListeners(this, EventId.FOCUS)) { + client.updateVariable(paintableId, EventId.FOCUS, "", true); } } @@ -568,10 +480,6 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, } } - public void onBeforeShortcutAction(Event e) { - valueChange(false); - } - // Here for backward compatibility; to be moved to TextArea public void setWordwrap(boolean enabled) { if (enabled == wordwrap) { @@ -601,8 +509,4 @@ public class VTextField extends TextBoxBase implements VPaintableWidget, Field, valueChange(false); } } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextFieldPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTextFieldPaintable.java new file mode 100644 index 0000000000..e3eecd5a09 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextFieldPaintable.java @@ -0,0 +1,124 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; + +public class VTextFieldPaintable extends VAbstractPaintableWidget implements + BeforeShortcutActionListener { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + + if (client.updateComponent(this, uidl, true)) { + return; + } + + if (uidl.getBooleanAttribute("readonly")) { + getWidgetForPaintable().setReadOnly(true); + } else { + getWidgetForPaintable().setReadOnly(false); + } + + getWidgetForPaintable().inputPrompt = uidl + .getStringAttribute(VTextField.ATTR_INPUTPROMPT); + + getWidgetForPaintable().setMaxLength( + uidl.hasAttribute("maxLength") ? uidl + .getIntAttribute("maxLength") : -1); + + getWidgetForPaintable().immediate = uidl + .getBooleanAttribute("immediate"); + + getWidgetForPaintable().listenTextChangeEvents = client + .hasEventListeners(this, "ie"); + if (getWidgetForPaintable().listenTextChangeEvents) { + getWidgetForPaintable().textChangeEventMode = uidl + .getStringAttribute(VTextField.ATTR_TEXTCHANGE_EVENTMODE); + if (getWidgetForPaintable().textChangeEventMode + .equals(VTextField.TEXTCHANGE_MODE_EAGER)) { + getWidgetForPaintable().textChangeEventTimeout = 1; + } else { + getWidgetForPaintable().textChangeEventTimeout = uidl + .getIntAttribute(VTextField.ATTR_TEXTCHANGE_TIMEOUT); + if (getWidgetForPaintable().textChangeEventTimeout < 1) { + // Sanitize and allow lazy/timeout with timeout set to 0 to + // work as eager + getWidgetForPaintable().textChangeEventTimeout = 1; + } + } + getWidgetForPaintable().sinkEvents(VTextField.TEXTCHANGE_EVENTS); + getWidgetForPaintable().attachCutEventListener( + getWidgetForPaintable().getElement()); + } + + if (uidl.hasAttribute("cols")) { + getWidgetForPaintable().setColumns( + new Integer(uidl.getStringAttribute("cols")).intValue()); + } + + final String text = uidl.getStringVariable("text"); + + /* + * We skip the text content update if field has been repainted, but text + * has not been changed. Additional sanity check verifies there is no + * change in the que (in which case we count more on the server side + * value). + */ + if (!(uidl + .getBooleanAttribute(VTextField.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) + && getWidgetForPaintable().valueBeforeEdit != null && text + .equals(getWidgetForPaintable().valueBeforeEdit))) { + getWidgetForPaintable().updateFieldContent(text); + } + + if (uidl.hasAttribute("selpos")) { + final int pos = uidl.getIntAttribute("selpos"); + final int length = uidl.getIntAttribute("sellen"); + /* + * Gecko defers setting the text so we need to defer the selection. + */ + Scheduler.get().scheduleDeferred(new Command() { + public void execute() { + getWidgetForPaintable().setSelectionRange(pos, length); + } + }); + } + + // Here for backward compatibility; to be moved to TextArea. + // Optimization: server does not send attribute for the default 'true' + // state. + if (uidl.hasAttribute("wordwrap") + && uidl.getBooleanAttribute("wordwrap") == false) { + getWidgetForPaintable().setWordwrap(false); + } else { + getWidgetForPaintable().setWordwrap(true); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VTextField.class); + } + + @Override + public VTextField getWidgetForPaintable() { + return (VTextField) super.getWidgetForPaintable(); + } + + public void onBeforeShortcutAction(Event e) { + getWidgetForPaintable().valueChange(false); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java index a522c79736..bb808321b9 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java @@ -14,25 +14,22 @@ import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.TextBox; -import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Focusable; import com.vaadin.terminal.gwt.client.LocaleNotLoadedException; import com.vaadin.terminal.gwt.client.LocaleService; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -public class VTextualDate extends VDateField implements VPaintableWidget, - Field, ChangeHandler, ContainerResizedListener, Focusable, SubPartAware { +public class VTextualDate extends VDateField implements Field, ChangeHandler, + ContainerResizedListener, Focusable, SubPartAware { private static final String PARSE_ERROR_CLASSNAME = CLASSNAME + "-parseerror"; - private final TextBox text; + protected final TextBox text; - private String formatStr; + protected String formatStr; private String width; @@ -40,11 +37,11 @@ public class VTextualDate extends VDateField implements VPaintableWidget, protected int fieldExtraWidth = -1; - private boolean lenient; + protected boolean lenient; private static final String CLASSNAME_PROMPT = "prompt"; - private static final String ATTR_INPUTPROMPT = "prompt"; - private String inputPrompt = ""; + protected static final String ATTR_INPUTPROMPT = "prompt"; + protected String inputPrompt = ""; private boolean prompting = false; public VTextualDate() { @@ -65,8 +62,8 @@ public class VTextualDate extends VDateField implements VPaintableWidget, setPrompting(false); } if (getClient() != null - && getClient().hasEventListeners(VTextualDate.this, - EventId.FOCUS)) { + && getClient().hasWidgetEventListeners( + VTextualDate.this, EventId.FOCUS)) { getClient() .updateVariable(getId(), EventId.FOCUS, "", true); } @@ -83,8 +80,8 @@ public class VTextualDate extends VDateField implements VPaintableWidget, text.setText(readonly ? "" : inputPrompt); } if (getClient() != null - && getClient().hasEventListeners(VTextualDate.this, - EventId.BLUR)) { + && getClient().hasWidgetEventListeners( + VTextualDate.this, EventId.BLUR)) { getClient().updateVariable(getId(), EventId.BLUR, "", true); } } @@ -92,37 +89,6 @@ public class VTextualDate extends VDateField implements VPaintableWidget, add(text); } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - int origRes = currentResolution; - String oldLocale = currentLocale; - super.updateFromUIDL(uidl, client); - if (origRes != currentResolution || oldLocale != currentLocale) { - // force recreating format string - formatStr = null; - } - if (uidl.hasAttribute("format")) { - formatStr = uidl.getStringAttribute("format"); - } - - inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT); - - lenient = !uidl.getBooleanAttribute("strict"); - - buildDate(); - // not a FocusWidget -> needs own tabindex handling - if (uidl.hasAttribute("tabindex")) { - text.setTabIndex(uidl.getIntAttribute("tabindex")); - } - - if (readonly) { - text.addStyleDependentName("readonly"); - } else { - text.removeStyleDependentName("readonly"); - } - - } - protected String getFormatString() { if (formatStr == null) { if (currentResolution == RESOLUTION_YEAR) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDatePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDatePaintable.java new file mode 100644 index 0000000000..6a9da31269 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDatePaintable.java @@ -0,0 +1,58 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VTextualDatePaintable extends VDateFieldPaintable { + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + int origRes = getWidgetForPaintable().currentResolution; + String oldLocale = getWidgetForPaintable().currentLocale; + super.updateFromUIDL(uidl, client); + if (origRes != getWidgetForPaintable().currentResolution + || oldLocale != getWidgetForPaintable().currentLocale) { + // force recreating format string + getWidgetForPaintable().formatStr = null; + } + if (uidl.hasAttribute("format")) { + getWidgetForPaintable().formatStr = uidl + .getStringAttribute("format"); + } + + getWidgetForPaintable().inputPrompt = uidl + .getStringAttribute(VTextualDate.ATTR_INPUTPROMPT); + + getWidgetForPaintable().lenient = !uidl.getBooleanAttribute("strict"); + + getWidgetForPaintable().buildDate(); + // not a FocusWidget -> needs own tabindex handling + if (uidl.hasAttribute("tabindex")) { + getWidgetForPaintable().text.setTabIndex(uidl + .getIntAttribute("tabindex")); + } + + if (getWidgetForPaintable().readonly) { + getWidgetForPaintable().text.addStyleDependentName("readonly"); + } else { + getWidgetForPaintable().text.removeStyleDependentName("readonly"); + } + + } + + @Override + protected Widget createWidget() { + return GWT.create(VTextualDate.class); + } + + @Override + public VTextualDate getWidgetForPaintable() { + return (VTextualDate) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index de7f6c652a..be337ae0cb 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -40,10 +40,10 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VPaintableMap; +import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.dd.DDUtil; import com.vaadin.terminal.gwt.client.ui.dd.VAbstractDropHandler; @@ -58,9 +58,9 @@ import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; /** * */ -public class VTree extends FocusElementPanel implements VPaintableWidget, - VHasDropHandler, FocusHandler, BlurHandler, KeyPressHandler, - KeyDownHandler, SubPartAware, ActionOwner { +public class VTree extends FocusElementPanel implements VHasDropHandler, + FocusHandler, BlurHandler, KeyPressHandler, KeyDownHandler, + SubPartAware, ActionOwner { public static final String CLASSNAME = "v-tree"; @@ -71,17 +71,17 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, private static final int CHARCODE_SPACE = 32; - private final FlowPanel body = new FlowPanel(); + final FlowPanel body = new FlowPanel(); - private Set<String> selectedIds = new HashSet<String>(); - private ApplicationConnection client; - private String paintableId; - private boolean selectable; - private boolean isMultiselect; + Set<String> selectedIds = new HashSet<String>(); + ApplicationConnection client; + String paintableId; + boolean selectable; + boolean isMultiselect; private String currentMouseOverKey; - private TreeNode lastSelection; - private TreeNode focusedNode; - private int multiSelectMode = MULTISELECT_MODE_DEFAULT; + TreeNode lastSelection; + TreeNode focusedNode; + int multiSelectMode = MULTISELECT_MODE_DEFAULT; private final HashMap<String, TreeNode> keyToNode = new HashMap<String, TreeNode>(); @@ -91,23 +91,23 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, */ private final HashMap<String, String> actionMap = new HashMap<String, String>(); - private boolean immediate; + boolean immediate; - private boolean isNullSelectionAllowed = true; + boolean isNullSelectionAllowed = true; - private boolean disabled = false; + boolean disabled = false; - private boolean readonly; + boolean readonly; - private boolean rendering; + boolean rendering; private VAbstractDropHandler dropHandler; - private int dragMode; + int dragMode; private boolean selectionHasChanged = false; - private String[] bodyActionKeys; + String[] bodyActionKeys; public VLazyExecutor iconLoaded = new VLazyExecutor(50, new ScheduledCommand() { @@ -206,24 +206,6 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, } } - private void updateActionMap(UIDL c) { - final Iterator<?> it = c.getChildIterator(); - while (it.hasNext()) { - final UIDL action = (UIDL) it.next(); - final String key = action.getStringAttribute("key"); - final String caption = action.getStringAttribute("caption"); - actionMap.put(key + "_c", caption); - if (action.hasAttribute("icon")) { - // TODO need some uri handling ?? - actionMap.put(key + "_i", client.translateVaadinUri(action - .getStringAttribute("icon"))); - } else { - actionMap.remove(key + "_i"); - } - } - - } - public String getActionCaption(String actionKey) { return actionMap.get(actionKey + "_c"); } @@ -232,94 +214,6 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, return actionMap.get(actionKey + "_i"); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // Ensure correct implementation and let container manage caption - if (client.updateComponent(this, uidl, true)) { - return; - } - - rendering = true; - - this.client = client; - - if (uidl.hasAttribute("partialUpdate")) { - handleUpdate(uidl); - rendering = false; - return; - } - - paintableId = uidl.getId(); - - immediate = uidl.hasAttribute("immediate"); - - disabled = uidl.getBooleanAttribute("disabled"); - readonly = uidl.getBooleanAttribute("readonly"); - - dragMode = uidl.hasAttribute("dragMode") ? uidl - .getIntAttribute("dragMode") : 0; - - isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); - - if (uidl.hasAttribute("alb")) { - bodyActionKeys = uidl.getStringArrayAttribute("alb"); - } - - body.clear(); - // clear out any references to nodes that no longer are attached - keyToNode.clear(); - TreeNode childTree = null; - UIDL childUidl = null; - for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { - childUidl = (UIDL) i.next(); - if ("actions".equals(childUidl.getTag())) { - updateActionMap(childUidl); - continue; - } else if ("-ac".equals(childUidl.getTag())) { - updateDropHandler(childUidl); - continue; - } - childTree = new TreeNode(); - childTree.updateFromUIDL(childUidl, client); - body.add(childTree); - childTree.addStyleDependentName("root"); - childTree.childNodeContainer.addStyleDependentName("root"); - } - if (childTree != null && childUidl != null) { - boolean leaf = !childUidl.getTag().equals("node"); - childTree.addStyleDependentName(leaf ? "leaf-last" : "last"); - childTree.childNodeContainer.addStyleDependentName("last"); - } - final String selectMode = uidl.getStringAttribute("selectmode"); - selectable = !"none".equals(selectMode); - isMultiselect = "multi".equals(selectMode); - - if (isMultiselect) { - multiSelectMode = uidl.getIntAttribute("multiselectmode"); - } - - selectedIds = uidl.getStringArrayVariableAsSet("selected"); - - // Update lastSelection and focusedNode to point to *actual* nodes again - // after the old ones have been cleared from the body. This fixes focus - // and keyboard navigation issues as described in #7057 and other - // tickets. - if (lastSelection != null) { - lastSelection = keyToNode.get(lastSelection.key); - } - if (focusedNode != null) { - setFocusedNode(keyToNode.get(focusedNode.key)); - } - - if (lastSelection == null && focusedNode == null - && !selectedIds.isEmpty()) { - setFocusedNode(keyToNode.get(selectedIds.iterator().next())); - focusedNode.setFocused(false); - } - - rendering = false; - - } - /** * Returns the first root node of the tree or null if there are no root * nodes. @@ -366,7 +260,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, drag.getDropDetails().put("itemIdOver", currentMouseOverKey); if (currentMouseOverKey != null) { - TreeNode treeNode = keyToNode.get(currentMouseOverKey); + TreeNode treeNode = getNodeByKey(currentMouseOverKey); VerticalDropLocation detail = treeNode.getDropDetail(drag .getCurrentGwtEvent()); Boolean overTreeNode = null; @@ -388,7 +282,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, return treeNode == null ? null : treeNode.key; } - private void updateDropHandler(UIDL childUidl) { + void updateDropHandler(UIDL childUidl) { if (dropHandler == null) { dropHandler = new VAbstractDropHandler() { @@ -430,7 +324,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, .getDropDetails().get("detail"); if (curDetail == detail && newKey.equals(currentMouseOverKey)) { - keyToNode.get(newKey).emphasis(detail); + getNodeByKey(newKey).emphasis(detail); } /* * Else drag is already on a different @@ -452,7 +346,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, private void cleanUp() { if (currentMouseOverKey != null) { - keyToNode.get(currentMouseOverKey).emphasis(null); + getNodeByKey(currentMouseOverKey).emphasis(null); currentMouseOverKey = null; } } @@ -465,7 +359,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, @Override public VPaintableWidget getPaintable() { - return VTree.this; + return VPaintableMap.get(client).getPaintable(VTree.this); } public ApplicationConnection getApplicationConnection() { @@ -477,24 +371,12 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, dropHandler.updateAcceptRules(childUidl); } - private void handleUpdate(UIDL uidl) { - final TreeNode rootNode = keyToNode.get(uidl - .getStringAttribute("rootKey")); - if (rootNode != null) { - if (!rootNode.getState()) { - // expanding node happened server side - rootNode.setState(true, false); - } - rootNode.renderChildNodes(uidl.getChildIterator()); - } - } - public void setSelected(TreeNode treeNode, boolean selected) { if (selected) { if (!isMultiselect) { while (selectedIds.size() > 0) { final String id = selectedIds.iterator().next(); - final TreeNode oldSelection = keyToNode.get(id); + final TreeNode oldSelection = getNodeByKey(id); if (oldSelection != null) { // can be null if the node is not visible (parent // collapsed) @@ -563,15 +445,15 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, public String key; - private String[] actionKeys = null; + String[] actionKeys = null; - private boolean childrenLoaded; + boolean childrenLoaded; - private Element nodeCaptionDiv; + Element nodeCaptionDiv; protected Element nodeCaptionSpan; - private FlowPanel childNodeContainer; + FlowPanel childNodeContainer; private boolean open; @@ -760,14 +642,14 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, } if (target == nodeCaptionSpan) { - client.handleTooltipEvent(event, VTree.this, key); + client.handleWidgetTooltipEvent(event, VTree.this, key); } final boolean inCaption = target == nodeCaptionSpan || (icon != null && target == icon.getElement()); if (inCaption - && client - .hasEventListeners(VTree.this, ITEM_CLICK_EVENT_ID) + && client.hasWidgetEventListeners(VTree.this, + ITEM_CLICK_EVENT_ID) && (type == Event.ONDBLCLICK || type == Event.ONMOUSEUP)) { fireClick(event); @@ -828,7 +710,8 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, if (mouseDownEvent != null) { // start actual drag on slight move when mouse is down VTransferable t = new VTransferable(); - t.setDragSource(VTree.this); + t.setDragSource(VPaintableMap.get(client).getPaintable( + VTree.this)); t.setData("itemId", key); VDragEvent drag = VDragAndDropManager.get().startDrag( t, mouseDownEvent, true); @@ -944,71 +827,6 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, setWidget(childNodeContainer); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - setText(uidl.getStringAttribute("caption")); - key = uidl.getStringAttribute("key"); - - keyToNode.put(key, this); - - if (uidl.hasAttribute("al")) { - actionKeys = uidl.getStringArrayAttribute("al"); - } - - if (uidl.getTag().equals("node")) { - if (uidl.getChildCount() == 0) { - childNodeContainer.setVisible(false); - } else { - renderChildNodes(uidl.getChildIterator()); - childrenLoaded = true; - } - } else { - addStyleName(CLASSNAME + "-leaf"); - } - if (uidl.hasAttribute("style")) { - addStyleName(CLASSNAME + "-" + uidl.getStringAttribute("style")); - Widget.setStyleName(nodeCaptionDiv, CLASSNAME + "-caption-" - + uidl.getStringAttribute("style"), true); - childNodeContainer.addStyleName(CLASSNAME + "-children-" - + uidl.getStringAttribute("style")); - } - - String description = uidl.getStringAttribute("descr"); - if (description != null && client != null) { - // Set tooltip - TooltipInfo info = new TooltipInfo(description); - client.registerTooltip(VTree.this, key, info); - } else { - // Remove possible previous tooltip - client.registerTooltip(VTree.this, key, null); - } - - if (uidl.getBooleanAttribute("expanded") && !getState()) { - setState(true, false); - } - - if (uidl.getBooleanAttribute("selected")) { - setSelected(true); - // ensure that identifier is in selectedIds array (this may be a - // partial update) - selectedIds.add(key); - } - - if (uidl.hasAttribute("icon")) { - if (icon == null) { - icon = new Icon(client); - DOM.insertBefore(DOM.getFirstChild(nodeCaptionDiv), - icon.getElement(), nodeCaptionSpan); - } - icon.setUri(uidl.getStringAttribute("icon")); - } else { - if (icon != null) { - DOM.removeChild(DOM.getFirstChild(nodeCaptionDiv), - icon.getElement()); - icon = null; - } - } - } - public boolean isLeaf() { String[] styleNames = getStyleName().split(" "); for (String styleName : styleNames) { @@ -1019,7 +837,7 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, return false; } - private void setState(boolean state, boolean notifyServer) { + void setState(boolean state, boolean notifyServer) { if (open == state) { return; } @@ -1050,38 +868,14 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, } } - private boolean getState() { + boolean getState() { return open; } - private void setText(String text) { + void setText(String text) { DOM.setInnerText(nodeCaptionSpan, text); } - private void renderChildNodes(Iterator<?> i) { - childNodeContainer.clear(); - childNodeContainer.setVisible(true); - while (i.hasNext()) { - final UIDL childUidl = (UIDL) i.next(); - // actions are in bit weird place, don't mix them with children, - // but current node's actions - if ("actions".equals(childUidl.getTag())) { - updateActionMap(childUidl); - continue; - } - final TreeNode childTree = new TreeNode(); - childTree.updateFromUIDL(childUidl, client); - childNodeContainer.add(childTree); - if (!i.hasNext()) { - childTree - .addStyleDependentName(childTree.isLeaf() ? "leaf-last" - : "last"); - childTree.childNodeContainer.addStyleDependentName("last"); - } - } - childrenLoaded = true; - } - public boolean isChildrenLoaded() { return childrenLoaded; } @@ -1231,6 +1025,34 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, Util.scrollIntoViewVertically(nodeCaptionDiv); } + public void setIcon(String iconUrl) { + if (iconUrl != null) { + // Add icon if not present + if (icon == null) { + icon = new Icon(client); + DOM.insertBefore(DOM.getFirstChild(nodeCaptionDiv), + icon.getElement(), nodeCaptionSpan); + } + icon.setUri(iconUrl); + } else { + // Remove icon if present + if (icon != null) { + DOM.removeChild(DOM.getFirstChild(nodeCaptionDiv), + icon.getElement()); + icon = null; + } + } + } + + public void setNodeStyleName(String styleName) { + addStyleName(TreeNode.CLASSNAME + "-" + styleName); + setStyleName(nodeCaptionDiv, TreeNode.CLASSNAME + "-caption-" + + styleName, true); + childNodeContainer.addStyleName(TreeNode.CLASSNAME + "-children-" + + styleName); + + } + } public VDropHandler getDropHandler() { @@ -2243,7 +2065,22 @@ public class VTree extends FocusElementPanel implements VPaintableWidget, } } - public Widget getWidgetForPaintable() { - return this; + public void registerAction(String key, String caption, String iconUrl) { + actionMap.put(key + "_c", caption); + if (iconUrl != null) { + actionMap.put(key + "_i", iconUrl); + } else { + actionMap.remove(key + "_i"); + } + } + + public void registerNode(TreeNode treeNode) { + keyToNode.put(treeNode.key, treeNode); + } + + public void clearNodeToKeyMap() { + keyToNode.clear(); + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java new file mode 100644 index 0000000000..c058a15376 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java @@ -0,0 +1,228 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.Iterator;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.TooltipInfo;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode;
+
+public class VTreePaintable extends VAbstractPaintableWidget {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ // Ensure correct implementation and let container manage caption
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().rendering = true;
+
+ getWidgetForPaintable().client = client;
+
+ if (uidl.hasAttribute("partialUpdate")) {
+ handleUpdate(uidl);
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ getWidgetForPaintable().paintableId = uidl.getId();
+
+ getWidgetForPaintable().immediate = uidl.hasAttribute("immediate");
+
+ getWidgetForPaintable().disabled = uidl.getBooleanAttribute("disabled");
+ getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly");
+
+ getWidgetForPaintable().dragMode = uidl.hasAttribute("dragMode") ? uidl
+ .getIntAttribute("dragMode") : 0;
+
+ getWidgetForPaintable().isNullSelectionAllowed = uidl
+ .getBooleanAttribute("nullselect");
+
+ if (uidl.hasAttribute("alb")) {
+ getWidgetForPaintable().bodyActionKeys = uidl
+ .getStringArrayAttribute("alb");
+ }
+
+ getWidgetForPaintable().body.clear();
+ // clear out any references to nodes that no longer are attached
+ getWidgetForPaintable().clearNodeToKeyMap();
+ TreeNode childTree = null;
+ UIDL childUidl = null;
+ for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
+ childUidl = (UIDL) i.next();
+ if ("actions".equals(childUidl.getTag())) {
+ updateActionMap(childUidl);
+ continue;
+ } else if ("-ac".equals(childUidl.getTag())) {
+ getWidgetForPaintable().updateDropHandler(childUidl);
+ continue;
+ }
+ childTree = getWidgetForPaintable().new TreeNode();
+ updateNodeFromUIDL(childTree, childUidl);
+ getWidgetForPaintable().body.add(childTree);
+ childTree.addStyleDependentName("root");
+ childTree.childNodeContainer.addStyleDependentName("root");
+ }
+ if (childTree != null && childUidl != null) {
+ boolean leaf = !childUidl.getTag().equals("node");
+ childTree.addStyleDependentName(leaf ? "leaf-last" : "last");
+ childTree.childNodeContainer.addStyleDependentName("last");
+ }
+ final String selectMode = uidl.getStringAttribute("selectmode");
+ getWidgetForPaintable().selectable = !"none".equals(selectMode);
+ getWidgetForPaintable().isMultiselect = "multi".equals(selectMode);
+
+ if (getWidgetForPaintable().isMultiselect) {
+ getWidgetForPaintable().multiSelectMode = uidl
+ .getIntAttribute("multiselectmode");
+ }
+
+ getWidgetForPaintable().selectedIds = uidl
+ .getStringArrayVariableAsSet("selected");
+
+ // Update lastSelection and focusedNode to point to *actual* nodes again
+ // after the old ones have been cleared from the body. This fixes focus
+ // and keyboard navigation issues as described in #7057 and other
+ // tickets.
+ if (getWidgetForPaintable().lastSelection != null) {
+ getWidgetForPaintable().lastSelection = getWidgetForPaintable()
+ .getNodeByKey(getWidgetForPaintable().lastSelection.key);
+ }
+ if (getWidgetForPaintable().focusedNode != null) {
+ getWidgetForPaintable().setFocusedNode(
+ getWidgetForPaintable().getNodeByKey(
+ getWidgetForPaintable().focusedNode.key));
+ }
+
+ if (getWidgetForPaintable().lastSelection == null
+ && getWidgetForPaintable().focusedNode == null
+ && !getWidgetForPaintable().selectedIds.isEmpty()) {
+ getWidgetForPaintable().setFocusedNode(
+ getWidgetForPaintable().getNodeByKey(
+ getWidgetForPaintable().selectedIds.iterator()
+ .next()));
+ getWidgetForPaintable().focusedNode.setFocused(false);
+ }
+
+ getWidgetForPaintable().rendering = false;
+
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VTree.class);
+ }
+
+ @Override
+ public VTree getWidgetForPaintable() {
+ return (VTree) super.getWidgetForPaintable();
+ }
+
+ private void handleUpdate(UIDL uidl) {
+ final TreeNode rootNode = getWidgetForPaintable().getNodeByKey(
+ uidl.getStringAttribute("rootKey"));
+ if (rootNode != null) {
+ if (!rootNode.getState()) {
+ // expanding node happened server side
+ rootNode.setState(true, false);
+ }
+ renderChildNodes(rootNode, (Iterator) uidl.getChildIterator());
+ }
+ }
+
+ /**
+ * Registers action for the root and also for individual nodes
+ *
+ * @param uidl
+ */
+ private void updateActionMap(UIDL uidl) {
+ final Iterator<?> it = uidl.getChildIterator();
+ while (it.hasNext()) {
+ final UIDL action = (UIDL) it.next();
+ final String key = action.getStringAttribute("key");
+ final String caption = action.getStringAttribute("caption");
+ String iconUrl = null;
+ if (action.hasAttribute("icon")) {
+ iconUrl = getConnection().translateVaadinUri(
+ action.getStringAttribute("icon"));
+ }
+ getWidgetForPaintable().registerAction(key, caption, iconUrl);
+ }
+
+ }
+
+ public void updateNodeFromUIDL(TreeNode treeNode, UIDL uidl) {
+ String nodeKey = uidl.getStringAttribute("key");
+ treeNode.setText(uidl.getStringAttribute("caption"));
+ treeNode.key = nodeKey;
+
+ getWidgetForPaintable().registerNode(treeNode);
+
+ if (uidl.hasAttribute("al")) {
+ treeNode.actionKeys = uidl.getStringArrayAttribute("al");
+ }
+
+ if (uidl.getTag().equals("node")) {
+ if (uidl.getChildCount() == 0) {
+ treeNode.childNodeContainer.setVisible(false);
+ } else {
+ renderChildNodes(treeNode, (Iterator) uidl.getChildIterator());
+ treeNode.childrenLoaded = true;
+ }
+ } else {
+ treeNode.addStyleName(TreeNode.CLASSNAME + "-leaf");
+ }
+ if (uidl.hasAttribute("style")) {
+ treeNode.setNodeStyleName(uidl.getStringAttribute("style"));
+ }
+
+ String description = uidl.getStringAttribute("descr");
+ if (description != null && getConnection() != null) {
+ // Set tooltip
+ TooltipInfo info = new TooltipInfo(description);
+ getConnection().registerTooltip(this, nodeKey, info);
+ } else {
+ // Remove possible previous tooltip
+ getConnection().registerTooltip(this, nodeKey, null);
+ }
+
+ if (uidl.getBooleanAttribute("expanded") && !treeNode.getState()) {
+ treeNode.setState(true, false);
+ }
+
+ if (uidl.getBooleanAttribute("selected")) {
+ treeNode.setSelected(true);
+ // ensure that identifier is in selectedIds array (this may be a
+ // partial update)
+ getWidgetForPaintable().selectedIds.add(nodeKey);
+ }
+
+ treeNode.setIcon(uidl.getStringAttribute("icon"));
+ }
+
+ void renderChildNodes(TreeNode containerNode, Iterator<UIDL> i) {
+ containerNode.childNodeContainer.clear();
+ containerNode.childNodeContainer.setVisible(true);
+ while (i.hasNext()) {
+ final UIDL childUidl = i.next();
+ // actions are in bit weird place, don't mix them with children,
+ // but current node's actions
+ if ("actions".equals(childUidl.getTag())) {
+ updateActionMap(childUidl);
+ continue;
+ }
+ final TreeNode childTree = getWidgetForPaintable().new TreeNode();
+ updateNodeFromUIDL(childTree, childUidl);
+ containerNode.add(childTree);
+ if (!i.hasNext()) {
+ childTree
+ .addStyleDependentName(childTree.isLeaf() ? "leaf-last"
+ : "last");
+ childTree.childNodeContainer.addStyleDependentName("last");
+ }
+ }
+ containerNode.childrenLoaded = true;
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java index 3a5d5f3b41..e733b2e73b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java @@ -27,7 +27,6 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; @@ -157,18 +156,7 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, return selectionsCaption; } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // Captions are updated before super call to ensure the widths are set - // correctly - if (!uidl.getBooleanAttribute("cached")) { - updateCaptions(uidl); - } - - super.updateFromUIDL(uidl, client); - } - - private void updateCaptions(UIDL uidl) { + protected void updateCaptions(UIDL uidl) { String leftCaption = (uidl.hasAttribute(ATTRIBUTE_LEFT_CAPTION) ? uidl .getStringAttribute(ATTRIBUTE_LEFT_CAPTION) : null); String rightCaption = (uidl.hasAttribute(ATTRIBUTE_RIGHT_CAPTION) ? uidl @@ -297,7 +285,7 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, Set<String> movedItems = moveSelectedItems(options, selections); selectedKeys.addAll(movedItems); - client.updateVariable(id, "selected", + client.updateVariable(paintableId, "selected", selectedKeys.toArray(new String[selectedKeys.size()]), isImmediate()); } @@ -306,7 +294,7 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, Set<String> movedItems = moveSelectedItems(selections, options); selectedKeys.removeAll(movedItems); - client.updateVariable(id, "selected", + client.updateVariable(paintableId, "selected", selectedKeys.toArray(new String[selectedKeys.size()]), isImmediate()); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelectPaintable.java new file mode 100644 index 0000000000..ce176113da --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelectPaintable.java @@ -0,0 +1,34 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VTwinColSelectPaintable extends VOptionGroupBasePaintable { + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Captions are updated before super call to ensure the widths are set + // correctly + if (!uidl.getBooleanAttribute("cached")) { + getWidgetForPaintable().updateCaptions(uidl); + } + + super.updateFromUIDL(uidl, client); + } + + @Override + protected Widget createWidget() { + return GWT.create(VTwinColSelect.class); + } + + @Override + public VTwinColSelect getWidgetForPaintable() { + return (VTwinColSelect) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponent.java b/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponent.java index 5b3790f521..ad702430f6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponent.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponent.java @@ -6,19 +6,14 @@ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.SimpleTree; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.VUIDLBrowser; -public class VUnknownComponent extends Composite implements VPaintableWidget { +public class VUnknownComponent extends Composite { com.google.gwt.user.client.ui.Label caption = new com.google.gwt.user.client.ui.Label();; SimpleTree uidlTree; - private VerticalPanel panel; - private String serverClassName = "unkwnown"; + protected VerticalPanel panel; + protected String serverClassName = "unkwnown"; public VUnknownComponent() { panel = new VerticalPanel(); @@ -32,33 +27,7 @@ public class VUnknownComponent extends Composite implements VPaintableWidget { this.serverClassName = serverClassName; } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, false)) { - return; - } - setCaption("Widgetset does not contain implementation for " - + serverClassName - + ". Check its @ClientWidget mapping, widgetsets " - + "GWT module description file and re-compile your" - + " widgetset. In case you have downloaded a vaadin" - + " add-on package, you might want to refer to " - + "<a href='http://vaadin.com/using-addons'>add-on " - + "instructions</a>. Unrendered UIDL:"); - if (uidlTree != null) { - uidlTree.removeFromParent(); - } - - uidlTree = new VUIDLBrowser(uidl, client.getConfiguration()); - uidlTree.open(true); - uidlTree.setText("Unrendered UIDL"); - panel.add(uidlTree); - } - public void setCaption(String c) { caption.getElement().setInnerHTML(c); } - - public Widget getWidgetForPaintable() { - return this; - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponentPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponentPaintable.java new file mode 100644 index 0000000000..252d7528ca --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VUnknownComponentPaintable.java @@ -0,0 +1,52 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VUIDLBrowser; + +public class VUnknownComponentPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + if (client.updateComponent(this, uidl, false)) { + return; + } + getWidgetForPaintable().setCaption( + "Widgetset does not contain implementation for " + + getWidgetForPaintable().serverClassName + + ". Check its @ClientWidget mapping, widgetsets " + + "GWT module description file and re-compile your" + + " widgetset. In case you have downloaded a vaadin" + + " add-on package, you might want to refer to " + + "<a href='http://vaadin.com/using-addons'>add-on " + + "instructions</a>. Unrendered UIDL:"); + if (getWidgetForPaintable().uidlTree != null) { + getWidgetForPaintable().uidlTree.removeFromParent(); + } + + getWidgetForPaintable().uidlTree = new VUIDLBrowser(uidl, + client.getConfiguration()); + getWidgetForPaintable().uidlTree.open(true); + getWidgetForPaintable().uidlTree.setText("Unrendered UIDL"); + getWidgetForPaintable().panel.add(getWidgetForPaintable().uidlTree); + } + + @Override + protected Widget createWidget() { + return GWT.create(VUnknownComponent.class); + } + + @Override + public VUnknownComponent getWidgetForPaintable() { + return (VUnknownComponent) super.getWidgetForPaintable(); + } + + public void setServerSideClassName(String serverClassName) { + getWidgetForPaintable().setServerSideClassName(serverClassName); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java index 66894417f3..bc94ae317a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java @@ -21,12 +21,9 @@ import com.google.gwt.user.client.ui.FormPanel; import com.google.gwt.user.client.ui.Hidden; import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.SimplePanel; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; /** @@ -35,7 +32,7 @@ import com.vaadin.terminal.gwt.client.VTooltip; * events even though the upload component is already detached. * */ -public class VUpload extends SimplePanel implements VPaintableWidget { +public class VUpload extends SimplePanel { private final class MyFileUpload extends FileUpload { @Override @@ -73,19 +70,19 @@ public class VUpload extends SimplePanel implements VPaintableWidget { ApplicationConnection client; - private String paintableId; + protected String paintableId; /** * Button that initiates uploading */ - private final VButton submitButton; + protected final VButton submitButton; /** * When expecting big files, programmer may initiate some UI changes when * uploading the file starts. Bit after submitting file we'll visit the * server to check possible changes. */ - private Timer t; + protected Timer t; /** * some browsers tries to send form twice if submit is called in button @@ -100,11 +97,11 @@ public class VUpload extends SimplePanel implements VPaintableWidget { private Hidden maxfilesize = new Hidden(); - private FormElement element; + protected FormElement element; private com.google.gwt.dom.client.Element synthesizedFrame; - private int nextUploadId; + protected int nextUploadId; public VUpload() { super(com.google.gwt.dom.client.Document.get().createFormElement()); @@ -137,7 +134,7 @@ public class VUpload extends SimplePanel implements VPaintableWidget { @Override public void onBrowserEvent(Event event) { if ((event.getTypeInt() & VTooltip.TOOLTIP_EVENTS) > 0) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } super.onBrowserEvent(event); } @@ -147,43 +144,7 @@ public class VUpload extends SimplePanel implements VPaintableWidget { form.enctype = encoding; }-*/; - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - if (uidl.hasAttribute("notStarted")) { - t.schedule(400); - return; - } - if (uidl.hasAttribute("forceSubmit")) { - submit(); - return; - } - setImmediate(uidl.getBooleanAttribute("immediate")); - this.client = client; - paintableId = uidl.getId(); - nextUploadId = uidl.getIntAttribute("nextid"); - final String action = client.translateVaadinUri(uidl - .getStringVariable("action")); - element.setAction(action); - if (uidl.hasAttribute("buttoncaption")) { - submitButton.setText(uidl.getStringAttribute("buttoncaption")); - submitButton.setVisible(true); - } else { - submitButton.setVisible(false); - } - fu.setName(paintableId + "_file"); - - if (uidl.hasAttribute("disabled") || uidl.hasAttribute("readonly")) { - disableUpload(); - } else if (!uidl.getBooleanAttribute("state")) { - // Enable the button only if an upload is not in progress - enableUpload(); - ensureTargetFrame(); - } - } - - private void setImmediate(boolean booleanAttribute) { + protected void setImmediate(boolean booleanAttribute) { if (immediate != booleanAttribute) { immediate = booleanAttribute; if (immediate) { @@ -277,7 +238,7 @@ public class VUpload extends SimplePanel implements VPaintableWidget { }); } - private void submit() { + protected void submit() { if (fu.getFilename().length() == 0 || submitted || !enabled) { VConsole.log("Submit cancelled (disabled, no file or already submitted)"); return; @@ -315,15 +276,12 @@ public class VUpload extends SimplePanel implements VPaintableWidget { } } - private void ensureTargetFrame() { + protected void ensureTargetFrame() { if (synthesizedFrame == null) { // Attach a hidden IFrame to the form. This is the target iframe to - // which - // the form will be submitted. We have to create the iframe using - // innerHTML, - // because setting an iframe's 'name' property dynamically doesn't - // work on - // most browsers. + // which the form will be submitted. We have to create the iframe + // using innerHTML, because setting an iframe's 'name' property + // dynamically doesn't work on most browsers. DivElement dummy = Document.get().createDivElement(); dummy.setInnerHTML("<iframe src=\"javascript:''\" name='" + getFrameName() @@ -354,9 +312,4 @@ public class VUpload extends SimplePanel implements VPaintableWidget { synthesizedFrame = null; } } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUploadPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VUploadPaintable.java new file mode 100644 index 0000000000..7fd59fc176 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VUploadPaintable.java @@ -0,0 +1,62 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VUploadPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + if (client.updateComponent(this, uidl, true)) { + return; + } + if (uidl.hasAttribute("notStarted")) { + getWidgetForPaintable().t.schedule(400); + return; + } + if (uidl.hasAttribute("forceSubmit")) { + getWidgetForPaintable().submit(); + return; + } + getWidgetForPaintable().setImmediate( + uidl.getBooleanAttribute("immediate")); + getWidgetForPaintable().client = client; + getWidgetForPaintable().paintableId = uidl.getId(); + getWidgetForPaintable().nextUploadId = uidl.getIntAttribute("nextid"); + final String action = client.translateVaadinUri(uidl + .getStringVariable("action")); + getWidgetForPaintable().element.setAction(action); + if (uidl.hasAttribute("buttoncaption")) { + getWidgetForPaintable().submitButton.setText(uidl + .getStringAttribute("buttoncaption")); + getWidgetForPaintable().submitButton.setVisible(true); + } else { + getWidgetForPaintable().submitButton.setVisible(false); + } + getWidgetForPaintable().fu.setName(getWidgetForPaintable().paintableId + + "_file"); + + if (uidl.hasAttribute("disabled") || uidl.hasAttribute("readonly")) { + getWidgetForPaintable().disableUpload(); + } else if (!uidl.getBooleanAttribute("state")) { + // Enable the button only if an upload is not in progress + getWidgetForPaintable().enableUpload(); + getWidgetForPaintable().ensureTargetFrame(); + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VUpload.class); + } + + @Override + public VUpload getWidgetForPaintable() { + return (VUpload) super.getWidgetForPaintable(); + } +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java new file mode 100644 index 0000000000..5378218ece --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVerticalLayoutPaintable.java @@ -0,0 +1,17 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+public class VVerticalLayoutPaintable extends VOrderedLayoutPaintable {
+
+ @Override
+ public VVerticalLayout getWidgetForPaintable() {
+ return (VVerticalLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected VVerticalLayout createWidget() {
+ return GWT.create(VVerticalLayout.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java new file mode 100644 index 0000000000..d60a3185af --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java @@ -0,0 +1,12 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+public class VVerticalSplitPanelPaintable extends VAbstractSplitPanelPaintable {
+
+ @Override
+ protected VAbstractSplitPanel createWidget() {
+ return GWT.create(VSplitPanelVertical.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVideo.java b/src/com/vaadin/terminal/gwt/client/ui/VVideo.java index 71be059319..36f17e1436 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VVideo.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VVideo.java @@ -8,13 +8,9 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.VideoElement; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; public class VVideo extends VMediaBase { - public static final String ATTR_POSTER = "poster"; private static String CLASSNAME = "v-video"; @@ -28,22 +24,6 @@ public class VVideo extends VMediaBase { updateDimensionsWhenMetadataLoaded(getElement()); } - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - super.updateFromUIDL(uidl, client); - setPosterFromUIDL(uidl); - } - - private void setPosterFromUIDL(UIDL uidl) { - if (uidl.hasAttribute(ATTR_POSTER)) { - video.setPoster(client.translateVaadinUri(uidl - .getStringAttribute(ATTR_POSTER))); - } - } - /** * Registers a listener that updates the dimensions of the widget when the * video metadata has been loaded. @@ -76,7 +56,8 @@ public class VVideo extends VMediaBase { return "Your browser does not support the <code>video</code> element."; } - public Widget getWidgetForPaintable() { - return this; + public void setPoster(String poster) { + video.setPoster(poster); } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java new file mode 100644 index 0000000000..a9a46671be --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVideoPaintable.java @@ -0,0 +1,38 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VVideoPaintable extends VMediaBasePaintable {
+ public static final String ATTR_POSTER = "poster";
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ super.updateFromUIDL(uidl, client);
+ setPosterFromUIDL(uidl);
+ }
+
+ private void setPosterFromUIDL(UIDL uidl) {
+ if (uidl.hasAttribute(ATTR_POSTER)) {
+ getWidgetForPaintable().setPoster(
+ getConnection().translateVaadinUri(
+ uidl.getStringAttribute(ATTR_POSTER)));
+ }
+ }
+
+ @Override
+ public VVideo getWidgetForPaintable() {
+ return (VVideo) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VVideo.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java index e3aba21096..7002c6279f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java @@ -5,8 +5,6 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; @@ -17,12 +15,10 @@ import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.event.dom.client.DomEvent.Type; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; -import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; @@ -30,7 +26,6 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; @@ -56,15 +51,15 @@ public class VView extends SimplePanel implements Container, ResizeHandler, public static final String NOTIFICATION_HTML_CONTENT_NOT_ALLOWED = "useplain"; - private String theme; + String theme; - private VPaintableWidget layout; + VPaintableWidget layout; - private final LinkedHashSet<VWindow> subWindows = new LinkedHashSet<VWindow>(); + final LinkedHashSet<VWindow> subWindows = new LinkedHashSet<VWindow>(); - private String id; + String id; - private ShortcutActionHandler actionHandler; + ShortcutActionHandler actionHandler; /** stored width for IE resize optimization */ private int width; @@ -72,7 +67,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, /** stored height for IE resize optimization */ private int height; - private ApplicationConnection connection; + ApplicationConnection connection; /** Identifies the click event */ public static final String CLICK_EVENT_ID = "click"; @@ -85,17 +80,17 @@ public class VView extends SimplePanel implements Container, ResizeHandler, */ private Timer resizeTimer; - private int scrollTop; + int scrollTop; - private int scrollLeft; + int scrollLeft; - private boolean rendering; + boolean rendering; - private boolean scrollable; + boolean scrollable; - private boolean immediate; + boolean immediate; - private boolean resizeLazy = false; + boolean resizeLazy = false; /** * Attribute name for the lazy resize setting . @@ -106,7 +101,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, * Reference to the parent frame/iframe. Null if there is no parent (i)frame * or if the application and parent frame are in different domains. */ - private Element parentFrame; + Element parentFrame; private HandlerRegistration historyHandlerRegistration; @@ -114,7 +109,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, * The current URI fragment, used to avoid sending updates if nothing has * changed. */ - private String currentFragment; + String currentFragment; /** * Listener for URI fragment changes. Notifies the server of the new value @@ -133,16 +128,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler, } }; - private ClickEventHandler clickEventHandler = new ClickEventHandler(this, - VPanel.CLICK_EVENT_IDENTIFIER) { - - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; - private VLazyExecutor delayedResizeExecutor = new VLazyExecutor(200, new ScheduledCommand() { public void execute() { @@ -212,7 +197,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, /** * Used to reload host page on theme changes. */ - private static native void reloadHostPage() + static native void reloadHostPage() /*-{ $wnd.location.reload(); }-*/; @@ -223,7 +208,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, * @param script * Script to be executed. */ - private static native void eval(String script) + static native void eval(String script) /*-{ try { if (script == null) return; @@ -244,229 +229,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler, .contains(ApplicationConnection.GENERATED_BODY_CLASSNAME); } - public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { - rendering = true; - - id = uidl.getId(); - boolean firstPaint = connection == null; - connection = client; - - immediate = uidl.hasAttribute("immediate"); - resizeLazy = uidl.hasAttribute(RESIZE_LAZY); - String newTheme = uidl.getStringAttribute("theme"); - if (theme != null && !newTheme.equals(theme)) { - // Complete page refresh is needed due css can affect layout - // calculations etc - reloadHostPage(); - } else { - theme = newTheme; - } - if (uidl.hasAttribute("style")) { - setStyleName(getStylePrimaryName() + " " - + uidl.getStringAttribute("style")); - } - - clickEventHandler.handleEventHandlerRegistration(client); - - if (!isEmbedded() && uidl.hasAttribute("caption")) { - // only change window title if we're in charge of the whole page - com.google.gwt.user.client.Window.setTitle(uidl - .getStringAttribute("caption")); - } - - // Process children - int childIndex = 0; - - // Open URL:s - boolean isClosed = false; // was this window closed? - while (childIndex < uidl.getChildCount() - && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { - final UIDL open = uidl.getChildUIDL(childIndex); - final String url = client.translateVaadinUri(open - .getStringAttribute("src")); - final String target = open.getStringAttribute("name"); - if (target == null) { - // source will be opened to this browser window, but we may have - // to finish rendering this window in case this is a download - // (and window stays open). - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - goTo(url); - } - }); - } else if ("_self".equals(target)) { - // This window is closing (for sure). Only other opens are - // relevant in this change. See #3558, #2144 - isClosed = true; - goTo(url); - } else { - String options; - if (open.hasAttribute("border")) { - if (open.getStringAttribute("border").equals("minimal")) { - options = "menubar=yes,location=no,status=no"; - } else { - options = "menubar=no,location=no,status=no"; - } - - } else { - options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; - } - - if (open.hasAttribute("width")) { - int w = open.getIntAttribute("width"); - options += ",width=" + w; - } - if (open.hasAttribute("height")) { - int h = open.getIntAttribute("height"); - options += ",height=" + h; - } - - Window.open(url, target, options); - } - childIndex++; - } - if (isClosed) { - // don't render the content, something else will be opened to this - // browser view - rendering = false; - return; - } - - // Draw this application level window - UIDL childUidl = uidl.getChildUIDL(childIndex); - final VPaintableWidget lo = client.getPaintable(childUidl); - - if (layout != null) { - if (layout != lo) { - // remove old - client.unregisterPaintable(layout); - // add new - setWidget(lo.getWidgetForPaintable()); - layout = lo; - } - } else { - setWidget(lo.getWidgetForPaintable()); - layout = lo; - } - - layout.updateFromUIDL(childUidl, client); - if (!childUidl.getBooleanAttribute("cached")) { - updateParentFrameSize(); - } - - // Save currently open subwindows to track which will need to be closed - final HashSet<VWindow> removedSubWindows = new HashSet<VWindow>( - subWindows); - - // Handle other UIDL children - while ((childUidl = uidl.getChildUIDL(++childIndex)) != null) { - String tag = childUidl.getTag().intern(); - if (tag == "actions") { - if (actionHandler == null) { - actionHandler = new ShortcutActionHandler(id, client); - } - actionHandler.updateActionMap(childUidl); - } else if (tag == "execJS") { - String script = childUidl.getStringAttribute("script"); - eval(script); - } else if (tag == "notifications") { - for (final Iterator<?> it = childUidl.getChildIterator(); it - .hasNext();) { - final UIDL notification = (UIDL) it.next(); - VNotification.showNotification(client, notification); - } - } else { - // subwindows - final VPaintableWidget w = client.getPaintable(childUidl); - if (subWindows.contains(w)) { - removedSubWindows.remove(w); - } else { - subWindows.add((VWindow) w); - } - w.updateFromUIDL(childUidl, client); - } - } - - // Close old windows which where not in UIDL anymore - for (final Iterator<VWindow> rem = removedSubWindows.iterator(); rem - .hasNext();) { - final VWindow w = rem.next(); - client.unregisterPaintable(w); - subWindows.remove(w); - w.hide(); - } - - if (uidl.hasAttribute("focused")) { - // set focused component when render phase is finished - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - VPaintableWidget paintable = (VPaintableWidget) uidl - .getPaintableAttribute("focused", connection); - - final Widget toBeFocused = paintable - .getWidgetForPaintable(); - /* - * Two types of Widgets can be focused, either implementing - * GWT HasFocus of a thinner Vaadin specific Focusable - * interface. - */ - if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { - final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; - toBeFocusedWidget.setFocus(true); - } else if (toBeFocused instanceof Focusable) { - ((Focusable) toBeFocused).focus(); - } else { - VConsole.log("Could not focus component"); - } - } - }); - } - - // Add window listeners on first paint, to prevent premature - // variablechanges - if (firstPaint) { - Window.addWindowClosingHandler(this); - Window.addResizeHandler(this); - } - - onResize(); - - // finally set scroll position from UIDL - if (uidl.hasVariable("scrollTop")) { - scrollable = true; - scrollTop = uidl.getIntVariable("scrollTop"); - DOM.setElementPropertyInt(getElement(), "scrollTop", scrollTop); - scrollLeft = uidl.getIntVariable("scrollLeft"); - DOM.setElementPropertyInt(getElement(), "scrollLeft", scrollLeft); - } else { - scrollable = false; - } - - // Safari workaround must be run after scrollTop is updated as it sets - // scrollTop using a deferred command. - if (BrowserInfo.get().isSafari()) { - Util.runWebkitOverflowAutoFix(getElement()); - } - - scrollIntoView(uidl); - - if (uidl.hasAttribute(FRAGMENT_VARIABLE)) { - currentFragment = uidl.getStringAttribute(FRAGMENT_VARIABLE); - if (!currentFragment.equals(History.getToken())) { - History.newItem(currentFragment, true); - } - } else { - // Initial request for which the server doesn't yet have a fragment - // (and haven't shown any interest in getting one) - currentFragment = History.getToken(); - - // Include current fragment in the next request - client.updateVariable(id, FRAGMENT_VARIABLE, currentFragment, false); - } - - rendering = false; - } - /** * Tries to scroll paintable referenced from given UIDL snippet to be * visible. @@ -530,7 +292,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, /** * Called when a resize event is received. */ - private void onResize() { + void onResize() { /* * IE (pre IE9 at least) will give us some false resize events due to * problems with scrollbars. Firefox 3 might also produce some extra @@ -742,7 +504,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, } - private void updateParentFrameSize() { + void updateParentFrameSize() { if (parentFrame == null) { return; } @@ -754,7 +516,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler, parentFrame.getStyle().setPropertyPx("height", childHeight); } - private static native Element getParentFrame() + static native Element getParentFrame() /*-{ try { var frameElement = $wnd.frameElement; @@ -769,10 +531,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler, return null; }-*/; - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // NOP Subwindows never draw caption for their first child (layout) - } - /** * Return an iterator for current subwindows. This method is meant for * testing purposes only. @@ -787,42 +545,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler, return windows; } - public void init(String rootPanelId, - ApplicationConnection applicationConnection) { - DOM.sinkEvents(getElement(), Event.ONKEYDOWN | Event.ONSCROLL); - - // iview is focused when created so element needs tabIndex - // 1 due 0 is at the end of natural tabbing order - DOM.setElementProperty(getElement(), "tabIndex", "1"); - - RootPanel root = RootPanel.get(rootPanelId); - - // Remove the v-app-loading or any splash screen added inside the div by - // the user - root.getElement().setInnerHTML(""); - // For backwards compatibility with static index pages only. - // No longer added by AbstractApplicationServlet/Portlet - root.removeStyleName("v-app-loading"); - - String themeUri = applicationConnection.getConfiguration() - .getThemeUri(); - String themeName = themeUri.substring(themeUri.lastIndexOf('/')); - themeName = themeName.replaceAll("[^a-zA-Z0-9]", ""); - root.addStyleName("v-theme-" + themeName); - - root.add(this); - - if (applicationConnection.getConfiguration().isStandalone()) { - // set focus to iview element by default to listen possible keyboard - // shortcuts. For embedded applications this is unacceptable as we - // don't want to steal focus from the main page nor we don't want - // side-effects from focusing (scrollIntoView). - getElement().focus(); - } - - parentFrame = getParentFrame(); - } - public ShortcutActionHandler getShortcutActionHandler() { return actionHandler; } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java new file mode 100644 index 0000000000..ebec292ecb --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java @@ -0,0 +1,331 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.History;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.Focusable;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VConsole;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VViewPaintable extends VAbstractPaintableWidgetContainer {
+
+ private static final String CLICK_EVENT_IDENTIFIER = VPanelPaintable.CLICK_EVENT_IDENTIFIER;
+
+ public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+
+ getWidgetForPaintable().id = uidl.getId();
+ boolean firstPaint = getWidgetForPaintable().connection == null;
+ getWidgetForPaintable().connection = client;
+
+ getWidgetForPaintable().immediate = uidl.hasAttribute("immediate");
+ getWidgetForPaintable().resizeLazy = uidl
+ .hasAttribute(VView.RESIZE_LAZY);
+ String newTheme = uidl.getStringAttribute("theme");
+ if (getWidgetForPaintable().theme != null
+ && !newTheme.equals(getWidgetForPaintable().theme)) {
+ // Complete page refresh is needed due css can affect layout
+ // calculations etc
+ getWidgetForPaintable().reloadHostPage();
+ } else {
+ getWidgetForPaintable().theme = newTheme;
+ }
+ if (uidl.hasAttribute("style")) {
+ getWidgetForPaintable().setStyleName(
+ getWidgetForPaintable().getStylePrimaryName() + " "
+ + uidl.getStringAttribute("style"));
+ }
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ if (!getWidgetForPaintable().isEmbedded()
+ && uidl.hasAttribute("caption")) {
+ // only change window title if we're in charge of the whole page
+ com.google.gwt.user.client.Window.setTitle(uidl
+ .getStringAttribute("caption"));
+ }
+
+ // Process children
+ int childIndex = 0;
+
+ // Open URL:s
+ boolean isClosed = false; // was this window closed?
+ while (childIndex < uidl.getChildCount()
+ && "open".equals(uidl.getChildUIDL(childIndex).getTag())) {
+ final UIDL open = uidl.getChildUIDL(childIndex);
+ final String url = client.translateVaadinUri(open
+ .getStringAttribute("src"));
+ final String target = open.getStringAttribute("name");
+ if (target == null) {
+ // source will be opened to this browser window, but we may have
+ // to finish rendering this window in case this is a download
+ // (and window stays open).
+ Scheduler.get().scheduleDeferred(new Command() {
+ public void execute() {
+ VView.goTo(url);
+ }
+ });
+ } else if ("_self".equals(target)) {
+ // This window is closing (for sure). Only other opens are
+ // relevant in this change. See #3558, #2144
+ isClosed = true;
+ VView.goTo(url);
+ } else {
+ String options;
+ if (open.hasAttribute("border")) {
+ if (open.getStringAttribute("border").equals("minimal")) {
+ options = "menubar=yes,location=no,status=no";
+ } else {
+ options = "menubar=no,location=no,status=no";
+ }
+
+ } else {
+ options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes";
+ }
+
+ if (open.hasAttribute("width")) {
+ int w = open.getIntAttribute("width");
+ options += ",width=" + w;
+ }
+ if (open.hasAttribute("height")) {
+ int h = open.getIntAttribute("height");
+ options += ",height=" + h;
+ }
+
+ Window.open(url, target, options);
+ }
+ childIndex++;
+ }
+ if (isClosed) {
+ // don't render the content, something else will be opened to this
+ // browser view
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ // Draw this application level window
+ UIDL childUidl = uidl.getChildUIDL(childIndex);
+ final VPaintableWidget lo = client.getPaintable(childUidl);
+
+ if (getWidgetForPaintable().layout != null) {
+ if (getWidgetForPaintable().layout != lo) {
+ // remove old
+ client.unregisterPaintable(getWidgetForPaintable().layout);
+ // add new
+ getWidgetForPaintable().setWidget(lo.getWidgetForPaintable());
+ getWidgetForPaintable().layout = lo;
+ }
+ } else {
+ getWidgetForPaintable().setWidget(lo.getWidgetForPaintable());
+ getWidgetForPaintable().layout = lo;
+ }
+
+ getWidgetForPaintable().layout.updateFromUIDL(childUidl, client);
+ if (!childUidl.getBooleanAttribute("cached")) {
+ getWidgetForPaintable().updateParentFrameSize();
+ }
+
+ // Save currently open subwindows to track which will need to be closed
+ final HashSet<VWindow> removedSubWindows = new HashSet<VWindow>(
+ getWidgetForPaintable().subWindows);
+
+ // Handle other UIDL children
+ while ((childUidl = uidl.getChildUIDL(++childIndex)) != null) {
+ String tag = childUidl.getTag().intern();
+ if (tag == "actions") {
+ if (getWidgetForPaintable().actionHandler == null) {
+ getWidgetForPaintable().actionHandler = new ShortcutActionHandler(
+ getWidgetForPaintable().id, client);
+ }
+ getWidgetForPaintable().actionHandler
+ .updateActionMap(childUidl);
+ } else if (tag == "execJS") {
+ String script = childUidl.getStringAttribute("script");
+ VView.eval(script);
+ } else if (tag == "notifications") {
+ for (final Iterator<?> it = childUidl.getChildIterator(); it
+ .hasNext();) {
+ final UIDL notification = (UIDL) it.next();
+ VNotification.showNotification(client, notification);
+ }
+ } else {
+ // subwindows
+ final VPaintableWidget w = client.getPaintable(childUidl);
+ if (getWidgetForPaintable().subWindows.contains(w)) {
+ removedSubWindows.remove(w);
+ } else {
+ getWidgetForPaintable().subWindows.add((VWindow) w);
+ }
+ w.updateFromUIDL(childUidl, client);
+ }
+ }
+
+ // Close old windows which where not in UIDL anymore
+ for (final Iterator<VWindow> rem = removedSubWindows.iterator(); rem
+ .hasNext();) {
+ final VWindow w = rem.next();
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(w));
+ getWidgetForPaintable().subWindows.remove(w);
+ w.hide();
+ }
+
+ if (uidl.hasAttribute("focused")) {
+ // set focused component when render phase is finished
+ Scheduler.get().scheduleDeferred(new Command() {
+ public void execute() {
+ VPaintableWidget paintable = (VPaintableWidget) uidl
+ .getPaintableAttribute("focused", getConnection());
+
+ final Widget toBeFocused = paintable
+ .getWidgetForPaintable();
+ /*
+ * Two types of Widgets can be focused, either implementing
+ * GWT HasFocus of a thinner Vaadin specific Focusable
+ * interface.
+ */
+ if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) {
+ final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused;
+ toBeFocusedWidget.setFocus(true);
+ } else if (toBeFocused instanceof Focusable) {
+ ((Focusable) toBeFocused).focus();
+ } else {
+ VConsole.log("Could not focus component");
+ }
+ }
+ });
+ }
+
+ // Add window listeners on first paint, to prevent premature
+ // variablechanges
+ if (firstPaint) {
+ Window.addWindowClosingHandler(getWidgetForPaintable());
+ Window.addResizeHandler(getWidgetForPaintable());
+ }
+
+ getWidgetForPaintable().onResize();
+
+ // finally set scroll position from UIDL
+ if (uidl.hasVariable("scrollTop")) {
+ getWidgetForPaintable().scrollable = true;
+ getWidgetForPaintable().scrollTop = uidl
+ .getIntVariable("scrollTop");
+ DOM.setElementPropertyInt(getWidgetForPaintable().getElement(),
+ "scrollTop", getWidgetForPaintable().scrollTop);
+ getWidgetForPaintable().scrollLeft = uidl
+ .getIntVariable("scrollLeft");
+ DOM.setElementPropertyInt(getWidgetForPaintable().getElement(),
+ "scrollLeft", getWidgetForPaintable().scrollLeft);
+ } else {
+ getWidgetForPaintable().scrollable = false;
+ }
+
+ // Safari workaround must be run after scrollTop is updated as it sets
+ // scrollTop using a deferred command.
+ if (BrowserInfo.get().isSafari()) {
+ Util.runWebkitOverflowAutoFix(getWidgetForPaintable().getElement());
+ }
+
+ getWidgetForPaintable().scrollIntoView(uidl);
+
+ if (uidl.hasAttribute(VView.FRAGMENT_VARIABLE)) {
+ getWidgetForPaintable().currentFragment = uidl
+ .getStringAttribute(VView.FRAGMENT_VARIABLE);
+ if (!getWidgetForPaintable().currentFragment.equals(History
+ .getToken())) {
+ History.newItem(getWidgetForPaintable().currentFragment, true);
+ }
+ } else {
+ // Initial request for which the server doesn't yet have a fragment
+ // (and haven't shown any interest in getting one)
+ getWidgetForPaintable().currentFragment = History.getToken();
+
+ // Include current fragment in the next request
+ client.updateVariable(getWidgetForPaintable().id,
+ VView.FRAGMENT_VARIABLE,
+ getWidgetForPaintable().currentFragment, false);
+ }
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void init(String rootPanelId,
+ ApplicationConnection applicationConnection) {
+ DOM.sinkEvents(getWidgetForPaintable().getElement(), Event.ONKEYDOWN
+ | Event.ONSCROLL);
+
+ // iview is focused when created so element needs tabIndex
+ // 1 due 0 is at the end of natural tabbing order
+ DOM.setElementProperty(getWidgetForPaintable().getElement(),
+ "tabIndex", "1");
+
+ RootPanel root = RootPanel.get(rootPanelId);
+
+ // Remove the v-app-loading or any splash screen added inside the div by
+ // the user
+ root.getElement().setInnerHTML("");
+ // For backwards compatibility with static index pages only.
+ // No longer added by AbstractApplicationServlet/Portlet
+ root.removeStyleName("v-app-loading");
+
+ String themeUri = applicationConnection.getConfiguration()
+ .getThemeUri();
+ String themeName = themeUri.substring(themeUri.lastIndexOf('/'));
+ themeName = themeName.replaceAll("[^a-zA-Z0-9]", "");
+ root.addStyleName("v-theme-" + themeName);
+
+ root.add(getWidgetForPaintable());
+
+ if (applicationConnection.getConfiguration().isStandalone()) {
+ // set focus to iview element by default to listen possible keyboard
+ // shortcuts. For embedded applications this is unacceptable as we
+ // don't want to steal focus from the main page nor we don't want
+ // side-effects from focusing (scrollIntoView).
+ getWidgetForPaintable().getElement().focus();
+ }
+
+ getWidgetForPaintable().parentFrame = VView.getParentFrame();
+ }
+
+ private ClickEventHandler clickEventHandler = new ClickEventHandler(this,
+ CLICK_EVENT_IDENTIFIER) {
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP The main view never draws caption for its layout
+ }
+
+ @Override
+ public VView getWidgetForPaintable() {
+ return (VView) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VView.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java index 95ab0dc773..662b77a7b0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java @@ -13,21 +13,17 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; -import com.google.gwt.event.dom.client.DomEvent.Type; import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.Frame; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; @@ -38,10 +34,8 @@ import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Focusable; import com.vaadin.terminal.gwt.client.RenderSpace; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; /** @@ -51,7 +45,7 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan */ public class VWindow extends VOverlay implements Container, ShortcutActionHandlerOwner, ScrollHandler, KeyDownHandler, - FocusHandler, BlurHandler, BeforeShortcutActionListener, Focusable { + FocusHandler, BlurHandler, Focusable { /** * Minimum allowed height of a window. This refers to the content area, not @@ -88,9 +82,9 @@ public class VWindow extends VOverlay implements Container, public static final int Z_INDEX = 10000; - private VPaintableWidget layout; + VPaintableWidget layout; - private Element contents; + Element contents; private Element header; @@ -98,7 +92,7 @@ public class VWindow extends VOverlay implements Container, private Element resizeBox; - private final FocusableScrollPanel contentPanel = new FocusableScrollPanel(); + final FocusableScrollPanel contentPanel = new FocusableScrollPanel(); private boolean dragging; @@ -116,11 +110,11 @@ public class VWindow extends VOverlay implements Container, private int origH; - private Element closeBox; + Element closeBox; protected ApplicationConnection client; - private String id; + String id; ShortcutActionHandler shortcutHandler; @@ -130,13 +124,13 @@ public class VWindow extends VOverlay implements Container, /** Last known positiony read from UIDL or updated to application connection */ private int uidlPositionY = -1; - private boolean vaadinModality = false; + boolean vaadinModality = false; - private boolean resizable = true; + boolean resizable = true; private boolean draggable = true; - private boolean resizeLazy = false; + boolean resizeLazy = false; private Element modalityCurtain; private Element draggingCurtain; @@ -163,23 +157,13 @@ public class VWindow extends VOverlay implements Container, private String height; - private boolean immediate; + boolean immediate; private Element wrapper, wrapper2; - private ClickEventHandler clickEventHandler = new ClickEventHandler(this, - VPanel.CLICK_EVENT_IDENTIFIER) { + boolean visibilityChangesDisabled; - @Override - protected <H extends EventHandler> HandlerRegistration registerHandler( - H handler, Type<H> type) { - return addDomHandler(handler, type); - } - }; - - private boolean visibilityChangesDisabled; - - private int bringToFrontSequence = -1; + int bringToFrontSequence = -1; private VLazyExecutor delayedContentsSizeUpdater = new VLazyExecutor(200, new ScheduledCommand() { @@ -284,230 +268,12 @@ public class VWindow extends VOverlay implements Container, } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - id = uidl.getId(); - this.client = client; - - // Workaround needed for Testing Tools (GWT generates window DOM - // slightly different in different browsers). - DOM.setElementProperty(closeBox, "id", id + "_window_close"); - - if (uidl.hasAttribute("invisible")) { - hide(); - return; - } - - if (!uidl.hasAttribute("cached")) { - if (uidl.getBooleanAttribute("modal") != vaadinModality) { - setVaadinModality(!vaadinModality); - } - if (!isAttached()) { - setVisible(false); // hide until possible centering - show(); - } - if (uidl.getBooleanAttribute("resizable") != resizable) { - setResizable(!resizable); - } - resizeLazy = uidl.hasAttribute(VView.RESIZE_LAZY); - - setDraggable(!uidl.hasAttribute("fixedposition")); - - // Caption must be set before required header size is measured. If - // the caption attribute is missing the caption should be cleared. - setCaption(uidl.getStringAttribute("caption"), - uidl.getStringAttribute("icon")); - } - - visibilityChangesDisabled = true; - if (client.updateComponent(this, uidl, false)) { - return; - } - visibilityChangesDisabled = false; - - clickEventHandler.handleEventHandlerRegistration(client); - - immediate = uidl.hasAttribute("immediate"); - - setClosable(!uidl.getBooleanAttribute("readonly")); - - // Initialize the position form UIDL - int positionx = uidl.getIntVariable("positionx"); - int positiony = uidl.getIntVariable("positiony"); - if (positionx >= 0 || positiony >= 0) { - if (positionx < 0) { - positionx = 0; - } - if (positiony < 0) { - positiony = 0; - } - setPopupPosition(positionx, positiony); - } - - boolean showingUrl = false; - int childIndex = 0; - UIDL childUidl = uidl.getChildUIDL(childIndex++); - while ("open".equals(childUidl.getTag())) { - // TODO multiple opens with the same target will in practice just - // open the last one - should we fix that somehow? - final String parsedUri = client.translateVaadinUri(childUidl - .getStringAttribute("src")); - if (!childUidl.hasAttribute("name")) { - final Frame frame = new Frame(); - DOM.setStyleAttribute(frame.getElement(), "width", "100%"); - DOM.setStyleAttribute(frame.getElement(), "height", "100%"); - DOM.setStyleAttribute(frame.getElement(), "border", "0px"); - frame.setUrl(parsedUri); - contentPanel.setWidget(frame); - showingUrl = true; - } else { - final String target = childUidl.getStringAttribute("name"); - Window.open(parsedUri, target, ""); - } - childUidl = uidl.getChildUIDL(childIndex++); - } - - final VPaintableWidget lo = client.getPaintable(childUidl); - if (layout != null) { - if (layout != lo) { - // remove old - client.unregisterPaintable(layout); - contentPanel.remove(layout.getWidgetForPaintable()); - // add new - if (!showingUrl) { - contentPanel.setWidget(lo.getWidgetForPaintable()); - } - layout = lo; - } - } else if (!showingUrl) { - contentPanel.setWidget(lo.getWidgetForPaintable()); - layout = lo; - } - - dynamicWidth = !uidl.hasAttribute("width"); - dynamicHeight = !uidl.hasAttribute("height"); - - layoutRelativeWidth = uidl.hasAttribute("layoutRelativeWidth"); - layoutRelativeHeight = uidl.hasAttribute("layoutRelativeHeight"); - - if (dynamicWidth && layoutRelativeWidth) { - /* - * Relative layout width, fix window width before rendering (width - * according to caption) - */ - setNaturalWidth(); - } - - layout.updateFromUIDL(childUidl, client); - if (!dynamicHeight && layoutRelativeWidth) { - /* - * Relative layout width, and fixed height. Must update the size to - * be able to take scrollbars into account (layout gets narrower - * space if it is higher than the window) -> only vertical scrollbar - */ - client.runDescendentsLayout(this); - } - - /* - * No explicit width is set and the layout does not have relative width - * so fix the size according to the layout. - */ - if (dynamicWidth && !layoutRelativeWidth) { - setNaturalWidth(); - } - - if (dynamicHeight && layoutRelativeHeight) { - // Prevent resizing until height has been fixed - resizable = false; - } - - // we may have actions and notifications - if (uidl.getChildCount() > 1) { - final int cnt = uidl.getChildCount(); - for (int i = 1; i < cnt; i++) { - childUidl = uidl.getChildUIDL(i); - if (childUidl.getTag().equals("actions")) { - if (shortcutHandler == null) { - shortcutHandler = new ShortcutActionHandler(id, client); - } - shortcutHandler.updateActionMap(childUidl); - } - } - - } - - // setting scrollposition must happen after children is rendered - contentPanel.setScrollPosition(uidl.getIntVariable("scrollTop")); - contentPanel.setHorizontalScrollPosition(uidl - .getIntVariable("scrollLeft")); - - // Center this window on screen if requested - // This has to be here because we might not know the content size before - // everything is painted into the window - if (uidl.getBooleanAttribute("center")) { - // mark as centered - this is unset on move/resize - centered = true; - center(); - } else { - // don't try to center the window anymore - centered = false; - } - updateShadowSizeAndPosition(); - setVisible(true); - - boolean sizeReduced = false; - // ensure window is not larger than browser window - if (getOffsetWidth() > Window.getClientWidth()) { - setWidth(Window.getClientWidth() + "px"); - sizeReduced = true; - } - if (getOffsetHeight() > Window.getClientHeight()) { - setHeight(Window.getClientHeight() + "px"); - sizeReduced = true; - } - - if (dynamicHeight && layoutRelativeHeight) { - /* - * Window height is undefined, layout is 100% high so the layout - * should define the initial window height but on resize the layout - * should be as high as the window. We fix the height to deal with - * this. - */ - - int h = contents.getOffsetHeight() + getExtraHeight(); - int w = getElement().getOffsetWidth(); - - client.updateVariable(id, "height", h, false); - client.updateVariable(id, "width", w, true); - } - - if (sizeReduced) { - // If we changed the size we need to update the size of the child - // component if it is relative (#3407) - client.runDescendentsLayout(this); - } - - Util.runWebkitOverflowAutoFix(contentPanel.getElement()); - - client.getView().scrollIntoView(uidl); - - if (uidl.hasAttribute("bringToFront")) { - /* - * Focus as a side-efect. Will be overridden by - * ApplicationConnection if another component was focused by the - * server side. - */ - contentPanel.focus(); - bringToFrontSequence = uidl.getIntAttribute("bringToFront"); - deferOrdering(); - } - } - /** * Calling this method will defer ordering algorithm, to order windows based * on servers bringToFront and modality instructions. Non changed windows * will be left intact. */ - private static void deferOrdering() { + static void deferOrdering() { if (!orderingDefered) { orderingDefered = true; Scheduler.get().scheduleFinally(new Command() { @@ -562,7 +328,7 @@ public class VWindow extends VOverlay implements Container, } } - private void setDraggable(boolean draggable) { + void setDraggable(boolean draggable) { if (this.draggable == draggable) { return; } @@ -573,7 +339,7 @@ public class VWindow extends VOverlay implements Container, } private void setCursorProperties() { - if (!this.draggable) { + if (!draggable) { header.getStyle().setProperty("cursor", "default"); footer.getStyle().setProperty("cursor", "default"); } else { @@ -582,7 +348,7 @@ public class VWindow extends VOverlay implements Container, } } - private void setNaturalWidth() { + void setNaturalWidth() { /* * Use max(layout width, window width) i.e layout content width or * caption width. We remove the previous set width so the width is @@ -676,7 +442,7 @@ public class VWindow extends VOverlay implements Container, super.hide(); } - private void setVaadinModality(boolean modality) { + void setVaadinModality(boolean modality) { vaadinModality = modality; if (vaadinModality) { if (isAttached()) { @@ -767,7 +533,7 @@ public class VWindow extends VOverlay implements Container, return curtain; } - private void setResizable(boolean resizability) { + void setResizable(boolean resizability) { resizable = resizability; if (resizability) { DOM.setElementProperty(footer, "className", CLASSNAME + "-footer"); @@ -832,7 +598,7 @@ public class VWindow extends VOverlay implements Container, if (client != null && header.isOrHasChild(target)) { // Handle window caption tooltips - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } if (resizing || resizeBox == target) { @@ -1088,7 +854,7 @@ public class VWindow extends VOverlay implements Container, private int extraH = 0; - private int getExtraHeight() { + int getExtraHeight() { extraH = header.getOffsetHeight() + footer.getOffsetHeight(); return extraH; } @@ -1238,10 +1004,6 @@ public class VWindow extends VOverlay implements Container, return true; } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // NOP, window has own caption, layout captio not rendered - } - public ShortcutActionHandler getShortcutActionHandler() { return shortcutHandler; } @@ -1263,22 +1025,17 @@ public class VWindow extends VOverlay implements Container, } public void onBlur(BlurEvent event) { - if (client.hasEventListeners(this, EventId.BLUR)) { + if (client.hasWidgetEventListeners(this, EventId.BLUR)) { client.updateVariable(id, EventId.BLUR, "", true); } } public void onFocus(FocusEvent event) { - if (client.hasEventListeners(this, EventId.FOCUS)) { + if (client.hasWidgetEventListeners(this, EventId.FOCUS)) { client.updateVariable(id, EventId.FOCUS, "", true); } } - public void onBeforeShortcutAction(Event e) { - // NOP, nothing to update just avoid workaround ( causes excess - // blur/focus ) - } - public void focus() { contentPanel.focus(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java new file mode 100644 index 0000000000..25fd951dd9 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java @@ -0,0 +1,296 @@ +package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.shared.EventHandler;
+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.Window;
+import com.google.gwt.user.client.ui.Frame;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
+
+public class VWindowPaintable extends VAbstractPaintableWidgetContainer
+ implements BeforeShortcutActionListener {
+
+ private static final String CLICK_EVENT_IDENTIFIER = VPanelPaintable.CLICK_EVENT_IDENTIFIER;
+
+ private ClickEventHandler clickEventHandler = new ClickEventHandler(this,
+ CLICK_EVENT_IDENTIFIER) {
+
+ @Override
+ protected <H extends EventHandler> HandlerRegistration registerHandler(
+ H handler, Type<H> type) {
+ return getWidgetForPaintable().addDomHandler(handler, type);
+ }
+ };
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().id = uidl.getId();
+ getWidgetForPaintable().client = client;
+
+ // Workaround needed for Testing Tools (GWT generates window DOM
+ // slightly different in different browsers).
+ DOM.setElementProperty(getWidgetForPaintable().closeBox, "id",
+ getWidgetForPaintable().id + "_window_close");
+
+ if (uidl.hasAttribute("invisible")) {
+ getWidgetForPaintable().hide();
+ return;
+ }
+
+ if (!uidl.hasAttribute("cached")) {
+ if (uidl.getBooleanAttribute("modal") != getWidgetForPaintable().vaadinModality) {
+ getWidgetForPaintable().setVaadinModality(
+ !getWidgetForPaintable().vaadinModality);
+ }
+ if (!getWidgetForPaintable().isAttached()) {
+ getWidgetForPaintable().setVisible(false); // hide until
+ // possible centering
+ getWidgetForPaintable().show();
+ }
+ if (uidl.getBooleanAttribute("resizable") != getWidgetForPaintable().resizable) {
+ getWidgetForPaintable().setResizable(
+ !getWidgetForPaintable().resizable);
+ }
+ getWidgetForPaintable().resizeLazy = uidl
+ .hasAttribute(VView.RESIZE_LAZY);
+
+ getWidgetForPaintable().setDraggable(
+ !uidl.hasAttribute("fixedposition"));
+
+ // Caption must be set before required header size is measured. If
+ // the caption attribute is missing the caption should be cleared.
+ getWidgetForPaintable().setCaption(
+ uidl.getStringAttribute("caption"),
+ uidl.getStringAttribute("icon"));
+ }
+
+ getWidgetForPaintable().visibilityChangesDisabled = true;
+ if (client.updateComponent(this, uidl, false)) {
+ return;
+ }
+ getWidgetForPaintable().visibilityChangesDisabled = false;
+
+ clickEventHandler.handleEventHandlerRegistration(client);
+
+ getWidgetForPaintable().immediate = uidl.hasAttribute("immediate");
+
+ getWidgetForPaintable().setClosable(
+ !uidl.getBooleanAttribute("readonly"));
+
+ // Initialize the position form UIDL
+ int positionx = uidl.getIntVariable("positionx");
+ int positiony = uidl.getIntVariable("positiony");
+ if (positionx >= 0 || positiony >= 0) {
+ if (positionx < 0) {
+ positionx = 0;
+ }
+ if (positiony < 0) {
+ positiony = 0;
+ }
+ getWidgetForPaintable().setPopupPosition(positionx, positiony);
+ }
+
+ boolean showingUrl = false;
+ int childIndex = 0;
+ UIDL childUidl = uidl.getChildUIDL(childIndex++);
+ while ("open".equals(childUidl.getTag())) {
+ // TODO multiple opens with the same target will in practice just
+ // open the last one - should we fix that somehow?
+ final String parsedUri = client.translateVaadinUri(childUidl
+ .getStringAttribute("src"));
+ if (!childUidl.hasAttribute("name")) {
+ final Frame frame = new Frame();
+ DOM.setStyleAttribute(frame.getElement(), "width", "100%");
+ DOM.setStyleAttribute(frame.getElement(), "height", "100%");
+ DOM.setStyleAttribute(frame.getElement(), "border", "0px");
+ frame.setUrl(parsedUri);
+ getWidgetForPaintable().contentPanel.setWidget(frame);
+ showingUrl = true;
+ } else {
+ final String target = childUidl.getStringAttribute("name");
+ Window.open(parsedUri, target, "");
+ }
+ childUidl = uidl.getChildUIDL(childIndex++);
+ }
+
+ final VPaintableWidget lo = client.getPaintable(childUidl);
+ if (getWidgetForPaintable().layout != null) {
+ if (getWidgetForPaintable().layout != lo) {
+ // remove old
+ client.unregisterPaintable(getWidgetForPaintable().layout);
+ getWidgetForPaintable().contentPanel
+ .remove(getWidgetForPaintable().layout
+ .getWidgetForPaintable());
+ // add new
+ if (!showingUrl) {
+ getWidgetForPaintable().contentPanel.setWidget(lo
+ .getWidgetForPaintable());
+ }
+ getWidgetForPaintable().layout = lo;
+ }
+ } else if (!showingUrl) {
+ getWidgetForPaintable().contentPanel.setWidget(lo
+ .getWidgetForPaintable());
+ getWidgetForPaintable().layout = lo;
+ }
+
+ getWidgetForPaintable().dynamicWidth = !uidl.hasAttribute("width");
+ getWidgetForPaintable().dynamicHeight = !uidl.hasAttribute("height");
+
+ getWidgetForPaintable().layoutRelativeWidth = uidl
+ .hasAttribute("layoutRelativeWidth");
+ getWidgetForPaintable().layoutRelativeHeight = uidl
+ .hasAttribute("layoutRelativeHeight");
+
+ if (getWidgetForPaintable().dynamicWidth
+ && getWidgetForPaintable().layoutRelativeWidth) {
+ /*
+ * Relative layout width, fix window width before rendering (width
+ * according to caption)
+ */
+ getWidgetForPaintable().setNaturalWidth();
+ }
+
+ getWidgetForPaintable().layout.updateFromUIDL(childUidl, client);
+ if (!getWidgetForPaintable().dynamicHeight
+ && getWidgetForPaintable().layoutRelativeWidth) {
+ /*
+ * Relative layout width, and fixed height. Must update the size to
+ * be able to take scrollbars into account (layout gets narrower
+ * space if it is higher than the window) -> only vertical scrollbar
+ */
+ client.runDescendentsLayout(getWidgetForPaintable());
+ }
+
+ /*
+ * No explicit width is set and the layout does not have relative width
+ * so fix the size according to the layout.
+ */
+ if (getWidgetForPaintable().dynamicWidth
+ && !getWidgetForPaintable().layoutRelativeWidth) {
+ getWidgetForPaintable().setNaturalWidth();
+ }
+
+ if (getWidgetForPaintable().dynamicHeight
+ && getWidgetForPaintable().layoutRelativeHeight) {
+ // Prevent resizing until height has been fixed
+ getWidgetForPaintable().resizable = false;
+ }
+
+ // we may have actions and notifications
+ if (uidl.getChildCount() > 1) {
+ final int cnt = uidl.getChildCount();
+ for (int i = 1; i < cnt; i++) {
+ childUidl = uidl.getChildUIDL(i);
+ if (childUidl.getTag().equals("actions")) {
+ if (getWidgetForPaintable().shortcutHandler == null) {
+ getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(
+ getId(), client);
+ }
+ getWidgetForPaintable().shortcutHandler
+ .updateActionMap(childUidl);
+ }
+ }
+
+ }
+
+ // setting scrollposition must happen after children is rendered
+ getWidgetForPaintable().contentPanel.setScrollPosition(uidl
+ .getIntVariable("scrollTop"));
+ getWidgetForPaintable().contentPanel.setHorizontalScrollPosition(uidl
+ .getIntVariable("scrollLeft"));
+
+ // Center this window on screen if requested
+ // This has to be here because we might not know the content size before
+ // everything is painted into the window
+ if (uidl.getBooleanAttribute("center")) {
+ // mark as centered - this is unset on move/resize
+ getWidgetForPaintable().centered = true;
+ getWidgetForPaintable().center();
+ } else {
+ // don't try to center the window anymore
+ getWidgetForPaintable().centered = false;
+ }
+ getWidgetForPaintable().updateShadowSizeAndPosition();
+ getWidgetForPaintable().setVisible(true);
+
+ boolean sizeReduced = false;
+ // ensure window is not larger than browser window
+ if (getWidgetForPaintable().getOffsetWidth() > Window.getClientWidth()) {
+ getWidgetForPaintable().setWidth(Window.getClientWidth() + "px");
+ sizeReduced = true;
+ }
+ if (getWidgetForPaintable().getOffsetHeight() > Window
+ .getClientHeight()) {
+ getWidgetForPaintable().setHeight(Window.getClientHeight() + "px");
+ sizeReduced = true;
+ }
+
+ if (getWidgetForPaintable().dynamicHeight
+ && getWidgetForPaintable().layoutRelativeHeight) {
+ /*
+ * Window height is undefined, layout is 100% high so the layout
+ * should define the initial window height but on resize the layout
+ * should be as high as the window. We fix the height to deal with
+ * this.
+ */
+
+ int h = getWidgetForPaintable().contents.getOffsetHeight()
+ + getWidgetForPaintable().getExtraHeight();
+ int w = getWidgetForPaintable().getElement().getOffsetWidth();
+
+ client.updateVariable(getId(), "height", h, false);
+ client.updateVariable(getId(), "width", w, true);
+ }
+
+ if (sizeReduced) {
+ // If we changed the size we need to update the size of the child
+ // component if it is relative (#3407)
+ client.runDescendentsLayout(getWidgetForPaintable());
+ }
+
+ Util.runWebkitOverflowAutoFix(getWidgetForPaintable().contentPanel
+ .getElement());
+
+ client.getView().getWidgetForPaintable().scrollIntoView(uidl);
+
+ if (uidl.hasAttribute("bringToFront")) {
+ /*
+ * Focus as a side-efect. Will be overridden by
+ * ApplicationConnection if another component was focused by the
+ * server side.
+ */
+ getWidgetForPaintable().contentPanel.focus();
+ getWidgetForPaintable().bringToFrontSequence = uidl
+ .getIntAttribute("bringToFront");
+ VWindow.deferOrdering();
+ }
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP, window has own caption, layout captio not rendered
+ }
+
+ public void onBeforeShortcutAction(Event e) {
+ // NOP, nothing to update just avoid workaround ( causes excess
+ // blur/focus )
+ }
+
+ @Override
+ public VWindow getWidgetForPaintable() {
+ return (VWindow) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VWindow.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java index 85f48859a4..9b38ba23ae 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java @@ -3,6 +3,7 @@ */ package com.vaadin.terminal.gwt.client.ui.layout; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -17,7 +18,6 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.Container; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.ui.VMarginInfo; @@ -28,7 +28,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container protected ApplicationConnection client = null; - protected DivElement root; + public DivElement root; public static final int ORIENTATION_VERTICAL = 0; public static final int ORIENTATION_HORIZONTAL = 1; @@ -40,15 +40,15 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container protected final Spacing spacingFromCSS = new Spacing(12, 12); protected final Spacing activeSpacing = new Spacing(0, 0); - private boolean dynamicWidth; + boolean dynamicWidth; - private boolean dynamicHeight; + boolean dynamicHeight; private final DivElement clearElement = Document.get().createDivElement(); private String lastStyleName = ""; - private boolean marginsNeedsRecalculation = false; + boolean marginsNeedsRecalculation = false; protected String STYLENAME_SPACING = ""; protected String STYLENAME_MARGIN_TOP = ""; @@ -105,32 +105,6 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container return widgetToComponentContainer.containsKey(component); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - - // Only non-cached UIDL:s can introduce changes - if (uidl.getBooleanAttribute("cached")) { - return; - } - - /** - * Margin and spacind detection depends on classNames and must be set - * before setting size. Here just update the details from UIDL and from - * overridden setStyleName run actual margin detections. - */ - updateMarginAndSpacingInfo(uidl); - - /* - * This call should be made first. Ensure correct implementation, handle - * size etc. - */ - if (client.updateComponent(this, uidl, true)) { - return; - } - - handleDynamicDimensions(uidl); - } - @Override public void setStyleName(String styleName) { super.setStyleName(styleName); @@ -159,27 +133,6 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container } } - private void handleDynamicDimensions(UIDL uidl) { - String w = uidl.hasAttribute("width") ? uidl - .getStringAttribute("width") : ""; - - String h = uidl.hasAttribute("height") ? uidl - .getStringAttribute("height") : ""; - - if (w.equals("")) { - dynamicWidth = true; - } else { - dynamicWidth = false; - } - - if (h.equals("")) { - dynamicHeight = true; - } else { - dynamicHeight = false; - } - - } - @Override public void setHeight(String height) { super.setHeight(height); @@ -195,7 +148,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container } } - protected void addOrMoveChild(ChildComponentContainer childComponent, + public void addOrMoveChild(ChildComponentContainer childComponent, int position) { if (childComponent.getParent() == this) { if (getWidgetIndex(childComponent) != position) { @@ -235,33 +188,22 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container } - protected ChildComponentContainer getComponentContainer(Widget child) { + public Collection<ChildComponentContainer> getComponentContainers() { + return widgetToComponentContainer.values(); + } + + public ChildComponentContainer getComponentContainer(Widget child) { return widgetToComponentContainer.get(child); } - protected boolean isDynamicWidth() { + public boolean isDynamicWidth() { return dynamicWidth; } - protected boolean isDynamicHeight() { + public boolean isDynamicHeight() { return dynamicHeight; } - private void updateMarginAndSpacingInfo(UIDL uidl) { - if (!uidl.hasAttribute("invisible")) { - int bitMask = uidl.getIntAttribute("margins"); - if (activeMarginsInfo.getBitMask() != bitMask) { - activeMarginsInfo = new VMarginInfo(bitMask); - marginsNeedsRecalculation = true; - } - boolean spacing = uidl.getBooleanAttribute("spacing"); - if (spacing != spacingEnabled) { - marginsNeedsRecalculation = true; - spacingEnabled = spacing; - } - } - } - private static DivElement measurement; private static DivElement measurement2; private static DivElement measurement3; @@ -342,7 +284,7 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container return (ChildComponentContainer) getChildren().get(0); } - protected void removeChildrenAfter(int pos) { + public void removeChildrenAfter(int pos) { // Remove all children after position "pos" but leave the clear element // in place diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java new file mode 100644 index 0000000000..e99425311b --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java @@ -0,0 +1,81 @@ +package com.vaadin.terminal.gwt.client.ui.layout;
+
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;
+import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
+
+public abstract class CellBasedLayoutPaintable extends
+ VAbstractPaintableWidgetContainer {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+
+ // Only non-cached UIDL:s can introduce changes
+ if (uidl.getBooleanAttribute("cached")) {
+ return;
+ }
+
+ /**
+ * Margin and spacind detection depends on classNames and must be set
+ * before setting size. Here just update the details from UIDL and from
+ * overridden setStyleName run actual margin detections.
+ */
+ updateMarginAndSpacingInfo(uidl);
+
+ /*
+ * This call should be made first. Ensure correct implementation, handle
+ * size etc.
+ */
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ handleDynamicDimensions(uidl);
+ }
+
+ private void handleDynamicDimensions(UIDL uidl) {
+ String w = uidl.hasAttribute("width") ? uidl
+ .getStringAttribute("width") : "";
+
+ String h = uidl.hasAttribute("height") ? uidl
+ .getStringAttribute("height") : "";
+
+ if (w.equals("")) {
+ getWidgetForPaintable().dynamicWidth = true;
+ } else {
+ getWidgetForPaintable().dynamicWidth = false;
+ }
+
+ if (h.equals("")) {
+ getWidgetForPaintable().dynamicHeight = true;
+ } else {
+ getWidgetForPaintable().dynamicHeight = false;
+ }
+
+ }
+
+ void updateMarginAndSpacingInfo(UIDL uidl) {
+ if (!uidl.hasAttribute("invisible")) {
+ int bitMask = uidl.getIntAttribute("margins");
+ if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) {
+ getWidgetForPaintable().activeMarginsInfo = new VMarginInfo(
+ bitMask);
+ getWidgetForPaintable().marginsNeedsRecalculation = true;
+ }
+ boolean spacing = uidl.getBooleanAttribute("spacing");
+ if (spacing != getWidgetForPaintable().spacingEnabled) {
+ getWidgetForPaintable().marginsNeedsRecalculation = true;
+ getWidgetForPaintable().spacingEnabled = spacing;
+ }
+ }
+ }
+
+ @Override
+ protected abstract CellBasedLayout createWidget();
+
+ @Override
+ public CellBasedLayout getWidgetForPaintable() {
+ return (CellBasedLayout) super.getWidgetForPaintable();
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java index 35d3247f9b..a586929d13 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java +++ b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java @@ -17,7 +17,6 @@ import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; @@ -27,12 +26,10 @@ import com.google.gwt.user.client.ui.RichTextArea; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.ui.Field; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; /** @@ -41,9 +38,8 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan * @author Vaadin Ltd. * */ -public class VRichTextArea extends Composite implements VPaintableWidget, Field, - ChangeHandler, BlurHandler, KeyPressHandler, KeyDownHandler, - BeforeShortcutActionListener, Focusable { +public class VRichTextArea extends Composite implements Field, ChangeHandler, + BlurHandler, KeyPressHandler, KeyDownHandler, Focusable { /** * The input node CSS classname. @@ -54,13 +50,13 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, protected ApplicationConnection client; - private boolean immediate = false; + boolean immediate = false; - private RichTextArea rta; + RichTextArea rta; private VRichTextToolbar formatter; - private HTML html = new HTML(); + HTML html = new HTML(); private final FlowPanel fp = new FlowPanel(); @@ -69,15 +65,15 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, private int extraHorizontalPixels = -1; private int extraVerticalPixels = -1; - private int maxLength = -1; + int maxLength = -1; private int toolbarNaturalWidth = 500; - private HandlerRegistration keyPressHandler; + HandlerRegistration keyPressHandler; private ShortcutActionHandlerOwner hasShortcutActionHandler; - private String currentValue = ""; + String currentValue = ""; private boolean readOnly = false; @@ -127,48 +123,7 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, } } - public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { - this.client = client; - id = uidl.getId(); - - if (uidl.hasVariable("text")) { - currentValue = uidl.getStringVariable("text"); - if (rta.isAttached()) { - rta.setHTML(currentValue); - } else { - html.setHTML(currentValue); - } - } - if (!uidl.hasAttribute("cached")) { - setEnabled(!uidl.getBooleanAttribute("disabled")); - } - - if (client.updateComponent(this, uidl, true)) { - return; - } - - setReadOnly(uidl.getBooleanAttribute("readonly")); - immediate = uidl.getBooleanAttribute("immediate"); - int newMaxLength = uidl.hasAttribute("maxLength") ? uidl - .getIntAttribute("maxLength") : -1; - if (newMaxLength >= 0) { - if (maxLength == -1) { - keyPressHandler = rta.addKeyPressHandler(this); - } - maxLength = newMaxLength; - } else if (maxLength != -1) { - getElement().setAttribute("maxlength", ""); - maxLength = -1; - keyPressHandler.removeHandler(); - } - - if (uidl.hasAttribute("selectAll")) { - selectAll(); - } - - } - - private void selectAll() { + void selectAll() { /* * There is a timing issue if trying to select all immediately on first * render. Simple deferred command is not enough. Using Timer with @@ -190,7 +145,7 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, }.schedule(320); } - private void setReadOnly(boolean b) { + void setReadOnly(boolean b) { if (isReadOnly() != b) { swapEditableArea(); readOnly = b; @@ -346,7 +301,8 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, if (shortcutHandler != null) { shortcutHandler .handleKeyboardEvent(com.google.gwt.user.client.Event - .as(event.getNativeEvent()), this); + .as(event.getNativeEvent()), + VPaintableMap.get(client).getPaintable(this)); } } @@ -364,10 +320,6 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field, return hasShortcutActionHandler; } - public void onBeforeShortcutAction(Event e) { - synchronizeContentToServer(); - } - public int getTabIndex() { return rta.getTabIndex(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java new file mode 100644 index 0000000000..477cd13dd5 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java @@ -0,0 +1,76 @@ +package com.vaadin.terminal.gwt.client.ui.richtextarea;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;
+
+public class VRichTextAreaPaintable extends VAbstractPaintableWidget implements
+ BeforeShortcutActionListener {
+
+ public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ if (uidl.hasVariable("text")) {
+ getWidgetForPaintable().currentValue = uidl
+ .getStringVariable("text");
+ if (getWidgetForPaintable().rta.isAttached()) {
+ getWidgetForPaintable().rta
+ .setHTML(getWidgetForPaintable().currentValue);
+ } else {
+ getWidgetForPaintable().html
+ .setHTML(getWidgetForPaintable().currentValue);
+ }
+ }
+ if (!uidl.hasAttribute("cached")) {
+ getWidgetForPaintable().setEnabled(
+ !uidl.getBooleanAttribute("disabled"));
+ }
+
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+
+ getWidgetForPaintable().setReadOnly(
+ uidl.getBooleanAttribute("readonly"));
+ getWidgetForPaintable().immediate = uidl
+ .getBooleanAttribute("immediate");
+ int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
+ .getIntAttribute("maxLength") : -1;
+ if (newMaxLength >= 0) {
+ if (getWidgetForPaintable().maxLength == -1) {
+ getWidgetForPaintable().keyPressHandler = getWidgetForPaintable().rta
+ .addKeyPressHandler(getWidgetForPaintable());
+ }
+ getWidgetForPaintable().maxLength = newMaxLength;
+ } else if (getWidgetForPaintable().maxLength != -1) {
+ getWidgetForPaintable().getElement().setAttribute("maxlength", "");
+ getWidgetForPaintable().maxLength = -1;
+ getWidgetForPaintable().keyPressHandler.removeHandler();
+ }
+
+ if (uidl.hasAttribute("selectAll")) {
+ getWidgetForPaintable().selectAll();
+ }
+
+ }
+
+ public void onBeforeShortcutAction(Event e) {
+ getWidgetForPaintable().synchronizeContentToServer();
+ }
+
+ @Override
+ public VRichTextArea getWidgetForPaintable() {
+ return (VRichTextArea) super.getWidgetForPaintable();
+ };
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VRichTextArea.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java index fad5220eb7..d3095512bb 100644 --- a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java +++ b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java @@ -18,6 +18,7 @@ import java.util.logging.Logger; import com.vaadin.terminal.Sizeable.Unit; import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.AbstractSplitPanel; import com.vaadin.ui.Component; import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.CustomComponent; @@ -26,7 +27,6 @@ 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.SplitPanel; import com.vaadin.ui.TabSheet; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; @@ -449,7 +449,7 @@ public class ComponentSizeValidator implements Serializable { } } - if (parent instanceof Panel || parent instanceof SplitPanel + if (parent instanceof Panel || parent instanceof AbstractSplitPanel || parent instanceof TabSheet || parent instanceof CustomComponent) { // height undefined, we know how how component works and no @@ -552,7 +552,7 @@ public class ComponentSizeValidator implements Serializable { * the component width */ return hasNonRelativeWidthComponent((Form) parent); - } else if (parent instanceof SplitPanel + } else if (parent instanceof AbstractSplitPanel || parent instanceof TabSheet || parent instanceof CustomComponent) { // FIXME Could we use com.vaadin package name here and diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java index aeef1951c8..2150748b54 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java @@ -24,7 +24,7 @@ import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.ui.VView; +import com.vaadin.terminal.gwt.client.ui.VViewPaintable; import com.vaadin.ui.ClientWidget; import com.vaadin.ui.ClientWidget.LoadStyle; import com.vaadin.ui.Root; @@ -258,7 +258,7 @@ public class WidgetMapGenerator extends Generator { if (widgetsWithInstantiator.contains(clientClass)) { continue; } - if (clientClass == VView.class) { + if (clientClass == VViewPaintable.class) { // VView's are not instantiated by widgetset continue; } @@ -374,7 +374,7 @@ public class WidgetMapGenerator extends Generator { sourceWriter.print("else "); } sourceWriter - .println("return com.vaadin.terminal.gwt.client.ui.VUnknownComponent.class;"); + .println("return com.vaadin.terminal.gwt.client.ui.VUnknownComponentPaintable.class;"); sourceWriter.outdent(); sourceWriter.println("}"); @@ -384,7 +384,7 @@ public class WidgetMapGenerator extends Generator { Class<? extends Paintable> class1) { Class<? extends com.vaadin.terminal.gwt.client.VPaintableWidget> clientClass; if (Root.class == class1) { - clientClass = VView.class; + clientClass = VViewPaintable.class; } else { ClientWidget annotation = class1.getAnnotation(ClientWidget.class); clientClass = annotation.value(); diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java index d6f9897664..c75073c02b 100644 --- a/src/com/vaadin/ui/AbsoluteLayout.java +++ b/src/com/vaadin/ui/AbsoluteLayout.java @@ -17,7 +17,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.gwt.client.EventId; -import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout; +import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayoutPaintable; /** * AbsoluteLayout is a layout implementation that mimics html absolute @@ -25,7 +25,7 @@ import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout; * */ @SuppressWarnings("serial") -@ClientWidget(VAbsoluteLayout.class) +@ClientWidget(VAbsoluteLayoutPaintable.class) public class AbsoluteLayout extends AbstractLayout implements LayoutClickNotifier { diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 62be25f73b..e27670530b 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -1517,6 +1517,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource size = Float.parseFloat(matcher.group(1)); if (size < 0) { size = -1; + unit = Unit.PIXELS; } else { String symbol = matcher.group(3); unit = Unit.getUnitFromSymbol(symbol); diff --git a/src/com/vaadin/ui/AbstractMedia.java b/src/com/vaadin/ui/AbstractMedia.java index 9117bce997..369ef773b9 100644 --- a/src/com/vaadin/ui/AbstractMedia.java +++ b/src/com/vaadin/ui/AbstractMedia.java @@ -12,7 +12,7 @@ import java.util.List; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.VMediaBase; +import com.vaadin.terminal.gwt.client.ui.VMediaBasePaintable; /** * Abstract base class for the HTML5 media components. @@ -203,25 +203,27 @@ public class AbstractMedia extends AbstractComponent { @Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); - target.addAttribute(VMediaBase.ATTR_CONTROLS, isShowControls()); + target.addAttribute(VMediaBasePaintable.ATTR_CONTROLS, isShowControls()); if (getAltText() != null) { - target.addAttribute(VMediaBase.ATTR_ALT_TEXT, getAltText()); + target.addAttribute(VMediaBasePaintable.ATTR_ALT_TEXT, getAltText()); } - target.addAttribute(VMediaBase.ATTR_HTML, isHtmlContentAllowed()); - target.addAttribute(VMediaBase.ATTR_AUTOPLAY, isAutoplay()); + target.addAttribute(VMediaBasePaintable.ATTR_HTML, + isHtmlContentAllowed()); + target.addAttribute(VMediaBasePaintable.ATTR_AUTOPLAY, isAutoplay()); for (Resource r : getSources()) { - target.startTag(VMediaBase.TAG_SOURCE); - target.addAttribute(VMediaBase.ATTR_RESOURCE, r); - target.addAttribute(VMediaBase.ATTR_RESOURCE_TYPE, r.getMIMEType()); - target.endTag(VMediaBase.TAG_SOURCE); + target.startTag(VMediaBasePaintable.TAG_SOURCE); + target.addAttribute(VMediaBasePaintable.ATTR_RESOURCE, r); + target.addAttribute(VMediaBasePaintable.ATTR_RESOURCE_TYPE, + r.getMIMEType()); + target.endTag(VMediaBasePaintable.TAG_SOURCE); } - target.addAttribute(VMediaBase.ATTR_MUTED, isMuted()); + target.addAttribute(VMediaBasePaintable.ATTR_MUTED, isMuted()); if (play) { - target.addAttribute(VMediaBase.ATTR_PLAY, true); + target.addAttribute(VMediaBasePaintable.ATTR_PLAY, true); play = false; } if (pause) { - target.addAttribute(VMediaBase.ATTR_PAUSE, true); + target.addAttribute(VMediaBasePaintable.ATTR_PAUSE, true); pause = false; } } diff --git a/src/com/vaadin/ui/AbstractSplitPanel.java b/src/com/vaadin/ui/AbstractSplitPanel.java index e0a2d24aaa..e03e73a781 100644 --- a/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/src/com/vaadin/ui/AbstractSplitPanel.java @@ -15,7 +15,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.ui.VSplitPanel; +import com.vaadin.terminal.gwt.client.ui.VAbstractSplitPanelPaintable; import com.vaadin.tools.ReflectTools; /** @@ -43,7 +43,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { private boolean locked = false; - private static final String SPLITTER_CLICK_EVENT = VSplitPanel.SPLITTER_CLICK_EVENT_IDENTIFIER; + private static final String SPLITTER_CLICK_EVENT = VAbstractSplitPanelPaintable.SPLITTER_CLICK_EVENT_IDENTIFIER; /** * Modifiable and Serializable Iterator for the components, used by diff --git a/src/com/vaadin/ui/Accordion.java b/src/com/vaadin/ui/Accordion.java index 5cf805615c..4ee75326ff 100644 --- a/src/com/vaadin/ui/Accordion.java +++ b/src/com/vaadin/ui/Accordion.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VAccordion; +import com.vaadin.terminal.gwt.client.ui.VAccordionPaintable; /** * An accordion is a component similar to a {@link TabSheet}, but with a @@ -16,8 +16,7 @@ import com.vaadin.terminal.gwt.client.ui.VAccordion; * * @see TabSheet */ -@SuppressWarnings("serial") -@ClientWidget(VAccordion.class) +@ClientWidget(VAccordionPaintable.class) public class Accordion extends TabSheet { } diff --git a/src/com/vaadin/ui/Audio.java b/src/com/vaadin/ui/Audio.java index 574c1f4186..048ef81c10 100644 --- a/src/com/vaadin/ui/Audio.java +++ b/src/com/vaadin/ui/Audio.java @@ -5,7 +5,7 @@ package com.vaadin.ui; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.VAudio; +import com.vaadin.terminal.gwt.client.ui.VAudioPaintable; /** * The Audio component translates into an HTML5 <audio> element and as @@ -28,7 +28,7 @@ import com.vaadin.terminal.gwt.client.ui.VAudio; * @author Vaadin Ltd * @since 6.7.0 */ -@ClientWidget(VAudio.class) +@ClientWidget(VAudioPaintable.class) public class Audio extends AbstractMedia { public Audio() { diff --git a/src/com/vaadin/ui/CheckBox.java b/src/com/vaadin/ui/CheckBox.java index 4b8c276c71..9dc96bb55d 100644 --- a/src/com/vaadin/ui/CheckBox.java +++ b/src/com/vaadin/ui/CheckBox.java @@ -15,7 +15,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.VCheckBox; -@ClientWidget(com.vaadin.terminal.gwt.client.ui.VCheckBox.class) +@ClientWidget(com.vaadin.terminal.gwt.client.ui.VCheckBoxPaintable.class) public class CheckBox extends AbstractField<Boolean> { /** * Creates a new checkbox. diff --git a/src/com/vaadin/ui/ComboBox.java b/src/com/vaadin/ui/ComboBox.java index 0fb8b9d873..b4307188a7 100644 --- a/src/com/vaadin/ui/ComboBox.java +++ b/src/com/vaadin/ui/ComboBox.java @@ -10,6 +10,7 @@ import com.vaadin.data.Container; import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.VFilterSelect;
+import com.vaadin.terminal.gwt.client.ui.VFilterSelectPaintable;
/**
* A filtering dropdown single-select. Suitable for newItemsAllowed, but it's
@@ -20,7 +21,7 @@ import com.vaadin.terminal.gwt.client.ui.VFilterSelect; *
*/
@SuppressWarnings("serial")
-@ClientWidget(VFilterSelect.class)
+@ClientWidget(VFilterSelectPaintable.class)
public class ComboBox extends Select {
private String inputPrompt = null;
diff --git a/src/com/vaadin/ui/CssLayout.java b/src/com/vaadin/ui/CssLayout.java index b9432df6b6..ebfee5a787 100644 --- a/src/com/vaadin/ui/CssLayout.java +++ b/src/com/vaadin/ui/CssLayout.java @@ -14,7 +14,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.gwt.client.EventId; -import com.vaadin.terminal.gwt.client.ui.VCssLayout; +import com.vaadin.terminal.gwt.client.ui.VCssLayoutPaintable; /** * CssLayout is a layout component that can be used in browser environment only. @@ -57,7 +57,7 @@ import com.vaadin.terminal.gwt.client.ui.VCssLayout; * @since 6.1 brought in from "FastLayouts" incubator project * */ -@ClientWidget(VCssLayout.class) +@ClientWidget(VCssLayoutPaintable.class) public class CssLayout extends AbstractLayout implements LayoutClickNotifier { private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; diff --git a/src/com/vaadin/ui/CustomComponent.java b/src/com/vaadin/ui/CustomComponent.java index 0f891ac0fa..7aba34b6bb 100644 --- a/src/com/vaadin/ui/CustomComponent.java +++ b/src/com/vaadin/ui/CustomComponent.java @@ -9,7 +9,7 @@ import java.util.Iterator; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VCustomComponent; +import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -27,7 +27,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(value = VCustomComponent.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VCustomComponentPaintable.class, loadStyle = LoadStyle.EAGER) public class CustomComponent extends AbstractComponentContainer { /** diff --git a/src/com/vaadin/ui/CustomField.java b/src/com/vaadin/ui/CustomField.java index 72f863ca8b..73f9050363 100644 --- a/src/com/vaadin/ui/CustomField.java +++ b/src/com/vaadin/ui/CustomField.java @@ -11,7 +11,7 @@ import java.util.Iterator; import com.vaadin.data.Property; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VCustomComponent; +import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable; /** * A {@link Field} whose UI content can be constructed by the user, enabling the @@ -35,7 +35,7 @@ import com.vaadin.terminal.gwt.client.ui.VCustomComponent; * * @since 7.0 */ -@ClientWidget(VCustomComponent.class) +@ClientWidget(VCustomComponentPaintable.class) public abstract class CustomField<T> extends AbstractField<T> implements ComponentContainer { diff --git a/src/com/vaadin/ui/CustomLayout.java b/src/com/vaadin/ui/CustomLayout.java index dc473fb549..fb0c369969 100644 --- a/src/com/vaadin/ui/CustomLayout.java +++ b/src/com/vaadin/ui/CustomLayout.java @@ -12,7 +12,7 @@ import java.util.Iterator; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VCustomLayout; +import com.vaadin.terminal.gwt.client.ui.VCustomLayoutPaintable; /** * <p> @@ -44,7 +44,7 @@ import com.vaadin.terminal.gwt.client.ui.VCustomLayout; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VCustomLayout.class) +@ClientWidget(VCustomLayoutPaintable.class) public class CustomLayout extends AbstractLayout { private static final int BUFFER_SIZE = 10000; diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java index b3f54a0a78..9589414f4d 100644 --- a/src/com/vaadin/ui/DateField.java +++ b/src/com/vaadin/ui/DateField.java @@ -27,7 +27,7 @@ import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.VDateField; -import com.vaadin.terminal.gwt.client.ui.VPopupCalendar; +import com.vaadin.terminal.gwt.client.ui.VPopupCalendarPaintable; /** * <p> @@ -50,7 +50,7 @@ import com.vaadin.terminal.gwt.client.ui.VPopupCalendar; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VPopupCalendar.class) +@ClientWidget(VPopupCalendarPaintable.class) public class DateField extends AbstractField<Date> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { diff --git a/src/com/vaadin/ui/DragAndDropWrapper.java b/src/com/vaadin/ui/DragAndDropWrapper.java index c6522f15c7..512b70e118 100644 --- a/src/com/vaadin/ui/DragAndDropWrapper.java +++ b/src/com/vaadin/ui/DragAndDropWrapper.java @@ -22,11 +22,12 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapper; +import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapperPaintable; import com.vaadin.terminal.gwt.client.ui.dd.HorizontalDropLocation; import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; @SuppressWarnings("serial") -@ClientWidget(VDragAndDropWrapper.class) +@ClientWidget(VDragAndDropWrapperPaintable.class) public class DragAndDropWrapper extends CustomComponent implements DropTarget, DragSource { diff --git a/src/com/vaadin/ui/Embedded.java b/src/com/vaadin/ui/Embedded.java index dc14cc6ef8..f655b55711 100644 --- a/src/com/vaadin/ui/Embedded.java +++ b/src/com/vaadin/ui/Embedded.java @@ -14,7 +14,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.ui.VEmbedded; +import com.vaadin.terminal.gwt.client.ui.VEmbeddedPaintable; /** * Component for embedding external objects. @@ -25,10 +25,10 @@ import com.vaadin.terminal.gwt.client.ui.VEmbedded; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VEmbedded.class) +@ClientWidget(VEmbeddedPaintable.class) public class Embedded extends AbstractComponent { - private static final String CLICK_EVENT = VEmbedded.CLICK_EVENT_IDENTIFIER; + private static final String CLICK_EVENT = VEmbeddedPaintable.CLICK_EVENT_IDENTIFIER; /** * General object type. diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 47210e1aed..c79804c7e7 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -27,7 +27,7 @@ import com.vaadin.terminal.CompositeErrorMessage; import com.vaadin.terminal.ErrorMessage; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VForm; +import com.vaadin.terminal.gwt.client.ui.VFormPaintable; /** * Form component provides easy way of creating and managing sets fields. @@ -62,8 +62,7 @@ import com.vaadin.terminal.gwt.client.ui.VForm; * @deprecated Use {@link FieldGroup} instead of {@link Form} for more * flexibility. */ -@SuppressWarnings("serial") -@ClientWidget(VForm.class) +@ClientWidget(VFormPaintable.class) @Deprecated public class Form extends AbstractField<Object> implements Item.Editor, Buffered, Item, Validatable, Action.Notifier { diff --git a/src/com/vaadin/ui/FormLayout.java b/src/com/vaadin/ui/FormLayout.java index eecf3372bb..c5c211924e 100644 --- a/src/com/vaadin/ui/FormLayout.java +++ b/src/com/vaadin/ui/FormLayout.java @@ -4,7 +4,7 @@ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VFormLayout; +import com.vaadin.terminal.gwt.client.ui.VFormLayoutPaintable; /** * FormLayout is used by {@link Form} to layout fields. It may also be used @@ -21,7 +21,7 @@ import com.vaadin.terminal.gwt.client.ui.VFormLayout; * bottom are by default on. * */ -@ClientWidget(VFormLayout.class) +@ClientWidget(VFormLayoutPaintable.class) public class FormLayout extends AbstractOrderedLayout { public FormLayout() { diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java index 24a57d462b..4588328345 100644 --- a/src/com/vaadin/ui/GridLayout.java +++ b/src/com/vaadin/ui/GridLayout.java @@ -18,7 +18,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.EventId; -import com.vaadin.terminal.gwt.client.ui.VGridLayout; +import com.vaadin.terminal.gwt.client.ui.VGridLayoutPaintable; /** * <p> @@ -41,7 +41,7 @@ import com.vaadin.terminal.gwt.client.ui.VGridLayout; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VGridLayout.class) +@ClientWidget(VGridLayoutPaintable.class) public class GridLayout extends AbstractLayout implements Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { diff --git a/src/com/vaadin/ui/HorizontalLayout.java b/src/com/vaadin/ui/HorizontalLayout.java index ed1cad8184..ba685ec410 100644 --- a/src/com/vaadin/ui/HorizontalLayout.java +++ b/src/com/vaadin/ui/HorizontalLayout.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VHorizontalLayout; +import com.vaadin.terminal.gwt.client.ui.VHorizontalLayoutPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -18,7 +18,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @since 5.3 */ @SuppressWarnings("serial") -@ClientWidget(value = VHorizontalLayout.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VHorizontalLayoutPaintable.class, loadStyle = LoadStyle.EAGER) public class HorizontalLayout extends AbstractOrderedLayout { public HorizontalLayout() { diff --git a/src/com/vaadin/ui/HorizontalSplitPanel.java b/src/com/vaadin/ui/HorizontalSplitPanel.java index d9368635df..d4a1e7cc0e 100644 --- a/src/com/vaadin/ui/HorizontalSplitPanel.java +++ b/src/com/vaadin/ui/HorizontalSplitPanel.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal; +import com.vaadin.terminal.gwt.client.ui.VHorizontalSplitPanelPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -29,7 +29,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @VERSION@ * @since 6.5 */ -@ClientWidget(value = VSplitPanelHorizontal.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VHorizontalSplitPanelPaintable.class, loadStyle = LoadStyle.EAGER) public class HorizontalSplitPanel extends AbstractSplitPanel { public HorizontalSplitPanel() { super(); diff --git a/src/com/vaadin/ui/InlineDateField.java b/src/com/vaadin/ui/InlineDateField.java index 0bf7924d34..b0e830a75a 100644 --- a/src/com/vaadin/ui/InlineDateField.java +++ b/src/com/vaadin/ui/InlineDateField.java @@ -7,7 +7,7 @@ package com.vaadin.ui; import java.util.Date;
import com.vaadin.data.Property;
-import com.vaadin.terminal.gwt.client.ui.VDateFieldCalendar;
+import com.vaadin.terminal.gwt.client.ui.VDateFieldCalendarPaintable;
/**
* <p>
@@ -22,7 +22,7 @@ import com.vaadin.terminal.gwt.client.ui.VDateFieldCalendar; * @VERSION@
* @since 5.0
*/
-@ClientWidget(VDateFieldCalendar.class)
+@ClientWidget(VDateFieldCalendarPaintable.class)
public class InlineDateField extends DateField {
public InlineDateField() {
diff --git a/src/com/vaadin/ui/Link.java b/src/com/vaadin/ui/Link.java index 99d742ec17..0b11151be7 100644 --- a/src/com/vaadin/ui/Link.java +++ b/src/com/vaadin/ui/Link.java @@ -7,7 +7,7 @@ package com.vaadin.ui; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.VLink; +import com.vaadin.terminal.gwt.client.ui.VLinkPaintable; /** * Link is used to create external or internal URL links. @@ -18,7 +18,7 @@ import com.vaadin.terminal.gwt.client.ui.VLink; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VLink.class) +@ClientWidget(VLinkPaintable.class) public class Link extends AbstractComponent { /* Target window border type constant: No window border */ diff --git a/src/com/vaadin/ui/ListSelect.java b/src/com/vaadin/ui/ListSelect.java index 5c879f00f5..cf0e6773f2 100644 --- a/src/com/vaadin/ui/ListSelect.java +++ b/src/com/vaadin/ui/ListSelect.java @@ -9,14 +9,14 @@ import java.util.Collection; import com.vaadin.data.Container; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VListSelect; +import com.vaadin.terminal.gwt.client.ui.VListSelectPaintable; /** * This is a simple list select without, for instance, support for new items, * lazyloading, and other advanced features. */ @SuppressWarnings("serial") -@ClientWidget(VListSelect.class) +@ClientWidget(VListSelectPaintable.class) public class ListSelect extends AbstractSelect { private int columns = 0; diff --git a/src/com/vaadin/ui/NativeSelect.java b/src/com/vaadin/ui/NativeSelect.java index e701d212b4..b0070426ad 100644 --- a/src/com/vaadin/ui/NativeSelect.java +++ b/src/com/vaadin/ui/NativeSelect.java @@ -9,7 +9,7 @@ import java.util.Collection; import com.vaadin.data.Container; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VNativeSelect; +import com.vaadin.terminal.gwt.client.ui.VNativeSelectPaintable; /** * This is a simple drop-down select without, for instance, support for @@ -18,7 +18,7 @@ import com.vaadin.terminal.gwt.client.ui.VNativeSelect; * better choice. */ @SuppressWarnings("serial") -@ClientWidget(VNativeSelect.class) +@ClientWidget(VNativeSelectPaintable.class) public class NativeSelect extends AbstractSelect { // width in characters, mimics TextField diff --git a/src/com/vaadin/ui/OptionGroup.java b/src/com/vaadin/ui/OptionGroup.java index 884e58824a..ddacc31554 100644 --- a/src/com/vaadin/ui/OptionGroup.java +++ b/src/com/vaadin/ui/OptionGroup.java @@ -18,12 +18,13 @@ import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.VOptionGroup; +import com.vaadin.terminal.gwt.client.ui.VOptionGroupPaintable; /** * Configures select to be used as an option group. */ @SuppressWarnings("serial") -@ClientWidget(VOptionGroup.class) +@ClientWidget(VOptionGroupPaintable.class) public class OptionGroup extends AbstractSelect implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java index a69413c28b..390279a62f 100644 --- a/src/com/vaadin/ui/Panel.java +++ b/src/com/vaadin/ui/Panel.java @@ -16,7 +16,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Scrollable; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.ui.VPanel; +import com.vaadin.terminal.gwt.client.ui.VPanelPaintable; import com.vaadin.ui.Component.Focusable; import com.vaadin.ui.themes.Reindeer; import com.vaadin.ui.themes.Runo; @@ -30,12 +30,12 @@ import com.vaadin.ui.themes.Runo; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VPanel.class) +@ClientWidget(VPanelPaintable.class) public class Panel extends AbstractComponentContainer implements Scrollable, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachListener, Action.Notifier, Focusable { - private static final String CLICK_EVENT = VPanel.CLICK_EVENT_IDENTIFIER; + private static final String CLICK_EVENT = VPanelPaintable.CLICK_EVENT_IDENTIFIER; /** * Removes extra decorations from the Panel. @@ -559,6 +559,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, /* * ACTIONS */ + @Override protected ActionManager getActionManager() { if (actionManager == null) { actionManager = new ActionManager(this); diff --git a/src/com/vaadin/ui/PasswordField.java b/src/com/vaadin/ui/PasswordField.java index 99874147d5..d5be4f378d 100644 --- a/src/com/vaadin/ui/PasswordField.java +++ b/src/com/vaadin/ui/PasswordField.java @@ -4,13 +4,13 @@ package com.vaadin.ui; import com.vaadin.data.Property; -import com.vaadin.terminal.gwt.client.ui.VPasswordField; +import com.vaadin.terminal.gwt.client.ui.VPasswordFieldPaintable; /** * A field that is used to enter secret text information like passwords. The * entered text is not displayed on the screen. */ -@ClientWidget(VPasswordField.class) +@ClientWidget(VPasswordFieldPaintable.class) public class PasswordField extends AbstractTextField { /** diff --git a/src/com/vaadin/ui/PopupView.java b/src/com/vaadin/ui/PopupView.java index fcad727510..5637ef69d7 100644 --- a/src/com/vaadin/ui/PopupView.java +++ b/src/com/vaadin/ui/PopupView.java @@ -10,7 +10,7 @@ import java.util.Map; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VPopupView; +import com.vaadin.terminal.gwt.client.ui.VPopupViewPaintable; /** * @@ -22,7 +22,7 @@ import com.vaadin.terminal.gwt.client.ui.VPopupView; * @author Vaadin Ltd. */ @SuppressWarnings("serial") -@ClientWidget(VPopupView.class) +@ClientWidget(VPopupViewPaintable.class) public class PopupView extends AbstractComponentContainer { private Content content; diff --git a/src/com/vaadin/ui/ProgressIndicator.java b/src/com/vaadin/ui/ProgressIndicator.java index cc17333cc4..9152a3adab 100644 --- a/src/com/vaadin/ui/ProgressIndicator.java +++ b/src/com/vaadin/ui/ProgressIndicator.java @@ -8,7 +8,7 @@ import com.vaadin.data.Property; import com.vaadin.data.util.ObjectProperty; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VProgressIndicator; +import com.vaadin.terminal.gwt.client.ui.VProgressIndicatorPaintable; /** * <code>ProgressIndicator</code> is component that shows user state of a @@ -25,7 +25,7 @@ import com.vaadin.terminal.gwt.client.ui.VProgressIndicator; * @since 4 */ @SuppressWarnings("serial") -@ClientWidget(VProgressIndicator.class) +@ClientWidget(VProgressIndicatorPaintable.class) public class ProgressIndicator extends AbstractField<Number> implements Property.Viewer, Property.ValueChangeListener { diff --git a/src/com/vaadin/ui/RichTextArea.java b/src/com/vaadin/ui/RichTextArea.java index ea22a6b54b..240063caf3 100644 --- a/src/com/vaadin/ui/RichTextArea.java +++ b/src/com/vaadin/ui/RichTextArea.java @@ -10,7 +10,7 @@ import java.util.Map; import com.vaadin.data.Property; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea; +import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextAreaPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -20,7 +20,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * {@link RichTextArea} may produce unexpected results as formatting is counted * into length of field. */ -@ClientWidget(value = VRichTextArea.class, loadStyle = LoadStyle.LAZY) +@ClientWidget(value = VRichTextAreaPaintable.class, loadStyle = LoadStyle.LAZY) public class RichTextArea extends AbstractField<String> { /** diff --git a/src/com/vaadin/ui/Select.java b/src/com/vaadin/ui/Select.java index 0ea331dc40..38785f3ab9 100644 --- a/src/com/vaadin/ui/Select.java +++ b/src/com/vaadin/ui/Select.java @@ -23,7 +23,7 @@ import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.VFilterSelect; +import com.vaadin.terminal.gwt.client.ui.VFilterSelectPaintable; /** * <p> @@ -44,7 +44,7 @@ import com.vaadin.terminal.gwt.client.ui.VFilterSelect; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VFilterSelect.class) +@ClientWidget(VFilterSelectPaintable.class) public class Select extends AbstractSelect implements AbstractSelect.Filtering, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { diff --git a/src/com/vaadin/ui/Slider.java b/src/com/vaadin/ui/Slider.java index f077afb8ff..aad1b60f87 100644 --- a/src/com/vaadin/ui/Slider.java +++ b/src/com/vaadin/ui/Slider.java @@ -8,7 +8,7 @@ import java.util.Map; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VSlider; +import com.vaadin.terminal.gwt.client.ui.VSliderPaintable; /** * A component for selecting a numerical value within a range. @@ -46,7 +46,7 @@ import com.vaadin.terminal.gwt.client.ui.VSlider; * * @author Vaadin Ltd. */ -@ClientWidget(VSlider.class) +@ClientWidget(VSliderPaintable.class) public class Slider extends AbstractField<Double> { public static final int ORIENTATION_HORIZONTAL = 0; diff --git a/src/com/vaadin/ui/SplitPanel.java b/src/com/vaadin/ui/SplitPanel.java deleted file mode 100644 index bae1bf7ce0..0000000000 --- a/src/com/vaadin/ui/SplitPanel.java +++ /dev/null @@ -1,114 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ - -package com.vaadin.ui; - -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal; -import com.vaadin.ui.ClientWidget.LoadStyle; - -/** - * SplitPanel. - * - * <code>SplitPanel</code> is a component container, that can contain two - * components (possibly containers) which are split by divider element. - * - * @author Vaadin Ltd. - * @version - * @VERSION@ - * @since 5.0 - * @deprecated in 6.5. Use {@link HorizontalSplitPanel} or - * {@link VerticalSplitPanel} instead. - */ -@Deprecated -@ClientWidget(value = VSplitPanelHorizontal.class, loadStyle = LoadStyle.EAGER) -public class SplitPanel extends AbstractSplitPanel { - - /* Predefined orientations */ - - /** - * Components are to be laid out vertically. - */ - public static final int ORIENTATION_VERTICAL = 0; - - /** - * Components are to be laid out horizontally. - */ - public static final int ORIENTATION_HORIZONTAL = 1; - - /** - * Orientation of the layout. - */ - private int orientation; - - /** - * Creates a new split panel. The orientation of the panels is - * <code>ORIENTATION_VERTICAL</code>. - */ - public SplitPanel() { - super(); - orientation = ORIENTATION_VERTICAL; - setSizeFull(); - } - - /** - * Create a new split panels. The orientation of the panel is given as - * parameters. - * - * @param orientation - * the Orientation of the layout. - */ - public SplitPanel(int orientation) { - this(); - setOrientation(orientation); - } - - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the paint operation failed. - */ - @Override - public void paintContent(PaintTarget target) throws PaintException { - super.paintContent(target); - - if (orientation == ORIENTATION_VERTICAL) { - target.addAttribute("vertical", true); - } - - } - - /** - * Gets the orientation of the split panel. - * - * @return the Value of property orientation. - * - */ - public int getOrientation() { - return orientation; - } - - /** - * Sets the orientation of the split panel. - * - * @param orientation - * the New value of property orientation. - */ - public void setOrientation(int orientation) { - - // Checks the validity of the argument - if (orientation < ORIENTATION_VERTICAL - || orientation > ORIENTATION_HORIZONTAL) { - throw new IllegalArgumentException(); - } - - this.orientation = orientation; - requestRepaint(); - } - -} diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index a13c336943..e256c51cfd 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -20,6 +20,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.ui.VTabsheet; +import com.vaadin.terminal.gwt.client.ui.VTabsheetPaintable; import com.vaadin.terminal.gwt.server.CommunicationManager; import com.vaadin.ui.themes.Reindeer; import com.vaadin.ui.themes.Runo; @@ -53,8 +54,7 @@ import com.vaadin.ui.themes.Runo; * @VERSION@ * @since 3.0 */ -@SuppressWarnings("serial") -@ClientWidget(VTabsheet.class) +@ClientWidget(VTabsheetPaintable.class) public class TabSheet extends AbstractComponentContainer { /** diff --git a/src/com/vaadin/ui/TextArea.java b/src/com/vaadin/ui/TextArea.java index e1e5aeabd4..a5e6bb5630 100644 --- a/src/com/vaadin/ui/TextArea.java +++ b/src/com/vaadin/ui/TextArea.java @@ -7,12 +7,12 @@ package com.vaadin.ui; import com.vaadin.data.Property; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VTextArea; +import com.vaadin.terminal.gwt.client.ui.VTextAreaPaintable; /** * A text field that supports multi line editing. */ -@ClientWidget(VTextArea.class) +@ClientWidget(VTextAreaPaintable.class) public class TextArea extends AbstractTextField { private static final int DEFAULT_ROWS = 5; diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java index e154aaad17..a3d873336c 100644 --- a/src/com/vaadin/ui/TextField.java +++ b/src/com/vaadin/ui/TextField.java @@ -5,7 +5,7 @@ package com.vaadin.ui; import com.vaadin.data.Property; -import com.vaadin.terminal.gwt.client.ui.VTextField; +import com.vaadin.terminal.gwt.client.ui.VTextFieldPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -29,7 +29,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(value = VTextField.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VTextFieldPaintable.class, loadStyle = LoadStyle.EAGER) public class TextField extends AbstractTextField { /** diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 554afda97c..4ea66cc6bf 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -45,6 +45,7 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VTree; +import com.vaadin.terminal.gwt.client.ui.VTreePaintable; import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; import com.vaadin.terminal.gwt.client.ui.dd.VTargetInSubtree; import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; @@ -60,7 +61,7 @@ import com.vaadin.tools.ReflectTools; * @since 3.0 */ @SuppressWarnings({ "serial", "deprecation" }) -@ClientWidget(VTree.class) +@ClientWidget(VTreePaintable.class) public class Tree extends AbstractSelect implements Container.Hierarchical, Action.Container, ItemClickSource, ItemClickNotifier, DragSource, DropTarget { diff --git a/src/com/vaadin/ui/TwinColSelect.java b/src/com/vaadin/ui/TwinColSelect.java index 1c1fe07a5c..fbdd825a66 100644 --- a/src/com/vaadin/ui/TwinColSelect.java +++ b/src/com/vaadin/ui/TwinColSelect.java @@ -10,13 +10,14 @@ import com.vaadin.data.Container; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.VTwinColSelect; +import com.vaadin.terminal.gwt.client.ui.VTwinColSelectPaintable; /** * Multiselect component with two lists: left side for available items and right * side for selected items. */ @SuppressWarnings("serial") -@ClientWidget(VTwinColSelect.class) +@ClientWidget(VTwinColSelectPaintable.class) public class TwinColSelect extends AbstractSelect { private int columns = 0; diff --git a/src/com/vaadin/ui/Upload.java b/src/com/vaadin/ui/Upload.java index 9d684291a5..08a8023ad5 100644 --- a/src/com/vaadin/ui/Upload.java +++ b/src/com/vaadin/ui/Upload.java @@ -15,7 +15,7 @@ import java.util.Map; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.StreamVariable.StreamingProgressEvent; -import com.vaadin.terminal.gwt.client.ui.VUpload; +import com.vaadin.terminal.gwt.client.ui.VUploadPaintable; import com.vaadin.terminal.gwt.server.NoInputStreamException; import com.vaadin.terminal.gwt.server.NoOutputStreamException; import com.vaadin.ui.ClientWidget.LoadStyle; @@ -61,7 +61,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(value = VUpload.class, loadStyle = LoadStyle.LAZY) +@ClientWidget(value = VUploadPaintable.class, loadStyle = LoadStyle.LAZY) public class Upload extends AbstractComponent implements Component.Focusable { /** diff --git a/src/com/vaadin/ui/VerticalLayout.java b/src/com/vaadin/ui/VerticalLayout.java index c40aeaea30..0c5de43bbd 100644 --- a/src/com/vaadin/ui/VerticalLayout.java +++ b/src/com/vaadin/ui/VerticalLayout.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VVerticalLayout; +import com.vaadin.terminal.gwt.client.ui.VVerticalLayoutPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -19,7 +19,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @since 5.3 */ @SuppressWarnings("serial") -@ClientWidget(value = VVerticalLayout.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VVerticalLayoutPaintable.class, loadStyle = LoadStyle.EAGER) public class VerticalLayout extends AbstractOrderedLayout { public VerticalLayout() { diff --git a/src/com/vaadin/ui/VerticalSplitPanel.java b/src/com/vaadin/ui/VerticalSplitPanel.java index 699bd9287c..46e9d681e8 100644 --- a/src/com/vaadin/ui/VerticalSplitPanel.java +++ b/src/com/vaadin/ui/VerticalSplitPanel.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical; +import com.vaadin.terminal.gwt.client.ui.VVerticalSplitPanelPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -23,7 +23,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * </pre> * */ -@ClientWidget(value = VSplitPanelVertical.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VVerticalSplitPanelPaintable.class, loadStyle = LoadStyle.EAGER) public class VerticalSplitPanel extends AbstractSplitPanel { public VerticalSplitPanel() { diff --git a/src/com/vaadin/ui/Video.java b/src/com/vaadin/ui/Video.java index ed6588f96a..a2e71b1120 100644 --- a/src/com/vaadin/ui/Video.java +++ b/src/com/vaadin/ui/Video.java @@ -7,7 +7,7 @@ package com.vaadin.ui; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; -import com.vaadin.terminal.gwt.client.ui.VVideo; +import com.vaadin.terminal.gwt.client.ui.VVideoPaintable; /** * The Video component translates into an HTML5 <video> element and as @@ -30,7 +30,7 @@ import com.vaadin.terminal.gwt.client.ui.VVideo; * @author Vaadin Ltd * @since 6.7.0 */ -@ClientWidget(VVideo.class) +@ClientWidget(VVideoPaintable.class) public class Video extends AbstractMedia { private Resource poster; @@ -80,7 +80,7 @@ public class Video extends AbstractMedia { public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); if (getPoster() != null) { - target.addAttribute(VVideo.ATTR_POSTER, getPoster()); + target.addAttribute(VVideoPaintable.ATTR_POSTER, getPoster()); } } } diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index a860d371b0..e6c8642b84 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -23,7 +23,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.gwt.client.ui.VView; -import com.vaadin.terminal.gwt.client.ui.VWindow; +import com.vaadin.terminal.gwt.client.ui.VWindowPaintable; /** * A component that represents an application (browser native) window or a sub @@ -71,7 +71,7 @@ import com.vaadin.terminal.gwt.client.ui.VWindow; * @since 3.0 */ @SuppressWarnings("serial") -@ClientWidget(VWindow.class) +@ClientWidget(VWindowPaintable.class) public class Window extends Panel implements FocusNotifier, BlurNotifier { /** diff --git a/tests/server-side/com/vaadin/tests/VaadinClasses.java b/tests/server-side/com/vaadin/tests/VaadinClasses.java index 707fc020b6..b74af660e4 100644 --- a/tests/server-side/com/vaadin/tests/VaadinClasses.java +++ b/tests/server-side/com/vaadin/tests/VaadinClasses.java @@ -27,7 +27,6 @@ import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.LoginForm; import com.vaadin.ui.PopupView; import com.vaadin.ui.Root; -import com.vaadin.ui.SplitPanel; import com.vaadin.ui.VerticalSplitPanel; import com.vaadin.ui.Window; @@ -105,7 +104,6 @@ public class VaadinClasses { public static List<Class<? extends ComponentContainer>> getComponentContainersSupportingUnlimitedNumberOfComponents() { List<Class<? extends ComponentContainer>> classes = getComponentContainersSupportingAddRemoveComponent(); - classes.remove(SplitPanel.class); classes.remove(VerticalSplitPanel.class); classes.remove(HorizontalSplitPanel.class); classes.remove(Window.class); diff --git a/tests/testbench/com/vaadin/tests/components/splitpanel/SplitPanels.java b/tests/testbench/com/vaadin/tests/components/splitpanel/SplitPanels.java deleted file mode 100644 index ebe94271cc..0000000000 --- a/tests/testbench/com/vaadin/tests/components/splitpanel/SplitPanels.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.vaadin.tests.components.splitpanel;
-
-import java.util.LinkedHashMap;
-
-import com.vaadin.ui.SplitPanel;
-
-@SuppressWarnings("deprecation")
-public class SplitPanels extends AbstractSplitPanelTest<SplitPanel> {
-
- private Command<SplitPanel, Integer> orientationCommand = new Command<SplitPanel, Integer>() {
-
- public void execute(SplitPanel c, Integer value, Object data) {
- c.setOrientation(value);
- }
- };
-
- @Override
- protected Class<SplitPanel> getTestClass() {
- return SplitPanel.class;
- }
-
- @Override
- protected void createActions() {
- super.createActions();
- createOrientationSelect(CATEGORY_FEATURES);
-
- }
-
- private void createOrientationSelect(String category) {
- LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
- options.put("Horizontal", SplitPanel.ORIENTATION_HORIZONTAL);
- options.put("Vertical", SplitPanel.ORIENTATION_VERTICAL);
- createSelectAction("Orientation", category, options, "Horizontal",
- orientationCommand);
-
- }
-}
diff --git a/tests/testbench/com/vaadin/tests/dd/CustomDDImplementation.java b/tests/testbench/com/vaadin/tests/dd/CustomDDImplementation.java index c789ead113..de3312d1a8 100644 --- a/tests/testbench/com/vaadin/tests/dd/CustomDDImplementation.java +++ b/tests/testbench/com/vaadin/tests/dd/CustomDDImplementation.java @@ -38,7 +38,7 @@ public class CustomDDImplementation extends CustomComponent { * Check the @ClientWidget * */ - @ClientWidget(VMyDropTarget.class) + @ClientWidget(VMyDropTargetPaintable.class) class MyDropTarget extends AbstractComponent implements DropTarget { public DropHandler getDropHandler() { return new DropHandler() { @@ -76,7 +76,7 @@ public class CustomDDImplementation extends CustomComponent { * operations that are controlled via server side api. * */ - @ClientWidget(VMyDragSource.class) + @ClientWidget(VMyDragSourcePaintable.class) public class MyDragSource extends AbstractComponent implements Component { } diff --git a/tests/testbench/com/vaadin/tests/dd/VMyDragSource.java b/tests/testbench/com/vaadin/tests/dd/VMyDragSource.java index eb77bfefd7..7e91d2b9aa 100644 --- a/tests/testbench/com/vaadin/tests/dd/VMyDragSource.java +++ b/tests/testbench/com/vaadin/tests/dd/VMyDragSource.java @@ -11,23 +11,19 @@ import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; import com.vaadin.terminal.gwt.client.ui.dd.VTransferable; /** * Example code to implement Component that has something to drag. */ -public class VMyDragSource extends Composite implements VPaintableWidget, - MouseDownHandler, MouseMoveHandler, MouseOutHandler { +public class VMyDragSource extends Composite implements MouseDownHandler, + MouseMoveHandler, MouseOutHandler { private boolean mouseDown; private MouseDownEvent mDownEvent; - @SuppressWarnings("unused") - private ApplicationConnection client; + @SuppressWarnings("unused") public VMyDragSource() { FlowPanel fp = new FlowPanel(); initWidget(fp); @@ -42,13 +38,6 @@ public class VMyDragSource extends Composite implements VPaintableWidget, } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (client.updateComponent(this, uidl, true)) { - return; - } - this.client = client; - } - /* * Below a sophisticated drag start implementation. Drag event is started if * mouse is moved 5 pixels with left mouse key down. diff --git a/tests/testbench/com/vaadin/tests/dd/VMyDragSourcePaintable.java b/tests/testbench/com/vaadin/tests/dd/VMyDragSourcePaintable.java new file mode 100644 index 0000000000..976638fe39 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/dd/VMyDragSourcePaintable.java @@ -0,0 +1,22 @@ +package com.vaadin.tests.dd;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;
+
+public class VMyDragSourcePaintable extends VAbstractPaintableWidget {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VMyDragSource.class);
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/dd/VMyDropTarget.java b/tests/testbench/com/vaadin/tests/dd/VMyDropTarget.java index 8efec186cb..81bbb09a5c 100644 --- a/tests/testbench/com/vaadin/tests/dd/VMyDropTarget.java +++ b/tests/testbench/com/vaadin/tests/dd/VMyDropTarget.java @@ -1,18 +1,16 @@ package com.vaadin.tests.dd; import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.dd.VDragEvent; import com.vaadin.terminal.gwt.client.ui.dd.VDropHandler; import com.vaadin.terminal.gwt.client.ui.dd.VHasDropHandler; public class VMyDropTarget extends Composite implements VHasDropHandler, - VDropHandler, VPaintableWidget { + VDropHandler { - private ApplicationConnection client; + ApplicationConnection client; public void dragEnter(VDragEvent drag) { } @@ -31,27 +29,18 @@ public class VMyDropTarget extends Composite implements VHasDropHandler, return false; } - public VPaintableWidget getPaintable() { - // Drophandler implemented by Paintable itself + public VDropHandler getDropHandler() { + // Drophandler implemented by widget itself return this; } - public VDropHandler getDropHandler() { - // Drophandler implemented by Paintable itself - return this; + public VPaintableWidget getPaintable() { + // TODO Auto-generated method stub + return null; } public ApplicationConnection getApplicationConnection() { return client; } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - - } - - public Widget getWidgetForPaintable() { - return this; - } - } diff --git a/tests/testbench/com/vaadin/tests/dd/VMyDropTargetPaintable.java b/tests/testbench/com/vaadin/tests/dd/VMyDropTargetPaintable.java new file mode 100644 index 0000000000..88455c4e68 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/dd/VMyDropTargetPaintable.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.dd;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;
+
+public class VMyDropTargetPaintable extends VAbstractPaintableWidget {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ if (client.updateComponent(this, uidl, true)) {
+ return;
+ }
+ getWidgetForPaintable().client = client;
+ }
+
+ @Override
+ public VMyDropTarget getWidgetForPaintable() {
+ return (VMyDropTarget) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VMyDropTarget.class);
+ }
+
+}
|