]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move widget classes from c.v.c.ui.<widget> to c.v.c.ui (#9392) 60/260/2
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 12 Nov 2012 11:22:47 +0000 (13:22 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 14 Nov 2012 09:39:16 +0000 (09:39 +0000)
Conflicts:

client/src/com/vaadin/client/ui/VScrollTable.java

Change-Id: Ie65e26c9e3df520b099744d4bc1aecc901eaa07a

13 files changed:
client/src/com/vaadin/client/ui/VEmbedded.java [new file with mode: 0644]
client/src/com/vaadin/client/ui/VFlash.java [new file with mode: 0644]
client/src/com/vaadin/client/ui/VForm.java [new file with mode: 0644]
client/src/com/vaadin/client/ui/VFormLayout.java [new file with mode: 0644]
client/src/com/vaadin/client/ui/VScrollTable.java
client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java
client/src/com/vaadin/client/ui/embedded/VEmbedded.java [deleted file]
client/src/com/vaadin/client/ui/flash/FlashConnector.java
client/src/com/vaadin/client/ui/flash/VFlash.java [deleted file]
client/src/com/vaadin/client/ui/form/FormConnector.java
client/src/com/vaadin/client/ui/form/VForm.java [deleted file]
client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java
client/src/com/vaadin/client/ui/formlayout/VFormLayout.java [deleted file]

diff --git a/client/src/com/vaadin/client/ui/VEmbedded.java b/client/src/com/vaadin/client/ui/VEmbedded.java
new file mode 100644 (file)
index 0000000..5315560
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.client.ui;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+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.vaadin.client.ApplicationConnection;
+import com.vaadin.client.BrowserInfo;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.ConnectorMap;
+import com.vaadin.client.UIDL;
+import com.vaadin.client.Util;
+import com.vaadin.client.VConsole;
+import com.vaadin.shared.ui.embedded.EmbeddedConstants;
+
+public class VEmbedded extends HTML {
+    public static String CLASSNAME = "v-embedded";
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element browserElement;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public String type;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public String mimetype;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public ApplicationConnection client;
+
+    public VEmbedded() {
+        setStyleName(CLASSNAME);
+    }
+
+    /**
+     * Creates the Object and Embed tags for the Flash plugin so it works
+     * cross-browser.
+     * <p>
+     * For internal use only. May be removed or replaced in the future.
+     * 
+     * @param uidl
+     *            The UIDL
+     * @return Tags concatenated into a string
+     */
+    public 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
+         * inside it a EMBED for all other browsers.
+         */
+
+        StringBuilder html = new StringBuilder();
+
+        // Start the object tag
+        html.append("<object ");
+
+        /*
+         * Add classid required for ActiveX to recognize the flash. This is a
+         * predefined value which ActiveX recognizes and must be the given
+         * value. More info can be found on
+         * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
+         * this by setting his own classid.
+         */
+        if (uidl.hasAttribute("classid")) {
+            html.append("classid=\""
+                    + Util.escapeAttribute(uidl.getStringAttribute("classid"))
+                    + "\" ");
+        } else {
+            html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
+        }
+
+        /*
+         * Add codebase required for ActiveX and must be exactly this according
+         * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
+         * given classid. Again, see more info on
+         * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
+         * 6.0.0.0 and above. Allow user to override this by setting his own
+         * codebase
+         */
+        if (uidl.hasAttribute("codebase")) {
+            html.append("codebase=\""
+                    + Util.escapeAttribute(uidl.getStringAttribute("codebase"))
+                    + "\" ");
+        } else {
+            html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
+        }
+
+        ComponentConnector paintable = ConnectorMap.get(client).getConnector(
+                this);
+        String height = paintable.getState().height;
+        String width = paintable.getState().width;
+
+        // Add width and height
+        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // Codetype
+        if (uidl.hasAttribute("codetype")) {
+            html.append("codetype=\""
+                    + Util.escapeAttribute(uidl.getStringAttribute("codetype"))
+                    + "\" ");
+        }
+
+        // Standby
+        if (uidl.hasAttribute("standby")) {
+            html.append("standby=\""
+                    + Util.escapeAttribute(uidl.getStringAttribute("standby"))
+                    + "\" ");
+        }
+
+        // Archive
+        if (uidl.hasAttribute("archive")) {
+            html.append("archive=\""
+                    + Util.escapeAttribute(uidl.getStringAttribute("archive"))
+                    + "\" ");
+        }
+
+        // End object tag
+        html.append(">");
+
+        // Ensure we have an movie parameter
+        Map<String, String> parameters = getParameters(uidl);
+        if (parameters.get("movie") == null) {
+            parameters.put("movie", getSrc(uidl, client));
+        }
+
+        // Add parameters to OBJECT
+        for (String name : parameters.keySet()) {
+            html.append("<param ");
+            html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
+            html.append("value=\"" + Util.escapeAttribute(parameters.get(name))
+                    + "\" ");
+            html.append("/>");
+        }
+
+        // Build inner EMBED tag
+        html.append("<embed ");
+        html.append("src=\"" + Util.escapeAttribute(getSrc(uidl, client))
+                + "\" ");
+        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // Add the parameters to the Embed
+        for (String name : parameters.keySet()) {
+            html.append(Util.escapeAttribute(name));
+            html.append("=");
+            html.append("\"" + Util.escapeAttribute(parameters.get(name))
+                    + "\"");
+        }
+
+        // End embed tag
+        html.append("></embed>");
+
+        if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
+            html.append(uidl
+                    .getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT));
+        }
+
+        // End object tag
+        html.append("</object>");
+
+        return html.toString();
+    }
+
+    /**
+     * Returns a map (name -> value) of all parameters in the UIDL.
+     * <p>
+     * For internal use only. May be removed or replaced in the future.
+     * 
+     * @param uidl
+     * @return
+     */
+    public static Map<String, String> getParameters(UIDL uidl) {
+        Map<String, String> parameters = new HashMap<String, String>();
+
+        Iterator<Object> childIterator = uidl.getChildIterator();
+        while (childIterator.hasNext()) {
+
+            Object child = childIterator.next();
+            if (child instanceof UIDL) {
+
+                UIDL childUIDL = (UIDL) child;
+                if (childUIDL.getTag().equals("embeddedparam")) {
+                    String name = childUIDL.getStringAttribute("name");
+                    String value = childUIDL.getStringAttribute("value");
+                    parameters.put(name, value);
+                }
+            }
+
+        }
+
+        return parameters;
+    }
+
+    /**
+     * Helper to return translated src-attribute from embedded's UIDL
+     * <p>
+     * For internal use only. May be removed or replaced in the future.
+     * 
+     * @param uidl
+     * @param client
+     * @return
+     */
+    public String getSrc(UIDL uidl, ApplicationConnection client) {
+        String url = client.translateVaadinUri(uidl.getStringAttribute("src"));
+        if (url == null) {
+            return "";
+        }
+        return url;
+    }
+
+    @Override
+    protected void onDetach() {
+        if (BrowserInfo.get().isIE()) {
+            // Force browser to fire unload event when component is detached
+            // from the view (IE doesn't do this automatically)
+            if (browserElement != null) {
+                /*
+                 * src was previously set to javascript:false, but this was not
+                 * enough to overcome a bug when detaching an iframe with a pdf
+                 * loaded in IE9. about:blank seems to cause the adobe reader
+                 * plugin to unload properly before the iframe is removed. See
+                 * #7855
+                 */
+                DOM.setElementAttribute(browserElement, "src", "about:blank");
+            }
+        }
+        super.onDetach();
+    }
+
+    @Override
+    public void onBrowserEvent(Event event) {
+        super.onBrowserEvent(event);
+        if (DOM.eventGetType(event) == Event.ONLOAD) {
+            VConsole.log("Embeddable onload");
+            Util.notifyParentOfSizeChange(this, true);
+        }
+    }
+
+}
diff --git a/client/src/com/vaadin/client/ui/VFlash.java b/client/src/com/vaadin/client/ui/VFlash.java
new file mode 100644 (file)
index 0000000..fede021
--- /dev/null
@@ -0,0 +1,230 @@
+package com.vaadin.client.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.client.Util;
+
+public class VFlash extends HTML {
+
+    public static final String CLASSNAME = "v-flash";
+
+    protected String source;
+    protected String altText;
+    protected String classId;
+    protected String codebase;
+    protected String codetype;
+    protected String standby;
+    protected String archive;
+    protected Map<String, String> embedParams = new HashMap<String, String>();
+    protected boolean needsRebuild = false;
+    protected String width;
+    protected String height;
+
+    public VFlash() {
+        setStyleName(CLASSNAME);
+    }
+
+    public void setSource(String source) {
+        if (this.source != source) {
+            this.source = source;
+            needsRebuild = true;
+        }
+    }
+
+    public void setAlternateText(String altText) {
+        if (this.altText != altText) {
+            this.altText = altText;
+            needsRebuild = true;
+        }
+    }
+
+    public void setClassId(String classId) {
+        if (this.classId != classId) {
+            this.classId = classId;
+            needsRebuild = true;
+        }
+    }
+
+    public void setCodebase(String codebase) {
+        if (this.codebase != codebase) {
+            this.codebase = codebase;
+            needsRebuild = true;
+        }
+    }
+
+    public void setCodetype(String codetype) {
+        if (this.codetype != codetype) {
+            this.codetype = codetype;
+            needsRebuild = true;
+        }
+    }
+
+    public void setStandby(String standby) {
+        if (this.standby != standby) {
+            this.standby = standby;
+            needsRebuild = true;
+        }
+    }
+
+    public void setArchive(String archive) {
+        if (this.archive != archive) {
+            this.archive = archive;
+            needsRebuild = true;
+        }
+    }
+
+    /**
+     * Call this after changing values of widget. It will rebuild embedding
+     * structure if needed.
+     */
+    public void rebuildIfNeeded() {
+        if (needsRebuild) {
+            needsRebuild = false;
+            this.setHTML(createFlashEmbed());
+        }
+    }
+
+    @Override
+    public void setWidth(String width) {
+        // super.setWidth(height);
+
+        if (this.width != width) {
+            this.width = width;
+            needsRebuild = true;
+        }
+    }
+
+    @Override
+    public void setHeight(String height) {
+        // super.setHeight(height);
+
+        if (this.height != height) {
+            this.height = height;
+            needsRebuild = true;
+        }
+    }
+
+    public void setEmbedParams(Map<String, String> params) {
+        if (params == null) {
+            if (!embedParams.isEmpty()) {
+                embedParams.clear();
+                needsRebuild = true;
+            }
+            return;
+        }
+
+        if (!embedParams.equals(params)) {
+            embedParams = new HashMap<String, String>(params);
+            needsRebuild = true;
+        }
+    }
+
+    protected String createFlashEmbed() {
+        /*
+         * 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
+         * inside it a EMBED for all other browsers.
+         */
+
+        StringBuilder html = new StringBuilder();
+
+        // Start the object tag
+        html.append("<object ");
+
+        /*
+         * Add classid required for ActiveX to recognize the flash. This is a
+         * predefined value which ActiveX recognizes and must be the given
+         * value. More info can be found on
+         * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
+         * this by setting his own classid.
+         */
+        if (classId != null) {
+            html.append("classid=\"" + Util.escapeAttribute(classId) + "\" ");
+        } else {
+            html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
+        }
+
+        /*
+         * Add codebase required for ActiveX and must be exactly this according
+         * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
+         * given classid. Again, see more info on
+         * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
+         * 6.0.0.0 and above. Allow user to override this by setting his own
+         * codebase
+         */
+        if (codebase != null) {
+            html.append("codebase=\"" + Util.escapeAttribute(codebase) + "\" ");
+        } else {
+            html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
+        }
+
+        // Add width and height
+        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // Codetype
+        if (codetype != null) {
+            html.append("codetype=\"" + Util.escapeAttribute(codetype) + "\" ");
+        }
+
+        // Standby
+        if (standby != null) {
+            html.append("standby=\"" + Util.escapeAttribute(standby) + "\" ");
+        }
+
+        // Archive
+        if (archive != null) {
+            html.append("archive=\"" + Util.escapeAttribute(archive) + "\" ");
+        }
+
+        // End object tag
+        html.append(">");
+
+        // Ensure we have an movie parameter
+        if (embedParams.get("movie") == null) {
+            embedParams.put("movie", source);
+        }
+
+        // Add parameters to OBJECT
+        for (String name : embedParams.keySet()) {
+            html.append("<param ");
+            html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
+            html.append("value=\""
+                    + Util.escapeAttribute(embedParams.get(name)) + "\" ");
+            html.append("/>");
+        }
+
+        // Build inner EMBED tag
+        html.append("<embed ");
+        html.append("src=\"" + Util.escapeAttribute(source) + "\" ");
+        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
+        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
+        html.append("type=\"application/x-shockwave-flash\" ");
+
+        // Add the parameters to the Embed
+        for (String name : embedParams.keySet()) {
+            html.append(Util.escapeAttribute(name));
+            html.append("=");
+            html.append("\"" + Util.escapeAttribute(embedParams.get(name))
+                    + "\"");
+        }
+
+        // End embed tag
+        html.append("></embed>");
+
+        if (altText != null) {
+            html.append("<noembed>");
+            html.append(altText);
+            html.append("</noembed>");
+        }
+
+        // End object tag
+        html.append("</object>");
+
+        return html.toString();
+    }
+
+}
diff --git a/client/src/com/vaadin/client/ui/VForm.java b/client/src/com/vaadin/client/ui/VForm.java
new file mode 100644 (file)
index 0000000..14dc574
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.client.ui;
+
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyDownHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.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.client.ApplicationConnection;
+import com.vaadin.client.VErrorMessage;
+
+public class VForm extends ComplexPanel implements KeyDownHandler {
+
+    public static final String CLASSNAME = "v-form";
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public String id;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Widget lo;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element legend = DOM.createLegend();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element caption = DOM.createSpan();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element desc = DOM.createDiv();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Icon icon;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public VErrorMessage errorMessage = new VErrorMessage();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element fieldContainer = DOM.createDiv();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element footerContainer = DOM.createDiv();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Element fieldSet = DOM.createFieldSet();
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public Widget footer;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public ApplicationConnection client;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public ShortcutActionHandler shortcutHandler;
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public HandlerRegistration keyDownRegistration;
+
+    public VForm() {
+        setElement(DOM.createDiv());
+        getElement().appendChild(fieldSet);
+        setStyleName(CLASSNAME);
+        fieldSet.appendChild(legend);
+        legend.appendChild(caption);
+
+        fieldSet.appendChild(desc); // Adding description for initial padding
+                                    // measurements, removed later if no
+                                    // description is set
+
+        fieldSet.appendChild(fieldContainer);
+        errorMessage.setVisible(false);
+
+        fieldSet.appendChild(errorMessage.getElement());
+        fieldSet.appendChild(footerContainer);
+
+        errorMessage.setOwner(this);
+    }
+
+    @Override
+    public void setStyleName(String style) {
+        super.setStyleName(style);
+        updateStyleNames();
+    }
+
+    @Override
+    public void setStylePrimaryName(String style) {
+        super.setStylePrimaryName(style);
+        updateStyleNames();
+    }
+
+    protected void updateStyleNames() {
+        fieldContainer.setClassName(getStylePrimaryName() + "-content");
+        errorMessage.setStyleName(getStylePrimaryName() + "-errormessage");
+        desc.setClassName(getStylePrimaryName() + "-description");
+        footerContainer.setClassName(getStylePrimaryName() + "-footer");
+    }
+
+    @Override
+    public void onKeyDown(KeyDownEvent event) {
+        shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));
+    }
+
+    /** For internal use only. May be removed or replaced in the future. */
+    @Override
+    public void add(Widget child, Element container) {
+        super.add(child, container);
+    }
+}
diff --git a/client/src/com/vaadin/client/ui/VFormLayout.java b/client/src/com/vaadin/client/ui/VFormLayout.java
new file mode 100644 (file)
index 0000000..a46a0a4
--- /dev/null
@@ -0,0 +1,382 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.client.ui;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+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.Element;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.BrowserInfo;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.Focusable;
+import com.vaadin.client.StyleConstants;
+import com.vaadin.client.VTooltip;
+import com.vaadin.shared.ComponentConstants;
+import com.vaadin.shared.ComponentState;
+import com.vaadin.shared.ui.ComponentStateUtil;
+import com.vaadin.shared.ui.MarginInfo;
+
+/**
+ * Two col Layout that places caption on left col and field on right col
+ */
+public class VFormLayout extends SimplePanel {
+
+    private final static String CLASSNAME = "v-formlayout";
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public VFormLayoutTable table;
+
+    public VFormLayout() {
+        super();
+        setStyleName(StyleConstants.UI_LAYOUT);
+        addStyleName(CLASSNAME);
+        table = new VFormLayoutTable();
+        setWidget(table);
+    }
+
+    /**
+     * Parses the stylenames from shared state
+     * 
+     * @param state
+     *            shared state of the component
+     * @param enabled
+     * @return An array of stylenames
+     */
+    private String[] getStylesFromState(ComponentState state, boolean enabled) {
+        List<String> styles = new ArrayList<String>();
+        if (ComponentStateUtil.hasStyles(state)) {
+            for (String name : state.styles) {
+                styles.add(name);
+            }
+        }
+
+        if (!enabled) {
+            styles.add(ApplicationConnection.DISABLED_CLASSNAME);
+        }
+
+        return styles.toArray(new String[styles.size()]);
+    }
+
+    public class VFormLayoutTable extends FlexTable implements ClickHandler {
+
+        private static final int COLUMN_CAPTION = 0;
+        private static final int COLUMN_ERRORFLAG = 1;
+        private static final int COLUMN_WIDGET = 2;
+
+        private HashMap<Widget, Caption> widgetToCaption = new HashMap<Widget, Caption>();
+        private HashMap<Widget, ErrorFlag> widgetToError = new HashMap<Widget, ErrorFlag>();
+
+        public VFormLayoutTable() {
+            DOM.setElementProperty(getElement(), "cellPadding", "0");
+            DOM.setElementProperty(getElement(), "cellSpacing", "0");
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see
+         * com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt
+         * .event.dom.client.ClickEvent)
+         */
+        @Override
+        public void onClick(ClickEvent event) {
+            Caption caption = (Caption) event.getSource();
+            if (caption.getOwner() != null) {
+                if (caption.getOwner() instanceof Focusable) {
+                    ((Focusable) caption.getOwner()).focus();
+                } else if (caption.getOwner() instanceof com.google.gwt.user.client.ui.Focusable) {
+                    ((com.google.gwt.user.client.ui.Focusable) caption
+                            .getOwner()).setFocus(true);
+                }
+            }
+        }
+
+        public void setMargins(MarginInfo margins) {
+            Element margin = getElement();
+            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());
+
+        }
+
+        public void setSpacing(boolean spacing) {
+            setStyleName(getElement(), CLASSNAME + "-" + "spacing", spacing);
+
+        }
+
+        public void setRowCount(int rowNr) {
+            for (int i = 0; i < rowNr; i++) {
+                prepareCell(i, COLUMN_CAPTION);
+                getCellFormatter().setStyleName(i, COLUMN_CAPTION,
+                        CLASSNAME + "-captioncell");
+
+                prepareCell(i, 1);
+                getCellFormatter().setStyleName(i, COLUMN_ERRORFLAG,
+                        CLASSNAME + "-errorcell");
+
+                prepareCell(i, 2);
+                getCellFormatter().setStyleName(i, COLUMN_WIDGET,
+                        CLASSNAME + "-contentcell");
+
+                String rowstyles = CLASSNAME + "-row";
+                if (i == 0) {
+                    rowstyles += " " + CLASSNAME + "-firstrow";
+                }
+                if (i == rowNr - 1) {
+                    rowstyles += " " + CLASSNAME + "-lastrow";
+                }
+
+                getRowFormatter().setStyleName(i, rowstyles);
+
+            }
+            while (getRowCount() != rowNr) {
+                removeRow(rowNr);
+            }
+        }
+
+        public void setChild(int rowNr, Widget childWidget, Caption caption,
+                ErrorFlag error) {
+            setWidget(rowNr, COLUMN_WIDGET, childWidget);
+            setWidget(rowNr, COLUMN_CAPTION, caption);
+            setWidget(rowNr, COLUMN_ERRORFLAG, error);
+
+            widgetToCaption.put(childWidget, caption);
+            widgetToError.put(childWidget, error);
+
+        }
+
+        public Caption getCaption(Widget childWidget) {
+            return widgetToCaption.get(childWidget);
+        }
+
+        public ErrorFlag getError(Widget childWidget) {
+            return widgetToError.get(childWidget);
+        }
+
+        public void cleanReferences(Widget oldChildWidget) {
+            widgetToError.remove(oldChildWidget);
+            widgetToCaption.remove(oldChildWidget);
+
+        }
+
+        public void updateCaption(Widget widget, ComponentState state,
+                boolean enabled) {
+            final Caption c = widgetToCaption.get(widget);
+            if (c != null) {
+                c.updateCaption(state, enabled);
+            }
+        }
+
+        public void updateError(Widget widget, String errorMessage,
+                boolean hideErrors) {
+            final ErrorFlag e = widgetToError.get(widget);
+            if (e != null) {
+                e.updateError(errorMessage, hideErrors);
+            }
+
+        }
+
+    }
+
+    // TODO why duplicated here?
+    public class Caption extends HTML {
+
+        public static final String CLASSNAME = "v-caption";
+
+        private final ComponentConnector owner;
+
+        private Element requiredFieldIndicator;
+
+        private Icon icon;
+
+        private Element captionText;
+
+        /**
+         * 
+         * @param component
+         *            optional owner of caption. If not set, getOwner will
+         *            return null
+         */
+        public Caption(ComponentConnector component) {
+            super();
+            owner = component;
+        }
+
+        private void setStyles(String[] styles) {
+            String styleName = CLASSNAME;
+
+            if (styles != null) {
+                for (String style : styles) {
+                    if (ApplicationConnection.DISABLED_CLASSNAME.equals(style)) {
+                        // Add v-disabled also without classname prefix so
+                        // generic v-disabled CSS rules work
+                        styleName += " " + style;
+                    }
+
+                    styleName += " " + CLASSNAME + "-" + style;
+                }
+            }
+
+            setStyleName(styleName);
+        }
+
+        public void updateCaption(ComponentState state, boolean enabled) {
+            // Update styles as they might have changed when the caption changed
+            setStyles(getStylesFromState(state, enabled));
+
+            boolean isEmpty = true;
+
+            if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
+                if (icon == null) {
+                    icon = new Icon(owner.getConnection());
+
+                    DOM.insertChild(getElement(), icon.getElement(), 0);
+                }
+                icon.setUri(state.resources.get(
+                        ComponentConstants.ICON_RESOURCE).getURL());
+                isEmpty = false;
+            } else {
+                if (icon != null) {
+                    DOM.removeChild(getElement(), icon.getElement());
+                    icon = null;
+                }
+
+            }
+
+            if (state.caption != null) {
+                if (captionText == null) {
+                    captionText = DOM.createSpan();
+                    DOM.insertChild(getElement(), captionText, icon == null ? 0
+                            : 1);
+                }
+                String c = state.caption;
+                if (c == null) {
+                    c = "";
+                } else {
+                    isEmpty = false;
+                }
+                DOM.setInnerText(captionText, c);
+            } else {
+                // TODO should span also be removed
+            }
+
+            if (state.description != null && captionText != null) {
+                addStyleDependentName("hasdescription");
+            } else {
+                removeStyleDependentName("hasdescription");
+            }
+
+            boolean required = owner instanceof AbstractFieldConnector
+                    && ((AbstractFieldConnector) owner).isRequired();
+            if (required) {
+                if (requiredFieldIndicator == null) {
+                    requiredFieldIndicator = DOM.createSpan();
+                    DOM.setInnerText(requiredFieldIndicator, "*");
+                    DOM.setElementProperty(requiredFieldIndicator, "className",
+                            "v-required-field-indicator");
+                    DOM.appendChild(getElement(), requiredFieldIndicator);
+                }
+            } else {
+                if (requiredFieldIndicator != null) {
+                    DOM.removeChild(getElement(), requiredFieldIndicator);
+                    requiredFieldIndicator = null;
+                }
+            }
+
+            // Workaround for IE weirdness, sometimes returns bad height in some
+            // circumstances when Caption is empty. See #1444
+            // IE7 bugs more often. I wonder what happens when IE8 arrives...
+            // FIXME: This could be unnecessary for IE8+
+            if (BrowserInfo.get().isIE()) {
+                if (isEmpty) {
+                    setHeight("0px");
+                    DOM.setStyleAttribute(getElement(), "overflow", "hidden");
+                } else {
+                    setHeight("");
+                    DOM.setStyleAttribute(getElement(), "overflow", "");
+                }
+
+            }
+
+        }
+
+        /**
+         * Returns Paintable for which this Caption belongs to.
+         * 
+         * @return owner Widget
+         */
+        public ComponentConnector getOwner() {
+            return owner;
+        }
+    }
+
+    /** For internal use only. May be removed or replaced in the future. */
+    public class ErrorFlag extends HTML {
+        private static final String CLASSNAME = VFormLayout.CLASSNAME
+                + "-error-indicator";
+        Element errorIndicatorElement;
+
+        private ComponentConnector owner;
+
+        public ErrorFlag(ComponentConnector owner) {
+            setStyleName(CLASSNAME);
+            sinkEvents(VTooltip.TOOLTIP_EVENTS);
+            this.owner = owner;
+        }
+
+        public ComponentConnector getOwner() {
+            return owner;
+        }
+
+        public void updateError(String errorMessage, boolean hideErrors) {
+            boolean showError = null != errorMessage;
+            if (hideErrors) {
+                showError = false;
+            }
+
+            if (showError) {
+                if (errorIndicatorElement == null) {
+                    errorIndicatorElement = DOM.createDiv();
+                    DOM.setInnerHTML(errorIndicatorElement, "&nbsp;");
+                    DOM.setElementProperty(errorIndicatorElement, "className",
+                            "v-errorindicator");
+                    DOM.appendChild(getElement(), errorIndicatorElement);
+                }
+
+            } else if (errorIndicatorElement != null) {
+                DOM.removeChild(getElement(), errorIndicatorElement);
+                errorIndicatorElement = null;
+            }
+        }
+
+    }
+}
index 2af58d85783524046ae286378a56f0dff18d0b3a..601c93428c75929e55d748d03918475a4477c780 100644 (file)
@@ -92,7 +92,6 @@ import com.vaadin.client.ui.dd.VDragAndDropManager;
 import com.vaadin.client.ui.dd.VDragEvent;
 import com.vaadin.client.ui.dd.VHasDropHandler;
 import com.vaadin.client.ui.dd.VTransferable;
