diff options
author | Tobias Schwarz | 2014-06-20 11:30:31 +0000 |
---|---|---|
committer | Tobias Schwarz | 2014-06-20 11:30:31 +0000 |
commit | e32199573d42c20d416ba814760423f04dfba01e (patch) | |
tree | 4a157e3e2f70cf25249d6ea9d82cd71fc0975a75 /target_explorer | |
parent | f7d3512fb48f712a308613943d781f37205ffb3f (diff) | |
download | org.eclipse.tcf-e32199573d42c20d416ba814760423f04dfba01e.tar.gz org.eclipse.tcf-e32199573d42c20d416ba814760423f04dfba01e.tar.xz org.eclipse.tcf-e32199573d42c20d416ba814760423f04dfba01e.zip |
Target Explorer: add proxy support
Diffstat (limited to 'target_explorer')
49 files changed, 2380 insertions, 533 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/constants/IPropertiesAccessServiceConstants.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/constants/IPropertiesAccessServiceConstants.java index 4e93fa6f9..65ac844cc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/constants/IPropertiesAccessServiceConstants.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/constants/IPropertiesAccessServiceConstants.java @@ -44,30 +44,12 @@ public interface IPropertiesAccessServiceConstants { public static String PROP_PORT = "port"; //$NON-NLS-1$ /** - * Target address to be used to construct a SSH connection. - * <p> - * If not specified, clients should fall back to {@link PROP_ADDRESS}. - */ - public static String PROP_SSH_ADDRESS = "ssh.address"; //$NON-NLS-1$ - - /** - * Target port to be used to construct a SSH connection. - * <p> - * If not specified, clients should assume the default "22". + * <code>true</code> if the port is retrieved automatically. */ - public static String PROP_SSH_PORT = "ssh.port"; //$NON-NLS-1$ + public static String PROP_PORT_IS_AUTO = "autoPort"; //$NON-NLS-1$ /** - * Target address to be used to construct a telnet connection. - * <p> - * If not specified, clients should fall back to {@link PROP_ADDRESS}. - */ - public static String PROP_TELNET_ADDRESS = "telnet.address"; //$NON-NLS-1$ - - /** - * Target port to be used to construct a telnet connection. - * <p> - * If not specified, clients should assume the default "23". + * Proxies to connect the target through. */ - public static String PROP_TELNET_PORT = "telnet.port"; //$NON-NLS-1$ + public static String PROP_PROXIES = "proxies"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml index cb8fdbb82..7fb76c053 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml @@ -61,6 +61,14 @@ </propertyTester> <propertyTester + class="org.eclipse.tcf.te.tcf.locator.internal.PeerModelPropertyTester" + id="org.eclipse.tcf.te.tcf.locator.LocatorModelPropertyTester2" + namespace="org.eclipse.tcf.te.tcf.locator" + properties="name,nameRegex,osName,osNameRegex,hasLocalService,hasRemoteService,hasOfflineService,hasAttribute,isAttribute,isProxy,isValueAdd,isOfType,isRemotePeer" + type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"> + </propertyTester> + + <propertyTester class="org.eclipse.tcf.te.tcf.locator.internal.SimulatorPropertyTester" id="org.eclipse.tcf.te.tcf.locator.SimulatorPropertyTester" namespace="org.eclipse.tcf.te.tcf.locator" diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ILocatorModelListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ILocatorModelListener.java index 73268f034..89a20d586 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ILocatorModelListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ILocatorModelListener.java @@ -9,8 +9,8 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.interfaces; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * Interface for clients to implement that wishes to listen to changes to the locator model. @@ -18,13 +18,13 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; public interface ILocatorModelListener { /** - * Invoked if a peer is added or removed to/from the locator model. + * Invoked if a locator node is added or removed to/from the locator model. * * @param model The changed locator model. - * @param peer The added/removed peer. - * @param added <code>True</code> if the peer got added, <code>false</code> if it got removed. + * @param locatorNode The added/removed locator node. + * @param added <code>True</code> if the locator node got added, <code>false</code> if it got removed. */ - public void modelChanged(ILocatorModel model, IPeer peer, boolean added); + public void modelChanged(ILocatorModel model, ILocatorNode locatorNode, boolean added); /** * Invoked if the locator model is disposed. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java index 4b82877c3..be5b17223 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java @@ -9,8 +9,6 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.interfaces.nodes; -import java.util.List; - import org.eclipse.core.runtime.IAdaptable; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.services.ILocator; @@ -70,27 +68,18 @@ public interface ILocatorModel extends IAdaptable { public boolean isDisposed(); /** - * Returns the list of known peers. + * Returns the list of locator nodes. * - * @return The list of known peers or an empty list. + * @return The list of locator nodes or an empty list. */ - public IPeer[] getPeers(); + public ILocatorNode[] getLocatorNodes(); /** - * Returns an unmodifiable list of known children for the given parent peer. - * - * @param parentPeerID The parent peer id. Must not be <code>null</code>. - * @return The child list. - */ - public List<IPeer> getChildren(String parentPeerID); - - /** - * Sets the list of known children for the given parent peer. + * Returns the list of known peers. * - * @param parentPeerID The parent peer id. Must not be <code>null</code>. - * @param children The list of children or <code>null</code> to remove the parent peer. + * @return The list of known peers or an empty list. */ - public void setChildren(String parentPeerID, List<IPeer> children); + public IPeer[] getPeers(); /** * Returns the locator model service, implementing at least the specified diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorNode.java new file mode 100644 index 000000000..3ecaad7ce --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorNode.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.locator.interfaces.nodes; + +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.core.interfaces.IDecoratable; +import org.eclipse.tcf.te.runtime.model.interfaces.IContainerModelNode; + +/** + * The locator node is an extension to the TCF peer representation. + * <p> + * <b>Note:</b> Read and write access to the peer model must happen within the TCF dispatch thread. + */ +public interface ILocatorNode extends IContainerModelNode, IDecoratable { + + public static final String PROPERTY_STATIC_INSTANCE = "staticInstance"; //$NON-NLS-1$ + + /** + * Returns the native {@link IPeer} object. + * <p> + * This method may be called from any thread. + * + * @return The native {@link IPeer} instance. + */ + public IPeer getPeer(); + + /** + * Returns the list of child peers this peer is a proxy for. + * + * @return The list of child peers or an empty list. + */ + public IPeer[] getPeers(); + + /** + * Returns <code>true</code> if this node was manually added. + * @return <code>true</code> for manually added nodes. + */ + public boolean isStatic(); + + /** + * Returns true, if a peer was already discovered for a static node. + */ + public boolean isDiscovered(); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java index 932fb7236..19e4da2ae 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java @@ -11,7 +11,6 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.nodes; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; -import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; /** * Default set of peer node properties. @@ -45,12 +44,6 @@ public interface IPeerNodeProperties { public static final String PROP_PEER_ID = "PeerId"; //$NON-NLS-1$ /** - * Property: List of proxies to use to connect to the target. - * @see IPeerProperties#PROP_PROXIES - */ - public static final String PROP_PROXIES = IPeerProperties.PROP_PROXIES; - - /** * Property: Ping interval. */ public static String PROP_PING_INTERVAL = "pingInterval"; //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPendingOperationNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPendingOperationNode.java new file mode 100644 index 000000000..85b1d3631 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPendingOperationNode.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.locator.interfaces.nodes; + +import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; + +/** + * Interface to be implemented by locator pending operation model nodes. + */ +public interface IPendingOperationNode extends IModelNode { + +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java index 5a6215ab2..ee022e9b2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java @@ -10,6 +10,7 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * The service to lookup/search in the parent locator model. @@ -39,4 +40,30 @@ public interface ILocatorModelLookupService extends ILocatorModelService { * @return The peer instances, or an empty list if the given name could not be matched. */ public IPeer[] lkupPeerByName(String name); + + /** + * Lookup the matching locator node for the given id. + * + * @param parent The parent locator node or <code>null</code>. + * @param id The id. Must not be <code>null</code>. + * @return The locator node instances, or an empty list if the given id could not be matched. + */ + public ILocatorNode[] lkupLocatorNodeById(ILocatorNode parent, String id); + + /** + * Lookup the matching locator node for the given agent id. + * + * @param parent The parent locator node or <code>null</code>. + * @param agentId The agent id. Must not be <code>null</code>. + * @return The locator node instances, or an empty list if the given agent id could not be matched. + */ + public ILocatorNode[] lkupLocatorNodeByAgentId(ILocatorNode parent, String agentId); + + /** + * Lookup the matching locator node for the given peer. + * + * @param peer The peer. + * @return The locator node for the given peer or <code>null</code>. + */ + public ILocatorNode lkupLocatorNode(IPeer peer); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java index d7190fbc9..017649462 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java @@ -10,6 +10,7 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * The service to refresh the parent locator model from remote. @@ -23,4 +24,12 @@ public interface ILocatorModelRefreshService extends ILocatorModelService { * @param callback The callback to invoke once the refresh operation finished, or <code>null</code>. */ public void refresh(ICallback callback); + + /** + * Refreshes the given locator node and its list of known children from the local locator service. + * + * @param locatorNode The locator node to refresh. + * @param callback The callback to invoke once the refresh operation finished, or <code>null</code>. + */ + public void refresh(ILocatorNode locatorNode, ICallback callback); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java index 694ec98c4..6ea9d78d4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java @@ -10,6 +10,7 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * The service to update the properties of given locator node. @@ -20,20 +21,32 @@ public interface ILocatorModelUpdateService extends ILocatorModelService { * Adds the given peer to the list of know peers. * * @param peer The peer to add. Must not be <code>null</code>. + * @return The new created or existing locator node. */ - public void add(IPeer peer); + public ILocatorNode add(IPeer peer); + + /** + * Adds the given static peer to the list of know peers. + * + * @param peer The static peer to add. Must not be <code>null</code>. + * @param isStatic <code>true</code> if this node is a manually added static peer. + * @return The new created or existing locator node. + */ + public ILocatorNode add(IPeer peer, boolean isStatic); /** * Removes the given peer from the list of known peers. * * @param peer The peer to remove. Must not be <code>null</code. + * @return The deleted locator node. */ - public void remove(IPeer peer); + public ILocatorNode remove(IPeer peer); /** * Update an old peer with the given new one. * @param oldPeer The old peer to update. Must not be <code>null</code. * @param newPeer The new peer. Must not be <code>null</code. + * @return The updated locator node. */ - public void update(IPeer oldPeer, IPeer newPeer); + public ILocatorNode update(IPeer oldPeer, IPeer newPeer); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java index 8947b8376..4153a7530 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.tcf.internal.core.RemotePeer; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; @@ -37,6 +38,9 @@ public class PeerModelPropertyTester extends PropertyTester { if (receiver instanceof IPeer) { receiver = Platform.getAdapterManager().getAdapter(receiver, IPeerNode.class); } + if (receiver instanceof ILocatorNode) { + receiver = Platform.getAdapterManager().getAdapter(((ILocatorNode)receiver).getPeer(), IPeerNode.class); + } // The receiver is expected to be a peer model node or a peer if (receiver instanceof IPeerNode) { final IPeerNode peerNode = (IPeerNode)receiver; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java index 797510f5b..bb8dd14fa 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelLocationUtil.java @@ -1,48 +1,74 @@ -/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.locator.model;
-
-import java.io.File;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator;
-
-/**
- * Peer model location utility implementation.
- */
-public final class ModelLocationUtil {
-
- /**
- * Returns the local static peers storage root location.
- *
- * @return The root location or <code>null</code> if the location cannot be determined.
- */
- public static IPath getStaticPeersRootLocation() {
- try {
- File file = CoreBundleActivator.getDefault().getStateLocation().append(".peers").toFile(); //$NON-NLS-1$
- boolean exists = file.exists();
- if (!exists) exists = file.mkdirs();
- if (exists && file.canRead() && file.isDirectory()) {
- return new Path(file.toString());
- }
- } catch (IllegalStateException e) {
- /* ignored on purpose */
- }
-
- // The users local peers lookup directory is $HOME/.tcf/.peers.
- File file = new Path(System.getProperty("user.home")).append(".tcf/.peers").toFile(); //$NON-NLS-1$ //$NON-NLS-2$
- if (file.canRead() && file.isDirectory()) {
- return new Path(file.toString());
- }
-
- return null;
- }
-}
+/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.locator.model; + +import java.io.File; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; + +/** + * Peer model location utility implementation. + */ +public final class ModelLocationUtil { + + /** + * Returns the local static peers storage root location. + * + * @return The root location or <code>null</code> if the location cannot be determined. + */ + public static IPath getStaticPeersRootLocation() { + try { + File file = CoreBundleActivator.getDefault().getStateLocation().append(".peers").toFile(); //$NON-NLS-1$ + boolean exists = file.exists(); + if (!exists) exists = file.mkdirs(); + if (exists && file.canRead() && file.isDirectory()) { + return new Path(file.toString()); + } + } catch (IllegalStateException e) { + /* ignored on purpose */ + } + + // The users local peers lookup directory is $HOME/.tcf/.peers. + File file = new Path(System.getProperty("user.home")).append(".tcf/.peers").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ + if (file.canRead() && file.isDirectory()) { + return new Path(file.toString()); + } + + return null; + } + + /** + * Returns the local static locators storage root location. + * + * @return The root location or <code>null</code> if the location cannot be determined. + */ + public static IPath getStaticLocatorsRootLocation() { + try { + File file = CoreBundleActivator.getDefault().getStateLocation().append(".locators").toFile(); //$NON-NLS-1$ + boolean exists = file.exists(); + if (!exists) exists = file.mkdirs(); + if (exists && file.canRead() && file.isDirectory()) { + return new Path(file.toString()); + } + } catch (IllegalStateException e) { + /* ignored on purpose */ + } + + // The users local peers lookup directory is $HOME/.tcf/.peers. + File file = new Path(System.getProperty("user.home")).append(".tcf/.locators").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ + if (file.canRead() && file.isDirectory()) { + return new Path(file.toString()); + } + + return null; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelManager.java index cdf1a28a3..321a365a6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/ModelManager.java @@ -116,10 +116,10 @@ public final class ModelManager { if (peerModel == null) { // Create the model instance IPeerModel model = new PeerModel(); - // Refresh the model right away - model.getService(IPeerModelRefreshService.class).refresh(null); // Apply to the global variable peerModel = model; + // Refresh the model right away + model.getService(IPeerModelRefreshService.class).refresh(null); } // If locator model is set in the mean while, initialize got @@ -128,10 +128,10 @@ public final class ModelManager { // Create the model instance ILocatorModel model = new LocatorModel(); // Refresh the model right away - model.getService(ILocatorModelRefreshService.class).refresh(null); - ((LocatorModel)model).checkLocatorListener(); // Apply to the global variable locatorModel = model; + model.getService(ILocatorModelRefreshService.class).refresh(null); + ((LocatorModel)model).checkLocatorListener(); } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.java index 30730e7b2..3a6e4a12b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.java @@ -77,4 +77,6 @@ public class Messages extends NLS { public static String PeerNode_info_connectionDisconnected; public static String StartPingTimerStep_warning_noDiagnosticsService; + + public static String PendingOperationModelNode_label; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.properties index 42720c79f..6880ce14d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nls/Messages.properties @@ -20,3 +20,5 @@ PeerNode_info_connectionLost=Connection to ''{0}'' lost PeerNode_info_connectionDisconnected=Connection to ''{0}'' disconnected StartPingTimerStep_warning_noDiagnosticsService=Missing Diagnostics service in ''{0}'' TCF agent. + +PendingOperationModelNode_label=Pending... diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java index 83d57bfe1..c1e007cfd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java @@ -10,13 +10,11 @@ package org.eclipse.tcf.te.tcf.locator.nodes; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.PlatformObject; @@ -29,6 +27,7 @@ import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelService; @@ -48,10 +47,8 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { // Flag to mark the model disposed private boolean disposed; - // The list of known peers - /* default */ final Map<String, IPeer> peers = new HashMap<String, IPeer>(); - // The list of "proxied" peers per proxy peer id - /* default */ final Map<String, List<IPeer>> peerChildren = new HashMap<String, List<IPeer>>(); + // The list of known locator nodes + /* default */ final Map<String, ILocatorNode> locatorNodes = new HashMap<String, ILocatorNode>(); // The list of registered model listeners private final List<ILocatorModelListener> modelListener = new ArrayList<ILocatorModelListener>(); @@ -81,7 +78,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { Assert.isNotNull(listener); if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.addListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ + CoreBundleActivator.getTraceHandler().trace("LocatorModel.addListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ } if (!modelListener.contains(listener)) modelListener.add(listener); @@ -95,7 +92,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { Assert.isNotNull(listener); if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.removeListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ + CoreBundleActivator.getTraceHandler().trace("LocatorModel.removeListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ } modelListener.remove(listener); @@ -118,7 +115,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.dispose()", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ + CoreBundleActivator.getTraceHandler().trace("LocatorModel.dispose()", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ } // If already disposed, we are done immediately @@ -143,7 +140,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { } modelListener.clear(); - peers.clear(); + locatorNodes.clear(); } /* (non-Javadoc) @@ -155,50 +152,24 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getPeers() + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getLocatorNodes() */ @Override - public IPeer[] getPeers() { - return peers.values().toArray(new IPeer[peers.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getChildren(java.lang.String) - */ - @Override - public List<IPeer> getChildren(final String parentPeerID) { - Assert.isNotNull(parentPeerID); - - final AtomicReference<List<IPeer>> result = new AtomicReference<List<IPeer>>(); - - Runnable runnable = new Runnable() { - @Override - public void run() { - List<IPeer> children = peerChildren.get(parentPeerID); - if (children == null) children = Collections.emptyList(); - result.set(children); - } - }; - - if (Protocol.isDispatchThread()) runnable.run(); - else Protocol.invokeAndWait(runnable); - - return Collections.unmodifiableList(result.get()); + public ILocatorNode[] getLocatorNodes() { + return locatorNodes.values().toArray(new ILocatorNode[locatorNodes.size()]); } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#setChildren(java.lang.String, java.util.List) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getPeers() */ @Override - public void setChildren(String parentPeerID, List<IPeer> children) { - Assert.isNotNull(parentPeerID); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + public IPeer[] getPeers() { + List<IPeer> peers = new ArrayList<IPeer>(); + for (ILocatorNode locatorNode : locatorNodes.values()) { + peers.add(locatorNode.getPeer()); + } - if (children == null || children.size() == 0) { - peerChildren.remove(parentPeerID); - } else { - peerChildren.put(parentPeerID, new ArrayList<IPeer>(children)); - } + return peers.toArray(new IPeer[peers.size()]); } /* (non-Javadoc) @@ -219,7 +190,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { return updateService; } if (adapter.isAssignableFrom(Map.class)) { - return peers; + return locatorNodes; } return super.getAdapter(adapter); @@ -234,17 +205,6 @@ 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 uniqueId.equals(((LocatorModel)obj).uniqueId); - } - return super.equals(obj); - } - - /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getService(java.lang.Class) */ @Override @@ -288,9 +248,9 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { final List<String> toRemove = new ArrayList<String>(); // Loop the discovered peers and find previous local host nodes - for (Entry<String, IPeer> entry : peers.entrySet()) { + for (Entry<String, ILocatorNode> entry : locatorNodes.entrySet()) { // Get the IP address from peers with transport type TCP or SSL - IPeer candidate = entry.getValue(); + IPeer candidate = entry.getValue().getPeer(); if (ITransportTypes.TRANSPORT_TYPE_TCP.equals(candidate.getTransportName()) || ITransportTypes.TRANSPORT_TYPE_SSL.equals(candidate.getTransportName())) { String ip = candidate.getAttributes().get(IPeer.ATTR_IP_HOST); Assert.isNotNull(ip); @@ -323,8 +283,8 @@ public class LocatorModel extends PlatformObject implements ILocatorModel { ITracing.ID_TRACE_LOCATOR_MODEL, this); } - IPeer p = peers.get(candidate); - if (p != null) getService(ILocatorModelUpdateService.class).remove(p); + ILocatorNode node = locatorNodes.get(candidate); + if (node != null) getService(ILocatorModelUpdateService.class).remove(node.getPeer()); } if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorNode.java new file mode 100644 index 000000000..642c48733 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorNode.java @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.locator.nodes; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.runtime.model.ContainerModelNode; +import org.eclipse.tcf.te.runtime.model.contexts.AsyncRefreshableCtxAdapter; +import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryState; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryType; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; + +/** + * Default locator node implementation. + */ +public class LocatorNode extends ContainerModelNode implements ILocatorNode { + // Locator nodes needs asynchronous refreshes + private final IAsyncRefreshableCtx refreshableCtxAdapter = new AsyncRefreshableCtxAdapter(); + + /** + * Constructor. + */ + public LocatorNode(IPeer peer, boolean isStatic) { + super(); + + Assert.isNotNull(peer); + + // Set the default properties before enabling the change events. + // The properties changed listeners should not be called from the + // constructor. + setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); + setProperty(ILocatorNode.PROPERTY_STATIC_INSTANCE, isStatic ? peer : null); + + PendingOperationNode pendingNode = new PendingOperationNode(); + pendingNode.setParent(this); + refreshableCtxAdapter.setPendingOperationNode(pendingNode); + + // Enable change events + setChangeEventsEnabled(true); + } + + /** + * Constructor. + * + * @param peer The peer. Must not be <code>null</code>. + */ + public LocatorNode(IPeer peer) { + this(peer, false); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.model.ContainerModelNode#add(org.eclipse.tcf.te.runtime.model.interfaces.IModelNode) + */ + @Override + public boolean add(IModelNode node) { + return super.add(node); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.properties.PropertiesContainer#checkThreadAccess() + */ + @Override + protected final boolean checkThreadAccess() { + return Protocol.isDispatchThread(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode#isDiscovered() + */ + @Override + public boolean isDiscovered() { + final AtomicBoolean isDiscovered = new AtomicBoolean(false); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + isDiscovered.set(getProperty(PROPERTY_STATIC_INSTANCE) != getProperty(IPeerNodeProperties.PROP_INSTANCE)); + } + }); + return isDiscovered.get(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode#isStatic() + */ + @Override + public boolean isStatic() { + final AtomicBoolean isStatic = new AtomicBoolean(false); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + isStatic.set(getProperty(PROPERTY_STATIC_INSTANCE) != null); + } + }); + return isStatic.get(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode#getPeer() + */ + @Override + public IPeer getPeer() { + return (IPeer)getAdapter(IPeer.class); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode#getPeers() + */ + @Override + public IPeer[] getPeers() { + List<IPeer> peers = new ArrayList<IPeer>(); + for (ILocatorNode locatorNode : getChildren(ILocatorNode.class)) { + peers.add(locatorNode.getPeer()); + } + + return peers.toArray(new IPeer[peers.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.model.ModelNode#getName() + */ + @Override + public String getName() { + return getPeer().getName(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) + */ + @Override + public Object getAdapter(final Class adapter) { + // NOTE: The getAdapter(...) method can be invoked from many place and + // many threads where we cannot control the calls. Therefore, this + // method is allowed be called from any thread. + final AtomicReference<Object> object = new AtomicReference<Object>(); + Runnable runnable = new Runnable() { + @Override + public void run() { + object.set(doGetAdapter(adapter)); + } + }; + + if (Protocol.isDispatchThread()) { + runnable.run(); + } + else { + Protocol.invokeAndWait(runnable); + } + + return object.get() != null ? object.get() : super.getAdapter(adapter); + } + + /** + * Returns an object which is an instance of the given class associated with this object. + * Returns <code>null</code> if no such object can be found. + * <p> + * This method must be called within the TCF dispatch thread! + * + * @param adapter The adapter class to look up. + * @return The adapter or <code>null</code>. + */ + protected Object doGetAdapter(Class<?> adapter) { + Assert.isTrue(checkThreadAccess(), "Illegal Thread Access"); //$NON-NLS-1$ + + if (ILocatorModel.class.isAssignableFrom(adapter)) { + return ModelManager.getLocatorModel(); + } + if (IAsyncRefreshableCtx.class.isAssignableFrom(adapter)) { + return refreshableCtxAdapter; + } + + Object peer = getProperty(IPeerNodeProperties.PROP_INSTANCE); + // Check with adapter.isAssignableFrom(...) to return the peer instance + // correctly if adapter is IPeer.class. + if (peer != null && adapter.isAssignableFrom(peer.getClass())) { + return peer; + } + + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.properties.PropertiesContainer#toString() + */ + @Override + public String toString() { + final StringBuilder buffer = new StringBuilder(getClass().getSimpleName()); + + Runnable runnable = new Runnable() { + @Override + public void run() { + IPeer peer = getPeer(); + buffer.append(": id=" + peer.getID()); //$NON-NLS-1$ + buffer.append(", name=" + peer.getName()); //$NON-NLS-1$ + } + }; + + if (Protocol.isDispatchThread()) { + runnable.run(); + } + else { + Protocol.invokeAndWait(runnable); + } + + buffer.append(", " + super.toString()); //$NON-NLS-1$ + return buffer.toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.model.ContainerModelNode#hasChildren() + */ + @Override + public boolean hasChildren() { + QueryState ctxQuery = refreshableCtxAdapter.getQueryState(QueryType.CONTEXT); + QueryState childQuery = refreshableCtxAdapter.getQueryState(QueryType.CHILD_LIST); + if (ctxQuery == QueryState.IN_PROGRESS || ctxQuery == QueryState.PENDING) { + return true; + } + if (childQuery == QueryState.IN_PROGRESS || childQuery == QueryState.PENDING) { + return true; + } + return super.hasChildren(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.model.ContainerModelNode#getChildren() + */ + @Override + public IModelNode[] getChildren() { + + List<IModelNode> children = getChildren(IModelNode.class); + + QueryState ctxQuery = refreshableCtxAdapter.getQueryState(QueryType.CONTEXT); + QueryState childQuery = refreshableCtxAdapter.getQueryState(QueryType.CHILD_LIST); + if (ctxQuery == QueryState.PENDING || childQuery == QueryState.PENDING) { + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + ILocatorModelRefreshService service = ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class); + service.refresh(LocatorNode.this, null); + } + }); + children.add(refreshableCtxAdapter.getPendingOperationNode()); + } + if (ctxQuery == QueryState.IN_PROGRESS || childQuery == QueryState.IN_PROGRESS) { + children.add(refreshableCtxAdapter.getPendingOperationNode()); + } + return children.toArray(new IModelNode[children.size()]); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java index 1fa7d1d99..42df91a2a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java @@ -43,7 +43,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { // Flag to mark the model disposed private boolean disposed; - // The list of known peers + // The list of known peer nodes /* default */ final Map<String, IPeerNode> peerNodes = new HashMap<String, IPeerNode>(); // The list of registered model listeners @@ -188,17 +188,6 @@ 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 uniqueId.equals(((PeerModel)obj).uniqueId); - } - return super.equals(obj); - } - - /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#getService(java.lang.Class) */ @Override diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PendingOperationNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PendingOperationNode.java new file mode 100644 index 000000000..b0f5edb20 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PendingOperationNode.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.locator.nodes; + +import org.eclipse.tcf.te.runtime.model.PendingOperationModelNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPendingOperationNode; + +/** + * An immutable model node to visualize a pending operation. + */ +public class PendingOperationNode extends PendingOperationModelNode implements IPendingOperationNode { + + /** + * Constructor. + */ + public PendingOperationNode() { + super(); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java index b73721f4b..d2110e440 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java @@ -10,12 +10,16 @@ package org.eclipse.tcf.te.tcf.locator.services; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; @@ -87,4 +91,105 @@ public class LocatorModelLookupService extends AbstractLocatorModelService imple return nodes.toArray(new IPeer[nodes.size()]); } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupLocatorNodeById(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode, java.lang.String) + */ + @Override + public ILocatorNode[] lkupLocatorNodeById(ILocatorNode parent, String id) { + Assert.isNotNull(id); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + List<ILocatorNode> locatorNodes; + if (parent != null) { + locatorNodes = parent.getChildren(ILocatorNode.class); + } + else { + locatorNodes = Arrays.asList(getLocatorModel().getLocatorNodes()); + } + + List<ILocatorNode> nodes = new ArrayList<ILocatorNode>(); + for (ILocatorNode node : locatorNodes) { + if (id.equals(node.getPeer().getID())) { + nodes.add(node); + } + } + + return nodes.toArray(new ILocatorNode[nodes.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupLocatorNodeByAgentId(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode, java.lang.String) + */ + @Override + public ILocatorNode[] lkupLocatorNodeByAgentId(ILocatorNode parent, String agentId) { + Assert.isNotNull(agentId); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + List<ILocatorNode> locatorNodes; + if (parent != null) { + locatorNodes = parent.getChildren(ILocatorNode.class); + } + else { + locatorNodes = Arrays.asList(getLocatorModel().getLocatorNodes()); + } + + List<ILocatorNode> nodes = new ArrayList<ILocatorNode>(); + for (ILocatorNode node : locatorNodes) { + if (agentId.equals(node.getPeer().getAgentID())) { + nodes.add(node); + } + } + + return nodes.toArray(new ILocatorNode[nodes.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupLocatorNode(org.eclipse.tcf.protocol.IPeer) + */ + @Override + public ILocatorNode lkupLocatorNode(IPeer peer) { + Assert.isNotNull(peer); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + String encProxies = peer.getAttributes().get(IPeerProperties.PROP_PROXIES); + IPeer[] proxies = PeerDataHelper.decodePeerList(encProxies); + + ILocatorNode parent = null; + + for (IPeer proxy : proxies) { + String agentId = proxy.getAgentID(); + String id = proxy.getID(); + ILocatorNode[] nodes = null; + if (agentId != null) { + nodes = lkupLocatorNodeByAgentId(parent, agentId); + } + if ((nodes == null || nodes.length == 0 ) && id != null) { + nodes = lkupLocatorNodeById(parent, id); + } + + if (nodes != null && nodes.length > 0) { + parent = nodes[0]; + } + else { + parent = null; + break; + } + } + + String agentId = peer.getAgentID(); + String id = peer.getID(); + ILocatorNode[] nodes = null; + if (agentId != null) { + nodes = lkupLocatorNodeByAgentId(parent, agentId); + } + if ((nodes == null || nodes.length == 0 ) && id != null) { + nodes = lkupLocatorNodeById(parent, id); + } + if (nodes != null && nodes.length > 0) { + return nodes[0]; + } + + return null; + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java index 3d355248d..b58ec710a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java @@ -9,23 +9,51 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.services; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.tcf.core.Command; +import org.eclipse.tcf.core.TransientPeer; +import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.services.ILocator; +import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryState; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryType; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; +import org.eclipse.tcf.te.runtime.services.ServiceManager; import org.eclipse.tcf.te.tcf.core.Tcf; +import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; +import org.eclipse.tcf.te.tcf.core.peers.Peer; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; - +import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; +import org.eclipse.tcf.te.tcf.locator.nodes.LocatorNode; /** * Default locator model refresh service implementation. @@ -59,8 +87,11 @@ public class LocatorModelRefreshService extends AbstractLocatorModelService impl } } - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService#refresh(org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + /* + * (non-Javadoc) + * @see + * org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService#refresh(org.eclipse + * .tcf.te.runtime.interfaces.callback.ICallback) */ @Override public void refresh(final ICallback callback) { @@ -81,8 +112,16 @@ public class LocatorModelRefreshService extends AbstractLocatorModelService impl return; } + refreshStaticPeers(); + // Get the list of old children (update node instances where possible) - final List<IPeer> oldChildren = new ArrayList<IPeer>(Arrays.asList(model.getPeers())); + ILocatorNode[] locatorNodes = model.getLocatorNodes(); + List<IPeer> oldChildren = new ArrayList<IPeer>(); + for (ILocatorNode node : locatorNodes) { + if (!node.isStatic()) { + oldChildren.add(node.getPeer()); + } + } // Refresh the static peer definitions processPeers(Protocol.getLocator().getPeers(), oldChildren, model); @@ -92,6 +131,11 @@ public class LocatorModelRefreshService extends AbstractLocatorModelService impl model.getService(ILocatorModelUpdateService.class).remove(oldChild); } + ILocatorModelListener[] listeners = model.getListener(); + for (ILocatorModelListener listener : listeners) { + listener.modelChanged(model, null, false); + } + // Invoke the callback invokeCallback(callback); } @@ -115,12 +159,14 @@ public class LocatorModelRefreshService extends AbstractLocatorModelService impl // Check if the peer is filtered if (isFiltered(peer)) continue; // Try to find an existing peer node first - IPeer lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(entry.getKey()); + IPeer lkupPeer = model.getService(ILocatorModelLookupService.class) + .lkupPeerById(entry.getKey()); // And create a new one if we cannot find it if (lkupPeer == null) { // Validate peer before adding lkupPeer = model.validatePeer(peer); - if (lkupPeer != null) model.getService(ILocatorModelUpdateService.class).add(lkupPeer); + if (lkupPeer != null) model.getService(ILocatorModelUpdateService.class) + .add(lkupPeer); } else { oldChildren.remove(peer); @@ -128,25 +174,313 @@ public class LocatorModelRefreshService extends AbstractLocatorModelService impl } } + /* + * (non-Javadoc) + * @see + * org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService#refresh(org + * .eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode, + * org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + */ + @Override + public void refresh(final ILocatorNode locatorNode, ICallback callback) { + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + // Get the parent peer model + ILocatorModel model = getLocatorModel(); + + // If the parent model is already disposed, the service will drop out immediately + if (model.isDisposed()) { + invokeCallback(callback); + return; + } + + // If the TCF framework isn't initialized yet, the service will drop out immediately + if (!Tcf.isRunning()) { + invokeCallback(callback); + return; + } + + final IAsyncRefreshableCtx refreshCtx = (IAsyncRefreshableCtx) locatorNode + .getAdapter(IAsyncRefreshableCtx.class); + refreshCtx.setQueryState(QueryType.CONTEXT, QueryState.IN_PROGRESS); + refreshCtx.setQueryState(QueryType.CHILD_LIST, QueryState.IN_PROGRESS); + + Map<String, Boolean> flags = new HashMap<String, Boolean>(); + flags.put(IChannelManager.FLAG_FORCE_NEW, Boolean.TRUE); + flags.put(IChannelManager.FLAG_NO_PATH_MAP, Boolean.TRUE); + flags.put(IChannelManager.FLAG_NO_VALUE_ADD, Boolean.TRUE); + + final ICallback finCb = new Callback(callback) { + @Override + protected void internalDone(Object caller, IStatus status) { + refreshCtx.setQueryState(QueryType.CONTEXT, QueryState.DONE); + refreshCtx.setQueryState(QueryType.CHILD_LIST, QueryState.DONE); + final ILocatorModel model = ModelManager.getLocatorModel(); + final ILocatorModelListener[] listeners = model.getListener(); + if (listeners.length > 0) { + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + for (ILocatorModelListener listener : listeners) { + listener.modelChanged(model, locatorNode, false); + } + } + }); + } + } + }; + + Tcf.getChannelManager() + .openChannel(locatorNode.getPeer(), flags, new IChannelManager.DoneOpenChannel() { + @Override + public void doneOpenChannel(Throwable error, final IChannel channel) { + if (error != null || channel == null) { + locatorNode.removeAll(ILocatorNode.class); + refreshCtx.setQueryState(QueryType.CONTEXT, QueryState.DONE); + refreshCtx.setQueryState(QueryType.CHILD_LIST, QueryState.DONE); + if (channel != null) { + Tcf.getChannelManager().closeChannel(channel); + } + invokeCallback(finCb); + } + else { + onDoneOpenChannelRefreshLocatorNode(channel, locatorNode, new Callback(finCb) { + @Override + protected void internalDone(Object caller, org.eclipse.core.runtime.IStatus status) { + Tcf.getChannelManager().closeChannel(channel); + } + }); + } + } + }); + } + + protected void onDoneOpenChannelRefreshLocatorNode(IChannel channel, ILocatorNode locatorNode, ICallback callback) { + ILocator locator = channel.getRemoteService(ILocator.class); + IAsyncRefreshableCtx refreshCtx = (IAsyncRefreshableCtx) locatorNode + .getAdapter(IAsyncRefreshableCtx.class); + if (locator == null) { + locatorNode.removeAll(ILocatorNode.class); + refreshCtx.setQueryState(QueryType.CONTEXT, QueryState.DONE); + refreshCtx.setQueryState(QueryType.CHILD_LIST, QueryState.DONE); + invokeCallback(callback); + } + else { + refreshCtx.setQueryState(QueryType.CONTEXT, QueryState.DONE); + getPeers(locator, channel, locatorNode, callback); + } + } + + protected void getPeers(final ILocator locator, final IChannel channel, final ILocatorNode locatorNode, final ICallback callback) { + @SuppressWarnings("unused") + Command cmd = new Command(channel, locator, "getPeers", null) { //$NON-NLS-1$ + @Override + public void done(Exception error, Object[] args) { + if (error == null) { + Assert.isTrue(args.length == 2); + error = toError(args[0]); + } + // If the error is still null here, process the returned peers + if (error == null && args[1] != null) { + // calculate proxies + String parentProxies = locatorNode.getPeer().getAttributes() + .get(IPeerProperties.PROP_PROXIES); + IPeer[] proxies = PeerDataHelper.decodePeerList(parentProxies); + List<IPeer> proxiesList = new ArrayList<IPeer>(Arrays.asList(proxies)); + proxiesList.add(locatorNode.getPeer()); + proxies = proxiesList.toArray(new IPeer[proxiesList.size()]); + String encProxies = PeerDataHelper.encodePeerList(proxies); + + List<ILocatorNode> oldChildren = locatorNode.getChildren(ILocatorNode.class); + + ILocatorModelLookupService lkup = getLocatorModel() + .getService(ILocatorModelLookupService.class); + + @SuppressWarnings("unchecked") + Collection<Map<String, String>> peerAttributesList = (Collection<Map<String, String>>) args[1]; + for (Map<String, String> attributes : peerAttributesList) { + + String agentId = attributes.get(IPeer.ATTR_AGENT_ID); + String id = attributes.get(IPeer.ATTR_ID); + ILocatorNode existing = null; + ILocatorNode[] lkupNodes = agentId != null ? lkup + .lkupLocatorNodeByAgentId(locatorNode, agentId) : new ILocatorNode[0]; + if (lkupNodes.length == 0) { + lkupNodes = id != null ? lkup.lkupLocatorNodeById(locatorNode, id) : new ILocatorNode[0]; + } + for (ILocatorNode node : lkupNodes) { + if (node.isStatic() && node.getPeer().getID().equals(id)) { + oldChildren.remove(node); + existing = node; + break; + } + } + + String parentAgentId = locatorNode.getPeer().getAgentID(); + String parentId = locatorNode.getPeer().getID(); + if (!agentId.equals(parentAgentId)) { + ILocatorNode parent = locatorNode.getParent(ILocatorNode.class); + ILocatorNode[] parentNodes = lkup + .lkupLocatorNodeByAgentId(parent, agentId); + while (parentNodes.length == 0 && parent != null) { + parent = parent.getParent(ILocatorNode.class); + parentNodes = lkup.lkupLocatorNodeByAgentId(parent, agentId); + } + + attributes = new HashMap<String, String>(attributes); + + if (parentAgentId == null && id.equals(parentId)) { + attributes.put(IPeerProperties.PROP_PROXIES, parentProxies); + IPeer peer = new TransientPeer(attributes); + locatorNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); + } + else { + attributes.put(IPeerProperties.PROP_PROXIES, encProxies); + IPeer peer = new TransientPeer(attributes); + if (existing == null) { + if (parentNodes.length == 0 && !isFiltered(peer)) { + locatorNode.add(new LocatorNode(peer)); + } + } + else { + existing.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); + } + } + } + } + for (ILocatorNode old : oldChildren) { + if (old.isStatic()) { + old.setProperty(IPeerNodeProperties.PROP_INSTANCE, old + .getProperty(ILocatorNode.PROPERTY_STATIC_INSTANCE)); + } + else { + locatorNode.remove(old, true); + } + } + if (locatorNode.isStatic() && locatorNode.getPeer().getAgentID() != null) { + String parentAgentId = locatorNode.getPeer().getAgentID(); + for (ILocatorNode child : locatorNode.getChildren(ILocatorNode.class)) { + if (parentAgentId.equals(child.getPeer().getAgentID())) { + locatorNode.remove(child, true); + } + } + } + } + else { + List<ILocatorNode> oldChildren = locatorNode.getChildren(ILocatorNode.class); + for (ILocatorNode old : oldChildren) { + if (old.isStatic()) { + old.setProperty(IPeerNodeProperties.PROP_INSTANCE, locatorNode + .getProperty(ILocatorNode.PROPERTY_STATIC_INSTANCE)); + } + else { + locatorNode.remove(old, true); + } + } + } + IAsyncRefreshableCtx refreshCtx = (IAsyncRefreshableCtx) locatorNode + .getAdapter(IAsyncRefreshableCtx.class); + refreshCtx.setQueryState(QueryType.CHILD_LIST, QueryState.DONE); + + // Invoke the callback + invokeCallback(callback); + } + }; + + } + /** * Returns if or if not the given peer is filtered. * * @param peer The peer or <code>null</code>. * @return <code>True</code> if the given peer is filtered, <code>false</code> otherwise. */ - private boolean isFiltered(IPeer peer) { + protected boolean isFiltered(IPeer peer) { boolean filtered = peer == null; if (!filtered) { String value = peer.getAttributes().get("ValueAdd"); //$NON-NLS-1$ boolean isValueAdd = value != null && ("1".equals(value.trim()) || Boolean.parseBoolean(value.trim())); //$NON-NLS-1$ - filtered |= isValueAdd; + boolean isCli = peer.getName() != null && (peer.getName().endsWith("Command Server") || peer.getName().endsWith("CLI Server")); //$NON-NLS-1$ //$NON-NLS-2$ - filtered |= peer.getName() != null - && (peer.getName().endsWith("Command Server") || peer.getName().endsWith("CLI Server")); //$NON-NLS-1$ //$NON-NLS-2$ + filtered = isValueAdd || isCli; } return filtered; } + + /** + * Returns the list of root locations to lookup for static locator definitions. + * + * @return The list of root locations or an empty list. + */ + protected File[] getStaticLocatorsLookupDirectories() { + // The list defining the root locations + List<File> rootLocations = new ArrayList<File>(); + + // always add default root location + IPath defaultPath = ModelLocationUtil.getStaticLocatorsRootLocation(); + if (defaultPath != null) { + File file = defaultPath.toFile(); + if (file.canRead() && file.isDirectory() && !rootLocations.contains(file)) { + rootLocations.add(file); + } + } + + return rootLocations.toArray(new File[rootLocations.size()]); + } + + /** + * Refresh the static locator definitions. + */ + protected void refreshStaticPeers() { + + // Get the root locations to lookup the static peer definitions + File[] roots = getStaticLocatorsLookupDirectories(); + if (roots.length > 0) { + // The lst of locator peers created from the static definitions + List<IPeer> peers = new ArrayList<IPeer>(); + // Process the root locations + for (File root : roots) { + // List all "*.locator" files within the root location + File[] candidates = root.listFiles(new FileFilter() { + @Override + public boolean accept(File pathname) { + IPath path = new Path(pathname.getAbsolutePath()); + return path.getFileExtension() != null && path.getFileExtension() + .toLowerCase().equals("locator"); //$NON-NLS-1$ + } + }); + // If there are ini files to read, process them + if (candidates != null && candidates.length > 0) { + + for (File candidate : candidates) { + try { + IURIPersistenceService service = ServiceManager.getInstance() + .getService(IURIPersistenceService.class); + IPeer tempPeer = (IPeer) service.read(IPeer.class, candidate + .getAbsoluteFile().toURI()); + Map<String, String> attrs = new HashMap<String, String>(tempPeer.getAttributes()); + // Remember the file path within the properties + attrs.put(IPersistableNodeProperties.PROPERTY_URI, candidate + .getAbsoluteFile().toURI().toString()); + // Construct the peer from the attributes + IPeer peer = new Peer(attrs); + peers.add(peer); + } + catch (IOException e) { + /* ignored on purpose */ + } + } + } + } + + for (IPeer peer : peers) { + ILocatorModelUpdateService update = getLocatorModel() + .getService(ILocatorModelUpdateService.class); + update.add(peer, true); + } + } + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java index f7392bc71..54e2ded09 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java @@ -14,9 +14,15 @@ import java.util.Map; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; +import org.eclipse.tcf.te.tcf.locator.nodes.LocatorNode; /** @@ -37,83 +43,124 @@ public class LocatorModelUpdateService extends AbstractLocatorModelService imple * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#add(org.eclipse.tcf.protocol.IPeer) */ @Override - public void add(final IPeer peer) { + public ILocatorNode add(IPeer peer) { + return add(peer, false); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#add(org.eclipse.tcf.protocol.IPeer, boolean) + */ + @Override + public ILocatorNode add(final IPeer peer, boolean isStatic) { Assert.isNotNull(peer); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); - Assert.isNotNull(peers); - peers.put(peer.getID(), peer); - - final ILocatorModelListener[] listeners = getLocatorModel().getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (ILocatorModelListener listener : listeners) { - listener.modelChanged(getLocatorModel(), peer, true); + String encProxies = peer.getAttributes().get(IPeerProperties.PROP_PROXIES); + ILocatorNode locatorNode = null; + + if (encProxies == null || encProxies.trim().length() == 0) { + Map<String, ILocatorNode> locatorNodes = (Map<String, ILocatorNode>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(locatorNodes); + locatorNode = new LocatorNode(peer, isStatic); + locatorNodes.put(peer.getID(), locatorNode); + } + else { + IPeer[] proxies = PeerDataHelper.decodePeerList(encProxies); + ILocatorNode parent = null; + for (IPeer proxy : proxies) { + ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + ILocatorNode proxyNode = lkup.lkupLocatorNode(proxy); + if (proxyNode == null) { + proxyNode = new LocatorNode(proxy, true); + if (parent == null) { + Map<String, ILocatorNode> locatorNodes = (Map<String, ILocatorNode>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(locatorNodes); + locatorNodes.put(proxy.getID(), proxyNode); + + } + else { + parent.add(proxyNode); } + parent = proxyNode; } - }); + else { + parent = proxyNode; + } + } + ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + locatorNode = lkup.lkupLocatorNode(peer); + if (locatorNode == null) { + locatorNode = new LocatorNode(peer, true); + parent.add(locatorNode); + } + } + + ILocatorModelListener[] listeners = getLocatorModel().getListener(); + for (ILocatorModelListener listener : listeners) { + listener.modelChanged(getLocatorModel(), locatorNode, true); } + + return locatorNode; } /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#remove(org.eclipse.tcf.protocol.IPeer) */ @Override - public void remove(final IPeer peer) { + public ILocatorNode remove(final IPeer peer) { Assert.isNotNull(peer); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); - Assert.isNotNull(peers); - peers.remove(peer.getID()); - - final ILocatorModelListener[] listeners = getLocatorModel().getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (ILocatorModelListener listener : listeners) { - listener.modelChanged(getLocatorModel(), peer, false); - } - } - }); + ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + ILocatorNode locatorNode = lkup.lkupLocatorNode(peer); + + if (locatorNode != null) { + ILocatorNode parent = locatorNode.getParent(ILocatorNode.class); + + if (parent == null) { + Map<String, ILocatorNode> locatorNodes = (Map<String, ILocatorNode>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(locatorNodes); + locatorNode = locatorNodes.remove(peer.getID()); + } + else { + parent.remove(locatorNode, true); + } + } + + ILocatorModelListener[] listeners = getLocatorModel().getListener(); + for (ILocatorModelListener listener : listeners) { + listener.modelChanged(getLocatorModel(), locatorNode, false); } + + return locatorNode; } /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#update(org.eclipse.tcf.protocol.IPeer, org.eclipse.tcf.protocol.IPeer) */ @Override - public void update(final IPeer oldPeer, final IPeer newPeer) { + public ILocatorNode update(final IPeer oldPeer, final IPeer newPeer) { Assert.isNotNull(oldPeer); Assert.isNotNull(newPeer); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); - Assert.isNotNull(peers); - peers.remove(oldPeer.getID()); - peers.put(newPeer.getID(), newPeer); - - - final ILocatorModelListener[] listeners = getLocatorModel().getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (ILocatorModelListener listener : listeners) { - if (!oldPeer.getID().equals(newPeer.getID())) { - listener.modelChanged(getLocatorModel(), oldPeer, false); - listener.modelChanged(getLocatorModel(), newPeer, true); - } - else { - listener.modelChanged(getLocatorModel(), newPeer, false); - } - } - } - }); + Map<String, ILocatorNode> locatorNodes = (Map<String, ILocatorNode>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(locatorNodes); + final ILocatorNode oldLocatorNode = locatorNodes.remove(oldPeer.getID()); + final ILocatorNode newLocatorNode = new LocatorNode(newPeer); + locatorNodes.put(newPeer.getID(), newLocatorNode); + + ILocatorModelListener[] listeners = getLocatorModel().getListener(); + for (ILocatorModelListener listener : listeners) { + if (!oldPeer.getID().equals(newPeer.getID())) { + listener.modelChanged(getLocatorModel(), oldLocatorNode, false); + listener.modelChanged(getLocatorModel(), newLocatorNode, true); + } + else { + listener.modelChanged(getLocatorModel(), newLocatorNode, false); + } } + + return newLocatorNode; } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java index 4552ef31d..507b4306b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IPath; @@ -144,35 +143,6 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements } } - private final AtomicBoolean REFRESH_STATIC_PEERS_GUARD = new AtomicBoolean(false); - - protected void refreshStaticPeers() { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // This method might be called reentrant while processing. Return immediately - // in this case. - if (REFRESH_STATIC_PEERS_GUARD.get()) { - return; - } - REFRESH_STATIC_PEERS_GUARD.set(true); - - // Get the parent peer model - IPeerModel model = getPeerModel(); - - // If the parent model is already disposed, the service will drop out immediately - if (model.isDisposed()) { - return; - } - - // Get the list of old children (update node instances where possible) - final List<IPeerNode> oldChildren = new ArrayList<IPeerNode>(Arrays.asList(model.getPeerNodes())); - - // Refresh the static peer definitions - refreshStaticPeers(oldChildren, model); - - REFRESH_STATIC_PEERS_GUARD.set(false); - } - /** * Refresh the static peer definitions. * diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PropertiesAccessService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PropertiesAccessService.java index a78a21034..51ddaf85e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PropertiesAccessService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PropertiesAccessService.java @@ -15,7 +15,9 @@ import java.util.Map; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.core.nodes.interfaces.wire.IWireTypeNetwork; import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; /** @@ -65,6 +67,16 @@ public class PropertiesAccessService extends org.eclipse.tcf.te.tcf.core.model.s if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$ result.put(IPropertiesAccessServiceConstants.PROP_TRANSPORT_NAME, value); } + + value = attributes.get(IPeerProperties.PROP_PROXIES); + if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$ + result.put(IPropertiesAccessServiceConstants.PROP_PROXIES, value); + } + + value = attributes.get(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO); + if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$ + result.put(IPropertiesAccessServiceConstants.PROP_PORT_IS_AUTO, value); + } } }); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml index 0e8997ce1..77f913217 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml @@ -19,6 +19,12 @@ </factory> <factory + adaptableType="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode" + class="org.eclipse.tcf.te.tcf.ui.internal.adapters.AdapterFactory"> + <adapter type="org.eclipse.jface.viewers.ILabelProvider"/> + </factory> + + <factory adaptableType="org.eclipse.tcf.te.ui.views.editor.EditorInput" class="org.eclipse.tcf.te.tcf.ui.internal.adapters.AdapterFactory"> <adapter type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> @@ -90,7 +96,7 @@ bundleId="org.eclipse.tcf.te.runtime.services" class="org.eclipse.tcf.te.runtime.services.interfaces.IMenuService"/> <enablement> - <instanceof value="org.eclipse.tcf.protocol.IPeer"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> </enablement> </service> @@ -167,10 +173,17 @@ <instanceof value="org.eclipse.tcf.te.ui.views.interfaces.IRoot"/> <instanceof value="org.eclipse.tcf.te.ui.views.interfaces.ICategory"/> <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPendingOperationNode"/> </or> </triggerPoints> <possibleChildren> - <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> + <or> + <instanceof value="org.eclipse.tcf.te.ui.views.interfaces.ICategory"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPendingOperationNode"/> + </or> </possibleChildren> <commonSorter class="org.eclipse.tcf.te.tcf.ui.navigator.ViewerSorter" @@ -180,7 +193,7 @@ wizardId="org.eclipse.tcf.te.tcf.ui.wizards.NewTargetWizard"> <enablement> <or> - <instanceof value="org.eclipse.tcf.protocol.IPeer"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> <and> <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> <test property="org.eclipse.tcf.te.tcf.locator.isOfType" value="null"/> @@ -207,13 +220,6 @@ </dropAssistant> </navigatorContent> <commonFilter - activeByDefault="true" - class="org.eclipse.tcf.te.tcf.ui.filter.RedirectPeersFilter" - id="org.eclipse.tcf.te.tcf.ui.navigator.RedirectPeersFilter" - name="%RedirectPeersFilter.name" - visibleInUI="false"> - </commonFilter> - <commonFilter activeByDefault="false" class="org.eclipse.tcf.te.tcf.ui.filter.PeersByCurrentUserFilter" id="org.eclipse.tcf.te.tcf.ui.navigator.PeersByCurrentUserFilter" @@ -229,8 +235,9 @@ id="org.eclipse.tcf.te.tcf.ui.peerLabelProviderDelegate"> <enablement> <or> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> - <instanceof value="org.eclipse.tcf.protocol.IPeer"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPendingOperationNode"/> </or> </enablement> </labelProviderDelegate> @@ -244,10 +251,7 @@ label="%peerhost.decorator.label" state="true"> <enablement> - <or> - <objectClass name="org.eclipse.tcf.protocol.IPeer"/> - <objectClass name="org.eclipse.tcf.te.core.interfaces.IDecoratable"/> - </or> + <objectClass name="org.eclipse.tcf.te.core.interfaces.IDecoratable"/> </enablement> </decorator> </extension> @@ -432,6 +436,36 @@ </visibleWhen> </command> </menuContribution> + <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.refresh"> + <command + commandId="org.eclipse.tcf.te.ui.command.refresh" + label="%command.refresh.label" + style="push" + tooltip="%command.refresh.tooltip"> + <visibleWhen checkEnabled="false"> + <with variable="selection"> + <count value="+"/> + <iterate operator="and" ifEmpty="false"> + <and> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> + <or> + <not> + <test + forcePluginActivation="true" + property="org.eclipse.tcf.te.runtime.services.hasService" + value="org.eclipse.tcf.te.runtime.services.interfaces.IMenuService"/> + </not> + <test + property="org.eclipse.tcf.te.runtime.services.menu.isVisible" + args="org.eclipse.tcf.te.ui.command.refresh" + value="true"/> + </or> + </and> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.launch.rundebug"> <command commandId="org.eclipse.tcf.te.tcf.ui.command.debug"> <visibleWhen checkEnabled="false"> @@ -540,7 +574,7 @@ <visibleWhen checkEnabled="false"> <with variable="selection"> <iterate operator="and" ifEmpty="false"> - <instanceof value="org.eclipse.tcf.protocol.IPeer"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> </iterate> </with> </visibleWhen> @@ -780,12 +814,12 @@ <extension point="org.eclipse.ui.handlers"> <handler commandId="org.eclipse.tcf.te.ui.command.connect" - class="org.eclipse.tcf.te.tcf.ui.handler.ConnectPeerCommandHandler"> + class="org.eclipse.tcf.te.tcf.ui.handler.ConnectLocatorNodeCommandHandler"> <activeWhen> <with variable="selection"> <count value="1"/> <iterate operator="and" ifEmpty="false"> - <instanceof value="org.eclipse.tcf.protocol.IPeer"/> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> </iterate> </with> </activeWhen> @@ -830,7 +864,7 @@ <handler commandId="org.eclipse.tcf.te.ui.command.refresh" - class="org.eclipse.tcf.te.tcf.ui.handler.RefreshHandler"> + class="org.eclipse.tcf.te.tcf.ui.handler.RefreshPeerNodeHandler"> <activeWhen> <with variable="selection"> <iterate operator="and" ifEmpty="false"> @@ -851,6 +885,25 @@ </handler> <handler + commandId="org.eclipse.tcf.te.ui.command.refresh" + class="org.eclipse.tcf.te.tcf.ui.handler.RefreshLocatorNodeHandler"> + <activeWhen> + <with variable="selection"> + <iterate operator="and" ifEmpty="false"> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> + </iterate> + </with> + </activeWhen> + <enabledWhen> + <with variable="selection"> + <iterate operator="and" ifEmpty="false"> + <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode"/> + </iterate> + </with> + </enabledWhen> + </handler> + + <handler commandId="org.eclipse.tcf.te.tcf.ui.command.debug" class="org.eclipse.tcf.te.tcf.ui.handler.StartDebugCommandHandler"> <activeWhen> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java index 513803d6b..b200bb226 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/activator/UIPlugin.java @@ -251,6 +251,8 @@ public class UIPlugin extends AbstractUIPlugin { registry.put(ImageConsts.PEER_NODE, ImageDescriptor.createFromURL(url)); url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_OBJ + "peer_discovered.gif"); //$NON-NLS-1$ registry.put(ImageConsts.PEER_DISCOVERED, ImageDescriptor.createFromURL(url)); + url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_OBJ + "peer.gif"); //$NON-NLS-1$ + registry.put(ImageConsts.PEER_STATIC, ImageDescriptor.createFromURL(url)); url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_OBJ + "targets_view.gif"); //$NON-NLS-1$ registry.put(ImageConsts.SYSTEM_MGNT_VIEW, ImageDescriptor.createFromURL(url)); url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_OBJ + "connection.gif"); //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/AbstractTreeSelectionDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/AbstractTreeSelectionDialog.java new file mode 100644 index 000000000..8dcfa83df --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/AbstractTreeSelectionDialog.java @@ -0,0 +1,282 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.ui.dialogs; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil; +import org.eclipse.tcf.te.tcf.ui.navigator.ViewerSorter; +import org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog; +import org.eclipse.tcf.te.ui.swt.SWTControlUtil; +import org.eclipse.tcf.te.ui.views.navigator.DelegatingLabelProvider; + +/** + * Tree selection dialog implementation. + */ +public abstract class AbstractTreeSelectionDialog extends CustomTitleAreaDialog { + // The tree viewer + /* default */ TreeViewer viewer; + + // The selection. Will be filled in if "OK" is pressed + private ISelection selection; + + /** + * Constructor. + * + * @param parent The parent shell used to view the dialog, or <code>null</code>. + * @param services The list of (remote) services the agents must provide to be selectree, or <code>null</code>. + */ + public AbstractTreeSelectionDialog(Shell shell, String contextHelpId) { + super(shell, contextHelpId); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#isResizable() + */ + @Override + protected boolean isResizable() { + return true; + } + + /** + * Returns whether the dialog shall support multi selection or not. + * <p> + * The default implementation returns <code>true</code>. + * + * @return <code>True</code> if multi selection is supported, <code>false</code> otherwise. + */ + protected boolean supportsMultiSelection() { + return false; + } + + /** + * Returns the tree viewer instance. + * + * @return The tree viewer instance or <code>null</code>. + */ + protected final TreeViewer getViewer() { + return viewer; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#createDialogAreaContent(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createDialogAreaContent(Composite parent) { + super.createDialogAreaContent(parent); + + setDialogTitle(getDialogTitle()); + setTitle(getTitle()); + setDefaultMessage(getDefaultMessage(), IMessageProvider.NONE); + + Composite comp = new Composite(parent, SWT.NONE); + GridLayout gl = new GridLayout(2, false); + gl.marginWidth = 0; + gl.marginHeight = 0; + comp.setLayout(gl); + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + comp.setLayoutData(layoutData); + + createTreeAreaContent(comp); + createButtonAreaContent(comp); + } + + protected TreeViewer createTreeAreaContent(Composite parent) { + // Create the tree viewer + viewer = new TreeViewer(parent, (supportsMultiSelection() ? SWT.MULTI : SWT.SINGLE) | SWT.BORDER); + + // Configure the tree + Tree tree = viewer.getTree(); + + @SuppressWarnings("unused") + TreeColumn column = new TreeColumn(tree, SWT.LEFT); + + ColumnViewerToolTipSupport.enableFor(viewer); + + TableLayout treeLayout = new TableLayout(); + treeLayout.addColumnData(new ColumnWeightData(100)); + tree.setLayout(treeLayout); + + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + layoutData.minimumWidth = 150; + layoutData.minimumHeight = 150; + tree.setLayoutData(layoutData); + + viewer.setContentProvider(getContentProvider()); + viewer.setLabelProvider(getLabelProvider()); + + // Subclasses may customize the viewer before setting the input + configureTreeViewer(viewer); + + viewer.setInput(getInput()); + viewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + if (!viewer.getSelection().isEmpty()) { + okPressed(); + } + } + }); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + updateEnablement(viewer); + } + }); + + viewer.refresh(); + updateSelection(getSelection()); + + return viewer; + } + + protected abstract void updateSelection(ISelection selection); + + protected abstract void createButtonAreaContent(Composite parent); + + protected abstract IContentProvider getContentProvider(); + + protected IBaseLabelProvider getLabelProvider() { + DelegatingLabelProvider labelProvider = new DelegatingLabelProvider(); + return new DecoratingLabelProvider(labelProvider, labelProvider); + } + + protected void refresh() { + ExecutorsUtil.executeInUI(new Runnable() { + @Override + public void run() { + viewer.refresh(); + updateEnablement(viewer); + } + }); + } + + protected abstract Object getInput(); + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createButtonBar(Composite parent) { + Control buttonBar = super.createButtonBar(parent); + updateEnablement(viewer); + return buttonBar; + } + + /** + * Update the enablement of the dialog widgets. + * + * @param viewer The tree viewer. Must not be <code>null</code>. + */ + protected void updateEnablement(TreeViewer viewer) { + Assert.isNotNull(viewer); + + // Adjust the OK button enablement + Button okButton = getButton(IDialogConstants.OK_ID); + SWTControlUtil.setEnabled(okButton, isValidSelection()); + } + + protected boolean isValidSelection() { + int selCount = viewer.getTree().getSelectionCount(); + return supportsMultiSelection() ? selCount > 0 : selCount == 1; + } + + /** + * Configure the tree viewer. + * <p> + * The default implementation does nothing. Subclasses may overwrite this + * method to customize the tree viewer before the input gets set. + * + * @param viewer The tree viewer. Must not be <code>null</code>. + */ + protected void configureTreeViewer(TreeViewer viewer) { + Assert.isNotNull(viewer); + viewer.setSorter(new ViewerSorter()); + } + + /** + * Returns the dialog title. + * + * @return The dialog title. + */ + protected abstract String getDialogTitle(); + + /** + * Returns the title. + * + * @return The title. + */ + protected abstract String getTitle(); + + /** + * Returns the default message. + * + * @return The default message. + */ + protected abstract String getDefaultMessage(); + + /** + * Returns the selection which had been set to the viewer at + * the time of closing the dialog with either "OK" or "Cancel". + * + * @return The selection or <code>null</code>. + */ + public ISelection getSelection() { + return selection; + } + + /** + * Set the selection to be shown when the dialog opens. + * @param selection The selection to set. + */ + public void setSelection(ISelection selection) { + this.selection = selection; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#okPressed() + */ + @Override + protected void okPressed() { + selection = viewer.getSelection(); + super.okPressed(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() + */ + @Override + protected void cancelPressed() { + selection = null; + super.cancelPressed(); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/LocatorNodeSelectionDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/LocatorNodeSelectionDialog.java new file mode 100644 index 000000000..eccfb68f2 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/LocatorNodeSelectionDialog.java @@ -0,0 +1,480 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.ui.dialogs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.tcf.core.TransientPeer; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.runtime.callback.AsyncCallbackCollector; +import org.eclipse.tcf.te.runtime.callback.Callback; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.model.interfaces.IContainerModelNode; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryState; +import org.eclipse.tcf.te.runtime.model.interfaces.contexts.IAsyncRefreshableCtx.QueryType; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; +import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; +import org.eclipse.tcf.te.tcf.core.interfaces.ITransportTypes; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; +import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; +import org.eclipse.tcf.te.tcf.ui.editor.sections.TcpTransportSection; +import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; +import org.eclipse.tcf.te.tcf.ui.navigator.ContentProvider; +import org.eclipse.tcf.te.tcf.ui.nls.Messages; +import org.eclipse.tcf.te.ui.async.UICallbackInvocationDelegate; +import org.eclipse.tcf.te.ui.dialogs.AbstractSectionDialog; +import org.eclipse.tcf.te.ui.forms.parts.AbstractSection; +import org.eclipse.tcf.te.ui.views.extensions.CategoriesExtensionPointManager; +import org.eclipse.tcf.te.ui.views.interfaces.ICategory; +import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; +import org.eclipse.ui.forms.IManagedForm; + +/** + * Locator node selection dialog implementation. + */ +public class LocatorNodeSelectionDialog extends AbstractTreeSelectionDialog implements ILocatorModelListener { + + Button addButton; + Button deleteButton; + Button refreshButton; + + /** + * Constructor. + * + * @param shell The shell used to view the dialog, or <code>null</code>. + */ + public LocatorNodeSelectionDialog(Shell shell) { + super(shell, IContextHelpIds.LOCATOR_NODE_SELECTION_DIALOG); + + ModelManager.getLocatorModel().addListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#createButtonAreaContent(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createButtonAreaContent(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + GridLayout gl = new GridLayout(); + gl.marginWidth = 0; + gl.marginHeight = 0; + comp.setLayout(gl); + GridData layoutData = new GridData(SWT.NONE, SWT.FILL, false, true); + comp.setLayoutData(layoutData); + + addButton = new Button(comp, SWT.PUSH); + layoutData = new GridData(SWT.FILL, SWT.FILL, false, false); + addButton.setLayoutData(layoutData); + addButton.setText(" " + Messages.LocatorNodeSelectionDialog_button_add + " "); //$NON-NLS-1$ //$NON-NLS-2$ + addButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + onButtonAddSelected(); + } + }); + + deleteButton = new Button(comp, SWT.PUSH); + layoutData = new GridData(SWT.FILL, SWT.FILL, false, false); + deleteButton.setLayoutData(layoutData); + deleteButton.setText(" " + Messages.LocatorNodeSelectionDialog_button_delete + " "); //$NON-NLS-1$ //$NON-NLS-2$ + deleteButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + onButtonDeleteSelected(); + } + }); + + Composite spacer = new Composite(comp, SWT.NONE); + layoutData = new GridData(SWT.FILL, SWT.FILL, false, true); + spacer.setLayoutData(layoutData); + + refreshButton = new Button(comp, SWT.PUSH); + layoutData = new GridData(SWT.FILL, SWT.FILL, false, false); + refreshButton.setLayoutData(layoutData); + refreshButton.setText(" " + Messages.LocatorNodeSelectionDialog_button_refresh + " "); //$NON-NLS-1$ //$NON-NLS-2$ + refreshButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + onButtonRefreshSelected(); + } + }); + } + + protected void onButtonAddSelected() { + final ISelection sel = getViewer().getSelection(); + if (sel instanceof IStructuredSelection) { + Object element = ((IStructuredSelection) sel).getFirstElement(); + + String encProxies; + if (element instanceof ICategory) { + encProxies = null; + } + else if (element instanceof ILocatorNode) { + ILocatorNode parent = (ILocatorNode) element; + String parentProxies = parent.getPeer().getAttributes() + .get(IPeerProperties.PROP_PROXIES); + IPeer[] proxies = PeerDataHelper.decodePeerList(parentProxies); + List<IPeer> proxiesList = new ArrayList<IPeer>(Arrays.asList(proxies)); + proxiesList.add(parent.getPeer()); + proxies = proxiesList.toArray(new IPeer[proxiesList.size()]); + encProxies = PeerDataHelper.encodePeerList(proxies); + } + else { + return; + } + + AbstractSectionDialog dialog = new AbstractSectionDialog(getShell(), + Messages.LocatorNodeSelectionDialog_add_dialogTitle, + Messages.LocatorNodeSelectionDialog_add_title, + Messages.LocatorNodeSelectionDialog_add_message, + false, null) { + @Override + protected AbstractSection[] createSections(IManagedForm form, Composite parent) { + return new AbstractSection[] { new TcpTransportSection(form, parent, false) }; + } + }; + IPropertiesContainer data = new PropertiesContainer(); + data.setProperty(IPeerProperties.PROP_PROXIES, encProxies); + data.setProperty(IPeer.ATTR_TRANSPORT_NAME, ITransportTypes.TRANSPORT_TYPE_TCP); + data.setProperty(IPeer.ATTR_IP_PORT, "1534"); //$NON-NLS-1$ + dialog.setupData(data); + + if (dialog.open() == Window.OK) { + dialog.extractData(data); + + String proxy = data.getStringProperty(IPeerProperties.PROP_PROXIES); + String host = data.getStringProperty(IPeer.ATTR_IP_HOST); + String port = data.getStringProperty(IPeer.ATTR_IP_PORT); + String transport = data.getStringProperty(IPeer.ATTR_TRANSPORT_NAME); + String id = transport + ":" + host + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$ + Map<String,String> attrs = new HashMap<String, String>(); + attrs.put(IPeer.ATTR_ID, id); + attrs.put(IPeer.ATTR_IP_HOST, host); + attrs.put(IPeer.ATTR_IP_PORT, port); + attrs.put(IPeer.ATTR_TRANSPORT_NAME, transport); + attrs.put(IPeerProperties.PROP_PROXIES, proxy); + final IPeer peer = new TransientPeer(attrs); + + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + final ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + ILocatorModelRefreshService refresh = ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class); + ILocatorNode node = lkup.lkupLocatorNode(peer); + if (node == null) { + try { + IURIPersistenceService persistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class); + String id = peer.getID(); + String name = id.replaceAll("\\W", "_").trim(); //$NON-NLS-1$ //$NON-NLS-2$ + IPath basePath = ModelLocationUtil.getStaticLocatorsRootLocation().append(name); + IPath path = basePath.addFileExtension("locator"); //$NON-NLS-1$ + int i = 0; + while (path.toFile().exists()) { + path = basePath.append("_"+i).addFileExtension("locator"); //$NON-NLS-1$ //$NON-NLS-2$ + } + persistenceService.write(peer, path.toFile().toURI()); + } + catch (Exception e) { + } + refresh.refresh(new Callback() { + @Override + protected void internalDone(Object caller, org.eclipse.core.runtime.IStatus status) { + final ILocatorNode node = lkup.lkupLocatorNode(peer); + getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (node != null) { + setSelection(new StructuredSelection(node)); + updateSelection(getSelection()); + } + } + }); + } + }); + } + else { + refresh.refresh(node, new Callback() { + @Override + protected void internalDone(Object caller, org.eclipse.core.runtime.IStatus status) { + final ILocatorNode node = lkup.lkupLocatorNode(peer); + getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (node != null) { + setSelection(new StructuredSelection(node)); + updateSelection(getSelection()); + } + } + }); + } + }); + } + } + }); + } + } + } + + protected void onButtonDeleteSelected() { + final ISelection sel = getViewer().getSelection(); + if (sel instanceof IStructuredSelection) { + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + Object element = ((IStructuredSelection)sel).getFirstElement(); + if (element instanceof ILocatorNode) { + doDelete((ILocatorNode)element); + ILocatorModelRefreshService refresh = ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class); + refresh.refresh(null); + } + } + }); + } + } + + protected void doDelete(ILocatorNode locatorNode) { + for (ILocatorNode child : locatorNode.getChildren(ILocatorNode.class)) { + doDelete(child); + } + + if (locatorNode.isStatic()) { + IURIPersistenceService persistenceService = ServiceManager.getInstance() + .getService(IURIPersistenceService.class); + try { + persistenceService.delete(locatorNode.isDiscovered() ? locatorNode + .getProperty(ILocatorNode.PROPERTY_STATIC_INSTANCE) : locatorNode + .getPeer(), null); + } + catch (Exception e) { + } + ILocatorModelUpdateService update = ModelManager.getLocatorModel() + .getService(ILocatorModelUpdateService.class); + update.remove(locatorNode.getPeer()); + } + } + + protected void onButtonRefreshSelected() { + final ISelection sel = getViewer().getSelection(); + if (sel instanceof IStructuredSelection) { + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + ILocatorModelRefreshService service = ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class); + Object element = ((IStructuredSelection)sel).getFirstElement(); + if (element instanceof ICategory) { + service.refresh(null); + } + if (element instanceof ILocatorNode) { + service.refresh((ILocatorNode)element, null); + } + } + }); + } + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#dispose() + */ + @Override + protected void dispose() { + super.dispose(); + ModelManager.getLocatorModel().removeListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#getInput() + */ + @Override + protected Object getInput() { + return ModelManager.getLocatorModel(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#getContentProvider() + */ + @Override + protected IContentProvider getContentProvider() { + return new ContentProvider(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#isValidSelection() + */ + @Override + protected boolean isValidSelection() { + boolean valid = false; + ISelection sel = getViewer().getSelection(); + if (sel instanceof IStructuredSelection) { + Object element = ((IStructuredSelection)sel).getFirstElement(); + valid = element instanceof ICategory || element instanceof ILocatorNode; + } + return valid; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#getDialogTitle() + */ + @Override + protected String getDialogTitle() { + return Messages.LocatorNodeSelectionDialog_dialogTitle; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#getTitle() + */ + @Override + protected String getTitle() { + return Messages.LocatorNodeSelectionDialog_title; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#getDefaultMessage() + */ + @Override + protected String getDefaultMessage() { + return Messages.LocatorNodeSelectionDialog_message; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelChanged(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel, org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode, boolean) + */ + @Override + public void modelChanged(ILocatorModel model, ILocatorNode locatorNode, boolean added) { + refresh(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelDisposed(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel) + */ + @Override + public void modelDisposed(ILocatorModel model) { + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#updateEnablement(org.eclipse.jface.viewers.TreeViewer) + */ + @Override + protected void updateEnablement(TreeViewer viewer) { + boolean valid = isValidSelection(); + + if (addButton != null && !addButton.isDisposed()) { + addButton.setEnabled(valid); + } + if (refreshButton != null && !refreshButton.isDisposed()) { + refreshButton.setEnabled(valid); + } + + if (deleteButton != null && !deleteButton.isDisposed()) { + valid = false; + ISelection sel = getViewer().getSelection(); + if (sel instanceof IStructuredSelection) { + Object element = ((IStructuredSelection)sel).getFirstElement(); + if (element instanceof ILocatorNode) { + valid = ((ILocatorNode)element).isStatic(); + } + } + deleteButton.setEnabled(valid); + } + + super.updateEnablement(viewer); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractTreeSelectionDialog#updateSelection(org.eclipse.jface.viewers.ISelection) + */ + @Override + protected void updateSelection(ISelection selection) { + ICategory category = CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_NEIGHBORHOOD, false); + if (selection instanceof IStructuredSelection) { + final Object element = ((IStructuredSelection)selection).getFirstElement(); + if (element instanceof ILocatorNode) { + final List<Object> treePath = new ArrayList<Object>(); + treePath.add(category); + treePath.add(element); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + IContainerModelNode container = ((ILocatorNode)element).getParent(); + while (container != null) { + treePath.add(1, container); + container = container.getParent(); + } + } + }); + + final TreePath path = new TreePath(treePath.toArray()); + + final AsyncCallbackCollector collector = new AsyncCallbackCollector(new Callback() { + @Override + protected void internalDone(Object caller, IStatus status) { + if (viewer != null && !viewer.getTree().isDisposed()) { + viewer.refresh(); + viewer.setSelection(new TreeSelection(path), true); + } + } + }, new UICallbackInvocationDelegate()); + for (Object pathNode : treePath) { + if (pathNode instanceof ILocatorNode) { + final ILocatorNode locatorNode = (ILocatorNode)pathNode; + IAsyncRefreshableCtx refreshCtx = (IAsyncRefreshableCtx)locatorNode.getAdapter(IAsyncRefreshableCtx.class); + if (refreshCtx.getQueryState(QueryType.CONTEXT) != QueryState.DONE || refreshCtx.getQueryState(QueryType.CHILD_LIST) != QueryState.DONE) { + final ICallback cb = locatorNode.isStatic() ? null : new AsyncCallbackCollector.SimpleCollectorCallback(collector); + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class).refresh(locatorNode, cb); + } + }); + } + } + } + collector.initDone(); + } + } + else { + viewer.expandToLevel(2); + viewer.setSelection(new StructuredSelection(category)); + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/PeerSelectionDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/PeerSelectionDialog.java deleted file mode 100644 index e47ef48a0..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/dialogs/PeerSelectionDialog.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved. - * 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.tcf.ui.dialogs; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.tcf.protocol.IPeer; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.callback.Callback; -import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil; -import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; -import org.eclipse.tcf.te.tcf.locator.model.ModelManager; -import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; -import org.eclipse.tcf.te.tcf.ui.nls.Messages; - -/** - * Peer selection dialog implementation. - */ -public class PeerSelectionDialog extends AbstractArraySelectionDialog implements ILocatorModelListener { - - /** - * Constructor. - * - * @param shell The shell used to view the dialog, or <code>null</code>. - */ - public PeerSelectionDialog(Shell shell) { - super(shell, IContextHelpIds.PEER_SELECTION_DIALOG); - - ModelManager.getLocatorModel().addListener(this); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#dispose() - */ - @Override - protected void dispose() { - super.dispose(); - ModelManager.getLocatorModel().removeListener(this); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#getInput() - */ - @Override - protected Object[] getInput() { - Assert.isTrue(!Protocol.isDispatchThread()); - final ILocatorModelRefreshService service = ModelManager.getLocatorModel().getService(ILocatorModelRefreshService.class); - if (service != null) { - final Callback cb = new Callback(); - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - service.refresh(cb); - } - }); - ExecutorsUtil.waitAndExecute(0, cb.getDoneConditionTester(null)); - } - return ModelManager.getLocatorModel().getPeers(); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#getDialogTitle() - */ - @Override - protected String getDialogTitle() { - return Messages.PeerSelectionDialog_dialogTitle; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#getTitle() - */ - @Override - protected String getTitle() { - return Messages.PeerSelectionDialog_title; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#getDefaultMessage() - */ - @Override - protected String getDefaultMessage() { - return Messages.PeerSelectionDialog_message; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelChanged(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel, org.eclipse.tcf.protocol.IPeer, boolean) - */ - @Override - public void modelChanged(ILocatorModel model, IPeer peer, boolean added) { - refresh(); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelDisposed(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel) - */ - @Override - public void modelDisposed(ILocatorModel model) { - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TcpTransportSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TcpTransportSection.java index 944285fb0..d73a4e75e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TcpTransportSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/editor/sections/TcpTransportSection.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.dialogs.IDialogSettings; @@ -31,11 +32,17 @@ import org.eclipse.tcf.te.core.nodes.interfaces.wire.IWireTypeNetwork; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.tcf.core.Tcf; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; import org.eclipse.tcf.te.tcf.core.interfaces.ITransportTypes; import org.eclipse.tcf.te.tcf.core.peers.Peer; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; import org.eclipse.tcf.te.tcf.ui.nls.Messages; +import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl; import org.eclipse.tcf.te.ui.controls.net.RemoteHostAddressControl; import org.eclipse.tcf.te.ui.controls.net.RemoteHostPortControl; import org.eclipse.tcf.te.ui.controls.validator.NameOrIPValidator; @@ -55,10 +62,12 @@ import org.eclipse.ui.forms.widgets.Section; * Transport section providing TCP transport only. */ public class TcpTransportSection extends AbstractSection implements IDataExchangeNode { + private BaseEditBrowseTextControl proxyControl = null; private MyRemoteHostAddressControl addressControl = null; private MyRemoteHostPortControl portControl = null; private boolean isAutoPort = false; + private String proxies = null; // Reference to the original data object protected IPeerNode od; @@ -208,11 +217,23 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang createClient(getSection(), form.getToolkit()); } + /** + * Constructor. + * + * @param form The parent managed form. Must not be <code>null</code>. + * @param parent The parent composite. Must not be <code>null</code>. + */ + public TcpTransportSection(IManagedForm form, Composite parent, boolean showTitleBar) { + super(form, parent, showTitleBar ? ExpandableComposite.EXPANDED : ExpandableComposite.NO_TITLE, showTitleBar); + createClient(getSection(), form.getToolkit()); + } + /* (non-Javadoc) * @see org.eclipse.ui.forms.AbstractFormPart#dispose() */ @Override public void dispose() { + if (proxyControl != null) { proxyControl.dispose(); proxyControl = null; } if (addressControl != null) { addressControl.dispose(); addressControl = null; } if (portControl != null) { portControl.dispose(); portControl = null; } super.dispose(); @@ -252,8 +273,17 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang Assert.isNotNull(client); section.setClient(client); + proxyControl = new BaseEditBrowseTextControl(null); + proxyControl.setParentControlIsInnerPanel(true); + proxyControl.setEditFieldLabel(Messages.TcpTransportSection_proxies_label); + proxyControl.setReadOnly(true); + proxyControl.setHasHistory(false); + proxyControl.setHideBrowseButton(true); + proxyControl.setupPanel(client); + addressControl = new MyRemoteHostAddressControl(); addressControl.setupPanel(client); + addressControl.getEditFieldControl().setFocus(); portControl = new MyRemoteHostPortControl(); portControl.setParentControlIsInnerPanel(true); @@ -325,6 +355,31 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang boolean isAutoPort = data.getBooleanProperty(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO); + if (proxyControl != null) { + proxies = data.getStringProperty(IPeerProperties.PROP_PROXIES); + IPeer[] proxyPeers = PeerDataHelper.decodePeerList(proxies); + String proxyInfo = ""; //$NON-NLS-1$ + for (final IPeer proxy : proxyPeers) { + final AtomicReference<ILocatorNode> locatorNode = new AtomicReference<ILocatorNode>(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + locatorNode.set(lkup.lkupLocatorNode(proxy)); + } + }); + if (proxyInfo.length() > 0) { + proxyInfo += " / "; //$NON-NLS-1$ + } + String name = locatorNode.get() != null ? locatorNode.get().getPeer().getName() : proxy.getID(); + if (name == null || name.trim().length() == 0) { + name = locatorNode.get() != null ? locatorNode.get().getPeer().getID() : proxy.getID(); + } + proxyInfo += name.trim(); + } + proxyControl.setEditFieldControlText(proxyInfo); + } + if (addressControl != null) { String ip = data.getStringProperty(IPeer.ATTR_IP_HOST); if (ip != null) @@ -394,6 +449,7 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang odc.setProperty(IPeer.ATTR_IP_HOST, node.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST)); odc.setProperty(IPeer.ATTR_IP_PORT, node.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT)); odc.setProperty(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO, node.getPeer().getAttributes().get(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO)); + odc.setProperty(IPeerProperties.PROP_PROXIES, node.getPeer().getAttributes().get(IPeerProperties.PROP_PROXIES)); // Initially, the working copy is a duplicate of the original data copy wc.setProperties(odc.getProperties()); @@ -426,6 +482,8 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang boolean isAutoPort = isAutoPort(); + data.setProperty(IPeerProperties.PROP_PROXIES, proxies); + if (addressControl != null) { String host = addressControl.getEditFieldControlText(); data.setProperty(IPeer.ATTR_IP_HOST, !"".equals(host) ? host : null); //$NON-NLS-1$ @@ -613,15 +671,21 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang } boolean autoPort = odc.getBooleanProperty(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO); - if (!autoPort && portControl != null) { String port = portControl.getEditFieldControlText(); String oldPort = odc.getStringProperty(IPeer.ATTR_IP_PORT); isDirty |= !port.equals(oldPort != null ? oldPort : ""); //$NON-NLS-1$ } - isDirty |= isAutoPort() != autoPort; + String newProxies = odc.getStringProperty(IPeerProperties.PROP_PROXIES); + if (proxies == null || proxies.trim().length() == 0) { + isDirty |= newProxies != null && newProxies.trim().length() > 0; + } + else { + isDirty |= newProxies == null || newProxies.trim().length() == 0; + } + // If dirty, mark the form part dirty. // Otherwise call refresh() to reset the dirty (and stale) flag markDirty(isDirty); @@ -638,6 +702,7 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang public void updateAttributes(IPropertiesContainer attributes) { Assert.isNotNull(attributes); + attributes.setProperty(IPeerProperties.PROP_PROXIES, null); attributes.setProperty(IPeer.ATTR_IP_HOST, null); attributes.setProperty(IPeer.ATTR_IP_PORT, null); attributes.setProperty(IWireTypeNetwork.PROPERTY_NETWORK_PORT_IS_AUTO, null); @@ -653,6 +718,7 @@ public class TcpTransportSection extends AbstractSection implements IDataExchang final Object input = od; // getManagedForm().getInput(); boolean enabled = !isReadOnly() && (!(input instanceof IPeerNode) || ((IPeerNode)input).getConnectState() == IConnectable.STATE_DISCONNECTED); + if (proxyControl != null) proxyControl.setEnabled(enabled); if (addressControl != null) addressControl.setEnabled(enabled); if (portControl != null) portControl.setEnabled(enabled && !isAutoPort); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/filter/RedirectPeersFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/filter/RedirectPeersFilter.java deleted file mode 100644 index 82dd4d08a..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/filter/RedirectPeersFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved. - * 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.tcf.ui.filter; - -import java.util.concurrent.atomic.AtomicReference; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.ui.views.interfaces.IRoot; - -/** - * Filter implementation filtering redirected peers from the root level. - */ -public class RedirectPeersFilter extends ViewerFilter { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - @Override - public boolean select(final Viewer viewer, final Object parentElement, final Object element) { - if (element instanceof IPeerNode && parentElement instanceof IRoot) { - final AtomicReference<IPeerNode> parent = new AtomicReference<IPeerNode>(); - Runnable runnable = new Runnable() { - @Override - public void run() { - parent.set(((IPeerNode)element).getParent(IPeerNode.class)); - } - }; - Assert.isTrue(!Protocol.isDispatchThread()); - Protocol.invokeAndWait(runnable); - - return parent.get() == null; - } - - return true; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ConnectPeerCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ConnectLocatorNodeCommandHandler.java index 3c00db584..3c759db9b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ConnectPeerCommandHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/ConnectLocatorNodeCommandHandler.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.ui.nls.Messages; import org.eclipse.tcf.te.ui.help.IContextHelpIds; @@ -37,7 +37,7 @@ import org.eclipse.ui.wizards.IWizardDescriptor; * Connect peer command handler implementation. */ @SuppressWarnings("restriction") -public class ConnectPeerCommandHandler extends AbstractHandler { +public class ConnectLocatorNodeCommandHandler extends AbstractHandler { /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) @@ -54,7 +54,7 @@ public class ConnectPeerCommandHandler extends AbstractHandler { // The selection contains only one element as multi element selections are not supported by this handler Object element = ((IStructuredSelection)selection).getFirstElement(); // The element must be of type IPeer - if (element instanceof IPeer) { + if (element instanceof ILocatorNode) { System.setProperty("NewWizard_" + IPeerNodeProperties.PROP_AUTO_CONNECT, Boolean.TRUE.toString()); //$NON-NLS-1$ // Get the list of enabled new wizards diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshLocatorNodeHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshLocatorNodeHandler.java new file mode 100644 index 000000000..305614c06 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshLocatorNodeHandler.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.ui.handler; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.model.ModelManager; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Locator node refresh handler implementation. + */ +public class RefreshLocatorNodeHandler extends AbstractHandler { + + /* (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + // Get the current selection + ISelection selection = HandlerUtil.getCurrentSelection(event); + + // The selection must be a structured selection and must not be empty + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + // The list of locator model instances to refresh + List<ILocatorNode> locatorNodesToRefresh = new ArrayList<ILocatorNode>(); + + // Iterate the selection and determine the model instances + Iterator<?> iterator = ((IStructuredSelection)selection).iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (element instanceof ILocatorNode) { + ILocatorNode node = (ILocatorNode)element; + + if (!locatorNodesToRefresh.contains(node)) { + locatorNodesToRefresh.add(node); + } + } + } + + final ILocatorModel model = ModelManager.getLocatorModel(); + + // Trigger an refresh on all determined models and wait for the + // refresh to complete. Once completed, fire the parent callback. + for (final ILocatorNode node : locatorNodesToRefresh) { + Runnable runnable = new Runnable() { + @Override + public void run() { + model.getService(ILocatorModelRefreshService.class).refresh(node, null); + } + }; + Protocol.invokeLater(runnable); + } + } + + return null; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshPeerNodeHandler.java index 49d72ea6c..7b705e9de 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RefreshPeerNodeHandler.java @@ -36,7 +36,7 @@ import org.eclipse.ui.handlers.HandlerUtil; /** * Refresh handler implementation. */ -public class RefreshHandler extends AbstractHandler { +public class RefreshPeerNodeHandler extends AbstractHandler { /* (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java index 76c02623e..1dcc07f40 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java @@ -45,7 +45,7 @@ public interface IContextHelpIds { /** * Peer selection dialog. */ - public final static String PEER_SELECTION_DIALOG = PREFIX + "PeerSelectionDialog"; //$NON-NLS-1$ + public final static String LOCATOR_NODE_SELECTION_DIALOG = PREFIX + "LocatorNodeSelectionDialog"; //$NON-NLS-1$ /** * Peer node selection dialog. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/ImageConsts.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/ImageConsts.java index afb481981..62c78bcff 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/ImageConsts.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/ImageConsts.java @@ -71,6 +71,11 @@ public interface ImageConsts { public static final String PEER_DISCOVERED = "PeerObjectDiscovered"; //$NON-NLS-1$ /** + * The key to access the base peer object image (static). + */ + public static final String PEER_STATIC = "PeerObjectStatic"; //$NON-NLS-1$ + + /** * The key to access the new peer wizard image. */ public static final String NEW_PEER_NODE = "NewPeerObject"; //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java index 84a344d45..78089ada8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java @@ -12,6 +12,7 @@ package org.eclipse.tcf.te.tcf.ui.internal.adapters; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.ui.views.editor.EditorInput; import org.eclipse.tcf.te.ui.views.interfaces.IEditorSaveAsAdapter; @@ -42,6 +43,12 @@ public class AdapterFactory implements IAdapterFactory { */ @Override public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof ILocatorNode) { + if (ILabelProvider.class.equals(adapterType)) { + return labelProvider; + } + } + if (adaptableObject instanceof IPeer) { if (ILabelProvider.class.equals(adapterType)) { return labelProvider; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/MenuService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/MenuService.java index c998a7e2e..d33109163 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/MenuService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/services/MenuService.java @@ -9,9 +9,9 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.ui.internal.services; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.runtime.services.AbstractService; import org.eclipse.tcf.te.runtime.services.interfaces.IMenuService; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * Menu service implementation. @@ -24,7 +24,7 @@ public class MenuService extends AbstractService implements IMenuService { @Override public boolean isVisible(Object context, String contributionID) { - if (context instanceof IPeer && contributionID.endsWith("NewActionProvider")) { //$NON-NLS-1$ + if (context instanceof ILocatorNode && contributionID.endsWith("NewActionProvider")) { //$NON-NLS-1$ return false; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerPropertiesSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerPropertiesSection.java index 82aa2c894..c845946a2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerPropertiesSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerPropertiesSection.java @@ -17,6 +17,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.ui.nls.Messages; import org.eclipse.tcf.te.tcf.ui.tabbed.AbstractMapPropertiesSection; import org.eclipse.ui.IWorkbenchPart; @@ -35,7 +36,10 @@ public class PeerPropertiesSection extends AbstractMapPropertiesSection { super.setInput(part, selection); Assert.isTrue(selection instanceof IStructuredSelection); Object input = ((IStructuredSelection) selection).getFirstElement(); - if (input instanceof IPeer) { + if (input instanceof ILocatorNode) { + peer = ((ILocatorNode)input).getPeer(); + } + else if (input instanceof IPeer) { peer = (IPeer)input; } else { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerSectionFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerSectionFilter.java index ae244b0d9..507ed1b93 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerSectionFilter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/tabbed/PeerSectionFilter.java @@ -11,6 +11,7 @@ package org.eclipse.tcf.te.tcf.ui.internal.tabbed; import org.eclipse.jface.viewers.IFilter; import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; /** * Peer general section filter implementation. @@ -22,7 +23,7 @@ public class PeerSectionFilter implements IFilter { */ @Override public boolean select(Object element) { - return element instanceof IPeer; + return element instanceof IPeer || element instanceof ILocatorNode; } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProvider.java index 626201369..81b88bbcb 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProvider.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProvider.java @@ -11,6 +11,7 @@ package org.eclipse.tcf.te.tcf.ui.navigator; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.Platform; @@ -22,8 +23,10 @@ import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPendingOperationNode; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.ModelManager; import org.eclipse.tcf.te.tcf.ui.activator.UIPlugin; @@ -169,7 +172,12 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent // If the parent element is a category, than we assume // the locator model as parent element. if (parentElement instanceof ICategory) { - parentElement = ModelManager.getPeerModel(); + if (IUIConstants.ID_CAT_NEIGHBORHOOD.equals(catID)) { + parentElement = ModelManager.getLocatorModel(); + } + else { + parentElement = ModelManager.getPeerModel(); + } } // If the parent element is the root element and "all" // categories are hidden, assume the locator model as parent element @@ -225,17 +233,6 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent } candidates.add(0, newConfigNode); } - else if (IUIConstants.ID_CAT_NEIGHBORHOOD.equals(catID)) { - for (IPeer peer : ModelManager.getLocatorModel().getPeers()) { - if (isFiltered(peer)) { - continue; - } - - if (!candidates.contains(peer)) { - candidates.add(peer); - } - } - } else if (catID != null) { for (IPeerNode peerNode : peerNodes) { if (isFiltered(peerNode)) { @@ -267,7 +264,30 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent } } - children = candidates.toArray(new Object[candidates.size()]); + children = candidates.toArray(); + } + else if (parentElement instanceof ILocatorModel) { + final List<Object> candidates = new ArrayList<Object>(); + if (IUIConstants.ID_CAT_NEIGHBORHOOD.equals(catID)) { + for (ILocatorNode locatorNode : ModelManager.getLocatorModel().getLocatorNodes()) { + if (isFiltered(locatorNode.getPeer())) { + continue; + } + + if (!candidates.contains(locatorNode)) { + candidates.add(locatorNode); + } + } + } + else { + candidates.add(CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_NEIGHBORHOOD, false)); + } + children = candidates.toArray(); + } + else if (parentElement instanceof ILocatorNode) { + ILocatorNode locatorNode = (ILocatorNode)parentElement; + + children = locatorNode.getChildren(); } return children; @@ -287,9 +307,22 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent */ @Override public Object getParent(final Object element) { - // If it is a peer model node, return the parent locator model - if (element instanceof IPeerNode) { - // Determine the parent category node + // If it is a peer model node, return the parent peer model + if (element instanceof ILocatorNode) { + final AtomicReference<Object> parent = new AtomicReference<Object>(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + parent.set(((ILocatorNode)element).getParent()); + } + }); + if (parent.get() == null) { + return CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_NEIGHBORHOOD, false); + } + return parent.get(); + } + else if (element instanceof IPeerNode) { + // Determine the parent category node1 ICategory category = null; String[] categoryIds = Managers.getCategoryManager().getCategoryIds(((IPeerNode)element).getPeerId()); // If we have more than one, take the first one as parent category. @@ -300,6 +333,10 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent return category != null ? category : ((IPeerNode)element).getModel(); } + else if (element instanceof IPendingOperationNode) { + return ((IPendingOperationNode)element).getParent(); + } + return null; } @@ -336,6 +373,11 @@ public class ContentProvider implements ICommonContentProvider, ITreePathContent */ @Override public boolean hasChildren(Object element) { + + if (element instanceof ILocatorNode) { + return ((ILocatorNode)element).hasChildren(); + } + Object[] children = getChildren(element); if (children != null && children.length > 0 && navFilterService != null) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/LocatorModelListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/LocatorModelListener.java index fe45be690..23549c679 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/LocatorModelListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/LocatorModelListener.java @@ -12,9 +12,9 @@ package org.eclipse.tcf.te.tcf.ui.navigator; import org.eclipse.core.runtime.Assert; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Tree; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.ui.navigator.CommonViewer; @@ -40,10 +40,10 @@ public class LocatorModelListener implements ILocatorModelListener { } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelChanged(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel, org.eclipse.tcf.protocol.IPeer, boolean) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.ILocatorModelListener#modelChanged(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel, org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode, boolean) */ @Override - public void modelChanged(ILocatorModel model, IPeer peer, boolean added) { + public void modelChanged(ILocatorModel model, ILocatorNode locatorNode, boolean added) { if (parentModel.equals(model)) { // Locator model changed -> refresh the tree Tree tree = viewer.getTree(); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/PeerLabelProviderDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/PeerLabelProviderDelegate.java index 9bb4bc326..ef755bc01 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/PeerLabelProviderDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/PeerLabelProviderDelegate.java @@ -19,8 +19,10 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; import org.eclipse.tcf.te.runtime.services.interfaces.delegates.ILabelProviderDelegate; import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; import org.eclipse.tcf.te.tcf.locator.model.ModelManager; @@ -39,7 +41,7 @@ public class PeerLabelProviderDelegate extends LabelProvider implements ILabelDe */ @Override public String getText(final Object element) { - if (element instanceof IPeerNode || element instanceof IPeer) { + if (element instanceof IPeerNode) { StringBuilder builder = new StringBuilder(); // Copy the peer node and peer attributes @@ -52,8 +54,8 @@ public class PeerLabelProviderDelegate extends LabelProvider implements ILabelDe attrs.putAll(((IPeerNode)element).getProperties()); attrs.putAll(((IPeerNode)element).getPeer().getAttributes()); } - else if (element instanceof IPeer) { - attrs.putAll(((IPeer)element).getAttributes()); + else if (element instanceof ILocatorNode) { + attrs.putAll((((ILocatorNode)element).getPeer()).getAttributes()); } } }; @@ -93,6 +95,16 @@ public class PeerLabelProviderDelegate extends LabelProvider implements ILabelDe return label; } } + else if (element instanceof ILocatorNode) { + String name = ((ILocatorNode)element).getName(); + if (name == null) { + name = ((ILocatorNode)element).getPeer().getID(); + } + return name; + } + else if (element instanceof IModelNode) { + return ((IModelNode)element).getName(); + } return null; } @@ -135,12 +147,18 @@ public class PeerLabelProviderDelegate extends LabelProvider implements ILabelDe * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ @Override - public Image getImage(final Object element) { + public Image getImage(Object element) { if (element instanceof IPeerNode) { return UIPlugin.getImage(ImageConsts.CONNECTION); } - if (element instanceof IPeer) { - return UIPlugin.getImage(ImageConsts.PEER_DISCOVERED); + if (element instanceof ILocatorNode) { + if (((ILocatorNode)element).isDiscovered()) { + return UIPlugin.getImage(ImageConsts.PEER_DISCOVERED); + } + return UIPlugin.getImage(ImageConsts.PEER_STATIC); + } + else if (element instanceof IModelNode) { + return UIPlugin.getImage(((IModelNode)element).getImageId()); } return super.getImage(element); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java index 273ec1ab2..f47414d79 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java @@ -69,6 +69,7 @@ public class Messages extends NLS { public static String TcpTransportSection_title; public static String TcpTransportSection_description; + public static String TcpTransportSection_proxies_label; public static String ServicesSection_title; public static String ServicesSection_description; @@ -144,9 +145,16 @@ public class Messages extends NLS { public static String DeleteHandlerDelegate_MsgDeleteOnePeer; - public static String PeerSelectionDialog_dialogTitle; - public static String PeerSelectionDialog_title; - public static String PeerSelectionDialog_message; + public static String LocatorNodeSelectionDialog_dialogTitle; + public static String LocatorNodeSelectionDialog_title; + public static String LocatorNodeSelectionDialog_message; + public static String LocatorNodeSelectionDialog_button_add; + public static String LocatorNodeSelectionDialog_button_delete; + public static String LocatorNodeSelectionDialog_button_refresh; + + public static String LocatorNodeSelectionDialog_add_dialogTitle; + public static String LocatorNodeSelectionDialog_add_title; + public static String LocatorNodeSelectionDialog_add_message; public static String PeerNodeSelectionDialog_dialogTitle; public static String PeerNodeSelectionDialog_title; @@ -186,6 +194,7 @@ public class Messages extends NLS { public static String TargetSelectorSection_title; public static String TargetSelectorSection_button_enableSimulator; + public static String TargetSelectorSection_button_configure; public static String TargetSelectorSection_button_enableReal; public static String SimulatorTypeSelectionControl_label; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties index ded8e3344..f39dd4d0d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties @@ -28,6 +28,7 @@ TransportSection_description=Select the transport type used to communicate with TcpTransportSection_title=Address TcpTransportSection_description=Specify the target agent's address and port. +TcpTransportSection_proxies_label=Proxy(s): ServicesSection_title=Services ServicesSection_description=This section describes the services. @@ -48,9 +49,9 @@ NewTargetWizardPage_description=Specify a name and attributes of the target to c NewTargetWizardPage_section_transportType=Specify the transport type and properties: NewTargetWizardPage_section_attributes=Specify additional target attributes: NewTargetWizardPage_error_nameInUse=This connection name is already used. Please choose a unique name. -NewTargetWizardPage_PeerSelectionDialog_dialogTitle=Browse +NewTargetWizardPage_PeerSelectionDialog_dialogTitle=Configure NewTargetWizardPage_PeerSelectionDialog_title=Select Target -NewTargetWizardPage_PeerSelectionDialog_message=Select the discovered target to create a connection for. +NewTargetWizardPage_PeerSelectionDialog_message=Select the discovered target to create a connection for.\nAdd a proxy or target if not discovered automatically. PeerIdControl_label=Target ID: @@ -100,9 +101,16 @@ DeleteHandlerDelegate_DialogTitle=Confirm Delete DeleteHandlerDelegate_MsgDeleteMultiplePeers=Are you sure you want to delete these {0} connections? DeleteHandlerDelegate_MsgDeleteOnePeer=Are you sure you want to delete connection ''{0}''? -PeerSelectionDialog_dialogTitle=Select -PeerSelectionDialog_title=Select Connection -PeerSelectionDialog_message=Select the discovered connection for the operation to perform. +LocatorNodeSelectionDialog_dialogTitle=Select +LocatorNodeSelectionDialog_title=Select Target +LocatorNodeSelectionDialog_message=Select the discovered target for the operation to perform.\n +LocatorNodeSelectionDialog_button_add=Add... +LocatorNodeSelectionDialog_button_delete=Delete +LocatorNodeSelectionDialog_button_refresh=Refresh + +LocatorNodeSelectionDialog_add_dialogTitle=Add +LocatorNodeSelectionDialog_add_title=Add a proxy or target +LocatorNodeSelectionDialog_add_message=Enter address and port of a not discovered proxy or target. PeerNodeSelectionDialog_dialogTitle=Select PeerNodeSelectionDialog_title=Select Connection @@ -143,7 +151,8 @@ ConnectableToolbarCommandHandler_tooltip_connect=Connect ''{0}'' ConnectableToolbarCommandHandler_tooltip_disconnect=Disconnect ''{0}'' TargetSelectorSection_title=Target -TargetSelectorSection_button_enableReal=Use running Target: +TargetSelectorSection_button_enableReal=Use Target: +TargetSelectorSection_button_configure=Configure... TargetSelectorSection_button_enableSimulator=Start local Simulator: SimulatorTypeSelectionControl_label=Simulator Type: diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/sections/SimulatorTypeSelectionSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/sections/SimulatorTypeSelectionSection.java index 0ebd0a624..21204c6b0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/sections/SimulatorTypeSelectionSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/sections/SimulatorTypeSelectionSection.java @@ -18,7 +18,8 @@ import java.util.Set; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; @@ -33,10 +34,11 @@ import org.eclipse.tcf.te.core.interfaces.IConnectable; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.tcf.core.peers.Peer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.ui.controls.SimulatorTypeSelectionControl; -import org.eclipse.tcf.te.tcf.ui.dialogs.PeerSelectionDialog; +import org.eclipse.tcf.te.tcf.ui.dialogs.LocatorNodeSelectionDialog; import org.eclipse.tcf.te.tcf.ui.nls.Messages; import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl; import org.eclipse.tcf.te.ui.forms.parts.AbstractSection; @@ -66,7 +68,7 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID protected static final int SELECTION_REAL = 0; protected static final int SELECTION_SIM = 1; - protected String selectedPeerId = null; + protected ILocatorNode selectedLocatorNode = null; /** * Constructor. @@ -151,13 +153,13 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID if (target.isLabelControlSelected()) { onSelectionChanged(SELECTION_REAL); if (!isUpdating()) { - onPeerChanged(false, true, selectedPeerId, selectedPeerId); + onLocatorNodeChanged(false, true, selectedLocatorNode, selectedLocatorNode); } } } @Override protected void onButtonControlSelected() { - PeerSelectionDialog dialog = new PeerSelectionDialog(null) { + LocatorNodeSelectionDialog dialog = new LocatorNodeSelectionDialog(null) { @Override protected String getDialogTitle() { return Messages.NewTargetWizardPage_PeerSelectionDialog_dialogTitle; @@ -171,22 +173,30 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID return Messages.NewTargetWizardPage_PeerSelectionDialog_message; } @Override - protected void configureTableViewer(TableViewer viewer) { - super.configureTableViewer(viewer); + protected void configureTreeViewer(TreeViewer viewer) { + super.configureTreeViewer(viewer); viewer.setFilters(getViewerFilters()); } }; + ILocatorNode locatorNode = getLocatorNode(); + + dialog.setSelection(locatorNode != null ? new StructuredSelection(locatorNode) : null); // Open the dialog if (dialog.open() == Window.OK) { // Get the selected proxy from the dialog ISelection selection = dialog.getSelection(); - if (selection instanceof IStructuredSelection && !selection.isEmpty() && ((IStructuredSelection)selection).getFirstElement() instanceof IPeer) { - String oldPeerId = selectedPeerId; - IPeer selectedPeer = (IPeer)((IStructuredSelection)selection).getFirstElement(); - selectedPeerId = selectedPeer != null ? selectedPeer.getID() : null; + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + Object element = ((IStructuredSelection)selection).getFirstElement(); + ILocatorNode oldLocatorNode = selectedLocatorNode; + if (element instanceof ILocatorNode) { + selectedLocatorNode = (ILocatorNode)element; + } + else { + selectedLocatorNode = null; + } dataChanged(null); - onPeerChanged(isLabelControlSelected(), isLabelControlSelected(), oldPeerId, selectedPeerId); + onLocatorNodeChanged(isLabelControlSelected(), isLabelControlSelected(), oldLocatorNode, selectedLocatorNode); } } } @@ -195,6 +205,7 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID target.setLabelButtonStyle(SWT.RADIO); target.setParentControlIsInnerPanel(true); target.setEditFieldLabel(Messages.TargetSelectorSection_button_enableReal); + target.setButtonLabel(Messages.TargetSelectorSection_button_configure); target.setHasHistory(false); target.setHideEditFieldControl(true); target.setReadOnly(true); @@ -242,6 +253,14 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID } /** + * Get the selection for the target browse dialog. + * @return The locator node that should be selected in the dialog or <code>null</code>. + */ + protected ILocatorNode getLocatorNode() { + return selectedLocatorNode; + } + + /** * Called on radio button selection changed. * @param selectionType The new selected simulator. */ @@ -262,14 +281,14 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID } /** - * Called on target enabled and selected peer changed. + * Called on target enabled and selected locator node changed. * * @param oldEnabled The old target enabled action. * @param newEnabled The new target enabled action. - * @param oldPeerId The old selected peer id. - * @param newPeerId The new selected peer id. + * @param oldLocatorNode The old selected locator node id. + * @param newLocatorNode The new selected locator node id. */ - protected void onPeerChanged(boolean oldEnabled, boolean newEnabled, String oldPeerId, String newPeerId) { + protected void onLocatorNodeChanged(boolean oldEnabled, boolean newEnabled, ILocatorNode oldLocatorNode, ILocatorNode newLocatorNode) { } /** @@ -313,7 +332,6 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID if (target != null) { target.setLabelControlSelection(!data.getBooleanProperty(IPeerNodeProperties.PROP_SIM_ENABLED)); - selectedPeerId = data.getStringProperty(IPeerNodeProperties.PROP_PEER_ID); } onSelectionChanged(data.getBooleanProperty(IPeerNodeProperties.PROP_SIM_ENABLED) ? SELECTION_SIM : SELECTION_REAL); @@ -409,7 +427,6 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID if (target != null) { data.setProperty(IPeerNodeProperties.PROP_SIM_ENABLED, target.isLabelControlSelected()); } - data.setProperty(IPeerNodeProperties.PROP_PEER_ID, selectedPeerId); if (simulator != null) { data.setProperty(IPeerNodeProperties.PROP_SIM_ENABLED, simulator.isLabelControlSelected()); @@ -550,14 +567,6 @@ public class SimulatorTypeSelectionSection extends AbstractSection implements ID isDirty |= (oldEnabled != target.isLabelControlSelected()); } - String oldPeerId = odc.getStringProperty(IPeerNodeProperties.PROP_PEER_ID); - String newPeerId = selectedPeerId; - if (newPeerId == null || "".equals(newPeerId)) { //$NON-NLS-1$ - isDirty |= oldPeerId != null && !"".equals(oldPeerId); //$NON-NLS-1$ - } else { - isDirty |= !newPeerId.equals(oldPeerId); - } - if (simulator != null) { if (simulator.isLabelControlSelected()) { String newType = simulator.getSelectedSimulatorId(); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewWizard.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewWizard.java index 809b2d239..e5f31b8b5 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewWizard.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/NewWizard.java @@ -32,7 +32,9 @@ import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; import org.eclipse.tcf.te.tcf.core.peers.Peer; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; @@ -75,9 +77,11 @@ public class NewWizard extends AbstractNewConfigWizard { } protected boolean isAllowedForeignAttribute(String key) { - return key.equals(IPeer.ATTR_TRANSPORT_NAME) || + return key.equals(IPeer.ATTR_NAME) || + key.equals(IPeer.ATTR_TRANSPORT_NAME) || key.equals(IPeer.ATTR_IP_HOST) || key.equals(IPeer.ATTR_IP_PORT) || + key.equals(IPeerProperties.PROP_PROXIES) || key.equals(IPeerNodeProperties.PROP_AUTO_CONNECT); } @@ -92,6 +96,9 @@ public class NewWizard extends AbstractNewConfigWizard { if (selection.getFirstElement() instanceof IPeer) { peer = (IPeer)selection.getFirstElement(); } + else if (selection.getFirstElement() instanceof ILocatorNode) { + peer = ((ILocatorNode)selection.getFirstElement()).getPeer(); + } else if (selection.getFirstElement() instanceof IPeerNode) { peer = ((IPeerNode)selection.getFirstElement()).getPeer(); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java index 7c4ec784c..cae5e3a20 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java @@ -10,9 +10,11 @@ package org.eclipse.tcf.te.tcf.ui.wizards.pages; import java.util.ArrayList; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.dialogs.Dialog; @@ -21,6 +23,7 @@ import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -29,12 +32,18 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.tcf.core.TransientPeer; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; +import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties; import org.eclipse.tcf.te.tcf.core.interfaces.ITransportTypes; +import org.eclipse.tcf.te.tcf.core.util.persistence.PeerDataHelper; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; import org.eclipse.tcf.te.tcf.locator.model.ModelManager; import org.eclipse.tcf.te.tcf.ui.controls.CustomTransportPanel; import org.eclipse.tcf.te.tcf.ui.controls.PeerAttributesTablePart; @@ -43,9 +52,10 @@ import org.eclipse.tcf.te.tcf.ui.controls.PipeTransportPanel; import org.eclipse.tcf.te.tcf.ui.controls.TcpTransportPanel; import org.eclipse.tcf.te.tcf.ui.controls.TransportTypeControl; import org.eclipse.tcf.te.tcf.ui.controls.TransportTypePanelControl; -import org.eclipse.tcf.te.tcf.ui.dialogs.PeerSelectionDialog; +import org.eclipse.tcf.te.tcf.ui.dialogs.LocatorNodeSelectionDialog; import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; import org.eclipse.tcf.te.tcf.ui.nls.Messages; +import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl; import org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel; import org.eclipse.tcf.te.ui.controls.validator.RegexValidator; import org.eclipse.tcf.te.ui.controls.validator.TextValidator; @@ -65,10 +75,12 @@ import org.eclipse.ui.forms.widgets.Section; */ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements IDataExchangeNode { private PeerNameControl peerNameControl; + BaseEditBrowseTextControl proxyControl = null; TransportTypeControl transportTypeControl; TransportTypePanelControl transportTypePanelControl; private PeerAttributesTablePart tablePart; /* default */ Button connect = null; + String proxies = null; private FormToolkit toolkit = null; @@ -261,7 +273,7 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements } @Override protected void onButtonControlSelected() { - PeerSelectionDialog dialog = new PeerSelectionDialog(null) { + LocatorNodeSelectionDialog dialog = new LocatorNodeSelectionDialog(null) { @Override protected String getDialogTitle() { return Messages.NewTargetWizardPage_PeerSelectionDialog_dialogTitle; @@ -276,22 +288,32 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements } }; + ILocatorNode locatorNode = getLocatorNode(); + + dialog.setSelection(locatorNode != null ? new StructuredSelection(locatorNode) : null); + // Open the dialog if (dialog.open() == Window.OK) { // Get the selected proxy from the dialog ISelection selection = dialog.getSelection(); - if (selection instanceof IStructuredSelection && !selection.isEmpty() && ((IStructuredSelection)selection).getFirstElement() instanceof IPeer) { - final IPeer peer = (IPeer)((IStructuredSelection)selection).getFirstElement(); - final IPropertiesContainer data = new PropertiesContainer(); - Protocol.invokeAndWait(new Runnable() { - @Override - public void run() { - for (Entry<String, String> attribute : peer.getAttributes().entrySet()) { - data.setProperty(attribute.getKey(), attribute.getValue()); - } - } - }); - setupData(data); + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + if (((IStructuredSelection)selection).getFirstElement() instanceof ILocatorNode) { + final IPeer peer = ((ILocatorNode)((IStructuredSelection)selection).getFirstElement()).getPeer(); + final IPropertiesContainer data = new PropertiesContainer(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + for (Entry<String, String> attribute : peer.getAttributes().entrySet()) { + data.setProperty(attribute.getKey(), attribute.getValue()); + } + } + }); + setupData(data); + } + else { + proxies = null; + proxyControl.setEditFieldControlText(""); //$NON-NLS-1$ + } } } } @@ -316,6 +338,17 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements createEmptySpace(client, 5, 2, toolkit); + proxyControl = new BaseEditBrowseTextControl(null); + proxyControl.setParentControlIsInnerPanel(false); + proxyControl.setHideBrowseButton(true); + proxyControl.setReadOnly(true); + proxyControl.setIsGroup(false); + proxyControl.setHasHistory(false); + proxyControl.setEditFieldLabel(Messages.TcpTransportSection_proxies_label); + proxyControl.setupPanel(client); + + createEmptySpace(client, 5, 2, toolkit); + // Create and configure the transport type section Section transportTypeSection = toolkit.createSection(client, ExpandableComposite.TITLE_BAR); transportTypeSection.setText(Messages.NewTargetWizardPage_section_transportType); @@ -384,6 +417,40 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements initializeUsedNameList(); } + protected ILocatorNode getLocatorNode() { + final AtomicReference<ILocatorNode> selectedLocatorNode = new AtomicReference<ILocatorNode>(); + if (transportTypeControl.isValid() && transportTypePanelControl.isValid()) { + final IPropertiesContainer transportData = new PropertiesContainer(); + extractData(transportData); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + String proxy = transportData.getStringProperty(IPeerProperties.PROP_PROXIES); + String host = transportData.getStringProperty(IPeer.ATTR_IP_HOST); + String port = transportData.getStringProperty(IPeer.ATTR_IP_PORT); + String transport = transportData.getStringProperty(IPeer.ATTR_TRANSPORT_NAME); + String id = transport + ":" + host + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$ + Map<String, String> attrs = new HashMap<String, String>(); + attrs.put(IPeer.ATTR_ID, id); + attrs.put(IPeer.ATTR_IP_HOST, host); + attrs.put(IPeer.ATTR_IP_PORT, port); + attrs.put(IPeer.ATTR_TRANSPORT_NAME, transport); + attrs.put(IPeerProperties.PROP_PROXIES, proxy); + IPeer peer = new TransientPeer(attrs); + ILocatorModelLookupService lkup = ModelManager.getLocatorModel() + .getService(ILocatorModelLookupService.class); + selectedLocatorNode.set(lkup.lkupLocatorNode(peer)); + if (selectedLocatorNode.get() == null) { + ILocatorModelUpdateService update = ModelManager.getLocatorModel() + .getService(ILocatorModelUpdateService.class); + selectedLocatorNode.set(update.add(peer, true)); + } + } + }); + } + return selectedLocatorNode.get(); + } + /** * Creates the peer attributes table controls. * @@ -450,6 +517,31 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements @Override public void setupData(IPropertiesContainer data) { + if (proxyControl != null) { + proxies = data.getStringProperty(IPeerProperties.PROP_PROXIES); + IPeer[] proxyPeers = PeerDataHelper.decodePeerList(proxies); + String proxyInfo = ""; //$NON-NLS-1$ + for (final IPeer proxy : proxyPeers) { + final AtomicReference<ILocatorNode> locatorNode = new AtomicReference<ILocatorNode>(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + ILocatorModelLookupService lkup = ModelManager.getLocatorModel().getService(ILocatorModelLookupService.class); + locatorNode.set(lkup.lkupLocatorNode(proxy)); + } + }); + if (proxyInfo.length() > 0) { + proxyInfo += " / "; //$NON-NLS-1$ + } + String name = locatorNode.get() != null ? locatorNode.get().getPeer().getName() : proxy.getID(); + if (name == null || name.trim().length() == 0) { + name = locatorNode.get() != null ? locatorNode.get().getPeer().getID() : proxy.getID(); + } + proxyInfo += name.trim(); + } + proxyControl.setEditFieldControlText(proxyInfo); + } + if (data.containsKey(IPeer.ATTR_NAME) && peerNameControl != null) { String name = data.getStringProperty(IPeer.ATTR_NAME); int i = 1; @@ -489,6 +581,8 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements peerAttributes.setProperty(IPeer.ATTR_ID, uuid.toString()); + peerAttributes.setProperty(IPeerProperties.PROP_PROXIES, proxies); + String value = peerNameControl != null ? peerNameControl.getEditFieldControlText() : null; if (value != null && !"".equals(value)) peerAttributes.setProperty(IPeer.ATTR_NAME, value); //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseEditBrowseTextControl.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseEditBrowseTextControl.java index ebafd9309..3df81a70f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseEditBrowseTextControl.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseEditBrowseTextControl.java @@ -852,7 +852,7 @@ public class BaseEditBrowseTextControl extends AbstractDecoratedDialogPageContro } else { int style = SWT.SINGLE; if (isReadOnly()) { - style |= SWT.READ_ONLY; + style |= SWT.READ_ONLY | SWT.NO_FOCUS; } editField = toolkit != null ? toolkit.createText(parent, null, doAdjustEditFieldControlStyles(SWT.BORDER | style)) : new Text(parent, doAdjustEditFieldControlStyles(SWT.BORDER | style)); ((Text)editField).addModifyListener(new ModifyListener() { |