Comparisons with the ==-operator between a proxy and it's underlying instance fail, so we should use a custom equals method instead. Change-Id: Iaa86ae830fecbedfb1f55636e25f5affebf5aba3tags/7.3.1
@@ -78,7 +78,10 @@ public class ActionManager implements Action.Container, Action.Handler, | |||
public <T extends Component & Container & VariableOwner> void setViewer( | |||
T viewer) { | |||
if (viewer == this.viewer) { | |||
// This somewhat complicated check exists to make sure that proxies are | |||
// handled correctly | |||
if (this.viewer == viewer | |||
|| (this.viewer != null && this.viewer.equals(viewer))) { | |||
return; | |||
} | |||
if (this.viewer != null) { | |||
@@ -113,7 +116,7 @@ public class ActionManager implements Action.Container, Action.Handler, | |||
@Override | |||
public void addActionHandler(Handler actionHandler) { | |||
if (actionHandler == this) { | |||
if (equals(actionHandler)) { | |||
// don't add the actionHandler to itself | |||
return; | |||
} |
@@ -47,6 +47,7 @@ import com.vaadin.ui.HasComponents; | |||
import com.vaadin.ui.LegacyComponent; | |||
import com.vaadin.ui.UI; | |||
/** | |||
* An abstract base class for ClientConnector implementations. This class | |||
* provides all the basic functionality required for connectors. | |||
@@ -549,7 +550,7 @@ public abstract class AbstractClientConnector implements ClientConnector, | |||
*/ | |||
protected void addExtension(Extension extension) { | |||
ClientConnector previousParent = extension.getParent(); | |||
if (previousParent == this) { | |||
if (equals(previousParent)) { | |||
// Nothing to do, already attached | |||
return; | |||
} else if (previousParent != null) { | |||
@@ -999,4 +1000,32 @@ public abstract class AbstractClientConnector implements ClientConnector, | |||
public void setErrorHandler(ErrorHandler errorHandler) { | |||
this.errorHandler = errorHandler; | |||
} | |||
private AbstractClientConnector getInstance() { | |||
// returns the underlying instance regardless of proxies | |||
return this; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see java.lang.Object#equals(java.lang.Object) | |||
*/ | |||
@Override | |||
public boolean equals(Object obj) { | |||
if (obj instanceof AbstractClientConnector) { | |||
return super.equals(((AbstractClientConnector) obj).getInstance()); | |||
} | |||
return false; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see java.lang.Object#hashCode() | |||
*/ | |||
@Override | |||
public int hashCode() { | |||
return super.hashCode(); | |||
} | |||
} |
@@ -462,7 +462,7 @@ public abstract class AbstractComponent extends AbstractClientConnector | |||
@Override | |||
public void setParent(HasComponents parent) { | |||
// If the parent is not changed, don't do anything | |||
if (parent == this.parent) { | |||
if (parent == null ? this.parent == null : parent.equals(this.parent)) { | |||
return; | |||
} | |||
@@ -1005,7 +1005,7 @@ public abstract class AbstractComponent extends AbstractClientConnector | |||
if (content instanceof HasComponents) { | |||
for (Component parent = this; parent != null; parent = parent | |||
.getParent()) { | |||
if (parent == content) { | |||
if (parent.equals(content)) { | |||
return true; | |||
} | |||
} |
@@ -220,7 +220,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent | |||
*/ | |||
@Override | |||
public void removeComponent(Component c) { | |||
if (c.getParent() == this) { | |||
if (equals(c.getParent())) { | |||
c.setParent(null); | |||
fireComponentDetachEvent(c); | |||
} |
@@ -105,7 +105,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements | |||
public void addComponentAsFirst(Component c) { | |||
// If c is already in this, we must remove it before proceeding | |||
// see ticket #7668 | |||
if (c.getParent() == this) { | |||
if (equals(c.getParent())) { | |||
removeComponent(c); | |||
} | |||
components.addFirst(c); | |||
@@ -131,7 +131,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements | |||
public void addComponent(Component c, int index) { | |||
// If c is already in this, we must remove it before proceeding | |||
// see ticket #7668 | |||
if (c.getParent() == this) { | |||
if (equals(c.getParent())) { | |||
// When c is removed, all components after it are shifted down | |||
if (index > getComponentIndex(c)) { | |||
index--; |
@@ -134,7 +134,7 @@ public abstract class AbstractSingleComponentContainer extends | |||
// do not set the same content twice | |||
return; | |||
} | |||
if (oldContent != null && oldContent.getParent() == this) { | |||
if (oldContent != null && equals(oldContent.getParent())) { | |||
oldContent.setParent(null); | |||
fireComponentDetachEvent(oldContent); | |||
} |
@@ -371,7 +371,7 @@ public class ConnectorTracker implements Serializable { | |||
for (ClientConnector child : children) { | |||
stack.add(child); | |||
if (child.getParent() != connector) { | |||
if (!connector.equals(child.getParent())) { | |||
noErrors = false; | |||
getLogger() | |||
.log(Level.WARNING, |
@@ -135,7 +135,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { | |||
public void addComponentAsFirst(Component c) { | |||
// If c is already in this, we must remove it before proceeding | |||
// see ticket #7668 | |||
if (c.getParent() == this) { | |||
if (equals(c.getParent())) { | |||
removeComponent(c); | |||
} | |||
components.addFirst(c); | |||
@@ -160,7 +160,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { | |||
public void addComponent(Component c, int index) { | |||
// If c is already in this, we must remove it before proceeding | |||
// see ticket #7668 | |||
if (c.getParent() == this) { | |||
if (equals(c.getParent())) { | |||
// When c is removed, all components after it are shifted down | |||
if (index > getComponentIndex(c)) { | |||
index--; |
@@ -107,7 +107,7 @@ public class CustomComponent extends AbstractComponent implements HasComponents | |||
*/ | |||
protected void setCompositionRoot(Component compositionRoot) { | |||
if (compositionRoot != root) { | |||
if (root != null && root.getParent() == this) { | |||
if (root != null && equals(root.getParent())) { | |||
// remove old component | |||
root.setParent(null); | |||
} |
@@ -723,7 +723,7 @@ public class DateField extends AbstractField<Date> implements | |||
Collection<?> visibleItemProperties = f.getItemPropertyIds(); | |||
for (Object fieldId : visibleItemProperties) { | |||
Field<?> field = f.getField(fieldId); | |||
if (field == this) { | |||
if (equals(field)) { | |||
/* | |||
* this datefield is logically in a form. Do the same | |||
* thing as form does in its value change listener that |
@@ -152,7 +152,7 @@ public class PopupView extends AbstractComponent implements HasComponents { | |||
} | |||
visibleComponent.setParent(this); | |||
} else { | |||
if (visibleComponent.getParent() == this) { | |||
if (equals(visibleComponent.getParent())) { | |||
visibleComponent.setParent(null); | |||
} | |||
visibleComponent = null; |
@@ -1174,7 +1174,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, | |||
@Override | |||
public Component getComponent() { | |||
for (Map.Entry<Component, Tab> entry : tabs.entrySet()) { | |||
if (entry.getValue() == this) { | |||
if (equals(entry.getValue())) { | |||
return entry.getKey(); | |||
} | |||
} |
@@ -2386,7 +2386,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
"Registered {0}: {1}", | |||
new Object[] { component.getClass().getSimpleName(), | |||
component.getCaption() }); | |||
if (component.getParent() != this) { | |||
if (!equals(component.getParent())) { | |||
component.setParent(this); | |||
} | |||
visibleComponents.add(component); | |||
@@ -4199,7 +4199,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
@Override | |||
public void valueChange(Property.ValueChangeEvent event) { | |||
if (event.getProperty() == this | |||
if (equals(event.getProperty()) | |||
|| event.getProperty() == getPropertyDataSource()) { | |||
super.valueChange(event); | |||
} else { |
@@ -319,9 +319,9 @@ public abstract class UI extends AbstractSingleComponentContainer implements | |||
if (pendingFocus != null) { | |||
// ensure focused component is still attached to this main window | |||
if (pendingFocus.getUI() == this | |||
|| (pendingFocus.getUI() != null && pendingFocus.getUI() | |||
.getParent() == this)) { | |||
if (equals(pendingFocus.getUI()) | |||
|| (pendingFocus.getUI() != null && equals(pendingFocus | |||
.getUI().getParent()))) { | |||
target.addAttribute("focused", pendingFocus); | |||
} | |||
pendingFocus = null; |