-import com.vaadin.client.ui.embedded.VEmbedded;
 import com.vaadin.shared.ComponentState;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.ui.dd.VerticalDropLocation;
index a15803beb775aab17a1c830b370f61d83e5eb1a8..97fab6d3d1f15ac09d0edb2b7bb44c0028782ad6 100644 (file)
@@ -34,6 +34,7 @@ import com.vaadin.client.VConsole;
 import com.vaadin.client.VTooltip;
 import com.vaadin.client.ui.AbstractComponentConnector;
 import com.vaadin.client.ui.ClickEventHandler;
+import com.vaadin.client.ui.VEmbedded;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.embedded.EmbeddedConstants;
diff --git a/client/src/com/vaadin/client/ui/embedded/VEmbedded.java b/client/src/com/vaadin/client/ui/embedded/VEmbedded.java
deleted file mode 100644 (file)
index 4dc85cd..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client.ui.embedded;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-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.vaadin.client.ApplicationConnection;
-import com.vaadin.client.BrowserInfo;
-import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ConnectorMap;
-import com.vaadin.client.UIDL;
-import com.vaadin.client.Util;
-import com.vaadin.client.VConsole;
-import com.vaadin.shared.ui.embedded.EmbeddedConstants;
-
-public class VEmbedded extends HTML {
-    public static String CLASSNAME = "v-embedded";
-
-    protected Element browserElement;
-
-    protected String type;
-    protected String mimetype;
-
-    protected ApplicationConnection client;
-
-    public VEmbedded() {
-        setStyleName(CLASSNAME);
-    }
-
-    /**
-     * Creates the Object and Embed tags for the Flash plugin so it works
-     * cross-browser
-     * 
-     * @param uidl
-     *            The UIDL
-     * @return Tags concatenated into a string
-     */
-    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
-         * inside it a EMBED for all other browsers.
-         */
-
-        StringBuilder html = new StringBuilder();
-
-        // Start the object tag
-        html.append("<object ");
-
-        /*
-         * Add classid required for ActiveX to recognize the flash. This is a
-         * predefined value which ActiveX recognizes and must be the given
-         * value. More info can be found on
-         * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
-         * this by setting his own classid.
-         */
-        if (uidl.hasAttribute("classid")) {
-            html.append("classid=\""
-                    + Util.escapeAttribute(uidl.getStringAttribute("classid"))
-                    + "\" ");
-        } else {
-            html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
-        }
-
-        /*
-         * Add codebase required for ActiveX and must be exactly this according
-         * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
-         * given classid. Again, see more info on
-         * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
-         * 6.0.0.0 and above. Allow user to override this by setting his own
-         * codebase
-         */
-        if (uidl.hasAttribute("codebase")) {
-            html.append("codebase=\""
-                    + Util.escapeAttribute(uidl.getStringAttribute("codebase"))
-                    + "\" ");
-        } else {
-            html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
-        }
-
-        ComponentConnector paintable = ConnectorMap.get(client).getConnector(
-                this);
-        String height = paintable.getState().height;
-        String width = paintable.getState().width;
-
-        // Add width and height
-        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
-        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
-        html.append("type=\"application/x-shockwave-flash\" ");
-
-        // Codetype
-        if (uidl.hasAttribute("codetype")) {
-            html.append("codetype=\""
-                    + Util.escapeAttribute(uidl.getStringAttribute("codetype"))
-                    + "\" ");
-        }
-
-        // Standby
-        if (uidl.hasAttribute("standby")) {
-            html.append("standby=\""
-                    + Util.escapeAttribute(uidl.getStringAttribute("standby"))
-                    + "\" ");
-        }
-
-        // Archive
-        if (uidl.hasAttribute("archive")) {
-            html.append("archive=\""
-                    + Util.escapeAttribute(uidl.getStringAttribute("archive"))
-                    + "\" ");
-        }
-
-        // End object tag
-        html.append(">");
-
-        // Ensure we have an movie parameter
-        Map<String, String> parameters = getParameters(uidl);
-        if (parameters.get("movie") == null) {
-            parameters.put("movie", getSrc(uidl, client));
-        }
-
-        // Add parameters to OBJECT
-        for (String name : parameters.keySet()) {
-            html.append("<param ");
-            html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
-            html.append("value=\"" + Util.escapeAttribute(parameters.get(name))
-                    + "\" ");
-            html.append("/>");
-        }
-
-        // Build inner EMBED tag
-        html.append("<embed ");
-        html.append("src=\"" + Util.escapeAttribute(getSrc(uidl, client))
-                + "\" ");
-        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
-        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
-        html.append("type=\"application/x-shockwave-flash\" ");
-
-        // Add the parameters to the Embed
-        for (String name : parameters.keySet()) {
-            html.append(Util.escapeAttribute(name));
-            html.append("=");
-            html.append("\"" + Util.escapeAttribute(parameters.get(name))
-                    + "\"");
-        }
-
-        // End embed tag
-        html.append("></embed>");
-
-        if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
-            html.append(uidl
-                    .getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT));
-        }
-
-        // End object tag
-        html.append("</object>");
-
-        return html.toString();
-    }
-
-    /**
-     * Returns a map (name -> value) of all parameters in the UIDL.
-     * 
-     * @param uidl
-     * @return
-     */
-    protected static Map<String, String> getParameters(UIDL uidl) {
-        Map<String, String> parameters = new HashMap<String, String>();
-
-        Iterator<Object> childIterator = uidl.getChildIterator();
-        while (childIterator.hasNext()) {
-
-            Object child = childIterator.next();
-            if (child instanceof UIDL) {
-
-                UIDL childUIDL = (UIDL) child;
-                if (childUIDL.getTag().equals("embeddedparam")) {
-                    String name = childUIDL.getStringAttribute("name");
-                    String value = childUIDL.getStringAttribute("value");
-                    parameters.put(name, value);
-                }
-            }
-
-        }
-
-        return parameters;
-    }
-
-    /**
-     * Helper to return translated src-attribute from embedded's UIDL
-     * 
-     * @param uidl
-     * @param client
-     * @return
-     */
-    protected String getSrc(UIDL uidl, ApplicationConnection client) {
-        String url = client.translateVaadinUri(uidl.getStringAttribute("src"));
-        if (url == null) {
-            return "";
-        }
-        return url;
-    }
-
-    @Override
-    protected void onDetach() {
-        if (BrowserInfo.get().isIE()) {
-            // Force browser to fire unload event when component is detached
-            // from the view (IE doesn't do this automatically)
-            if (browserElement != null) {
-                /*
-                 * src was previously set to javascript:false, but this was not
-                 * enough to overcome a bug when detaching an iframe with a pdf
-                 * loaded in IE9. about:blank seems to cause the adobe reader
-                 * plugin to unload properly before the iframe is removed. See
-                 * #7855
-                 */
-                DOM.setElementAttribute(browserElement, "src", "about:blank");
-            }
-        }
-        super.onDetach();
-    }
-
-    @Override
-    public void onBrowserEvent(Event event) {
-        super.onBrowserEvent(event);
-        if (DOM.eventGetType(event) == Event.ONLOAD) {
-            VConsole.log("Embeddable onload");
-            Util.notifyParentOfSizeChange(this, true);
-        }
-    }
-
-}
index eaccc4736c1c29bd2fdf4bde31e8e11e8871eca8..c8ca750840880aa8fa25be3ec3a155fb96f9be47 100644 (file)
@@ -2,6 +2,7 @@ package com.vaadin.client.ui.flash;
 
 import com.vaadin.client.communication.StateChangeEvent;
 import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.client.ui.VFlash;
 import com.vaadin.shared.ui.AbstractEmbeddedState;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.flash.FlashState;
