diff options
author | joheriks <joheriks@vaadin.com> | 2013-09-29 18:22:56 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-10-02 12:03:25 +0000 |
commit | 2bebf738b2c6cc393b3e8d21a56535e9f1b180ea (patch) | |
tree | 59dcf9c53e6af17d99434d186eec2713a4a659b1 | |
parent | 2bbb36705385f7c1bafce7eb527d5e66875b689c (diff) | |
download | vaadin-framework-2bebf738b2c6cc393b3e8d21a56535e9f1b180ea.tar.gz vaadin-framework-2bebf738b2c6cc393b3e8d21a56535e9f1b180ea.zip |
Link no longer implements LegacyComponent (#10015)
Change-Id: Iaadc82384d15704017077be282767141529889f2
-rw-r--r-- | client/src/com/vaadin/client/ui/VLink.java | 4 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/link/LinkConnector.java | 59 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Link.java | 84 | ||||
-rw-r--r-- | shared/src/com/vaadin/shared/ui/link/LinkState.java | 6 |
4 files changed, 43 insertions, 110 deletions
diff --git a/client/src/com/vaadin/client/ui/VLink.java b/client/src/com/vaadin/client/ui/VLink.java index fa4ee36bcf..064a012873 100644 --- a/client/src/com/vaadin/client/ui/VLink.java +++ b/client/src/com/vaadin/client/ui/VLink.java @@ -23,7 +23,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTML; -import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Util; import com.vaadin.shared.ui.BorderStyle; @@ -70,9 +69,6 @@ public class VLink extends HTML implements ClickHandler { /** 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 ApplicationConnection client; - public VLink() { super(); getElement().appendChild(anchor); diff --git a/client/src/com/vaadin/client/ui/link/LinkConnector.java b/client/src/com/vaadin/client/ui/link/LinkConnector.java index 228897278e..d2c41e9f38 100644 --- a/client/src/com/vaadin/client/ui/link/LinkConnector.java +++ b/client/src/com/vaadin/client/ui/link/LinkConnector.java @@ -17,38 +17,21 @@ package com.vaadin.client.ui.link; 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.client.ui.VLink; -import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.link.LinkConstants; import com.vaadin.shared.ui.link.LinkState; import com.vaadin.ui.Link; @Connect(Link.class) -public class LinkConnector extends AbstractComponentConnector implements - Paintable { +public class LinkConnector extends AbstractComponentConnector { @Override protected void init() { super.init(); - addStateChangeHandler("resources", new StateChangeHandler() { - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - getWidget().src = getResourceUrl(LinkConstants.HREF_RESOURCE); - if (getWidget().src == null) { - getWidget().anchor.removeAttribute("href"); - } else { - getWidget().anchor.setAttribute("href", getWidget().src); - } - } - }); } @Override @@ -62,35 +45,30 @@ public class LinkConnector extends AbstractComponentConnector implements } @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - if (!isRealUpdate(uidl)) { - return; - } - - getWidget().client = client; + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); getWidget().enabled = isEnabled(); - if (uidl.hasAttribute("name")) { - getWidget().target = uidl.getStringAttribute("name"); - getWidget().anchor.setAttribute("target", getWidget().target); - } - - if (uidl.hasAttribute("border")) { - if ("none".equals(uidl.getStringAttribute("border"))) { - getWidget().borderStyle = BorderStyle.NONE; + if (stateChangeEvent.hasPropertyChanged("resources")) { + getWidget().src = getResourceUrl(LinkConstants.HREF_RESOURCE); + if (getWidget().src == null) { + getWidget().anchor.removeAttribute("href"); } else { - getWidget().borderStyle = BorderStyle.MINIMAL; + getWidget().anchor.setAttribute("href", getWidget().src); } + } + + getWidget().target = getState().target; + if (getWidget().target == null) { + getWidget().anchor.removeAttribute("target"); } else { - getWidget().borderStyle = BorderStyle.DEFAULT; + getWidget().anchor.setAttribute("target", getWidget().target); } - getWidget().targetHeight = uidl.hasAttribute("targetHeight") ? uidl - .getIntAttribute("targetHeight") : -1; - getWidget().targetWidth = uidl.hasAttribute("targetWidth") ? uidl - .getIntAttribute("targetWidth") : -1; + getWidget().borderStyle = getState().targetBorder; + getWidget().targetWidth = getState().targetWidth; + getWidget().targetHeight = getState().targetHeight; // Set link caption getWidget().captionElement.setInnerText(getState().caption); @@ -111,13 +89,12 @@ public class LinkConnector extends AbstractComponentConnector implements if (getIcon() != null) { if (getWidget().icon == null) { - getWidget().icon = new Icon(client); + getWidget().icon = new Icon(getConnection()); getWidget().anchor.insertBefore(getWidget().icon.getElement(), getWidget().captionElement); } getWidget().icon.setUri(getIcon()); } - } @Override diff --git a/server/src/com/vaadin/ui/Link.java b/server/src/com/vaadin/ui/Link.java index cf8e1a9693..e1a47777bd 100644 --- a/server/src/com/vaadin/ui/Link.java +++ b/server/src/com/vaadin/ui/Link.java @@ -16,13 +16,10 @@ package com.vaadin.ui; -import java.util.Map; - -import com.vaadin.server.PaintException; -import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.link.LinkConstants; +import com.vaadin.shared.ui.link.LinkState; /** * Link is used to create external or internal URL links. @@ -31,7 +28,7 @@ import com.vaadin.shared.ui.link.LinkConstants; * @since 3.0 */ @SuppressWarnings("serial") -public class Link extends AbstractComponent implements LegacyComponent { +public class Link extends AbstractComponent { /** * @deprecated As of 7.0, use {@link BorderStyle#NONE} instead @@ -51,14 +48,6 @@ public class Link extends AbstractComponent implements LegacyComponent { @Deprecated public static final BorderStyle TARGET_BORDER_DEFAULT = BorderStyle.DEFAULT; - private String targetName; - - private BorderStyle targetBorder = BorderStyle.DEFAULT; - - private int targetWidth = -1; - - private int targetHeight = -1; - /** * Creates a new link. */ @@ -105,43 +94,14 @@ public class Link extends AbstractComponent implements LegacyComponent { setTargetBorder(border); } - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the paint operation failed. - */ @Override - public void paintContent(PaintTarget target) throws PaintException { - if (getResource() == null) { - return; - } - - // Target window name - final String name = getTargetName(); - if (name != null && name.length() > 0) { - target.addAttribute("name", name); - } - - // Target window size - if (getTargetWidth() >= 0) { - target.addAttribute("targetWidth", getTargetWidth()); - } - if (getTargetHeight() >= 0) { - target.addAttribute("targetHeight", getTargetHeight()); - } - - // Target window border - switch (getTargetBorder()) { - case MINIMAL: - target.addAttribute("border", "minimal"); - break; - case NONE: - target.addAttribute("border", "none"); - break; - } + protected LinkState getState() { + return (LinkState) super.getState(); + } + + @Override + protected LinkState getState(boolean markAsDirty) { + return (LinkState) super.getState(markAsDirty); } /** @@ -150,7 +110,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * @return the target window border. */ public BorderStyle getTargetBorder() { - return targetBorder; + return getState(false).targetBorder; } /** @@ -159,7 +119,8 @@ public class Link extends AbstractComponent implements LegacyComponent { * @return the target window height. */ public int getTargetHeight() { - return targetHeight < 0 ? -1 : targetHeight; + return getState(false).targetHeight < 0 ? -1 + : getState(false).targetHeight; } /** @@ -169,7 +130,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * @return the target window name. */ public String getTargetName() { - return targetName; + return getState(false).target; } /** @@ -178,7 +139,8 @@ public class Link extends AbstractComponent implements LegacyComponent { * @return the target window width. */ public int getTargetWidth() { - return targetWidth < 0 ? -1 : targetWidth; + return getState(false).targetWidth < 0 ? -1 + : getState(false).targetWidth; } /** @@ -188,8 +150,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * the targetBorder to set. */ public void setTargetBorder(BorderStyle targetBorder) { - this.targetBorder = targetBorder; - markAsDirty(); + getState().targetBorder = targetBorder; } /** @@ -199,8 +160,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * the targetHeight to set. */ public void setTargetHeight(int targetHeight) { - this.targetHeight = targetHeight; - markAsDirty(); + getState().targetHeight = targetHeight; } /** @@ -210,8 +170,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * the targetName to set. */ public void setTargetName(String targetName) { - this.targetName = targetName; - markAsDirty(); + getState().target = targetName; } /** @@ -221,8 +180,7 @@ public class Link extends AbstractComponent implements LegacyComponent { * the targetWidth to set. */ public void setTargetWidth(int targetWidth) { - this.targetWidth = targetWidth; - markAsDirty(); + getState().targetWidth = targetWidth; } /** @@ -244,8 +202,4 @@ public class Link extends AbstractComponent implements LegacyComponent { setResource(LinkConstants.HREF_RESOURCE, resource); } - @Override - public void changeVariables(Object source, Map<String, Object> variables) { - // TODO Remove once LegacyComponent is no longer implemented - } } diff --git a/shared/src/com/vaadin/shared/ui/link/LinkState.java b/shared/src/com/vaadin/shared/ui/link/LinkState.java index 269496767d..33ede86378 100644 --- a/shared/src/com/vaadin/shared/ui/link/LinkState.java +++ b/shared/src/com/vaadin/shared/ui/link/LinkState.java @@ -16,9 +16,15 @@ package com.vaadin.shared.ui.link; import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.ui.BorderStyle; public class LinkState extends AbstractComponentState { { primaryStyleName = "v-link"; } + public String name = ""; + public String target = null; + public BorderStyle targetBorder = BorderStyle.DEFAULT; + public int targetWidth = -1; + public int targetHeight = -1; } |