From: Artur Signell Date: Fri, 23 Mar 2012 07:52:33 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/6.8' X-Git-Tag: 7.0.0.alpha2~230 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b052e30bb6aad20a4a7f840ff4fa646c2967e290;p=vaadin-framework.git Merge remote-tracking branch 'origin/6.8' Conflicts: src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java tests/testbench/com/vaadin/tests/components/embedded/EmbeddedPdf.java --- b052e30bb6aad20a4a7f840ff4fa646c2967e290 diff --cc src/com/vaadin/terminal/gwt/client/ui/EmbeddedConnector.java index d57f56d9ef,0000000000..b724e8fe9e mode 100644,000000..100644 --- a/src/com/vaadin/terminal/gwt/client/ui/EmbeddedConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/EmbeddedConnector.java @@@ -1,185 -1,0 +1,186 @@@ +/* +@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 EmbeddedConnector extends AbstractComponentConnector { + + public static final String CLICK_EVENT_IDENTIFIER = "click"; ++ public static final String ALTERNATE_TEXT = "alt"; + + @Override + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + if (!isRealUpdate(uidl)) { + return; + } + + // Save details + getWidget().client = client; + + boolean clearBrowserElement = true; + + clickEventHandler.handleEventHandlerRegistration(); + + if (uidl.hasAttribute("type")) { + getWidget().type = uidl.getStringAttribute("type"); + if (getWidget().type.equals("image")) { + getWidget().addStyleName(VEmbedded.CLASSNAME + "-image"); + Element el = null; + boolean created = false; + NodeList nodes = getWidget().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) { + getWidget().setHTML(""); + el = DOM.createImg(); + created = true; + DOM.sinkEvents(el, Event.ONLOAD); + } + + // Set attributes + Style style = el.getStyle(); + style.setProperty("width", getState().getWidth()); + style.setProperty("height", getState().getHeight()); + + DOM.setElementProperty(el, "src", + getWidget().getSrc(uidl, client)); + + if (created) { + // insert in dom late + getWidget().getElement().appendChild(el); + } + + /* + * Sink tooltip events so tooltip is displayed when hovering the + * image. + */ + getWidget().sinkEvents(VTooltip.TOOLTIP_EVENTS); + + } else if (getWidget().type.equals("browser")) { + getWidget().addStyleName(VEmbedded.CLASSNAME + "-browser"); + if (getWidget().browserElement == null) { + getWidget().setHTML( + ""); + getWidget().browserElement = DOM.getFirstChild(getWidget() + .getElement()); + } + DOM.setElementAttribute(getWidget().browserElement, "src", + getWidget().getSrc(uidl, client)); + clearBrowserElement = false; + } else { + VConsole.log("Unknown Embedded type '" + getWidget().type + "'"); + } + } else if (uidl.hasAttribute("mimetype")) { + final String mime = uidl.getStringAttribute("mimetype"); + if (mime.equals("application/x-shockwave-flash")) { + // Handle embedding of Flash + getWidget().addStyleName(VEmbedded.CLASSNAME + "-flash"); + getWidget().setHTML(getWidget().createFlashEmbed(uidl)); + + } else if (mime.equals("image/svg+xml")) { + getWidget().addStyleName(VEmbedded.CLASSNAME + "-svg"); + String data; + Map parameters = VEmbedded.getParameters(uidl); + if (parameters.get("data") == null) { + data = getWidget().getSrc(uidl, client); + } else { + data = "data:image/svg+xml," + parameters.get("data"); + } + getWidget().setHTML(""); + ObjectElement obj = Document.get().createObjectElement(); + obj.setType(mime); + obj.setData(data); + if (!isUndefinedWidth()) { + obj.getStyle().setProperty("width", "100%"); + } + if (!isUndefinedHeight()) { + 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")); + } + getWidget().getElement().appendChild(obj); + + } else { + VConsole.log("Unknown Embedded mimetype '" + mime + "'"); + } + } else { + VConsole.log("Unknown Embedded; no type or mimetype attribute"); + } + + if (clearBrowserElement) { + getWidget().browserElement = null; + } + } + + @Override + protected Widget createWidget() { + return GWT.create(VEmbedded.class); + } + + @Override + public VEmbedded getWidget() { + return (VEmbedded) super.getWidget(); + } + + protected final ClickEventHandler clickEventHandler = new ClickEventHandler( + this, CLICK_EVENT_IDENTIFIER) { + + @Override + protected HandlerRegistration registerHandler( + H handler, Type type) { + return getWidget().addDomHandler(handler, type); + } + + }; + +} diff --cc src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java index 71240d9c1d,2783db99d1..26b45d10e1 --- a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java @@@ -152,6 -313,10 +152,11 @@@ public class VEmbedded extends HTML // End embed tag html.append(">"); - if (uidl.hasAttribute(ALTERNATE_TEXT)) { - html.append(uidl.getStringAttribute(ALTERNATE_TEXT)); ++ if (uidl.hasAttribute(EmbeddedConnector.ALTERNATE_TEXT)) { ++ html.append(uidl ++ .getStringAttribute(EmbeddedConnector.ALTERNATE_TEXT)); + } + // End object tag html.append(""); diff --cc src/com/vaadin/ui/Button.java index 2e23d4ae74,3c99784592..dbebd9200c --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@@ -306,10 -512,20 +306,21 @@@ public class Button extends AbstractCom * the Listener to be removed. */ public void removeListener(ClickListener listener) { - removeListener(ClickEvent.class, listener, BUTTON_CLICK_METHOD); + removeListener(ClickEvent.class, listener, + ClickListener.BUTTON_CLICK_METHOD); } + /** + * Simulates a button click, notifying all server-side listeners. + * + * No action is taken is the button is disabled. + */ + public void click() { + if (isEnabled() && !isReadOnly()) { + fireClick(); + } + } + /** * Fires a click event to all listeners without any event details. * diff --cc src/com/vaadin/ui/Embedded.java index bc4c2a3ff4,181cbbfb96..906f1ca1ed --- a/src/com/vaadin/ui/Embedded.java +++ b/src/com/vaadin/ui/Embedded.java @@@ -146,6 -148,9 +148,9 @@@ public class Embedded extends AbstractC if (archive != null && !"".equals(archive)) { target.addAttribute("archive", archive); } + if (altText != null && !"".equals(altText)) { - target.addAttribute(VEmbedded.ALTERNATE_TEXT, altText); ++ target.addAttribute(EmbeddedConnector.ALTERNATE_TEXT, altText); + } // Params for (final Iterator i = getParameterNames(); i.hasNext();) { diff --cc tests/testbench/com/vaadin/tests/components/embedded/EmbeddedPdf.java index e551e153db,320df648b1..d507cebebc --- a/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedPdf.java +++ b/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedPdf.java @@@ -26,7 -28,13 +28,13 @@@ public class EmbeddedPdf extends TestBa player.setSource(new ClassResource(getClass(), "test.pdf", this)); addComponent(player); + addComponent(new Button("Remove pdf", new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + removeComponent(player); + } + })); + - player.getWindow().addWindow(new Window("Testwindow")); + player.getRoot().addWindow(new Window("Testwindow")); } }