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;
/** 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);
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
}
@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);
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
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.
* @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
@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.
*/
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);
}
/**
* @return the target window border.
*/
public BorderStyle getTargetBorder() {
- return targetBorder;
+ return getState(false).targetBorder;
}
/**
* @return the target window height.
*/
public int getTargetHeight() {
- return targetHeight < 0 ? -1 : targetHeight;
+ return getState(false).targetHeight < 0 ? -1
+ : getState(false).targetHeight;
}
/**
* @return the target window name.
*/
public String getTargetName() {
- return targetName;
+ return getState(false).target;
}
/**
* @return the target window width.
*/
public int getTargetWidth() {
- return targetWidth < 0 ? -1 : targetWidth;
+ return getState(false).targetWidth < 0 ? -1
+ : getState(false).targetWidth;
}
/**
* the targetBorder to set.
*/
public void setTargetBorder(BorderStyle targetBorder) {
- this.targetBorder = targetBorder;
- markAsDirty();
+ getState().targetBorder = targetBorder;
}
/**
* the targetHeight to set.
*/
public void setTargetHeight(int targetHeight) {
- this.targetHeight = targetHeight;
- markAsDirty();
+ getState().targetHeight = targetHeight;
}
/**
* the targetName to set.
*/
public void setTargetName(String targetName) {
- this.targetName = targetName;
- markAsDirty();
+ getState().target = targetName;
}
/**
* the targetWidth to set.
*/
public void setTargetWidth(int targetWidth) {
- this.targetWidth = targetWidth;
- markAsDirty();
+ getState().targetWidth = targetWidth;
}
/**
setResource(LinkConstants.HREF_RESOURCE, resource);
}
- @Override
- public void changeVariables(Object source, Map<String, Object> variables) {
- // TODO Remove once LegacyComponent is no longer implemented
- }
}
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;
}