diff --git a/client/src/com/vaadin/client/ui/flash/VFlash.java b/client/src/com/vaadin/client/ui/flash/VFlash.java
deleted file mode 100644 (file)
index 0f91ff8..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-package com.vaadin.client.ui.flash;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.google.gwt.user.client.ui.HTML;
-import com.vaadin.client.Util;
-
-public class VFlash extends HTML {
-
-    public static final String CLASSNAME = "v-flash";
-
-    protected String source;
-    protected String altText;
-    protected String classId;
-    protected String codebase;
-    protected String codetype;
-    protected String standby;
-    protected String archive;
-    protected Map<String, String> embedParams = new HashMap<String, String>();
-    protected boolean needsRebuild = false;
-    protected String width;
-    protected String height;
-
-    public VFlash() {
-        setStyleName(CLASSNAME);
-    }
-
-    public void setSource(String source) {
-        if (this.source != source) {
-            this.source = source;
-            needsRebuild = true;
-        }
-    }
-
-    public void setAlternateText(String altText) {
-        if (this.altText != altText) {
-            this.altText = altText;
-            needsRebuild = true;
-        }
-    }
-
-    public void setClassId(String classId) {
-        if (this.classId != classId) {
-            this.classId = classId;
-            needsRebuild = true;
-        }
-    }
-
-    public void setCodebase(String codebase) {
-        if (this.codebase != codebase) {
-            this.codebase = codebase;
-            needsRebuild = true;
-        }
-    }
-
-    public void setCodetype(String codetype) {
-        if (this.codetype != codetype) {
-            this.codetype = codetype;
-            needsRebuild = true;
-        }
-    }
-
-    public void setStandby(String standby) {
-        if (this.standby != standby) {
-            this.standby = standby;
-            needsRebuild = true;
-        }
-    }
-
-    public void setArchive(String archive) {
-        if (this.archive != archive) {
-            this.archive = archive;
-            needsRebuild = true;
-        }
-    }
-
-    /**
-     * Call this after changing values of widget. It will rebuild embedding
-     * structure if needed.
-     */
-    public void rebuildIfNeeded() {
-        if (needsRebuild) {
-            needsRebuild = false;
-            this.setHTML(createFlashEmbed());
-        }
-    }
-
-    @Override
-    public void setWidth(String width) {
-        // super.setWidth(height);
-
-        if (this.width != width) {
-            this.width = width;
-            needsRebuild = true;
-        }
-    }
-
-    @Override
-    public void setHeight(String height) {
-        // super.setHeight(height);
-
-        if (this.height != height) {
-            this.height = height;
-            needsRebuild = true;
-        }
-    }
-
-    public void setEmbedParams(Map<String, String> params) {
-        if (params == null) {
-            if (!embedParams.isEmpty()) {
-                embedParams.clear();
-                needsRebuild = true;
-            }
-            return;
-        }
-
-        if (!embedParams.equals(params)) {
-            embedParams = new HashMap<String, String>(params);
-            needsRebuild = true;
-        }
-    }
-
-    protected String createFlashEmbed() {
-        /*
-         * 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
-         * inside it a EMBED for all other browsers.
-         */
-
-        StringBuilder html = new StringBuilder();
-
-        // Start the object tag
-        html.append("<object ");
-
-        /*
-         * Add classid required for ActiveX to recognize the flash. This is a
-         * predefined value which ActiveX recognizes and must be the given
-         * value. More info can be found on
-         * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
-         * this by setting his own classid.
-         */
-        if (classId != null) {
-            html.append("classid=\"" + Util.escapeAttribute(classId) + "\" ");
-        } else {
-            html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
-        }
-
-        /*
-         * Add codebase required for ActiveX and must be exactly this according
-         * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
-         * given classid. Again, see more info on
-         * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
-         * 6.0.0.0 and above. Allow user to override this by setting his own
-         * codebase
-         */
-        if (codebase != null) {
-            html.append("codebase=\"" + Util.escapeAttribute(codebase) + "\" ");
-        } else {
-            html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
-        }
-
-        // Add width and height
-        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
-        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
-        html.append("type=\"application/x-shockwave-flash\" ");
-
-        // Codetype
-        if (codetype != null) {
-            html.append("codetype=\"" + Util.escapeAttribute(codetype) + "\" ");
-        }
-
-        // Standby
-        if (standby != null) {
-            html.append("standby=\"" + Util.escapeAttribute(standby) + "\" ");
-        }
-
-        // Archive
-        if (archive != null) {
-            html.append("archive=\"" + Util.escapeAttribute(archive) + "\" ");
-        }
-
-        // End object tag
-        html.append(">");
-
-        // Ensure we have an movie parameter
-        if (embedParams.get("movie") == null) {
-            embedParams.put("movie", source);
-        }
-
-        // Add parameters to OBJECT
-        for (String name : embedParams.keySet()) {
-            html.append("<param ");
-            html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
-            html.append("value=\""
-                    + Util.escapeAttribute(embedParams.get(name)) + "\" ");
-            html.append("/>");
-        }
-
-        // Build inner EMBED tag
-        html.append("<embed ");
-        html.append("src=\"" + Util.escapeAttribute(source) + "\" ");
-        html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
-        html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
-        html.append("type=\"application/x-shockwave-flash\" ");
-
-        // Add the parameters to the Embed
-        for (String name : embedParams.keySet()) {
-            html.append(Util.escapeAttribute(name));
-            html.append("=");
-            html.append("\"" + Util.escapeAttribute(embedParams.get(name))
-                    + "\"");
-        }
-
-        // End embed tag
-        html.append("></embed>");
-
-        if (altText != null) {
-            html.append("<noembed>");
-            html.append(altText);
-            html.append("</noembed>");
-        }
-
-        // End object tag
-        html.append("</object>");
-
-        return html.toString();
-    }
-
-}
index 0c2e4a8ecd5f69d6ec5e8637414b83a1797eb981..bd7ab6ff6e354154eb45392ada22bebab7ae448e 100644 (file)
@@ -27,6 +27,7 @@ import com.vaadin.client.UIDL;
 import com.vaadin.client.ui.AbstractComponentContainerConnector;
 import com.vaadin.client.ui.Icon;
 import com.vaadin.client.ui.ShortcutActionHandler;
