summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-30 11:30:39 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-30 12:47:35 +0300
commitfd3826abf42f69db546eff18d269e462843feb49 (patch)
tree2852b77e657e90061842bc2d99dad09b36cd4150 /client
parente71794ee177e309a4cba15ebd6b65d5950721dd7 (diff)
downloadvaadin-framework-fd3826abf42f69db546eff18d269e462843feb49.tar.gz
vaadin-framework-fd3826abf42f69db546eff18d269e462843feb49.zip
Replace ApplicationResource with ConnectorResource (#9419)
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/VCaption.java9
-rw-r--r--client/src/com/vaadin/client/ui/AbstractComponentConnector.java18
-rw-r--r--client/src/com/vaadin/client/ui/AbstractConnector.java26
-rw-r--r--client/src/com/vaadin/client/ui/button/ButtonConnector.java6
-rw-r--r--client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/flash/FlashConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/form/FormConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/formlayout/VFormLayout.java6
-rw-r--r--client/src/com/vaadin/client/ui/image/ImageConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/link/LinkConnector.java27
-rw-r--r--client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/panel/PanelConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/video/VideoConnector.java9
-rw-r--r--client/src/com/vaadin/client/ui/window/WindowConnector.java4
15 files changed, 90 insertions, 43 deletions
diff --git a/client/src/com/vaadin/client/VCaption.java b/client/src/com/vaadin/client/VCaption.java
index 769428e16b..58e0b847f0 100644
--- a/client/src/com/vaadin/client/VCaption.java
+++ b/client/src/com/vaadin/client/VCaption.java
@@ -23,6 +23,7 @@ import com.google.gwt.user.client.ui.HTML;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.Icon;
import com.vaadin.shared.AbstractFieldState;
+import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ComponentState;
public class VCaption extends HTML {
@@ -119,7 +120,8 @@ public class VCaption extends HTML {
}
setStyleName(style);
- boolean hasIcon = owner.getState().getIcon() != null;
+ boolean hasIcon = owner.getState().resources
+ .containsKey(ComponentConstants.ICON_RESOURCE);
boolean showRequired = false;
boolean showError = owner.getState().getErrorMessage() != null;
if (owner.getState() instanceof AbstractFieldState) {
@@ -143,7 +145,8 @@ public class VCaption extends HTML {
// Icon forces the caption to be above the component
placedAfterComponent = false;
- icon.setUri(owner.getState().getIcon().getURL());
+ icon.setUri(owner.getState().resources.get(
+ ComponentConstants.ICON_RESOURCE).getURL());
} else if (icon != null) {
// Remove existing
@@ -392,7 +395,7 @@ public class VCaption extends HTML {
if (state.getCaption() != null) {
return true;
}
- if (state.getIcon() != null) {
+ if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
return true;
}
if (state.getErrorMessage() != null) {
diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
index 8a875fe363..18c13b4b7f 100644
--- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
+++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
@@ -39,6 +39,7 @@ import com.vaadin.client.metadata.Type;
import com.vaadin.client.metadata.TypeData;
import com.vaadin.client.ui.UI.UIConnector;
import com.vaadin.client.ui.datefield.PopupDateFieldConnector;
+import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ComponentState;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.TabIndexState;
@@ -248,9 +249,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.client.ComponentConnector#delegateCaptionHandling
- * ()
+ * @see com.vaadin.client.ComponentConnector#delegateCaptionHandling ()
*/
@Override
public boolean delegateCaptionHandling() {
@@ -421,8 +420,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.client.ComponentConnector#getTooltipInfo(com.
+ * @see com.vaadin.client.ComponentConnector#getTooltipInfo(com.
* google.gwt.dom.client.Element)
*/
@Override
@@ -430,4 +428,14 @@ public abstract class AbstractComponentConnector extends AbstractConnector
return new TooltipInfo(getState().getDescription(), getState()
.getErrorMessage());
}
+
+ /**
+ * Gets the icon set for this component.
+ *
+ * @return the URL of the icon, or <code>null</code> if no icon has been
+ * defined.
+ */
+ protected String getIcon() {
+ return getResourceUrl(ComponentConstants.ICON_RESOURCE);
+ }
}
diff --git a/client/src/com/vaadin/client/ui/AbstractConnector.java b/client/src/com/vaadin/client/ui/AbstractConnector.java
index a100f34130..989867d40e 100644
--- a/client/src/com/vaadin/client/ui/AbstractConnector.java
+++ b/client/src/com/vaadin/client/ui/AbstractConnector.java
@@ -36,6 +36,7 @@ import com.vaadin.client.metadata.Type;
import com.vaadin.client.metadata.TypeData;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.SharedState;
+import com.vaadin.shared.communication.URLReference;
/**
* An abstract implementation of Connector.
@@ -344,4 +345,29 @@ public abstract class AbstractConnector implements ServerConnector,
c.updateEnabledState(c.isEnabled());
}
}
+
+ /**
+ * Gets the URL for a resource that has been added by the server-side
+ * connector using
+ * {@link com.vaadin.terminal.AbstractClientConnector#setResource(String, com.vaadin.terminal.Resource)}
+ * with the same key. <code>null</code> is returned if no corresponding
+ * resource is found.
+ * <p>
+ * To get an event when a resource changes, you can use
+ * {@link #addStateChangeHandler(String, StateChangeHandler)} with
+ * <code>resources.[key]</code> as the property name.
+ *
+ * @param key
+ * a string identifying the resource.
+ * @return the resource URL as a string, or <code>null</code> if no
+ * corresponding resource is found.
+ */
+ public String getResourceUrl(String key) {
+ URLReference urlReference = getState().resources.get(key);
+ if (urlReference == null) {
+ return null;
+ } else {
+ return urlReference.getURL();
+ }
+ }
}
diff --git a/client/src/com/vaadin/client/ui/button/ButtonConnector.java b/client/src/com/vaadin/client/ui/button/ButtonConnector.java
index 103d0f5ae9..65acddb0a4 100644
--- a/client/src/com/vaadin/client/ui/button/ButtonConnector.java
+++ b/client/src/com/vaadin/client/ui/button/ButtonConnector.java
@@ -83,17 +83,17 @@ public class ButtonConnector extends AbstractComponentConnector implements
}
});
- addStateChangeHandler("icon", new StateChangeHandler() {
+ addStateChangeHandler("resources.icon", new StateChangeHandler() {
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
- if (getState().getIcon() != null) {
+ if (getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(getConnection());
getWidget().wrapper.insertBefore(
getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(getState().getIcon().getURL());
+ getWidget().icon.setUri(getIcon());
} else {
if (getWidget().icon != null) {
getWidget().wrapper.removeChild(getWidget().icon
diff --git a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
index 8fb202ca9d..1a6547a85c 100644
--- a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
@@ -96,7 +96,7 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
getWidget().setEnabled(false);
}
- if (getState().getIcon() != null) {
+ if (getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(getConnection());
DOM.insertChild(getWidget().getElement(),
@@ -104,7 +104,7 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
getWidget().icon.sinkEvents(VTooltip.TOOLTIP_EVENTS);
getWidget().icon.sinkEvents(Event.ONCLICK);
}
- getWidget().icon.setUri(getState().getIcon().getURL());
+ getWidget().icon.setUri(getIcon());
} else if (getWidget().icon != null) {
// detach icon
DOM.removeChild(getWidget().getElement(),
diff --git a/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java b/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java
index 6333cb2288..b0cd6d773d 100644
--- a/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java
+++ b/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java
@@ -2,6 +2,7 @@ package com.vaadin.client.ui.embeddedbrowser;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.AbstractEmbeddedState;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.embeddedbrowser.EmbeddedBrowserState;
@@ -30,8 +31,7 @@ public class EmbeddedBrowserConnector extends AbstractComponentConnector {
getWidget().setAlternateText(getState().getAlternateText());
getWidget().setSource(
- getState().getSource() != null ? getState().getSource()
- .getURL() : null);
+ getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE));
getWidget().setName(getConnectorId());
}
diff --git a/client/src/com/vaadin/client/ui/flash/FlashConnector.java b/client/src/com/vaadin/client/ui/flash/FlashConnector.java
index e6158aa558..cc5423dd20 100644
--- a/client/src/com/vaadin/client/ui/flash/FlashConnector.java
+++ b/client/src/com/vaadin/client/ui/flash/FlashConnector.java
@@ -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.shared.ui.AbstractEmbeddedState;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.flash.FlashState;
@@ -29,8 +30,7 @@ public class FlashConnector extends AbstractComponentConnector {
super.onStateChanged(stateChangeEvent);
getWidget().setSource(
- getState().getSource() != null ? getState().getSource()
- .getURL() : null);
+ getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE));
getWidget().setArchive(getState().getArchive());
getWidget().setClassId(getState().getClassId());
getWidget().setCodebase(getState().getCodebase());
diff --git a/client/src/com/vaadin/client/ui/form/FormConnector.java b/client/src/com/vaadin/client/ui/form/FormConnector.java
index 506813ef37..1b97bbc4cb 100644
--- a/client/src/com/vaadin/client/ui/form/FormConnector.java
+++ b/client/src/com/vaadin/client/ui/form/FormConnector.java
@@ -87,12 +87,12 @@ public class FormConnector extends AbstractComponentContainerConnector
} else {
getWidget().caption.setInnerText("");
}
- if (getState().getIcon() != null) {
+ if (getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().legend.insertFirst(getWidget().icon.getElement());
}
- getWidget().icon.setUri(getState().getIcon().getURL());
+ getWidget().icon.setUri(getIcon());
legendEmpty = false;
} else {
if (getWidget().icon != null) {
diff --git a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java
index a178fe1cf5..890275dfe4 100644
--- a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java
+++ b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java
@@ -36,6 +36,7 @@ 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.MarginInfo;
@@ -253,13 +254,14 @@ public class VFormLayout extends SimplePanel {
boolean isEmpty = true;
- if (state.getIcon() != null) {
+ if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
if (icon == null) {
icon = new Icon(owner.getConnection());
DOM.insertChild(getElement(), icon.getElement(), 0);
}
- icon.setUri(state.getIcon().getURL());
+ icon.setUri(state.resources.get(
+ ComponentConstants.ICON_RESOURCE).getURL());
isEmpty = false;
} else {
if (icon != null) {
diff --git a/client/src/com/vaadin/client/ui/image/ImageConnector.java b/client/src/com/vaadin/client/ui/image/ImageConnector.java
index ce92ec48dd..7c3eb973d2 100644
--- a/client/src/com/vaadin/client/ui/image/ImageConnector.java
+++ b/client/src/com/vaadin/client/ui/image/ImageConnector.java
@@ -8,6 +8,7 @@ import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.ClickEventHandler;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.AbstractEmbeddedState;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.image.ImageServerRpc;
import com.vaadin.shared.ui.image.ImageState;
@@ -48,8 +49,7 @@ public class ImageConnector extends AbstractComponentConnector {
clickEventHandler.handleEventHandlerRegistration();
getWidget().setUrl(
- getState().getSource() != null ? getState().getSource()
- .getURL() : null);
+ getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE));
getWidget().setAltText(getState().getAlternateText());
}
diff --git a/client/src/com/vaadin/client/ui/link/LinkConnector.java b/client/src/com/vaadin/client/ui/link/LinkConnector.java
index 2b19a943b3..26e0e78654 100644
--- a/client/src/com/vaadin/client/ui/link/LinkConnector.java
+++ b/client/src/com/vaadin/client/ui/link/LinkConnector.java
@@ -20,10 +20,13 @@ import com.google.gwt.user.client.DOM;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
+import com.vaadin.client.communication.StateChangeEvent;
+import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.Icon;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.link.LinkConstants;
import com.vaadin.ui.Link;
@Connect(Link.class)
@@ -31,6 +34,21 @@ public class LinkConnector extends AbstractComponentConnector implements
Paintable {
@Override
+ protected void init() {
+ super.init();
+ addStateChangeHandler("resources." + LinkConstants.HREF_RESOURCE,
+ new StateChangeHandler() {
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ getWidget().src = getResourceUrl(LinkConstants.HREF_RESOURCE);
+ getWidget().anchor
+ .setAttribute("href", getWidget().src);
+
+ }
+ });
+ }
+
+ @Override
public boolean delegateCaptionHandling() {
return false;
}
@@ -50,11 +68,6 @@ public class LinkConnector extends AbstractComponentConnector implements
getWidget().target = uidl.getStringAttribute("name");
getWidget().anchor.setAttribute("target", getWidget().target);
}
- if (uidl.hasAttribute("src")) {
- getWidget().src = client.translateVaadinUri(uidl
- .getStringAttribute("src"));
- getWidget().anchor.setAttribute("href", getWidget().src);
- }
if (uidl.hasAttribute("border")) {
if ("none".equals(uidl.getStringAttribute("border"))) {
@@ -88,13 +101,13 @@ public class LinkConnector extends AbstractComponentConnector implements
"none");
}
- if (getState().getIcon() != null) {
+ if (getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().anchor.insertBefore(getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(getState().getIcon().getURL());
+ getWidget().icon.setUri(getIcon());
}
}
diff --git a/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java b/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java
index 852be8e3cf..e821ae1422 100644
--- a/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java
+++ b/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java
@@ -91,14 +91,14 @@ public class NativeButtonConnector extends AbstractComponentConnector implements
getWidget().errorIndicatorElement = null;
}
- if (getState().getIcon() != null) {
+ if (getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(getConnection());
getWidget().getElement().insertBefore(
getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(getState().getIcon().getURL());
+ getWidget().icon.setUri(getIcon());
} else {
if (getWidget().icon != null) {
getWidget().getElement().removeChild(
diff --git a/client/src/com/vaadin/client/ui/panel/PanelConnector.java b/client/src/com/vaadin/client/ui/panel/PanelConnector.java
index 740a92d7cd..f991d295b4 100644
--- a/client/src/com/vaadin/client/ui/panel/PanelConnector.java
+++ b/client/src/com/vaadin/client/ui/panel/PanelConnector.java
@@ -140,8 +140,8 @@ public class PanelConnector extends AbstractComponentContainerConnector
getWidget().client = client;
getWidget().id = uidl.getId();
- if (getState().getIcon() != null) {
- getWidget().setIconUri(getState().getIcon().getURL(), client);
+ if (getIcon() != null) {
+ getWidget().setIconUri(getIcon(), client);
} else {
getWidget().setIconUri(null, client);
}
diff --git a/client/src/com/vaadin/client/ui/video/VideoConnector.java b/client/src/com/vaadin/client/ui/video/VideoConnector.java
index ff40c74c3d..d2d9804f66 100644
--- a/client/src/com/vaadin/client/ui/video/VideoConnector.java
+++ b/client/src/com/vaadin/client/ui/video/VideoConnector.java
@@ -17,8 +17,8 @@ package com.vaadin.client.ui.video;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.MediaBaseConnector;
-import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.video.VideoConstants;
import com.vaadin.shared.ui.video.VideoState;
import com.vaadin.ui.Video;
@@ -33,12 +33,7 @@ public class VideoConnector extends MediaBaseConnector {
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
- URLReference poster = getState().getPoster();
- if (poster != null) {
- getWidget().setPoster(poster.getURL());
- } else {
- getWidget().setPoster(null);
- }
+ getWidget().setPoster(getResourceUrl(VideoConstants.POSTER_RESOURCE));
}
@Override
diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java
index f15866d602..b013bcaee0 100644
--- a/client/src/com/vaadin/client/ui/window/WindowConnector.java
+++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java
@@ -115,8 +115,8 @@ SimpleManagedLayout, PostLayoutListener, MayScrollChildren {
// Caption must be set before required header size is measured. If
// the caption attribute is missing the caption should be cleared.
String iconURL = null;
- if (getState().getIcon() != null) {
- iconURL = getState().getIcon().getURL();
+ if (getIcon() != null) {
+ iconURL = getIcon();
}
getWidget().setCaption(getState().getCaption(), iconURL);
}