Skip to content

Commit

Permalink
Do not remove Icon when changing text (#14536)
Browse files Browse the repository at this point in the history
Change-Id: Ia4c9be0619eb5a221545b5bf2ae8c48f46f27c1b
  • Loading branch information
manolo authored and Vaadin Code Review committed Sep 2, 2014
1 parent f64af92 commit 3dcb1d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,23 @@ public String getCaption() {
return caption;
}

public void setIcon(Icon icon) {

if (icon == null) {
if (this.icon != null) {
getElement().removeChild(this.icon.getElement());
public void setIcon(Icon newIcon) {
if (newIcon == null) {
if (icon != null) {
getElement().removeChild(icon.getElement());
}
} else if (this.icon != null) {
getElement()
.replaceChild(this.icon.getElement(), icon.getElement());
} else if (icon != null
// icon might have been removed by a call to #setText (#14536)
&& getElement().isOrHasChild(icon.getElement())) {
getElement().replaceChild(icon.getElement(), newIcon.getElement());
} else {
getElement().insertFirst(icon.getElement());
getElement().insertFirst(newIcon.getElement());
}
this.icon = icon;
icon = newIcon;
}

public void setDescription(String description) {
if (description != null && !description.trim().isEmpty()) {

if (descriptionElement == null) {
descriptionElement = Document.get().createSpanElement();
descriptionElement.setClassName(NAVBUTTON_CLASSNAME + "-desc");
Expand All @@ -97,7 +96,6 @@ public void setDescription(String description) {
descriptionElement.setInnerHTML(description);

} else if (descriptionElement != null) {

descriptionElement.removeFromParent();
descriptionElement = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.vaadin.client.communication.RpcProxy;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.Icon;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

Expand Down Expand Up @@ -52,9 +50,7 @@ public void onStateChanged(StateChangeEvent stateChangeEvent) {
getWidget().setText(caption);
getWidget().setEnabled(getState().enabled);

Icon icon = getConnection().getIcon(
getResourceUrl(ComponentConstants.ICON_RESOURCE));
getWidget().setIcon(icon);
getWidget().setIcon(getIcon());

String description = getState().description;
getWidget().setDescription(description);
Expand Down

0 comments on commit 3dcb1d3

Please sign in to comment.