diff options
author | ustieber | 2011-04-29 19:30:22 +0000 |
---|---|---|
committer | ustieber | 2011-04-29 19:30:22 +0000 |
commit | 209681bc46f83fb35e03ac75ca1242178193a94c (patch) | |
tree | 394f2fc12fb532f4ced66cb611234281840f519d | |
parent | b12bd88e98b4299e90a1bed516f16027b33cb24c (diff) | |
download | org.eclipse.tcf-209681bc46f83fb35e03ac75ca1242178193a94c.tar.gz org.eclipse.tcf-209681bc46f83fb35e03ac75ca1242178193a94c.tar.xz org.eclipse.tcf-209681bc46f83fb35e03ac75ca1242178193a94c.zip |
Target Explorer: Add equals methods and fix one issue in peerAdded model update
3 files changed, 91 insertions, 27 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/LocatorListener.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/LocatorListener.java index a6fb3d4ca..47618d0f1 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/LocatorListener.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/LocatorListener.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Uwe Stieber (Wind River) - initial API and implementation *******************************************************************************/ @@ -47,18 +47,21 @@ public class LocatorListener implements ILocator.LocatorListener { if (fModel != null && peer != null) { // find the corresponding model node to remove (expected to be null) IPeerModel peerNode = fModel.getService(ILocatorModelLookupService.class).lkupPeerModelById(peer.getID()); - // If found, remove the old node - if (peerNode != null) fModel.getService(ILocatorModelUpdateService.class).remove(peerNode); - // Create a new peer node instance - peerNode = new PeerModel(fModel, peer); - // Validate the peer node before adding - if (peerNode != null) peerNode = fModel.validatePeerNodeForAdd(peerNode); - // Add the peer node to the model - if (peerNode != null) { - fModel.getService(ILocatorModelUpdateService.class).add(peerNode); - // And schedule for immediate status update - Runnable runnable = new ScannerRunnable(fModel.getScanner(), peerNode); - Protocol.invokeLater(runnable); + // If not found, create a new peer node instance + if (peerNode == null) { + peerNode = new PeerModel(fModel, peer); + // Validate the peer node before adding + if (peerNode != null) peerNode = fModel.validatePeerNodeForAdd(peerNode); + // Add the peer node to the model + if (peerNode != null) { + fModel.getService(ILocatorModelUpdateService.class).add(peerNode); + // And schedule for immediate status update + Runnable runnable = new ScannerRunnable(fModel.getScanner(), peerNode); + Protocol.invokeLater(runnable); + } + } else { + // Peer node found, update the peer instance + if (peerNode != null) peerNode.setProperty(IPeerModelProperties.PROP_INSTANCE, peer); } } } diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/LocatorModel.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/LocatorModel.java index f1ceea621..9ac09c061 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/LocatorModel.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/LocatorModel.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Uwe Stieber (Wind River) - initial API and implementation *******************************************************************************/ @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PlatformObject; @@ -45,6 +46,8 @@ import org.eclipse.tm.te.tcf.locator.utils.IPAddressUtil; * Default locator model implementation. */ public class LocatorModel extends PlatformObject implements ILocatorModel { + // The unique model id + private final UUID fUniqueId = UUID.randomUUID(); // Flag to mark the model disposed private boolean fDisposed; @@ -187,6 +190,17 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { } /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(Object obj) { + if (obj instanceof LocatorModel) { + return fUniqueId.equals(((LocatorModel)obj).fUniqueId); + } + return super.equals(obj); + } + + /* (non-Javadoc) * @see org.eclipse.tm.te.tcf.locator.core.interfaces.nodes.ILocatorModel#getService(java.lang.Class) */ @SuppressWarnings("unchecked") diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/PeerModel.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/PeerModel.java index 1b1230c9e..37a0d4471 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/PeerModel.java +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/nodes/PeerModel.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Uwe Stieber (Wind River) - initial API and implementation *******************************************************************************/ @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.UUID; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.tm.tcf.protocol.IPeer; @@ -29,6 +30,8 @@ import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModelProperties; public class PeerModel extends PlatformObject implements IPeerModel { // Reference to the parent locator model private final ILocatorModel fParentModel; + // The unique node id + private final UUID fUniqueId = UUID.randomUUID(); /** * The custom properties map. The keys are always strings, the value might be any object. @@ -53,10 +56,14 @@ public class PeerModel extends PlatformObject implements IPeerModel { public PeerModel(ILocatorModel parent, IPeer peer) { super(); - assert parent != null; + assert Protocol.isDispatchThread() && parent != null; + fParentModel = parent; - setProperty(IPeerModelProperties.PROP_INSTANCE, peer); + // Write the properties directly to the properties map. The + // properties changed listeners should not be called from the + // constructor. + fProperties.put(IPeerModelProperties.PROP_INSTANCE, peer); } /* (non-Javadoc) @@ -120,6 +127,42 @@ public class PeerModel extends PlatformObject implements IPeerModel { } /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(Object obj) { + if (obj instanceof PeerModel) { + return fUniqueId.equals(((PeerModel)obj).fUniqueId); + } + return super.equals(obj); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder buffer = new StringBuilder(getClass().getSimpleName()); + + if (Protocol.isDispatchThread()) { + IPeer peer = getPeer(); + buffer.append(": id=" + peer.getID()); //$NON-NLS-1$ + buffer.append(", name=" + peer.getName()); //$NON-NLS-1$ + } else { + Protocol.invokeAndWait(new Runnable() { + public void run() { + IPeer peer = getPeer(); + buffer.append(": id=" + peer.getID()); //$NON-NLS-1$ + buffer.append(", name=" + peer.getName()); //$NON-NLS-1$ + } + }); + } + buffer.append(", UUID=" + fUniqueId.toString()); //$NON-NLS-1$ + return buffer.toString(); + } + + + /* (non-Javadoc) * @see org.eclipse.tm.te.tcf.locator.core.interfaces.nodes.IPeerModel#getProperties() */ public Map<String, Object> getProperties() { @@ -310,7 +353,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { * @see org.eclipse.tm.te.tcf.locator.core.interfaces.nodes.IPeerModel#setProperty(java.lang.String, java.lang.Object) */ public boolean setProperty(String key, Object value) { - assert Protocol.isDispatchThread(); + assert Protocol.isDispatchThread() && key != null; Object oldValue = fProperties.get(key); if ((oldValue == null && value != null) || (oldValue != null && !oldValue.equals(value))) { @@ -320,16 +363,20 @@ public class PeerModel extends PlatformObject implements IPeerModel { fProperties.remove(key); } - final IModelListener[] listeners = fParentModel.getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @SuppressWarnings("synthetic-access") - public void run() { - for (IModelListener listener : listeners) { - listener.peerModelChanged(fParentModel, PeerModel.this); + // Notify registered listeners that the peer changed. Property + // changes for property slots ending with ".silent" are suppressed. + if (!key.endsWith(".silent")) { //$NON-NLS-1$ + final IModelListener[] listeners = fParentModel.getListener(); + if (listeners.length > 0) { + Protocol.invokeLater(new Runnable() { + @SuppressWarnings("synthetic-access") + public void run() { + for (IModelListener listener : listeners) { + listener.peerModelChanged(fParentModel, PeerModel.this); + } } - } - }); + }); + } } return true; |