+import com.vaadin.client.ui.VForm;
 import com.vaadin.client.ui.layout.ElementResizeEvent;
 import com.vaadin.client.ui.layout.ElementResizeListener;
 import com.vaadin.client.ui.layout.MayScrollChildren;
diff --git a/client/src/com/vaadin/client/ui/form/VForm.java b/client/src/com/vaadin/client/ui/form/VForm.java
deleted file mode 100644 (file)
index ac877bd..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client.ui.form;
-
-import com.google.gwt.event.dom.client.KeyDownEvent;
-import com.google.gwt.event.dom.client.KeyDownHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.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.client.ApplicationConnection;
-import com.vaadin.client.VErrorMessage;
-import com.vaadin.client.ui.Icon;
-import com.vaadin.client.ui.ShortcutActionHandler;
-
-public class VForm extends ComplexPanel implements KeyDownHandler {
-
-    protected String id;
-
-    public static final String CLASSNAME = "v-form";
-
-    Widget lo;
-    Element legend = DOM.createLegend();
-    Element caption = DOM.createSpan();
-    Element desc = DOM.createDiv();
-    Icon icon;
-    VErrorMessage errorMessage = new VErrorMessage();
-
-    Element fieldContainer = DOM.createDiv();
-
-    Element footerContainer = DOM.createDiv();
-
-    Element fieldSet = DOM.createFieldSet();
-
-    Widget footer;
-
-    ApplicationConnection client;
-
-    ShortcutActionHandler shortcutHandler;
-
-    HandlerRegistration keyDownRegistration;
-
-    public VForm() {
-        setElement(DOM.createDiv());
-        getElement().appendChild(fieldSet);
-        setStyleName(CLASSNAME);
-        fieldSet.appendChild(legend);
-        legend.appendChild(caption);
-
-        fieldSet.appendChild(desc); // Adding description for initial padding
-                                    // measurements, removed later if no
-                                    // description is set
-
-        fieldSet.appendChild(fieldContainer);
-        errorMessage.setVisible(false);
-
-        fieldSet.appendChild(errorMessage.getElement());
-        fieldSet.appendChild(footerContainer);
-
-        errorMessage.setOwner(this);
-    }
-
-    @Override
-    public void setStyleName(String style) {
-        super.setStyleName(style);
-        updateStyleNames();
-    }
-
-    @Override
-    public void setStylePrimaryName(String style) {
-        super.setStylePrimaryName(style);
-        updateStyleNames();
-    }
-
-    protected void updateStyleNames() {
-        fieldContainer.setClassName(getStylePrimaryName() + "-content");
-        errorMessage.setStyleName(getStylePrimaryName() + "-errormessage");
-        desc.setClassName(getStylePrimaryName() + "-description");
-        footerContainer.setClassName(getStylePrimaryName() + "-footer");
-    }
-
-    @Override
-    public void onKeyDown(KeyDownEvent event) {
-        shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));
-    }
-
-    @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);
-    }
-}
index 6379ae47be61b3ff75ab3ba7f5b0ce60031aba40..ed873ae80924d6f865834799e91f704d4e01a493 100644 (file)
@@ -24,9 +24,10 @@ import com.vaadin.client.Util;
 import com.vaadin.client.communication.StateChangeEvent;
 import com.vaadin.client.ui.AbstractFieldConnector;
 import com.vaadin.client.ui.AbstractLayoutConnector;
