Browse Source

Make Vaadin component handling proxy-friendly (#14639)

Comparisons with the ==-operator between a proxy and it's underlying
instance fail, so we should use a custom equals method instead.
Change-Id: Iaa86ae830fecbedfb1f55636e25f5affebf5aba3
tags/7.3.1
Juuso Valli 9 years ago
parent
commit
4a60f1a712

+ 5
- 2
server/src/com/vaadin/event/ActionManager.java View File



public <T extends Component & Container & VariableOwner> void setViewer( public <T extends Component & Container & VariableOwner> void setViewer(
T viewer) { 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; return;
} }
if (this.viewer != null) { if (this.viewer != null) {


@Override @Override
public void addActionHandler(Handler actionHandler) { public void addActionHandler(Handler actionHandler) {
if (actionHandler == this) {
if (equals(actionHandler)) {
// don't add the actionHandler to itself // don't add the actionHandler to itself
return; return;
} }

+ 30
- 1
server/src/com/vaadin/server/AbstractClientConnector.java View File

import com.vaadin.ui.LegacyComponent; import com.vaadin.ui.LegacyComponent;
import com.vaadin.ui.UI; import com.vaadin.ui.UI;



/** /**
* An abstract base class for ClientConnector implementations. This class * An abstract base class for ClientConnector implementations. This class
* provides all the basic functionality required for connectors. * provides all the basic functionality required for connectors.
*/ */
protected void addExtension(Extension extension) { protected void addExtension(Extension extension) {
ClientConnector previousParent = extension.getParent(); ClientConnector previousParent = extension.getParent();
if (previousParent == this) {
if (equals(previousParent)) {
// Nothing to do, already attached // Nothing to do, already attached
return; return;
} else if (previousParent != null) { } else if (previousParent != null) {
public void setErrorHandler(ErrorHandler errorHandler) { public void setErrorHandler(ErrorHandler errorHandler) {
this.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();
}
} }

+ 2
- 2
server/src/com/vaadin/ui/AbstractComponent.java View File

@Override @Override
public void setParent(HasComponents parent) { public void setParent(HasComponents parent) {
// If the parent is not changed, don't do anything // 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; return;
} }


if (content instanceof HasComponents) { if (content instanceof HasComponents) {
for (Component parent = this; parent != null; parent = parent for (Component parent = this; parent != null; parent = parent
.getParent()) { .getParent()) {
if (parent == content) {
if (parent.equals(content)) {
return true; return true;
} }
} }

+ 1
- 1
server/src/com/vaadin/ui/AbstractComponentContainer.java View File

*/ */
@Override @Override
public void removeComponent(Component c) { public void removeComponent(Component c) {
if (c.getParent() == this) {
if (equals(c.getParent())) {
c.setParent(null); c.setParent(null);
fireComponentDetachEvent(c); fireComponentDetachEvent(c);
} }

+ 2
- 2
server/src/com/vaadin/ui/AbstractOrderedLayout.java View File

public void addComponentAsFirst(Component c) { public void addComponentAsFirst(Component c) {
// If c is already in this, we must remove it before proceeding // If c is already in this, we must remove it before proceeding
// see ticket #7668 // see ticket #7668
if (c.getParent() == this) {
if (equals(c.getParent())) {
removeComponent(c); removeComponent(c);
} }
components.addFirst(c); components.addFirst(c);
public void addComponent(Component c, int index) { public void addComponent(Component c, int index) {
// If c is already in this, we must remove it before proceeding // If c is already in this, we must remove it before proceeding
// see ticket #7668 // see ticket #7668
if (c.getParent() == this) {
if (equals(c.getParent())) {
// When c is removed, all components after it are shifted down // When c is removed, all components after it are shifted down
if (index > getComponentIndex(c)) { if (index > getComponentIndex(c)) {
index--; index--;

+ 1
- 1
server/src/com/vaadin/ui/AbstractSingleComponentContainer.java View File

// do not set the same content twice // do not set the same content twice
return; return;
} }
if (oldContent != null && oldContent.getParent() == this) {
if (oldContent != null && equals(oldContent.getParent())) {
oldContent.setParent(null); oldContent.setParent(null);
fireComponentDetachEvent(oldContent); fireComponentDetachEvent(oldContent);
} }

+ 1
- 1
server/src/com/vaadin/ui/ConnectorTracker.java View File

for (ClientConnector child : children) { for (ClientConnector child : children) {
stack.add(child); stack.add(child);


if (child.getParent() != connector) {
if (!connector.equals(child.getParent())) {
noErrors = false; noErrors = false;
getLogger() getLogger()
.log(Level.WARNING, .log(Level.WARNING,

+ 2
- 2
server/src/com/vaadin/ui/CssLayout.java View File

public void addComponentAsFirst(Component c) { public void addComponentAsFirst(Component c) {
// If c is already in this, we must remove it before proceeding // If c is already in this, we must remove it before proceeding
// see ticket #7668 // see ticket #7668
if (c.getParent() == this) {
if (equals(c.getParent())) {
removeComponent(c); removeComponent(c);
} }
components.addFirst(c); components.addFirst(c);
public void addComponent(Component c, int index) { public void addComponent(Component c, int index) {
// If c is already in this, we must remove it before proceeding // If c is already in this, we must remove it before proceeding
// see ticket #7668 // see ticket #7668
if (c.getParent() == this) {
if (equals(c.getParent())) {
// When c is removed, all components after it are shifted down // When c is removed, all components after it are shifted down
if (index > getComponentIndex(c)) { if (index > getComponentIndex(c)) {
index--; index--;

+ 1
- 1
server/src/com/vaadin/ui/CustomComponent.java View File

*/ */
protected void setCompositionRoot(Component compositionRoot) { protected void setCompositionRoot(Component compositionRoot) {
if (compositionRoot != root) { if (compositionRoot != root) {
if (root != null && root.getParent() == this) {
if (root != null && equals(root.getParent())) {
// remove old component // remove old component
root.setParent(null); root.setParent(null);
} }

+ 1
- 1
server/src/com/vaadin/ui/DateField.java View File

Collection<?> visibleItemProperties = f.getItemPropertyIds(); Collection<?> visibleItemProperties = f.getItemPropertyIds();
for (Object fieldId : visibleItemProperties) { for (Object fieldId : visibleItemProperties) {
Field<?> field = f.getField(fieldId); Field<?> field = f.getField(fieldId);
if (field == this) {
if (equals(field)) {
/* /*
* this datefield is logically in a form. Do the same * this datefield is logically in a form. Do the same
* thing as form does in its value change listener that * thing as form does in its value change listener that

+ 1
- 1
server/src/com/vaadin/ui/PopupView.java View File

} }
visibleComponent.setParent(this); visibleComponent.setParent(this);
} else { } else {
if (visibleComponent.getParent() == this) {
if (equals(visibleComponent.getParent())) {
visibleComponent.setParent(null); visibleComponent.setParent(null);
} }
visibleComponent = null; visibleComponent = null;

+ 1
- 1
server/src/com/vaadin/ui/TabSheet.java View File

@Override @Override
public Component getComponent() { public Component getComponent() {
for (Map.Entry<Component, Tab> entry : tabs.entrySet()) { for (Map.Entry<Component, Tab> entry : tabs.entrySet()) {
if (entry.getValue() == this) {
if (equals(entry.getValue())) {
return entry.getKey(); return entry.getKey();
} }
} }

+ 2
- 2
server/src/com/vaadin/ui/Table.java View File

"Registered {0}: {1}", "Registered {0}: {1}",
new Object[] { component.getClass().getSimpleName(), new Object[] { component.getClass().getSimpleName(),
component.getCaption() }); component.getCaption() });
if (component.getParent() != this) {
if (!equals(component.getParent())) {
component.setParent(this); component.setParent(this);
} }
visibleComponents.add(component); visibleComponents.add(component);


@Override @Override
public void valueChange(Property.ValueChangeEvent event) { public void valueChange(Property.ValueChangeEvent event) {
if (event.getProperty() == this
if (equals(event.getProperty())
|| event.getProperty() == getPropertyDataSource()) { || event.getProperty() == getPropertyDataSource()) {
super.valueChange(event); super.valueChange(event);
} else { } else {

+ 3
- 3
server/src/com/vaadin/ui/UI.java View File



if (pendingFocus != null) { if (pendingFocus != null) {
// ensure focused component is still attached to this main window // 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); target.addAttribute("focused", pendingFocus);
} }
pendingFocus = null; pendingFocus = null;

Loading…
Cancel
Save