-import com.vaadin.client.ui.formlayout.VFormLayout.Caption;
-import com.vaadin.client.ui.formlayout.VFormLayout.ErrorFlag;
-import com.vaadin.client.ui.formlayout.VFormLayout.VFormLayoutTable;
+import com.vaadin.client.ui.VFormLayout;
+import com.vaadin.client.ui.VFormLayout.Caption;
+import com.vaadin.client.ui.VFormLayout.ErrorFlag;
+import com.vaadin.client.ui.VFormLayout.VFormLayoutTable;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.MarginInfo;
 import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState;
diff --git a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java
deleted file mode 100644 (file)
index cbdef66..0000000
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client.ui.formlayout;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-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.Element;
-import com.google.gwt.user.client.ui.FlexTable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.SimplePanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.client.ApplicationConnection;
-import com.vaadin.client.BrowserInfo;
-import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.Focusable;
-import com.vaadin.client.StyleConstants;
-import com.vaadin.client.VTooltip;
-import com.vaadin.client.ui.AbstractFieldConnector;
-import com.vaadin.client.ui.Icon;
-import com.vaadin.shared.ComponentConstants;
-import com.vaadin.shared.ComponentState;
-import com.vaadin.shared.ui.ComponentStateUtil;
-import com.vaadin.shared.ui.MarginInfo;
-
-/**
- * Two col Layout that places caption on left col and field on right col
- */
-public class VFormLayout extends SimplePanel {
-
-    private final static String CLASSNAME = "v-formlayout";
-
-    VFormLayoutTable table;
-
-    public VFormLayout() {
-        super();
-        setStyleName(StyleConstants.UI_LAYOUT);
-        addStyleName(CLASSNAME);
-        table = new VFormLayoutTable();
-        setWidget(table);
-    }
-
-    /**
-     * Parses the stylenames from shared state
-     * 
-     * @param state
-     *            shared state of the component
-     * @param enabled
-     * @return An array of stylenames
-     */
-    private String[] getStylesFromState(ComponentState state, boolean enabled) {
-        List<String> styles = new ArrayList<String>();
-        if (ComponentStateUtil.hasStyles(state)) {
-            for (String name : state.styles) {
-                styles.add(name);
-            }
-        }
-
-        if (!enabled) {
-            styles.add(ApplicationConnection.DISABLED_CLASSNAME);
-        }
-
-        return styles.toArray(new String[styles.size()]);
-    }
-
-    public class VFormLayoutTable extends FlexTable implements ClickHandler {
-
-        private static final int COLUMN_CAPTION = 0;
-        private static final int COLUMN_ERRORFLAG = 1;
-        private static final int COLUMN_WIDGET = 2;
-
-        private HashMap<Widget, Caption> widgetToCaption = new HashMap<Widget, Caption>();
-        private HashMap<Widget, ErrorFlag> widgetToError = new HashMap<Widget, ErrorFlag>();
-
-        public VFormLayoutTable() {
-            DOM.setElementProperty(getElement(), "cellPadding", "0");
-            DOM.setElementProperty(getElement(), "cellSpacing", "0");
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see
-         * com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt
-         * .event.dom.client.ClickEvent)
-         */
-        @Override
-        public void onClick(ClickEvent event) {
-            Caption caption = (Caption) event.getSource();
-            if (caption.getOwner() != null) {
-                if (caption.getOwner() instanceof Focusable) {
-                    ((Focusable) caption.getOwner()).focus();
-                } else if (caption.getOwner() instanceof com.google.gwt.user.client.ui.Focusable) {
-                    ((com.google.gwt.user.client.ui.Focusable) caption
-                            .getOwner()).setFocus(true);
-                }
-            }
-        }
-
-        public void setMargins(MarginInfo margins) {
-            Element margin = getElement();
-            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());
-
-        }
-
-        public void setSpacing(boolean spacing) {
-            setStyleName(getElement(), CLASSNAME + "-" + "spacing", spacing);
-
-        }
-
-        public void setRowCount(int rowNr) {
-            for (int i = 0; i < rowNr; i++) {
-                prepareCell(i, COLUMN_CAPTION);
-                getCellFormatter().setStyleName(i, COLUMN_CAPTION,
-                        CLASSNAME + "-captioncell");
-
-                prepareCell(i, 1);
-                getCellFormatter().setStyleName(i, COLUMN_ERRORFLAG,
-                        CLASSNAME + "-errorcell");
-
-                prepareCell(i, 2);
-                getCellFormatter().setStyleName(i, COLUMN_WIDGET,
-                        CLASSNAME + "-contentcell");
-
-                String rowstyles = CLASSNAME + "-row";
-                if (i == 0) {
-                    rowstyles += " " + CLASSNAME + "-firstrow";
-                }
-                if (i == rowNr - 1) {
-                    rowstyles += " " + CLASSNAME + "-lastrow";
-                }
-
-                getRowFormatter().setStyleName(i, rowstyles);
-
-            }
-            while (getRowCount() != rowNr) {
-                removeRow(rowNr);
-            }
-        }
-
-        public void setChild(int rowNr, Widget childWidget, Caption caption,
-                ErrorFlag error) {
-            setWidget(rowNr, COLUMN_WIDGET, childWidget);
-            setWidget(rowNr, COLUMN_CAPTION, caption);
-            setWidget(rowNr, COLUMN_ERRORFLAG, error);
-
-            widgetToCaption.put(childWidget, caption);
-            widgetToError.put(childWidget, error);
-
-        }
-
-        public Caption getCaption(Widget childWidget) {
-            return widgetToCaption.get(childWidget);
-        }
-
-        public ErrorFlag getError(Widget childWidget) {
-            return widgetToError.get(childWidget);
-        }
-
-        public void cleanReferences(Widget oldChildWidget) {
-            widgetToError.remove(oldChildWidget);
-            widgetToCaption.remove(oldChildWidget);
-
-        }
-
-        public void updateCaption(Widget widget, ComponentState state,
-                boolean enabled) {
-            final Caption c = widgetToCaption.get(widget);
-            if (c != null) {
-                c.updateCaption(state, enabled);
-            }
-        }
-
-        public void updateError(Widget widget, String errorMessage,
-                boolean hideErrors) {
-            final ErrorFlag e = widgetToError.get(widget);
-            if (e != null) {
-                e.updateError(errorMessage, hideErrors);
-            }
-
-        }
-
-    }
-
-    // TODO why duplicated here?
-    public class Caption extends HTML {
-
-        public static final String CLASSNAME = "v-caption";
-
-        private final ComponentConnector owner;
-
-        private Element requiredFieldIndicator;
-
-        private Icon icon;
-
-        private Element captionText;
-
-        /**
-         * 
-         * @param component
-         *            optional owner of caption. If not set, getOwner will
-         *            return null
-         */
-        public Caption(ComponentConnector component) {
-            super();
-            owner = component;
-        }
-
-        private void setStyles(String[] styles) {
-            String styleName = CLASSNAME;
-
-            if (styles != null) {
-                for (String style : styles) {
-                    if (ApplicationConnection.DISABLED_CLASSNAME.equals(style)) {
-                        // Add v-disabled also without classname prefix so
-                        // generic v-disabled CSS rules work
-                        styleName += " " + style;
-                    }
-
-                    styleName += " " + CLASSNAME + "-" + style;
-                }
-            }
-
-            setStyleName(styleName);
-        }
-
-        public void updateCaption(ComponentState state, boolean enabled) {
-            // Update styles as they might have changed when the caption changed
-            setStyles(getStylesFromState(state, enabled));
-
-            boolean isEmpty = true;
-
-            if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
-                if (icon == null) {
-                    icon = new Icon(owner.getConnection());
-
-                    DOM.insertChild(getElement(), icon.getElement(), 0);
-                }
-                icon.setUri(state.resources.get(
-                        ComponentConstants.ICON_RESOURCE).getURL());
-                isEmpty = false;
-            } else {
-                if (icon != null) {
-                    DOM.removeChild(getElement(), icon.getElement());
-                    icon = null;
-                }
-
-            }
-
-            if (state.caption != null) {
-                if (captionText == null) {
-                    captionText = DOM.createSpan();
-                    DOM.insertChild(getElement(), captionText, icon == null ? 0
-                            : 1);
-                }
-                String c = state.caption;
-                if (c == null) {
-                    c = "";
-                } else {
-                    isEmpty = false;
-                }
-                DOM.setInnerText(captionText, c);
-            } else {
-                // TODO should span also be removed
-            }
-
-            if (state.description != null && captionText != null) {
-                addStyleDependentName("hasdescription");
-            } else {
-                removeStyleDependentName("hasdescription");
-            }
-
-            boolean required = owner instanceof AbstractFieldConnector
-                    && ((AbstractFieldConnector) owner).isRequired();
-            if (required) {
-                if (requiredFieldIndicator == null) {
-                    requiredFieldIndicator = DOM.createSpan();
-                    DOM.setInnerText(requiredFieldIndicator, "*");
-                    DOM.setElementProperty(requiredFieldIndicator, "className",
-                            "v-required-field-indicator");
-                    DOM.appendChild(getElement(), requiredFieldIndicator);
-                }
-            } else {
-                if (requiredFieldIndicator != null) {
-                    DOM.removeChild(getElement(), requiredFieldIndicator);
-                    requiredFieldIndicator = null;
-                }
-            }
-
-            // Workaround for IE weirdness, sometimes returns bad height in some
-            // circumstances when Caption is empty. See #1444
-            // IE7 bugs more often. I wonder what happens when IE8 arrives...
-            // FIXME: This could be unnecessary for IE8+
-            if (BrowserInfo.get().isIE()) {
-                if (isEmpty) {
-                    setHeight("0px");
-                    DOM.setStyleAttribute(getElement(), "overflow", "hidden");
-                } else {
-                    setHeight("");
-                    DOM.setStyleAttribute(getElement(), "overflow", "");
-                }
-
-            }
-
-        }
-
-        /**
-         * Returns Paintable for which this Caption belongs to.
-         * 
-         * @return owner Widget
-         */
-        public ComponentConnector getOwner() {
-            return owner;
-        }
-    }
-
-    class ErrorFlag extends HTML {
-        private static final String CLASSNAME = VFormLayout.CLASSNAME
-                + "-error-indicator";
-        Element errorIndicatorElement;
-
-        private ComponentConnector owner;
-
-        public ErrorFlag(ComponentConnector owner) {
-            setStyleName(CLASSNAME);
-            sinkEvents(VTooltip.TOOLTIP_EVENTS);
-            this.owner = owner;
-        }
-
-        public ComponentConnector getOwner() {
-            return owner;
-        }
-
-        public void updateError(String errorMessage, boolean hideErrors) {
-            boolean showError = null != errorMessage;
-            if (hideErrors) {
-                showError = false;
-            }
-
-            if (showError) {
-                if (errorIndicatorElement == null) {
-                    errorIndicatorElement = DOM.createDiv();
-                    DOM.setInnerHTML(errorIndicatorElement, "&nbsp;");
-                    DOM.setElementProperty(errorIndicatorElement, "className",
-                            "v-errorindicator");
-                    DOM.appendChild(getElement(), errorIndicatorElement);
-                }
-
-            } else if (errorIndicatorElement != null) {
-                DOM.removeChild(getElement(), errorIndicatorElement);
-                errorIndicatorElement = null;
-            }
-        }
-
-    }
-}