diff options
author | Uwe Stieber | 2012-01-03 14:38:43 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-01-03 14:38:43 +0000 |
commit | 647f7c346abf597c5cc614fc4c70e627aa8638cb (patch) | |
tree | ce6025714eed08b47b9e157e0901782d8e7fec1e | |
parent | ebaf42b47ff41f8cc6bc68aa8d0784f7a97f21d7 (diff) | |
download | org.eclipse.tcf-647f7c346abf597c5cc614fc4c70e627aa8638cb.tar.gz org.eclipse.tcf-647f7c346abf597c5cc614fc4c70e627aa8638cb.tar.xz org.eclipse.tcf-647f7c346abf597c5cc614fc4c70e627aa8638cb.zip |
Target Explorer: Reworked working set support
49 files changed, 2042 insertions, 692 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java index e4a90ec62..4f1f44f26 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/launcher/ScriptLauncher.java @@ -36,7 +36,7 @@ import org.eclipse.tcf.te.tcf.core.scripting.interfaces.IScriptLauncherPropertie import org.eclipse.tcf.te.tcf.core.scripting.nls.Messages;
import org.eclipse.tcf.te.tcf.core.scripting.parser.Parser;
import org.eclipse.tcf.te.tcf.core.scripting.parser.Token;
-import org.eclipse.tcf.te.tcf.core.utils.JSONUtils;
+import org.eclipse.tcf.te.tcf.core.util.JSONUtils;
/**
* Script launcher implementation.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF index e14b41336..906fb8842 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF @@ -13,12 +13,16 @@ Bundle-ActivationPolicy: lazy Bundle-Localization: plugin Export-Package: org.eclipse.tcf.te.tcf.core, org.eclipse.tcf.te.tcf.core.activator;x-internal:=true, + org.eclipse.tcf.te.tcf.core.concurrent, + org.eclipse.tcf.te.tcf.core.concurrent.interfaces, + org.eclipse.tcf.te.tcf.core.concurrent.internal;x-internal:=true, org.eclipse.tcf.te.tcf.core.interfaces, - org.eclipse.tcf.te.tcf.core.interfaces.listeners, + org.eclipse.tcf.te.tcf.core.interfaces.tracing, org.eclipse.tcf.te.tcf.core.internal;x-internal:=true, - org.eclipse.tcf.te.tcf.core.internal.interfaces;x-internal:=true, - org.eclipse.tcf.te.tcf.core.internal.listener;x-internal:=true, - org.eclipse.tcf.te.tcf.core.internal.nls;x-internal:=true, org.eclipse.tcf.te.tcf.core.internal.utils;x-internal:=true, + org.eclipse.tcf.te.tcf.core.listeners;x-internal:=true, + org.eclipse.tcf.te.tcf.core.listeners.interfaces, + org.eclipse.tcf.te.tcf.core.nls;x-internal:=true, org.eclipse.tcf.te.tcf.core.streams, - org.eclipse.tcf.te.tcf.core.utils + org.eclipse.tcf.te.tcf.core.util, + org.eclipse.tcf.te.tcf.core.util.persistence diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/Tcf.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/Tcf.java index 6a7bcbfc1..1e10366a4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/Tcf.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/Tcf.java @@ -19,12 +19,11 @@ import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.protocol.Protocol.ChannelOpenListener; import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; -import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener; -import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IProtocolStateChangeListener; import org.eclipse.tcf.te.tcf.core.internal.ChannelManager; import org.eclipse.tcf.te.tcf.core.internal.Startup; -import org.eclipse.tcf.te.tcf.core.internal.interfaces.IChannelOpenListener; -import org.eclipse.tcf.te.tcf.core.internal.listener.InternalChannelOpenListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelOpenListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IProtocolStateChangeListener; /** @@ -188,7 +187,7 @@ public final class Tcf { // Create and register the global channel open listener if (tcf.channelOpenListener == null) { - tcf.channelOpenListener = new InternalChannelOpenListener(); + tcf.channelOpenListener = new org.eclipse.tcf.te.tcf.core.listeners.ChannelOpenListener(); Protocol.addChannelOpenListener(tcf.channelOpenListener); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/BlockingCallProxy.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/BlockingCallProxy.java index 00e4f8986..86aee910d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/BlockingCallProxy.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/BlockingCallProxy.java @@ -7,7 +7,7 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.concurrent;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -15,6 +15,8 @@ import java.lang.reflect.Proxy; import org.eclipse.core.runtime.Assert;
import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.tcf.core.concurrent.interfaces.IProxyDescriptor;
+import org.eclipse.tcf.te.tcf.core.concurrent.internal.DefaultProxyDescriptor;
/**
* BlockingCallProxy is a utility class. It can create an instance of a proxy class for the specified
@@ -35,7 +37,7 @@ import org.eclipse.tcf.protocol.Protocol; * <p>
* Now if you want to invoke this method and wait for the result, you can use the following code
* with this class:
- *
+ *
* <pre>
* IFileSystem service = ... // Get the file system service.
* IFileSystem proxy = BlockingCallProxy.newInstance(IFileSystem.class, service);
@@ -49,7 +51,7 @@ import org.eclipse.tcf.protocol.Protocol; * output.write(result[0]); // Now use the reading result.
* ...
* </pre>
- *
+ *
* In the above code, the line that does the read operation over the proxy object will block and
* will not return until "doneRead" of the callback is called. The line that follows the read
* operation can safely consume the read data.
@@ -72,7 +74,7 @@ public class BlockingCallProxy implements InvocationHandler { /**
* Create an instance of a proxy class for the specified interface that dispatches method
* invocations to the delegate object. This delegate object must implement the same interface.
- *
+ *
* @param proxyInterface The proxy interface for the proxy class.
* @param delegate The delegate object which the proxy dispatches the method invocations to.
* @return The proxy instance.
@@ -84,7 +86,7 @@ public class BlockingCallProxy implements InvocationHandler { /**
* Create an instance of a proxy class for the specified interface that dispatches method
* invocations to the delegate object. This delegate object must implement the same interface.
- *
+ *
* @param proxyInterface The proxy interface for the proxy class.
* @param proxyDescriptor The proxy descriptor for the proxy class.
* @param delegate The delegate object which the proxy dispatches the method invocations to.
@@ -106,7 +108,7 @@ public class BlockingCallProxy implements InvocationHandler { /**
* Create an instance of BlockingCall as the dynamic invocation handler of the proxy class.
- *
+ *
* @param delegate The delegate object which the proxy dispatches the method invocations to.
*/
private BlockingCallProxy(IProxyDescriptor proxyDescriptor, Object delegate) {
@@ -138,10 +140,10 @@ public class BlockingCallProxy implements InvocationHandler { * a dynamic generated proxy that could delegate the invocation and unblock the callback.
* Return a rendezvous object to be used to block the call. If it is not a proxy method, then
* just return null object.
- *
+ *
* @param method The method being called.
- * @param args The invocation arguments.
- * @return The rendezvous object of the proxy call or null if no blocking is needed.
+ * @param args The invocation arguments.
+ * @return The rendezvous object of the proxy call or null if no blocking is needed.
*/
private Rendezvous prepareArguments(final Method method, final Object[] args) {
if (proxyDescriptor.isProxyMethod(method)) {
@@ -151,17 +153,17 @@ public class BlockingCallProxy implements InvocationHandler { // Replace the callback with a proxy that block the call.
Rendezvous rendezvous = new Rendezvous();
Class<?>[] aTypes = method.getParameterTypes();
- args[index] = Proxy.newProxyInstance(aTypes[index].getClassLoader(),
+ args[index] = Proxy.newProxyInstance(aTypes[index].getClassLoader(),
new Class[] { aTypes[index] }, new DoneHandler(rendezvous, args[index]));
return rendezvous;
}
}
return null;
}
-
+
/**
* The invocation handler of the callback proxy. Used to delegate the callback invocation
- * and unblock the rendezvous object.
+ * and unblock the rendezvous object.
*/
private class DoneHandler implements InvocationHandler {
// The callback handler that delegates the invocation.
@@ -170,7 +172,7 @@ public class BlockingCallProxy implements InvocationHandler { private Rendezvous rendezvous;
/**
* Constructor with the two arguments to initialize the two fields.
- *
+ *
* @param rendezvous The rendezvous object to unblock the invocation
* @param done The callback handler that delegates the invocation.
*/
@@ -191,12 +193,12 @@ public class BlockingCallProxy implements InvocationHandler { }
/**
- * Invoke the call directly in the current thread, using the rendezous object to block the call.
+ * Invoke the call directly in the current thread, using the rendezvous object to block the call.
* If the rendezvous object is null, then just invoke the call directly.
- *
+ *
* @param method The method to be invoked.
* @param args The argument of the invocation.
- * @param rendezvous The rendezous object to wait for the call.
+ * @param rendezvous The rendezvous object to wait for the call.
* @return The invocation result.
* @throws Throwable Thrown during invocation.
*/
@@ -209,12 +211,12 @@ public class BlockingCallProxy implements InvocationHandler { }
/**
- * Dispatch the method invocation in the dispatching thread, using the rendezous object to block
+ * Dispatch the method invocation in the dispatching thread, using the rendezvous object to block
* the call. If the rendezvous object is null, then just invoke the call in the dispatching thread.
- *
+ *
* @param method The method to be invoked.
* @param args The argument of the invocation.
- * @param rendezvous The rendezous object to wait for the call.
+ * @param rendezvous The rendezvous object to wait for the call.
* @return The invocation result.
* @throws Throwable Thrown during invocation.
*/
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/Rendezvous.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/Rendezvous.java index 49d17b6a2..da158e020 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/Rendezvous.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/Rendezvous.java @@ -7,7 +7,7 @@ * Contributors:
* William Chen (Wind River)- [345387]Open the remote files with a proper editor
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.concurrent;
import java.util.concurrent.TimeoutException;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/IProxyDescriptor.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/interfaces/IProxyDescriptor.java index e60201b68..bea30efa5 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/IProxyDescriptor.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/interfaces/IProxyDescriptor.java @@ -7,23 +7,26 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.concurrent.interfaces;
import java.lang.reflect.Method;
+import org.eclipse.tcf.te.tcf.core.concurrent.BlockingCallProxy;
+import org.eclipse.tcf.te.tcf.core.concurrent.internal.DefaultProxyDescriptor;
+
/**
* The proxy descriptor to describe a proxy interface, providing which method should be
- * executed in the dispatching thread, which method is a proxy method that
+ * executed in the dispatching thread, which method is a proxy method that
* should be handled by BlockingProxy and get the index of the callback of a specified
* proxy method.
- *
+ *
* @see BlockingCallProxy
* @see DefaultProxyDescriptor
*/
public interface IProxyDescriptor {
/**
* Check if the method should be called inside the dispatching thread. .
- *
+ *
* @param method The method to be checked.
* @return true if it should be called inside the dispatching thread.
*/
@@ -32,15 +35,15 @@ public interface IProxyDescriptor { /**
* Return if the method requires blocking invocation. The method requires blocking invocation if
* it has a callback parameter called in the dispatching thread.
- *
+ *
* @param method The method to check.
* @return true if it requires a blocking invocation.
*/
boolean isProxyMethod(Method method);
/**
- * Get the index of the callback parameter.
- *
+ * Get the index of the callback parameter.
+ *
* @param method The method to search the callback parameter.
* @return The callback paramter's index.
*/
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/DefaultProxyDescriptor.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/internal/DefaultProxyDescriptor.java index 9f454bafd..0cbd8c640 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/DefaultProxyDescriptor.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/concurrent/internal/DefaultProxyDescriptor.java @@ -7,21 +7,24 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.concurrent.internal;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.tcf.te.tcf.core.concurrent.BlockingCallProxy;
+import org.eclipse.tcf.te.tcf.core.concurrent.interfaces.IProxyDescriptor;
+
/**
* The default proxy descriptor for proxy interfaces. It assumes the method with a parameter
* whose type is an interface, and whose name has a segment of "$Done", is the proxy method.
- *
+ *
* @see BlockingCallProxy
* @see IProxyDescriptor
*/
-class DefaultProxyDescriptor implements IProxyDescriptor {
+public class DefaultProxyDescriptor implements IProxyDescriptor {
// Descriptor cache to store known proxy descriptors.
private static Map<Class<?>, IProxyDescriptor> descriptorCache;
@@ -29,7 +32,7 @@ class DefaultProxyDescriptor implements IProxyDescriptor { * Get a default proxy descriptor from the cache using the class as the key.
* If no such proxy descriptor is found, then create a default proxy descriptor for it
* and cache it.
- *
+ *
* @param proxyInterface The proxy interface.
* @return A default proxy descriptor for the proxy interface.
*/
@@ -49,7 +52,7 @@ class DefaultProxyDescriptor implements IProxyDescriptor { private Map<Method, Integer> callbacks;
/**
* Constructor using the proxy interface.
- *
+ *
* @param proxyInterface The proxy interface.
*/
private DefaultProxyDescriptor(Class<?> proxyInterface) {
@@ -67,7 +70,7 @@ class DefaultProxyDescriptor implements IProxyDescriptor { /**
* Find the index of the callback parameter in the specified method.
- *
+ *
* @param method The method to be checked.
* @return the index of the callback parameter or -1 if there's no callback parameter.
*/
@@ -81,10 +84,10 @@ class DefaultProxyDescriptor implements IProxyDescriptor { }
return -1;
}
-
+
/*
* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.core.utils.IProxyDescriptor#isDispatchMethod(java.lang.reflect.Method)
+ * @see org.eclipse.tcf.te.tcf.core.util.IProxyDescriptor#isDispatchMethod(java.lang.reflect.Method)
*/
@Override
public boolean isDispatchMethod(Method method) {
@@ -93,7 +96,7 @@ class DefaultProxyDescriptor implements IProxyDescriptor { /*
* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.core.utils.IProxyDescriptor#isProxyMethod(java.lang.reflect.Method)
+ * @see org.eclipse.tcf.te.tcf.core.util.IProxyDescriptor#isProxyMethod(java.lang.reflect.Method)
*/
@Override
public boolean isProxyMethod(Method method) {
@@ -102,7 +105,7 @@ class DefaultProxyDescriptor implements IProxyDescriptor { /*
* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.core.utils.IProxyDescriptor#getCallbackIndex(java.lang.reflect.Method)
+ * @see org.eclipse.tcf.te.tcf.core.util.IProxyDescriptor#getCallbackIndex(java.lang.reflect.Method)
*/
@Override
public int getCallbackIndex(Method method) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfacesl/tracing/ITraceIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/tracing/ITraceIds.java index 0438d85c6..2bbb1ebdd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfacesl/tracing/ITraceIds.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/tracing/ITraceIds.java @@ -7,7 +7,7 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.interfacesl.tracing;
+package org.eclipse.tcf.te.tcf.core.interfaces.tracing;
/**
* TCF core plug-in trace slot identifiers.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java index 3e6882ed3..0de683c95 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java @@ -25,8 +25,8 @@ import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.core.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; -import org.eclipse.tcf.te.tcf.core.interfacesl.tracing.ITraceIds; -import org.eclipse.tcf.te.tcf.core.internal.nls.Messages; +import org.eclipse.tcf.te.tcf.core.interfaces.tracing.ITraceIds; +import org.eclipse.tcf.te.tcf.core.nls.Messages; /** diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/listener/InternalChannelListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/ChannelListener.java index 71397ac2f..00195798a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/listener/InternalChannelListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/ChannelListener.java @@ -7,23 +7,23 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.internal.listener; +package org.eclipse.tcf.te.tcf.core.listeners; import org.eclipse.core.runtime.Assert; import org.eclipse.osgi.util.NLS; import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.interfacesl.tracing.ITraceIds; -import org.eclipse.tcf.te.tcf.core.internal.interfaces.IChannelOpenListener; -import org.eclipse.tcf.te.tcf.core.internal.nls.Messages; +import org.eclipse.tcf.te.tcf.core.interfaces.tracing.ITraceIds; import org.eclipse.tcf.te.tcf.core.internal.utils.LogUtils; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelOpenListener; +import org.eclipse.tcf.te.tcf.core.nls.Messages; /** - * Internal channel listener. Attached to a TCF channel for tracing purpose. + * Channel listener implementation. */ -public class InternalChannelListener implements IChannel.IChannelListener { +public class ChannelListener implements IChannel.IChannelListener { // The reference to the channel private final IChannel channel; @@ -32,7 +32,7 @@ public class InternalChannelListener implements IChannel.IChannelListener { * * @param channel The channel. Must not be <code>null</code>. */ - public InternalChannelListener(IChannel channel) { + public ChannelListener(IChannel channel) { Assert.isNotNull(channel); this.channel = channel; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/listener/InternalChannelOpenListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/ChannelOpenListener.java index 0cf6fcfbb..07be327ba 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/listener/InternalChannelOpenListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/ChannelOpenListener.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.internal.listener; +package org.eclipse.tcf.te.tcf.core.listeners; import java.util.HashMap; import java.util.Map; @@ -17,16 +17,16 @@ import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.IChannel.IChannelListener; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.interfacesl.tracing.ITraceIds; -import org.eclipse.tcf.te.tcf.core.internal.interfaces.IChannelOpenListener; -import org.eclipse.tcf.te.tcf.core.internal.nls.Messages; +import org.eclipse.tcf.te.tcf.core.interfaces.tracing.ITraceIds; import org.eclipse.tcf.te.tcf.core.internal.utils.LogUtils; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelOpenListener; +import org.eclipse.tcf.te.tcf.core.nls.Messages; /** - * Internal channel open listener taking care of logging and caching. + * Channel open listener implementation. */ -public class InternalChannelOpenListener implements IChannelOpenListener { +public class ChannelOpenListener implements IChannelOpenListener { // Static map containing the channel listeners per channel. Access to the // map should happen from the TCF protocol dispatch thread only. private final Map<IChannel, IChannel.IChannelListener> channelListeners = new HashMap<IChannel, IChannel.IChannelListener>(); @@ -46,7 +46,7 @@ public class InternalChannelOpenListener implements IChannelOpenListener { IChannel.IChannelListener channelListener = channelListeners.remove(channel); if (channelListener != null) channel.removeChannelListener(channelListener); // Create a new channel listener instance - channelListener = new InternalChannelListener(channel); + channelListener = new ChannelListener(channel); // Add the channel listener to the global map setChannelListener(channel, channelListener); // Attach channel listener to the channel diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/interfaces/IChannelOpenListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IChannelOpenListener.java index f665ad52b..c8e2c88b6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/interfaces/IChannelOpenListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IChannelOpenListener.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.internal.interfaces; +package org.eclipse.tcf.te.tcf.core.listeners.interfaces; import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.Protocol.ChannelOpenListener; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/listeners/IChannelStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IChannelStateChangeListener.java index 3257bd225..5d1608571 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/listeners/IChannelStateChangeListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IChannelStateChangeListener.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.interfaces.listeners; +package org.eclipse.tcf.te.tcf.core.listeners.interfaces; import org.eclipse.tcf.protocol.IChannel; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/listeners/IProtocolStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IProtocolStateChangeListener.java index ff69500f8..f42195444 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/listeners/IProtocolStateChangeListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/listeners/interfaces/IProtocolStateChangeListener.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.interfaces.listeners; +package org.eclipse.tcf.te.tcf.core.listeners.interfaces; /** * Interface for clients to implement that wishes to listen diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java index 5291bf610..43eaaba85 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.core.internal.nls; +package org.eclipse.tcf.te.tcf.core.nls; import java.lang.reflect.Field; @@ -19,7 +19,7 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { // The plug-in resource bundle name - private static final String BUNDLE_NAME = "org.eclipse.tcf.te.tcf.core.internal.nls.Messages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.eclipse.tcf.te.tcf.core.nls.Messages"; //$NON-NLS-1$ /** * Static constructor. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties index 074a24a6d..074a24a6d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/ExceptionUtils.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/ExceptionUtils.java index 58deb17b5..e7a78f370 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/ExceptionUtils.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/ExceptionUtils.java @@ -7,7 +7,7 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.util;
import java.util.concurrent.ExecutionException;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/JSONUtils.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/JSONUtils.java index 6e7f1b6d5..7cc727131 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/utils/JSONUtils.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/JSONUtils.java @@ -7,7 +7,7 @@ * Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.tcf.core.utils;
+package org.eclipse.tcf.te.tcf.core.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/persistence/PersistableNameUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/persistence/PersistableNameUtil.java new file mode 100644 index 000000000..c006a4904 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/util/persistence/PersistableNameUtil.java @@ -0,0 +1,48 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.core.util.persistence;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
+
+/**
+ * Persistable name utility method implementations.
+ */
+public class PersistableNameUtil {
+ /* default */ final static Pattern pattern = Pattern.compile("TCP:([0-9\\.]+):[0-9]+", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+
+ /**
+ * Matches the given name against a set of patterns to isolate the IP address.
+ * If the address could be isolated and the address is an local host address,
+ * replace the address with the string "localhost".
+ *
+ * @param name
+ * @return
+ */
+ public static String normalizeLocalhostAddress(String name) {
+ Assert.isNotNull(name);
+
+ // Let's see if the name matches the pattern
+ Matcher matcher = pattern.matcher(name);
+ if (matcher.matches()) {
+ String ip = matcher.group(1);
+ // If the IP address is for the local host, reconstruct the name
+ // string to include "localhost" instead of the IP address
+ if (IPAddressUtil.getInstance().isLocalHost(ip)) {
+ name = name.replace(ip, "localhost"); //$NON-NLS-1$
+ }
+ }
+
+ return name;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java index 0b3a9e780..f57df102e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java @@ -36,9 +36,9 @@ import org.eclipse.tcf.services.IFileSystem.DoneRemove; import org.eclipse.tcf.services.IFileSystem.FileSystemException; import org.eclipse.tcf.services.IFileSystem.IFileHandle; import org.eclipse.tcf.te.tcf.core.Tcf; +import org.eclipse.tcf.te.tcf.core.concurrent.BlockingCallProxy; import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager.DoneOpenChannel; -import org.eclipse.tcf.te.tcf.core.utils.BlockingCallProxy; import org.eclipse.tcf.te.tcf.filesystem.activator.UIPlugin; import org.eclipse.tcf.te.tcf.filesystem.internal.ImageConsts; import org.eclipse.tcf.te.tcf.filesystem.internal.exceptions.TCFChannelException; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java index 09e6ff740..aa36be2c2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java @@ -13,7 +13,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; 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 031efb9d4..36fc9fb2a 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 @@ -25,7 +25,7 @@ import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.services.ILocator; import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; import org.eclipse.tcf.te.tcf.locator.Scanner; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java index f394a0b41..daff01026 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java @@ -25,8 +25,8 @@ import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.events.EventManager;
import org.eclipse.tcf.te.tcf.core.Tcf;
-import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener;
-import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IProtocolStateChangeListener;
+import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener;
+import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IProtocolStateChangeListener;
import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent;
import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys;
@@ -154,7 +154,7 @@ public final class LogManager implements IProtocolStateChangeListener { }
/* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.core.interfaces.listeners.IProtocolStateChangeListener#stateChanged(boolean)
+ * @see org.eclipse.tcf.te.tcf.core.listeners.interfaces.IProtocolStateChangeListener#stateChanged(boolean)
*/
@Override
public void stateChanged(boolean state) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelStateChangeListener.java index 49056f42e..f744d727f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelStateChangeListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelStateChangeListener.java @@ -11,7 +11,7 @@ package org.eclipse.tcf.te.tcf.log.core.internal.listener; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener; +import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; /** * TCF logging channel state listener implementation. @@ -19,7 +19,7 @@ import org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListe public class ChannelStateChangeListener implements IChannelStateChangeListener { /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.core.interfaces.listeners.IChannelStateChangeListener#stateChanged(org.eclipse.tcf.protocol.IChannel, int) + * @see org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener#stateChanged(org.eclipse.tcf.protocol.IChannel, int) */ @Override public void stateChanged(IChannel channel, int state) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java index be031d30b..613ddcad6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.osgi.util.NLS; import org.eclipse.tcf.core.AbstractChannel.TraceListener; import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.te.tcf.core.utils.JSONUtils; +import org.eclipse.tcf.te.tcf.core.util.JSONUtils; import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent; import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java index e59269143..583ab43a6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java @@ -35,7 +35,7 @@ import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.tcf.core.streams.StreamsDataProvider; import org.eclipse.tcf.te.tcf.core.streams.StreamsDataReceiver; -import org.eclipse.tcf.te.tcf.core.utils.ExceptionUtils; +import org.eclipse.tcf.te.tcf.core.util.ExceptionUtils; /** * Remote process streams listener implementation. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java index e928966c7..d13bf1d11 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java @@ -36,7 +36,7 @@ import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.tcf.core.streams.StreamsDataProvider; import org.eclipse.tcf.te.tcf.core.streams.StreamsDataReceiver; -import org.eclipse.tcf.te.tcf.core.utils.ExceptionUtils; +import org.eclipse.tcf.te.tcf.core.util.ExceptionUtils; /** * Remote terminal streams listener implementation. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF index d799e6b8f..3b49fb8a8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/META-INF/MANIFEST.MF @@ -27,6 +27,7 @@ Export-Package: org.eclipse.tcf.te.ui.views, org.eclipse.tcf.te.ui.views.extensions, org.eclipse.tcf.te.ui.views.handler, org.eclipse.tcf.te.ui.views.interfaces, + org.eclipse.tcf.te.ui.views.interfaces.tracing;x-internal:=true, org.eclipse.tcf.te.ui.views.interfaces.workingsets, org.eclipse.tcf.te.ui.views.internal;x-internal:=true, org.eclipse.tcf.te.ui.views.internal.editor;x-internal:=true, @@ -35,4 +36,6 @@ Export-Package: org.eclipse.tcf.te.ui.views, org.eclipse.tcf.te.ui.views.perspective, org.eclipse.tcf.te.ui.views.tabbed, org.eclipse.tcf.te.ui.views.workingsets, + org.eclipse.tcf.te.ui.views.workingsets.actions, + org.eclipse.tcf.te.ui.views.workingsets.dialogs, org.eclipse.tcf.te.ui.views.workingsets.pages diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/icons/obj16/workingset.gif b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/icons/obj16/workingset.gif Binary files differindex 549f74ced..d46c5370d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/icons/obj16/workingset.gif +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/icons/obj16/workingset.gif diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties index 159565482..a6c0ba09e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties @@ -37,10 +37,10 @@ filters.workingSet.description=Hides unselected working sets [not visible in UI] workingsets.extension.name=Working Sets workingset.name=Target Explorer -workingset.description=Working set for Target Explorer elements. +workingset.description=Target Explorer working sets. -workingset.others.name=Other Targets -workingset.others.description=Working set containing all elements not in any Target Explorer group. +workingset.others.name=Other +workingset.others.description=Working set containing all elements not in any group. # ***** Command and menu contributions ***** Command.open.name=Open diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml index 555b8d2c7..967a532ac 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml @@ -84,7 +84,7 @@ <!-- Working Sets navigator action contributions --> <actionProvider - class="org.eclipse.tcf.te.ui.views.actions.WorkingSetActionProvider" + class="org.eclipse.tcf.te.ui.views.workingsets.actions.WorkingSetActionProvider" id="org.eclipse.tcf.te.ui.views.navigator.actions.WorkingSetActions"> <enablement> <or> @@ -115,10 +115,18 @@ name="%workingsets.extension.name" priority="higher"> <triggerPoints> - <instanceof value="org.eclipse.ui.IWorkingSet"/> + <or> + <instanceof value="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetViewStateManager"/> + <instanceof value="org.eclipse.ui.IWorkingSet"/> + <instanceof value="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetElementHolder"/> + </or> </triggerPoints> <possibleChildren> - <instanceof value="java.lang.Object"/> + <or> + <instanceof value="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetViewStateManager"/> + <instanceof value="org.eclipse.ui.IWorkingSet"/> + <instanceof value="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetElementHolder"/> + </or> </possibleChildren> <commonSorter class="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetViewerSorter" @@ -202,6 +210,10 @@ class="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetElementHolderFactory" id="org.eclipse.tcf.te.ui.views.workingsets.WorkingSetElementHolderFactory"> </factory> + <factory + class="org.eclipse.tcf.te.ui.views.workingsets.CustomizedOrderComparatorFactory" + id="org.eclipse.tcf.te.ui.views.workingsets.CustomizedOrderComparatorFactory"> + </factory> </extension> <!-- Adapter factories --> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/actions/WorkingSetActionProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/actions/WorkingSetActionProvider.java deleted file mode 100644 index 68de84446..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/actions/WorkingSetActionProvider.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 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.ui.views.actions; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.tcf.te.ui.views.activator.UIPlugin; -import org.eclipse.tcf.te.ui.views.internal.ViewRoot; -import org.eclipse.tcf.te.ui.views.nls.Messages; -import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetFilter; -import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetsContentProvider; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IAggregateWorkingSet; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IWorkbenchPreferenceConstants; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.IWorkingSetManager; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkingSetFilterActionGroup; -import org.eclipse.ui.internal.navigator.NavigatorFilterService; -import org.eclipse.ui.navigator.CommonActionProvider; -import org.eclipse.ui.navigator.CommonViewer; -import org.eclipse.ui.navigator.ICommonActionExtensionSite; -import org.eclipse.ui.navigator.IExtensionActivationListener; -import org.eclipse.ui.navigator.IExtensionStateModel; -import org.eclipse.ui.navigator.INavigatorContentService; - -/** - * Working set action provider implementation. - * <p> - * Copied and adapted from <code>org.eclipse.ui.internal.navigator.resources.actions.WorkingSetActionProvider</code>. - */ -@SuppressWarnings("restriction") -public class WorkingSetActionProvider extends CommonActionProvider { - - private static final String TAG_CURRENT_WORKING_SET_NAME = "currentWorkingSetName"; //$NON-NLS-1$ - - private static final String WORKING_SET_FILTER_ID = "org.eclipse.tcf.te.ui.views.navigator.filters.workingSet"; //$NON-NLS-1$ - - private boolean contributedToViewMenu = false; - - /* default */ CommonViewer viewer; - - /* default */ INavigatorContentService contentService; - - private NavigatorFilterService filterService; - - private WorkingSetFilterActionGroup workingSetActionGroup; - /* default */ WorkingSetRootModeActionGroup workingSetRootModeActionGroup; - - private Object originalViewerInput = null; - - /* default */ IExtensionStateModel extensionStateModel; - - /* default */ boolean emptyWorkingSet; - /* default */ IWorkingSet workingSet; - - /* default */ IPropertyChangeListener topLevelModeListener; - - /* default */ boolean ignoreFilterChangeEvents; - - /** - * Provides a smart listener to monitor changes to the Working Set Manager. - * - */ - public class WorkingSetManagerListener implements IPropertyChangeListener { - - private boolean listening = false; - - @Override - public void propertyChange(PropertyChangeEvent event) { - String property = event.getProperty(); - Object newValue = event.getNewValue(); - Object oldValue = event.getOldValue(); - - String newLabel = null; - if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(property) && oldValue == workingSet) { - newLabel = ""; //$NON-NLS-1$ - setWorkingSet(null); - } else if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property) && newValue == workingSet) { - newLabel = workingSet.getLabel(); - } else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property) && newValue == workingSet) { - if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) { - // act as if the working set has been made null - if (!emptyWorkingSet) { - emptyWorkingSet = true; - setWorkingSetFilter(null); - } - } else { - // we've gone from empty to non-empty on our set. - // Restore it. - if (emptyWorkingSet) { - emptyWorkingSet = false; - setWorkingSetFilter(workingSet); - newLabel = workingSet.getLabel(); - } - } - } - if (viewer != null) { - if (newLabel != null) - viewer.getCommonNavigator().setWorkingSetLabel(newLabel); - viewer.getFrameList().reset(); - viewer.refresh(); - } - } - - /** - * Begin listening to the correct source if not already listening. - */ - public synchronized void listen() { - if (!listening) { - PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(managerChangeListener); - listening = true; - } - } - - /** - * Begin listening to the correct source if not already listening. - */ - public synchronized void ignore() { - if (listening) { - PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(managerChangeListener); - listening = false; - } - } - } - - private IPropertyChangeListener filterChangeListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - - if (ignoreFilterChangeEvents) - return; - - IWorkingSet newWorkingSet = (IWorkingSet) event.getNewValue(); - - setWorkingSet(newWorkingSet); - if (newWorkingSet != null) { - if (!contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) { - contentService.getActivationService().activateExtensions( - new String[] { WorkingSetsContentProvider.EXTENSION_ID }, false); - contentService.getActivationService().persistExtensionActivations(); - } - if (newWorkingSet.isAggregateWorkingSet()) { - IAggregateWorkingSet agWs = (IAggregateWorkingSet) newWorkingSet; - IWorkingSet[] comps = agWs.getComponents(); - if (comps.length > 1) { - viewer.getCommonNavigator().setWorkingSetLabel(Messages.WorkingSetActionProvider_multipleWorkingSets); - } else if (comps.length > 0) { - viewer.getCommonNavigator().setWorkingSetLabel(comps[0].getLabel()); - } else { - viewer.getCommonNavigator().setWorkingSetLabel(null); - } - } else - viewer.getCommonNavigator().setWorkingSetLabel(workingSet.getLabel()); - } else { - viewer.getCommonNavigator().setWorkingSetLabel(null); - } - - viewer.getFrameList().reset(); - } - }; - - /* default */ WorkingSetManagerListener managerChangeListener = new WorkingSetManagerListener(); - - private IExtensionActivationListener activationListener = new IExtensionActivationListener() { - - private IWorkingSet savedWorkingSet; - - @Override - public void onExtensionActivation(String aViewerId, String[] theNavigatorExtensionIds, boolean isActive) { - - for (int i = 0; i < theNavigatorExtensionIds.length; i++) { - if (WorkingSetsContentProvider.EXTENSION_ID.equals(theNavigatorExtensionIds[i])) { - if (isActive) { - extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID); - workingSetRootModeActionGroup.setStateModel(extensionStateModel); - extensionStateModel.addPropertyChangeListener(topLevelModeListener); - - if (savedWorkingSet != null) { - setWorkingSet(savedWorkingSet); - } - managerChangeListener.listen(); - - } else { - savedWorkingSet = workingSet; - setWorkingSet(null); - viewer.getCommonNavigator().setWorkingSetLabel(null); - managerChangeListener.ignore(); - workingSetRootModeActionGroup.setShowTopLevelWorkingSets(false); - extensionStateModel.removePropertyChangeListener(topLevelModeListener); - - } - } - } - } - - }; - - @Override - public void init(ICommonActionExtensionSite site) { - viewer = (CommonViewer) site.getStructuredViewer(); - contentService = site.getContentService(); - filterService = (NavigatorFilterService) contentService.getFilterService(); - originalViewerInput = ViewRoot.getInstance(); - - extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID); - - workingSetActionGroup = new WorkingSetFilterActionGroup(site.getViewSite().getShell(), filterChangeListener); - workingSetRootModeActionGroup = new WorkingSetRootModeActionGroup(viewer, extensionStateModel); - - topLevelModeListener = new IPropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent event) { - setWorkingSet(workingSet); - viewer.getFrameList().reset(); - } - }; - - if (contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) { - managerChangeListener.listen(); - extensionStateModel.addPropertyChangeListener(topLevelModeListener); - } - - contentService.getActivationService().addExtensionActivationListener(activationListener); - } - - /** - * Restores the working set filter from the persistence store. - */ - protected void initWorkingSetFilter(String workingSetName) { - IWorkingSet workingSet = null; - - if (workingSetName != null && workingSetName.length() > 0) { - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); - workingSet = workingSetManager.getWorkingSet(workingSetName); - } else if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT)) { - // use the window set by default if the global preference is set - workingSet = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getAggregateWorkingSet(); - } - - if (workingSet != null) { - setWorkingSet(workingSet); - } - } - - /* default */ void setWorkingSetFilter(IWorkingSet workingSet) { - setWorkingSetFilter(workingSet, true); - } - - private void setWorkingSetFilter(IWorkingSet workingSet, boolean firstTime) { - WorkingSetFilter workingSetFilter = null; - ViewerFilter[] filters = viewer.getFilters(); - for (int i = 0; i < filters.length; i++) { - if (filters[i] instanceof WorkingSetFilter) { - workingSetFilter = (WorkingSetFilter) filters[i]; - break; - } - } - if (workingSetFilter == null) { - if (firstTime) { - filterService.addActiveFilterIds(new String[] { WORKING_SET_FILTER_ID }); - filterService.updateViewer(); - setWorkingSetFilter(workingSet, false); - return; - } - - IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), - "Required filter " + WORKING_SET_FILTER_ID //$NON-NLS-1$ - + " is not present. Working set support will not function correctly."); //$NON-NLS-1$ - UIPlugin.getDefault().getLog().log(status); - return; - } - workingSetFilter.setActive(extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS)); - } - - /** - * Set current active working set. - * - * @param workingSet - * working set to be activated, may be <code>null</code> - */ - protected void setWorkingSet(IWorkingSet workingSet) { - this.workingSet = workingSet; - emptyWorkingSet = workingSet != null && workingSet.isAggregateWorkingSet() && workingSet.isEmpty(); - - ignoreFilterChangeEvents = true; - try { - workingSetActionGroup.setWorkingSet(workingSet); - } finally { - ignoreFilterChangeEvents = false; - } - - if (viewer != null) { - setWorkingSetFilter(workingSet); - if (workingSet == null || emptyWorkingSet - || !extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS)) { - if (viewer.getInput() != originalViewerInput) { - viewer.setInput(originalViewerInput); - } else { - viewer.refresh(); - } - } else { - if (!workingSet.isAggregateWorkingSet()) { - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); - viewer.setInput(workingSetManager.createAggregateWorkingSet( - "", "", new IWorkingSet[] { workingSet })); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - viewer.setInput(workingSet); - } - } - } - } - - @Override - public void restoreState(final IMemento aMemento) { - super.restoreState(aMemento); - - // Need to run this async to avoid being reentered when processing a selection change - viewer.getControl().getShell().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - boolean showWorkingSets = true; - if (aMemento != null) { - Integer showWorkingSetsInt = aMemento - .getInteger(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS); - showWorkingSets = showWorkingSetsInt == null || showWorkingSetsInt.intValue() == 1; - extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, - showWorkingSets); - workingSetRootModeActionGroup.setShowTopLevelWorkingSets(showWorkingSets); - - String lastWorkingSetName = aMemento.getString(TAG_CURRENT_WORKING_SET_NAME); - initWorkingSetFilter(lastWorkingSetName); - } else { - showWorkingSets = false; - - extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, - showWorkingSets); - workingSetRootModeActionGroup.setShowTopLevelWorkingSets(showWorkingSets); - } - } - }); - } - - @Override - public void saveState(IMemento aMemento) { - super.saveState(aMemento); - - if (aMemento != null) { - int showWorkingSets = extensionStateModel - .getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS) ? 1 : 0; - aMemento.putInteger(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets); - - if (workingSet != null) { - aMemento.putString(TAG_CURRENT_WORKING_SET_NAME, workingSet.getName()); - } - } - - } - - @Override - public void fillActionBars(IActionBars actionBars) { - if (!contributedToViewMenu) { - try { - super.fillActionBars(actionBars); - workingSetActionGroup.fillActionBars(actionBars); - if (workingSetRootModeActionGroup != null) { - workingSetRootModeActionGroup.fillActionBars(actionBars); - } - } finally { - contributedToViewMenu = true; - } - } - } - - @Override - public void dispose() { - super.dispose(); - workingSetActionGroup.dispose(); - if (workingSetRootModeActionGroup != null) { - workingSetRootModeActionGroup.dispose(); - } - - managerChangeListener.ignore(); - extensionStateModel.removePropertyChangeListener(topLevelModeListener); - - contentService.getActivationService().removeExtensionActivationListener(activationListener); - } - - /** - * This is used only for the tests. - * - * @return a PropertyChangeListener - */ - public IPropertyChangeListener getFilterChangeListener() { - return filterChangeListener; - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java index af0a31ef6..028381d5f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/View.java @@ -34,8 +34,8 @@ import org.eclipse.tcf.te.ui.views.activator.UIPlugin; import org.eclipse.tcf.te.ui.views.interfaces.IRoot; import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.nls.Messages; +import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetViewStateManager; import org.eclipse.ui.IAggregateWorkingSet; -import org.eclipse.ui.ILocalWorkingSetManager; import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkingSet; @@ -70,14 +70,16 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon private String workingSetLabel; /** - * The local working set manager instance. + * The working set view state manager. */ - private final ILocalWorkingSetManager localWorkingSetManager = PlatformUI.getWorkbench().createLocalWorkingSetManager(); + private final WorkingSetViewStateManager stateManager; /** * Constructor. */ public View() { + super(); + stateManager = new WorkingSetViewStateManager(this); } /* (non-Javadoc) @@ -131,12 +133,12 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon } /** - * Returns the local working set manager instance. + * Returns the working set view state manager instance. * - * @return The local working set manager instance. + * @return The working set view state manager instance. */ - public final ILocalWorkingSetManager getLocalWorkingSetManager() { - return localWorkingSetManager; + public final WorkingSetViewStateManager getStateManager() { + return stateManager; } /* (non-Javadoc) @@ -144,7 +146,7 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon */ @Override public void dispose() { - localWorkingSetManager.dispose(); + stateManager.dispose(); super.dispose(); } @@ -245,7 +247,7 @@ public class View extends CommonNavigator implements ITabbedPropertySheetPageCon IWorkbenchAdapter adapter = (IWorkbenchAdapter) ((IAdaptable) input).getAdapter(IWorkbenchAdapter.class); if (adapter != null) contentDescription = adapter.getLabel(input); } - else if (input instanceof IRoot) { + else if (input instanceof IRoot || input instanceof WorkingSetViewStateManager) { // The root node does not have a content description } else if (input != null && !(input instanceof IAggregateWorkingSet)) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewer.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewer.java index a7bba6e63..18e00adbc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewer.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewer.java @@ -9,6 +9,8 @@ *******************************************************************************/
package org.eclipse.tcf.te.ui.views.internal;
+import java.util.EventObject;
+
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.te.runtime.events.EventManager;
@@ -20,10 +22,15 @@ import org.eclipse.ui.navigator.CommonViewerSorter; * Target Explorer common viewer implementation.
*/
public class ViewViewer extends CommonViewer {
+ // Flag to mark the viewer silent. In silent mode, no
+ // ViewerContentChangeEvents are send.
+ private boolean silent = false;
/**
* Constructor.
*
+ * @param view
+ * The common navigator based parent view. Must not be <code>null</code>.
* @param viewerId
* An id tied to the extensions that is used to focus specific
* content to a particular instance of the Common Navigator
@@ -37,6 +44,29 @@ public class ViewViewer extends CommonViewer { super(viewerId, parent, style);
}
+ /**
+ * Fire the given event if the viewer is not in silent mode.
+ *
+ * @param event The event or <code>null</code>.
+ */
+ private void fireEvent(EventObject event) {
+ if (!silent && event != null) {
+ EventManager.getInstance().fireEvent(event);
+ }
+ }
+
+ /**
+ * Sets the viewers event firing silent mode.
+ *
+ * @param silent <code>True</code> to stop firing change events, <code>false</code> otherwise.
+ * @return <code>True</code> if the silent mode changed.
+ */
+ public boolean setSilentMode(boolean silent) {
+ boolean changed = this.silent != silent;
+ this.silent = silent;
+ return changed;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonViewer#add(java.lang.Object, java.lang.Object[])
*/
@@ -45,7 +75,7 @@ public class ViewViewer extends CommonViewer { super.add(parentElement, childElements);
ViewerContentChangeEvent event = new ViewerContentChangeEvent(this, ViewerContentChangeEvent.ADD);
- EventManager.getInstance().fireEvent(event);
+ fireEvent(event);
}
/* (non-Javadoc)
@@ -56,7 +86,7 @@ public class ViewViewer extends CommonViewer { super.remove(elements);
ViewerContentChangeEvent event = new ViewerContentChangeEvent(this, ViewerContentChangeEvent.REMOVE);
- EventManager.getInstance().fireEvent(event);
+ fireEvent(event);
}
/* (non-Javadoc)
@@ -67,18 +97,7 @@ public class ViewViewer extends CommonViewer { super.remove(parent, elements);
ViewerContentChangeEvent event = new ViewerContentChangeEvent(this, ViewerContentChangeEvent.REMOVE);
- EventManager.getInstance().fireEvent(event);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.navigator.CommonViewer#refresh(java.lang.Object)
- */
- @Override
- public void refresh(Object element) {
- super.refresh(element);
-
- ViewerContentChangeEvent event = new ViewerContentChangeEvent(this, ViewerContentChangeEvent.REFRESH);
- EventManager.getInstance().fireEvent(event);
+ fireEvent(event);
}
/* (non-Javadoc)
@@ -89,7 +108,7 @@ public class ViewViewer extends CommonViewer { super.refresh(element, updateLabels);
ViewerContentChangeEvent event = new ViewerContentChangeEvent(this, ViewerContentChangeEvent.REFRESH);
- EventManager.getInstance().fireEvent(event);
+ fireEvent(event);
}
/* (non-Javadoc)
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerSorter.java index eae72bd89..f505c9e62 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/ViewViewerSorter.java @@ -14,6 +14,7 @@ import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreePathViewerSorter;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.tcf.te.ui.trees.TreeViewerSorter;
+import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.navigator.CommonViewerSorter;
import org.eclipse.ui.navigator.INavigatorContentService;
@@ -52,9 +53,11 @@ public final class ViewViewerSorter extends TreePathViewerSorter { public int compare(Viewer viewer, TreePath parentPath, Object e1, Object e2) {
int result = sorter.compare(viewer, parentPath, e1, e2);
- if (result == category(e1) - category(e2)) {
- int defaultSorterResult = defaultSorter.compare(viewer, parentPath, e1, e2);
- if (defaultSorterResult != 0) result = defaultSorterResult;
+ if (!(e1 instanceof IWorkingSet) && !(e2 instanceof IWorkingSet)) {
+ if (result == category(e1) - category(e2)) {
+ int defaultSorterResult = defaultSorter.compare(viewer, parentPath, e1, e2);
+ if (defaultSorterResult != 0) result = defaultSorterResult;
+ }
}
return result;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java index 675ed9708..7a7a45930 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java @@ -40,11 +40,14 @@ public class Messages extends NLS { public static String WorkingSetActionProvider_multipleWorkingSets; - public static String WorkingSetRootModeActionGroup_Top_Level_Element; - public static String WorkingSetRootModeActionGroup_Target; - public static String WorkingSetRootModeActionGroup_Working_Set; + public static String WorkingSetActionGroup_Top_Level_Element; + public static String WorkingSetActionGroup_Elements; + public static String WorkingSetActionGroup_Working_Set; - public static String WorkingSetContentProvider_others_name; + public static String ViewStateManager_others_name; + + public static String ConfigureWorkingSetAction_text; + public static String ConfigureWorkingSetAction_toolTip; public static String PropertiesCommandHandler_error_initPartFailed; @@ -61,4 +64,15 @@ public class Messages extends NLS { public static String TargetWorkingSetPage_warning_resourceMustBeChecked; public static String TargetWorkingSetPage_title; public static String TargetWorkingSetPage_workingSet_description; + + public static String WorkingSetConfigurationDialog_down_label; + public static String WorkingSetConfigurationDialog_up_label; + public static String WorkingSetConfigurationDialog_title; + public static String WorkingSetConfigurationDialog_selectAll_label; + public static String WorkingSetConfigurationDialog_edit_label; + public static String WorkingSetConfigurationDialog_message; + public static String WorkingSetConfigurationDialog_deselectAll_label; + public static String WorkingSetConfigurationDialog_new_label; + public static String WorkingSetConfigurationDialog_sort_working_sets; + public static String WorkingSetConfigurationDialog_remove_label; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties index d7cec009a..a79c015c1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties @@ -14,15 +14,18 @@ View_workingSetModel=Working Sets NewActionProvider_NewMenu_label=&New NewActionProvider_NewWizardCommandAction_label=&Other... -NewActionProvider_NewWizardCommandAction_tooltip=Open the New target wizard +NewActionProvider_NewWizardCommandAction_tooltip=Open the New wizard WorkingSetActionProvider_multipleWorkingSets=Multiple Working Sets -WorkingSetRootModeActionGroup_Top_Level_Element=&Top Level Elements -WorkingSetRootModeActionGroup_Target=Targets -WorkingSetRootModeActionGroup_Working_Set=Working Sets +WorkingSetActionGroup_Top_Level_Element=&Top Level Elements +WorkingSetActionGroup_Elements=Elements +WorkingSetActionGroup_Working_Set=Working Sets -WorkingSetContentProvider_others_name=Other Targets +ViewStateManager_others_name=Other + +ConfigureWorkingSetAction_text=Configure Working Sets... +ConfigureWorkingSetAction_toolTip=Configure Working Sets... # ***** Command Handler ***** @@ -43,3 +46,14 @@ TargetWorkingSetPage_warning_resourceMustBeChecked=No resources selected. TargetWorkingSetPage_addAll_button=A&dd All -> TargetWorkingSetPage_title=Target Working Set TargetWorkingSetPage_warning_nameWhitespace=The name must not have leading or trailing whitespace. + +WorkingSetConfigurationDialog_down_label=&Down +WorkingSetConfigurationDialog_up_label=&Up +WorkingSetConfigurationDialog_title=Configure Working Sets +WorkingSetConfigurationDialog_selectAll_label=Select &All +WorkingSetConfigurationDialog_edit_label=&Edit... +WorkingSetConfigurationDialog_message=Select and sort &working sets visible in Target Explorer\: +WorkingSetConfigurationDialog_deselectAll_label=Dese&lect All +WorkingSetConfigurationDialog_new_label=&New... +WorkingSetConfigurationDialog_sort_working_sets=&Sort working sets +WorkingSetConfigurationDialog_remove_label=&Remove diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparator.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparator.java new file mode 100644 index 000000000..13ed9becd --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparator.java @@ -0,0 +1,120 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.ui.views.workingsets;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.navigator.IMementoAware;
+
+/**
+ * <p>
+ * The comparator to sort working sets in the order specified by end users.
+ * It reads a series of working set names and sort the given list in the order
+ * of the working set names.
+ * </p>
+ */
+public class CustomizedOrderComparator implements Comparator<IWorkingSet>, IMementoAware, IPersistableElement, IAdaptable {
+ // The separator delimiter to separate working set names store in the memento file.
+ private static final String WORKINGSET_SEPARATOR = "|"; //$NON-NLS-1$
+ // The sequence of the sorted working set.
+ private static final String ATTR_SEQUENCE = "sequence"; //$NON-NLS-1$
+
+ // Working set names which are used to sort working sets.
+ private List<String> workingSetNames;
+
+ /**
+ * Create a comparator instance.
+ */
+ public CustomizedOrderComparator() {
+ }
+
+ /**
+ * Create a comparator instance using the same order of the
+ * specified working set array.
+ *
+ * @param workingSets The working set array
+ */
+ public CustomizedOrderComparator(IWorkingSet[] workingSets) {
+ workingSetNames = new ArrayList<String>();
+ for (IWorkingSet workingSet : workingSets) {
+ workingSetNames.add(workingSet.getName());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ StringBuilder buf = new StringBuilder();
+ for (String name : workingSetNames) {
+ buf.append(name + WORKINGSET_SEPARATOR);
+ }
+ if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1);
+ memento.putString(ATTR_SEQUENCE, buf.toString());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void restoreState(IMemento aMemento) {
+ String wsNames = aMemento.getString(ATTR_SEQUENCE);
+ StringTokenizer st = new StringTokenizer(wsNames, WORKINGSET_SEPARATOR);
+ workingSetNames = new ArrayList<String>();
+ while (st.hasMoreTokens()) {
+ workingSetNames.add(st.nextToken());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPersistableElement#getFactoryId()
+ */
+ @Override
+ public String getFactoryId() {
+ return CustomizedOrderComparatorFactory.FACTORY_ID;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter == IPersistableElement.class) {
+ return this;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(IWorkingSet o1, IWorkingSet o2) {
+ String id1 = o1.getName();
+ String id2 = o2.getName();
+ int index1 = workingSetNames.indexOf(id1);
+ int index2 = workingSetNames.indexOf(id2);
+ if (index1 != -1 && index2 != -1) return index1 > index2 ? 1 : (index1 < index2 ? -1 : 0);
+ return 0;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparatorFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparatorFactory.java new file mode 100644 index 000000000..44ebd62fc --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/CustomizedOrderComparatorFactory.java @@ -0,0 +1,31 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.ui.views.workingsets;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+/**
+ * The element factory to create a CustomizedOrderComparator from a
+ * memento.
+ */
+public class CustomizedOrderComparatorFactory implements IElementFactory {
+ public static final String FACTORY_ID = "org.eclipse.tcf.te.ui.views.workingsets.CustomizedOrderComparatorFactory"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public IAdaptable createElement(IMemento memento) {
+ CustomizedOrderComparator comparator = new CustomizedOrderComparator();
+ comparator.restoreState(memento);
+ return comparator;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/OthersWorkingSetElementUpdater.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/OthersWorkingSetElementUpdater.java index 28adbc63d..319d8d178 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/OthersWorkingSetElementUpdater.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/OthersWorkingSetElementUpdater.java @@ -14,11 +14,11 @@ import java.util.List; import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.tcf.te.ui.views.internal.ViewRoot;
import org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement;
+import org.eclipse.tcf.te.ui.views.internal.View;
+import org.eclipse.tcf.te.ui.views.internal.ViewRoot;
+import org.eclipse.tcf.te.ui.views.internal.ViewViewer;
import org.eclipse.ui.IWorkingSet;
-import org.eclipse.ui.IWorkingSetManager;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonViewer;
/**
@@ -70,8 +70,8 @@ public class OthersWorkingSetElementUpdater extends WorkingSetElementUpdater { Object[] elements = viewer.getNavigatorContentService().createCommonContentProvider().getElements(ViewRoot.getInstance());
// Get all working sets
- IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
- IWorkingSet[] allWorkingSets = manager.getAllWorkingSets();
+ WorkingSetViewStateManager manager = viewer.getCommonNavigator() instanceof View ? ((View)viewer.getCommonNavigator()).getStateManager() : null;
+ IWorkingSet[] allWorkingSets = manager != null ? manager.getAllWorkingSets() : new IWorkingSet[0];
// Loop the elements and check if they are contained in a working set
for (Object element : elements) {
@@ -79,13 +79,41 @@ public class OthersWorkingSetElementUpdater extends WorkingSetElementUpdater { boolean isContained = isContained((IWorkingSetElement)element, allWorkingSets);
if (!isContained) {
- WorkingSetElementHolder holder = new WorkingSetElementHolder(othersWorkingSet.getName(), ((IWorkingSetElement)element).getElementId());
- holder.setElement((IWorkingSetElement)element);
+ WorkingSetElementHolder holder = null;
+
+ IAdaptable[] wsElements = othersWorkingSet.getElements();
+ for (IAdaptable wsElement : wsElements) {
+ if (!(wsElement instanceof WorkingSetElementHolder)) continue;
+
+ IWorkingSetElement candidate = ((WorkingSetElementHolder)wsElement).getElement();
+ String candidateId = ((WorkingSetElementHolder)wsElement).getElementId();
+
+ if (element.equals(candidate)) {
+ holder = (WorkingSetElementHolder)wsElement;
+ break;
+ } else if (candidate == null && (((IWorkingSetElement)element).getElementId().equals(candidateId))) {
+ holder = (WorkingSetElementHolder)wsElement;
+ ((WorkingSetElementHolder)wsElement).setElement((IWorkingSetElement)element);
+ break;
+ }
+ }
+
+ if (holder == null) {
+ holder = new WorkingSetElementHolder(othersWorkingSet.getName(), ((IWorkingSetElement)element).getElementId());
+ holder.setElement((IWorkingSetElement)element);
+ }
otherElements.add(holder);
}
}
othersWorkingSet.setElements(otherElements.toArray(new IAdaptable[otherElements.size()]));
+
+ // Trigger a view update, but without triggering ourselves again.
+ if (viewer instanceof ViewViewer) {
+ boolean changed = ((ViewViewer)viewer).setSilentMode(true);
+ viewer.refresh();
+ if (changed) ((ViewViewer)viewer).setSilentMode(false);
+ }
}
/**
@@ -104,25 +132,45 @@ public class OthersWorkingSetElementUpdater extends WorkingSetElementUpdater { boolean contained = false;
for (IWorkingSet workingSet : allWorkingSets) {
- IAdaptable[] wsElements = workingSet.getElements();
- for (IAdaptable wsElement : wsElements) {
- if (!(wsElement instanceof WorkingSetElementHolder)) continue;
-
- IWorkingSetElement candidate = ((WorkingSetElementHolder)wsElement).getElement();
- String candidateId = ((WorkingSetElementHolder)wsElement).getElementId();
-
- if (element.equals(candidate)) {
- contained = true;
- break;
- } else if (candidate == null && element.getElementId().equals(candidateId)) {
- contained = true;
- ((WorkingSetElementHolder)wsElement).setElement(element);
- break;
- }
- }
+ if (workingSet.equals(othersWorkingSet)) continue;
+ contained = isContained(element, workingSet);
if (contained) break;
}
return contained;
}
+
+ /**
+ * Checks if the element is contained in the given working set.
+ *
+ * @param element The element. Must not be <code>null</code>.
+ * @param workingSet The working set. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the element is contained in the given working set, <code>false</code> otherwise.
+ */
+ protected boolean isContained(IWorkingSetElement element, IWorkingSet workingSet) {
+ Assert.isNotNull(element);
+ Assert.isNotNull(workingSet);
+
+ boolean contained = false;
+
+ IAdaptable[] wsElements = workingSet.getElements();
+ for (IAdaptable wsElement : wsElements) {
+ if (!(wsElement instanceof WorkingSetElementHolder)) continue;
+
+ IWorkingSetElement candidate = ((WorkingSetElementHolder)wsElement).getElement();
+ String candidateId = ((WorkingSetElementHolder)wsElement).getElementId();
+
+ if (element.equals(candidate)) {
+ contained = true;
+ break;
+ } else if (candidate == null && element.getElementId().equals(candidateId)) {
+ contained = true;
+ ((WorkingSetElementHolder)wsElement).setElement(element);
+ break;
+ }
+ }
+
+ return contained;
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetElementHolder.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetElementHolder.java index 91c4c33d1..e4ed9c94f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetElementHolder.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetElementHolder.java @@ -10,8 +10,8 @@ package org.eclipse.tcf.te.ui.views.workingsets;
import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetNameIDs;
import org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement;
+import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetNameIDs;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;
@@ -134,4 +134,46 @@ public final class WorkingSetElementHolder extends PlatformObject implements IPe }
return super.getAdapter(adapter);
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ if (elementId != null) {
+ int hash = elementId.hashCode();
+ if (wsName != null) {
+ hash = hash << 16;
+ hash += wsName.hashCode();
+ }
+ return hash;
+ }
+ else if (wsName != null) {
+ return wsName.hashCode();
+ }
+
+ return super.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ // Working set element holder are identical if the element id
+ // and working set name matches
+ if (obj instanceof WorkingSetElementHolder) {
+ boolean equal = true;
+
+ if (elementId == null) equal &= ((WorkingSetElementHolder)obj).elementId == null;
+ else equal &= elementId.equals(((WorkingSetElementHolder)obj).elementId);
+
+ if (wsName == null) equal &= ((WorkingSetElementHolder)obj).wsName == null;
+ else equal &= wsName.equals(((WorkingSetElementHolder)obj).wsName);
+
+ return equal;
+ }
+
+ return super.equals(obj);
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetFilter.java index dfc0aff13..9d1f6796f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetFilter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetFilter.java @@ -14,11 +14,10 @@ import java.util.List; import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs;
import org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement;
-import org.eclipse.ui.IAggregateWorkingSet;
import org.eclipse.ui.IContainmentAdapter;
import org.eclipse.ui.IWorkingSet;
@@ -45,19 +44,24 @@ public class WorkingSetFilter extends ViewerFilter { */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (active && parentElement instanceof IWorkingSet) {
+ // If the filter is not active, all elements pass
+ if (!active) return true;
+
+ // If the parent element is a tree path, assume the last element as parent element
+ if (parentElement instanceof TreePath) {
+ parentElement = ((TreePath)parentElement).getLastSegment();
+ }
+
+ if (parentElement instanceof IWorkingSet) {
if (((IWorkingSet)parentElement).isEmpty()) {
return true;
}
- if (parentElement instanceof IAggregateWorkingSet) {
- List<IWorkingSet> workingSets = Arrays.asList(((IAggregateWorkingSet)parentElement).getComponents());
- if (workingSets.contains(element) || IWorkingSetIDs.ID_WS_OTHERS.equals(((IWorkingSet)element).getId())) {
- return true;
- }
- }
if (element != null) {
return isEnclosed((IWorkingSet)parentElement, element);
}
+ } else if (parentElement instanceof WorkingSetViewStateManager && element instanceof IWorkingSet) {
+ List<IWorkingSet> workingSets = Arrays.asList(((WorkingSetViewStateManager)parentElement).getAllWorkingSets());
+ return workingSets.contains(element);
}
return true;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewStateManager.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewStateManager.java new file mode 100644 index 000000000..17e7a5c31 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewStateManager.java @@ -0,0 +1,430 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.ui.views.workingsets;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.tcf.te.ui.views.activator.UIPlugin;
+import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs;
+import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetNameIDs;
+import org.eclipse.tcf.te.ui.views.internal.View;
+import org.eclipse.tcf.te.ui.views.nls.Messages;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.ILocalWorkingSetManager;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.navigator.IMementoAware;
+
+/**
+ * The WorkingSetViewStateManager is a state manager used to load and save persisted
+ * states from external storage and provide runtime access and modification
+ * methods.
+ */
+public final class WorkingSetViewStateManager implements IMementoAware {
+ // The file used to persist the states used in this plugin.
+ private static final String STATES_XML = "states.xml"; //$NON-NLS-1$
+
+ // The memento element name id's.
+
+ /** The root element of working set manager.*/
+ private static final String WORKING_SET_MANAGER = "workingSetManager"; //$NON-NLS-1$
+ /** The property name used to save the sorting flag of the working sets.*/
+ private static final String SORTED_WORKINGSET = "sortedWorkingSet"; //$NON-NLS-1$
+ /** The element used to save the order of the working sets specified by end users.*/
+ private static final String WORKINGSET_ORDER = "order"; //$NON-NLS-1$
+ /** The root element of visible working sets.*/
+ private static final String WORKINGSET_VISIBLE = "visibleWorkingSets"; //$NON-NLS-1$
+ /** The working set element. */
+ private static final String ELEMENT_WORKINGSET = "workingset"; //$NON-NLS-1$
+ /** The attribute to store name. */
+ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
+ /** The attribute to store the option that if the default working set should be sorted on top. */
+ private static final String ATTR_DEFAULT_WORKINGSET_ONTOP = "defaultWorkingSetOnTop"; //$NON-NLS-1$
+
+ // The parent view instance.
+ /* default */ View view;
+ // The working set manager used.
+ /* default */ ILocalWorkingSetManager localWorkingSetManager;
+ // If the working set is sorted
+ private boolean sortedWorkingSet;
+ // If the default fixed working sets, including My Targets and Local Subnet, should be on top when sorting.
+ private boolean defaultWorkingSetOnTop = true;
+ // The working set comparator used to sort the working set in the order specified by end users.
+ private CustomizedOrderComparator workingSetComparator;
+ // The list of active (checked) working sets
+ private List<IWorkingSet> visibleWorkingSets;
+
+ // Workbench wide working set manager property change listener
+ private IPropertyChangeListener workingSetManagerListener;
+
+ /**
+ * Constructor.
+ *
+ * @param view The parent view instance. Must not be <code>null</code>.
+ */
+ public WorkingSetViewStateManager(View view) {
+ Assert.isNotNull(view);
+ this.view = view;
+
+ IMemento memento = readWorkingSetMemento();
+ restoreState(memento);
+
+ initializeListener();
+ }
+
+ /**
+ * Returns the parent view instance.
+ *
+ * @return The parent view instance.
+ */
+ public View getParentView() {
+ return view;
+ }
+
+ /**
+ * If the default working sets are on top when sorting.
+ * @return true if it is or else false.
+ */
+ public boolean isDefaultWorkingSetOnTop() {
+ return defaultWorkingSetOnTop;
+ }
+
+ /**
+ * Get the current local working set manager used.
+ *
+ * @return The current local working set manager.
+ */
+ public ILocalWorkingSetManager getLocalWorkingSetManager() {
+ return localWorkingSetManager;
+ }
+
+ /**
+ * Returns the list of all working sets.
+ *
+ * @return The list of all working sets or an empty list.
+ */
+ public IWorkingSet[] getAllWorkingSets() {
+ List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>();
+
+ // Add the workbench wide working sets (target explorer type only)
+ IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet[] candidates = manager.getAllWorkingSets();
+ for (IWorkingSet candidate : candidates) {
+ if (!candidate.isAggregateWorkingSet() && IWorkingSetIDs.ID_WS_TARGET_EXPLORER.equals(candidate.getId())) {
+ if (!workingSets.contains(candidate)) {
+ workingSets.add(candidate);
+ }
+ }
+ }
+ // Add all local working sets
+ candidates = localWorkingSetManager.getAllWorkingSets();
+ for (IWorkingSet candidate : candidates) {
+ if (!workingSets.contains(candidate)) {
+ workingSets.add(candidate);
+ }
+ }
+
+ return workingSets.toArray(new IWorkingSet[workingSets.size()]);
+ }
+
+ /**
+ * Get the visible working sets displayed in the working set viewer.
+ * @return The visible working sets in a list.
+ */
+ public List<IWorkingSet> getVisibleWorkingSets() {
+ return visibleWorkingSets;
+ }
+
+ /**
+ * Set the visible working sets with a new working set list.
+ * @param visibleWorkingSets The new working set list.
+ */
+ public void setVisibleWorkingSets(List<IWorkingSet> visibleWorkingSets) {
+ this.visibleWorkingSets = visibleWorkingSets;
+ }
+
+ /**
+ * If the current working sets are sorted.
+ * @return true if they are sorted.
+ */
+ public boolean isSortedWorkingSet() {
+ return sortedWorkingSet;
+ }
+
+ /**
+ * Set the flag if the current working sets are sorted.
+ * @param sortedWorkingSet The new value.
+ */
+ public void setSortedWorkingSet(boolean sortedWorkingSet) {
+ this.sortedWorkingSet = sortedWorkingSet;
+ }
+
+ /**
+ * Get the customized ordered comparator. This comparator is
+ * used to sort the working sets when users define the order of the working sets.
+ * @return The comparator.
+ */
+ public CustomizedOrderComparator getWorkingSetComparator() {
+ return workingSetComparator;
+ }
+
+ /**
+ * Set the new customized ordered working set comparator.
+ *
+ * @param workingSetComparator The new comparator.
+ */
+ public void setWorkingSetComparator(CustomizedOrderComparator workingSetComparator) {
+ this.workingSetComparator = workingSetComparator;
+ }
+
+ /**
+ * Dispose the working set view state manager.
+ */
+ public void dispose() {
+ XMLMemento memento = XMLMemento.createWriteRoot(WORKING_SET_MANAGER);
+ saveState(memento);
+ try {
+ writeWorkingSetMemento(memento);
+ }
+ catch (IOException e) {
+ if (Platform.inDebugMode()) e.printStackTrace();
+ }
+ localWorkingSetManager.dispose();
+ if (workingSetManagerListener != null) {
+ PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(workingSetManagerListener);
+ workingSetManagerListener = null;
+ }
+ }
+
+ /**
+ * Initialize the working set view state manager listeners.
+ */
+ private void initializeListener() {
+ // Listen to changes to the workbench wide working set manager
+ // and trigger view updates on changes.
+ workingSetManagerListener = new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (IWorkingSetManager.CHANGE_WORKING_SET_ADD.equals(event.getProperty())) {
+ // A new working set got added to the manager. Newly added
+ // working sets are active (checked) by default.
+ IWorkingSet workingSet = (IWorkingSet)event.getNewValue();
+ if (workingSet != null) {
+ List<IWorkingSet> visible = getVisibleWorkingSets();
+ if (!visible.contains(workingSet)) {
+ visible.add(workingSet);
+ }
+ }
+ }
+ else if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(event.getProperty())) {
+ // A working set got removed. Remove from the list
+ // of visible working sets
+ IWorkingSet workingSet = (IWorkingSet)event.getOldValue();
+ if (workingSet != null) {
+ List<IWorkingSet> visible = getVisibleWorkingSets();
+ if (visible.contains(workingSet)) {
+ visible.remove(workingSet);
+ }
+ }
+ }
+
+ if (view != null && view.getCommonViewer() != null) {
+ view.getCommonViewer().refresh();
+ }
+ }
+ };
+ PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(workingSetManagerListener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void restoreState(IMemento memento) {
+ Boolean bool = memento.getBoolean(SORTED_WORKINGSET);
+ sortedWorkingSet = bool != null && bool.booleanValue();
+ if (!sortedWorkingSet) {
+ restoreWorkingSetOrder(memento);
+ }
+ bool = memento.getBoolean(ATTR_DEFAULT_WORKINGSET_ONTOP);
+ if (bool != null) {
+ defaultWorkingSetOnTop = bool.booleanValue();
+ }
+
+ // The local working set manager contains only automatic generated
+ // working sets. Do not restore anything from the memento
+ localWorkingSetManager = PlatformUI.getWorkbench().createLocalWorkingSetManager();
+ // Restore the local automatic working sets
+ restoreLocalWorkingSets();
+
+ // Restore the active (checked) working sets
+ restoreVisibleWorkingSet(memento);
+ }
+
+ /**
+ * Restore the local automatic working sets.
+ */
+ private void restoreLocalWorkingSets() {
+ Assert.isNotNull(localWorkingSetManager);
+ // Create the "Others" working set if not restored from the memento
+ IWorkingSet others = localWorkingSetManager.getWorkingSet(Messages.ViewStateManager_others_name);
+ if (others == null) {
+ others = localWorkingSetManager.createWorkingSet(Messages.ViewStateManager_others_name, new IAdaptable[0]);
+ others.setId(IWorkingSetIDs.ID_WS_OTHERS);
+ localWorkingSetManager.addWorkingSet(others);
+ } else {
+ others.setId(IWorkingSetIDs.ID_WS_OTHERS);
+ }
+ }
+
+ /**
+ * Restore the visible working sets from the specified memento element.
+ * @param memento The element.
+ */
+ private void restoreVisibleWorkingSet(IMemento memento) {
+ IMemento vwsMemento = memento.getChild(WORKINGSET_VISIBLE);
+ visibleWorkingSets = new ArrayList<IWorkingSet>();
+ if (vwsMemento != null) {
+ IMemento[] children = vwsMemento.getChildren(ELEMENT_WORKINGSET);
+ if (children != null && children.length > 0) {
+ IWorkingSet[] allWorkingSets = getAllWorkingSets();
+ for (IMemento child : children) {
+ String wsName = child.getString(ATTR_NAME);
+ for (IWorkingSet workingSet : allWorkingSets) {
+ if (wsName.equals(workingSet.getName())) {
+ visibleWorkingSets.add(workingSet);
+ }
+ }
+ }
+ }
+ } else {
+ IWorkingSet[] workingSets = getAllWorkingSets();
+ for (IWorkingSet workingSet : workingSets) {
+ visibleWorkingSets.add(workingSet);
+ }
+ }
+ }
+
+ /**
+ * Restore the order of working sets specified in the memento element.
+ * @param memento The element.
+ */
+ private void restoreWorkingSetOrder(IMemento memento) {
+ IMemento child = memento.getChild(WORKINGSET_ORDER);
+ if (child != null) {
+ String factoryId = child.getString(IWorkingSetNameIDs.FACTORY_ID);
+ IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId);
+ IAdaptable adaptable = factory.createElement(child);
+ IPersistableElement element = (IPersistableElement) adaptable.getAdapter(IPersistableElement.class);
+ if (element instanceof CustomizedOrderComparator) {
+ workingSetComparator = (CustomizedOrderComparator) element;
+ }
+ }
+ }
+
+ /**
+ * Save the states to the specified memento element.
+ */
+ @Override
+ public void saveState(IMemento memento) {
+ memento.putBoolean(SORTED_WORKINGSET, sortedWorkingSet);
+ if (!sortedWorkingSet) {
+ if (workingSetComparator != null) {
+ IMemento child = memento.createChild(WORKINGSET_ORDER);
+ child.putString(IWorkingSetNameIDs.FACTORY_ID, workingSetComparator.getFactoryId());
+ workingSetComparator.saveState(child);
+ }
+ }
+ memento.putBoolean(ATTR_DEFAULT_WORKINGSET_ONTOP, defaultWorkingSetOnTop);
+ IMemento vwsMemento = memento.createChild(WORKINGSET_VISIBLE);
+ for (IWorkingSet workingSet : visibleWorkingSets) {
+ IMemento child = vwsMemento.createChild(ELEMENT_WORKINGSET);
+ child.putString(ATTR_NAME, workingSet.getName());
+ }
+ }
+
+ /**
+ * Returns the file used as the persistence store, or <code>null</code> if
+ * there is no available file.
+ *
+ * @return the file used as the persistence store, or <code>null</code>
+ */
+ private File getStateFile() {
+ try {
+ IPath path = UIPlugin.getDefault().getStateLocation();
+ path = path.append(STATES_XML);
+ return path.toFile();
+ }catch (IllegalStateException e) {
+ // An RCP workspace-less environment (-data @none)
+ File root = new File(System.getProperty("user.home"), ".tcf"); //$NON-NLS-1$ //$NON-NLS-2$
+ File ws = new File(root, "ws"); //$NON-NLS-1$
+ return new File(ws, STATES_XML);
+ }
+ }
+
+ /**
+ * Read the working set memento element from the state file.
+ * @return The working set memento.
+ */
+ private IMemento readWorkingSetMemento() {
+ File stateFile = getStateFile();
+ if (stateFile != null && stateFile.exists()) {
+ BufferedReader reader = null;
+ try {
+ FileInputStream input = new FileInputStream(stateFile);
+ reader = new BufferedReader(new InputStreamReader(input, "utf-8")); //$NON-NLS-1$
+ IMemento memento = XMLMemento.createReadRoot(reader);
+ return memento;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+ return XMLMemento.createWriteRoot(WORKING_SET_MANAGER);
+ }
+
+ /**
+ * Write working set memento to the state file.
+ * @param memento The working set memento.
+ * @throws IOException thrown when writing fails.
+ */
+ private void writeWorkingSetMemento(XMLMemento memento) throws IOException {
+ File stateFile = getStateFile();
+ FileOutputStream stream = new FileOutputStream(stateFile);
+ OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
+ memento.save(writer);
+ writer.close();
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewerSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewerSorter.java index 1c6a890a3..fd9d998be 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewerSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetViewerSorter.java @@ -10,28 +10,35 @@ package org.eclipse.tcf.te.ui.views.workingsets; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs; import org.eclipse.tcf.te.ui.trees.TreeViewerSorter; +import org.eclipse.tcf.te.ui.views.internal.View; import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.internal.WorkingSetComparator; +import org.eclipse.ui.navigator.CommonViewer; /** * Working set viewer sorter implementation. */ +@SuppressWarnings("restriction") public class WorkingSetViewerSorter extends TreeViewerSorter { + private final WorkingSetComparator wsComparator = new WorkingSetComparator(); /* (non-Javadoc) * @see org.eclipse.tcf.te.ui.trees.TreeViewerSorter#doCompare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object, java.lang.String, int, int) */ - @Override + @Override protected int doCompare(Viewer viewer, Object node1, Object node2, String sortColumn, int index, int inverter) { if (node1 instanceof IWorkingSet && node2 instanceof IWorkingSet) { - // The "Others" working set will appear always at the bottom of the tree - if (IWorkingSetIDs.ID_WS_OTHERS.equals(((IWorkingSet)node1).getId())) { - return 1; + WorkingSetViewStateManager manager = null; + if (viewer instanceof CommonViewer && ((CommonViewer)viewer).getCommonNavigator() instanceof View) { + manager = ((View)((CommonViewer)viewer).getCommonNavigator()).getStateManager(); } - if (IWorkingSetIDs.ID_WS_OTHERS.equals(((IWorkingSet)node2).getId())) { - return -1; + if (manager != null) { + if (manager.isSortedWorkingSet()) return wsComparator.compare(node1, node2); + CustomizedOrderComparator comparator = manager.getWorkingSetComparator(); + if (comparator != null) return comparator.compare((IWorkingSet)node1, (IWorkingSet)node2); } + } return super.doCompare(viewer, node1, node2, sortColumn, index, inverter); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetsContentProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetsContentProvider.java index 8b3e344b7..6c8f17803 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetsContentProvider.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/WorkingSetsContentProvider.java @@ -12,26 +12,28 @@ package org.eclipse.tcf.te.ui.views.workingsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.tcf.te.runtime.events.EventManager; +import org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement; +import org.eclipse.tcf.te.ui.views.activator.UIPlugin; import org.eclipse.tcf.te.ui.views.events.ViewerContentChangeEvent; import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs; import org.eclipse.tcf.te.ui.views.internal.View; import org.eclipse.tcf.te.ui.views.internal.ViewRoot; import org.eclipse.tcf.te.ui.views.nls.Messages; -import org.eclipse.tcf.te.runtime.events.EventManager; -import org.eclipse.tcf.te.runtime.interfaces.workingsets.IWorkingSetElement; -import org.eclipse.ui.IAggregateWorkingSet; import org.eclipse.ui.ILocalWorkingSetManager; import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.navigator.NavigatorContentService; @@ -40,6 +42,7 @@ import org.eclipse.ui.navigator.CommonViewer; import org.eclipse.ui.navigator.ICommonContentExtensionSite; import org.eclipse.ui.navigator.ICommonContentProvider; import org.eclipse.ui.navigator.IExtensionStateModel; +import org.eclipse.ui.navigator.INavigatorFilterService; /** * Provides children and parents for IWorkingSets. @@ -56,20 +59,33 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { /** * A key used by the Extension State Model to keep track of whether top level Working Sets or - * Projects should be shown in the viewer. + * Elements should be shown in the viewer. */ public static final String SHOW_TOP_LEVEL_WORKING_SETS = EXTENSION_ID + ".showTopLevelWorkingSets"; //$NON-NLS-1$ + /** + * Working set filter extension id. + */ + private static final String WORKING_SET_FILTER_ID = "org.eclipse.tcf.te.ui.views.navigator.filters.workingSet"; //$NON-NLS-1$ + + /** + * Child elements returned by this content provider in case there + * are no children. + */ private static final Object[] NO_CHILDREN = new Object[0]; - private WorkingSetHelper helper; - /* default */ IAggregateWorkingSet workingSetRoot; + // The common navigator working set content extension state model. private IExtensionStateModel extensionStateModel; - private CommonNavigator targetExplorer; + // The parent viewer object private CommonViewer viewer; + // The working set filter instance + private WorkingSetFilter filter; - private ILocalWorkingSetManager localWorkingSetManager; - + /** + * The root mode listener listens to property changes of the working set content + * extension state model to update the viewer root mode if the user changes the + * top level element type. + */ private IPropertyChangeListener rootModeListener = new IPropertyChangeListener() { /* (non-Javadoc) @@ -82,7 +98,6 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { updateRootMode(); } } - }; /* (non-Javadoc) @@ -92,9 +107,27 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { public void init(ICommonContentExtensionSite config) { NavigatorContentService cs = (NavigatorContentService) config.getService(); viewer = (CommonViewer) cs.getViewer(); - targetExplorer = viewer.getCommonNavigator(); - localWorkingSetManager = targetExplorer instanceof View ? ((View)targetExplorer).getLocalWorkingSetManager() : PlatformUI.getWorkbench().createLocalWorkingSetManager(); + // Get the filter service to activate the working set viewer filter + INavigatorFilterService filterService = cs.getFilterService(); + // The working set filter should be among the visible filters + ViewerFilter[] filters = filterService.getVisibleFilters(false); + for (ViewerFilter candidate : filters) { + if (candidate instanceof WorkingSetFilter) { + filter = (WorkingSetFilter)candidate; + } + } + + if (filter != null && !filterService.isActive(WORKING_SET_FILTER_ID)) { + filterService.activateFilterIdsAndUpdateViewer(new String[] { WORKING_SET_FILTER_ID }); + filterService.persistFilterActivationState(); + } + else if (filter == null) { + IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), + "Required filter " + WORKING_SET_FILTER_ID //$NON-NLS-1$ + + " is not present. Working set support will not function correctly."); //$NON-NLS-1$ + UIPlugin.getDefault().getLog().log(status); + } extensionStateModel = config.getExtensionStateModel(); extensionStateModel.addPropertyChangeListener(rootModeListener); @@ -107,20 +140,20 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public void restoreState(IMemento memento) { - // We can call the local working set manager restoreState(memento) method - // only as long the working set manager is empty - if (memento != null && localWorkingSetManager.getWorkingSets().length == 0) { - localWorkingSetManager.restoreState(memento); - - IWorkingSet old = localWorkingSetManager.getWorkingSet("Others"); //$NON-NLS-1$ - if (old != null) localWorkingSetManager.removeWorkingSet(old); + // Determine the target explorer view local working set manager instance + ILocalWorkingSetManager manager = null; + if (viewer.getCommonNavigator() instanceof View) { + manager = ((View)viewer.getCommonNavigator()).getStateManager().getLocalWorkingSetManager(); + } + // Recreate the local automatic working sets + if (manager != null) { // Create the "Others" working set if not restored from the memento - IWorkingSet others = localWorkingSetManager.getWorkingSet(Messages.WorkingSetContentProvider_others_name); + IWorkingSet others = manager.getWorkingSet(Messages.ViewStateManager_others_name); if (others == null) { - others = localWorkingSetManager.createWorkingSet(Messages.WorkingSetContentProvider_others_name, new IAdaptable[0]); + others = manager.createWorkingSet(Messages.ViewStateManager_others_name, new IAdaptable[0]); others.setId(IWorkingSetIDs.ID_WS_OTHERS); - localWorkingSetManager.addWorkingSet(others); + manager.addWorkingSet(others); } else { others.setId(IWorkingSetIDs.ID_WS_OTHERS); } @@ -136,7 +169,6 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public void saveState(IMemento memento) { - if (memento != null) localWorkingSetManager.saveState(memento); } /* (non-Javadoc) @@ -145,21 +177,16 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof IWorkingSet) { - IWorkingSet workingSet = (IWorkingSet) parentElement; - if (workingSet.isAggregateWorkingSet() && targetExplorer != null) { - switch (targetExplorer.getRootMode()) { - case IUIConstants.MODE_WORKING_SETS: - List<IWorkingSet> allWorkingSets = new ArrayList<IWorkingSet>(); - allWorkingSets.addAll(Arrays.asList(((IAggregateWorkingSet) workingSet).getComponents())); - allWorkingSets.addAll(Arrays.asList(localWorkingSetManager.getWorkingSets())); - return allWorkingSets.toArray(new IWorkingSet[allWorkingSets.size()]); - case IUIConstants.MODE_NORMAL: - return getWorkingSetElements(workingSet); - } + // Return the working set elements + return getWorkingSetElements((IWorkingSet)parentElement); + } + else if (parentElement instanceof WorkingSetViewStateManager) { + List<IWorkingSet> workingSets = ((WorkingSetViewStateManager)parentElement).getVisibleWorkingSets(); + if (workingSets != null && !workingSets.isEmpty()) { + return workingSets.toArray(); } - - return getWorkingSetElements(workingSet); } + return NO_CHILDREN; } @@ -194,7 +221,27 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public Object getParent(Object element) { - if (helper != null) return helper.getParent(element); + if (element instanceof IWorkingSet) { + CommonNavigator navigator = viewer.getCommonNavigator(); + if (navigator instanceof View) { + WorkingSetViewStateManager manager = ((View)navigator).getStateManager(); + List<IWorkingSet> allWorkingSets = Arrays.asList(manager.getAllWorkingSets()); + if (allWorkingSets.contains(element)) { + return manager; + } + } + } + else if (element instanceof WorkingSetElementHolder) { + String wsName = ((WorkingSetElementHolder)element).getWorkingSetName(); + if (wsName != null) { + IWorkingSet ws = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(wsName); + if (ws == null && viewer.getCommonNavigator() instanceof View) { + ws = ((View)viewer.getCommonNavigator()).getStateManager().getLocalWorkingSetManager().getWorkingSet(wsName); + } + return ws; + } + } + return null; } @@ -203,6 +250,9 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public boolean hasChildren(Object element) { + if (element instanceof IWorkingSet) { + return ((IWorkingSet)element).getElements().length > 0; + } return true; } @@ -219,10 +269,7 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public void dispose() { - helper = null; extensionStateModel.removePropertyChangeListener(rootModeListener); - // If we have create the local working set manager, we have to dispose it - if (!(targetExplorer instanceof View)) localWorkingSetManager.dispose(); } /* (non-Javadoc) @@ -230,69 +277,45 @@ public class WorkingSetsContentProvider implements ICommonContentProvider { */ @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (newInput instanceof IWorkingSet) { - IWorkingSet rootSet = (IWorkingSet) newInput; - helper = new WorkingSetHelper(rootSet); - } } + /** + * Update the common navigator root mode. + */ private void updateRootMode() { - if (targetExplorer == null) { - return; - } + CommonNavigator navigator = viewer.getCommonNavigator(); + if (navigator == null) return; + + Object newInput; + boolean filterActive; if (extensionStateModel.getBooleanProperty(SHOW_TOP_LEVEL_WORKING_SETS)) { - targetExplorer.setRootMode(IUIConstants.MODE_WORKING_SETS); + navigator.setRootMode(IUIConstants.MODE_WORKING_SETS); + newInput = ((View)navigator).getStateManager(); + filterActive = true; } else { - targetExplorer.setRootMode(IUIConstants.MODE_NORMAL); - } - } + navigator.setRootMode(IUIConstants.MODE_NORMAL); - protected class WorkingSetHelper { - - private final IWorkingSet workingSet; - private final Map<Object, Object> parents = new WeakHashMap<Object, Object>(); - - /** - * Create a Helper class for the given working set - * - * @param set The set to use to build the item to parent map. - */ - public WorkingSetHelper(IWorkingSet set) { - workingSet = set; - - if (workingSet.isAggregateWorkingSet()) { - IAggregateWorkingSet aggregateSet = (IAggregateWorkingSet) workingSet; - if (workingSetRoot == null) workingSetRoot = aggregateSet; - - IWorkingSet[] components = aggregateSet.getComponents(); - - for (int componentIndex = 0; componentIndex < components.length; componentIndex++) { - IAdaptable[] elements = getWorkingSetElements(components[componentIndex]); - for (int elementsIndex = 0; elementsIndex < elements.length; elementsIndex++) { - parents.put(elements[elementsIndex], components[componentIndex]); - } - parents.put(components[componentIndex], aggregateSet); - - } - } - else { - IAdaptable[] elements = getWorkingSetElements(workingSet); - for (int elementsIndex = 0; elementsIndex < elements.length; elementsIndex++) { - parents.put(elements[elementsIndex], workingSet); - } + // Determine if to use the windows working set by default + IWorkingSet windowWorkingSet = null; + if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT)) { + windowWorkingSet = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getAggregateWorkingSet(); } + + newInput = windowWorkingSet != null ? windowWorkingSet : ViewRoot.getInstance(); + filterActive = windowWorkingSet != null; } - /** - * - * @param element An element from the viewer - * @return The parent associated with the element, if any. - */ - public Object getParent(Object element) { - if (element instanceof IWorkingSet && element != workingSetRoot) return workingSetRoot; - return parents.get(element); + if (!newInput.equals(viewer.getInput())) { + viewer.setInput(newInput); } + setFilterActive(filterActive); } + /** + * Update the working set viewer filter active state. + */ + private void setFilterActive(boolean active) { + if (filter != null) filter.setActive(active); + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/ConfigureWorkingSetAction.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/ConfigureWorkingSetAction.java new file mode 100644 index 000000000..14156eae5 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/ConfigureWorkingSetAction.java @@ -0,0 +1,181 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.ui.views.workingsets.actions;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs;
+import org.eclipse.tcf.te.ui.views.internal.View;
+import org.eclipse.tcf.te.ui.views.nls.Messages;
+import org.eclipse.tcf.te.ui.views.workingsets.CustomizedOrderComparator;
+import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetViewStateManager;
+import org.eclipse.tcf.te.ui.views.workingsets.dialogs.WorkingSetConfigurationDialog;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Configure working sets action implementation.
+ */
+public class ConfigureWorkingSetAction extends Action {
+ // The parent viewer instance.
+ private StructuredViewer viewer;
+
+ /**
+ * Constructor.
+ *
+ * @param view The parent viewer instance. Must not be <code>null</code>.
+ */
+ public ConfigureWorkingSetAction(StructuredViewer viewer) {
+ super(Messages.ConfigureWorkingSetAction_text);
+ setToolTipText(Messages.ConfigureWorkingSetAction_toolTip);
+
+ Assert.isNotNull(viewer);
+ this.viewer = viewer;
+ }
+
+ /**
+ * Duplicate the specified working sets and return a working set list for editing.
+ *
+ * @param workingSets The working sets
+ * @return A duplication list of the working sets.
+ */
+ private List<IWorkingSet> duplicate(IWorkingSet[] workingSets) {
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+ List<IWorkingSet> result = new ArrayList<IWorkingSet>();
+ for (IWorkingSet workingSet : workingSets) {
+ // Local automatic working sets are not editable
+ // -> no need to create a duplicate
+ if (isLocalWorkingSet(workingSet)) {
+ result.add(workingSet);
+ } else {
+ IWorkingSet newWorkingSet = workingSetManager.createWorkingSet(workingSet.getName(), workingSet.getElements());
+ newWorkingSet.setId(workingSet.getId());
+ result.add(newWorkingSet);
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ // Get the view working set state manager
+ WorkingSetViewStateManager manager = ((View)((CommonViewer)viewer).getCommonNavigator()).getStateManager();
+ // Get the workbench wide working set manager
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+
+ // Get all working sets (both local and workbench wide, target explorer type only)
+ IWorkingSet[] allWorkingSets = manager.getAllWorkingSets();
+ // Create working copies of the (sorted) working sets
+ List<IWorkingSet> workingSets = duplicate(allWorkingSets);
+
+ // Determine the active (checked) working sets
+ List<IWorkingSet> visibleWorkingSets = manager.getVisibleWorkingSets();
+ IWorkingSet[] activeWorkingSets = visibleWorkingSets.toArray(new IWorkingSet[visibleWorkingSets.size()]);
+
+ // Sort the working sets if necessary
+ boolean sortedWorkingSets = manager.isSortedWorkingSet();
+ if (!sortedWorkingSets) {
+ Comparator<IWorkingSet> workingSetComparator = manager.getWorkingSetComparator();
+ if (workingSetComparator != null) Collections.sort(workingSets, workingSetComparator);
+ }
+
+ // Create the working set configuration dialog
+ WorkingSetConfigurationDialog dialog = new WorkingSetConfigurationDialog(workingSetManager,
+ viewer.getControl().getShell(),
+ workingSets.toArray(new IWorkingSet[workingSets.size()]),
+ sortedWorkingSets);
+ // Set the active working sets
+ dialog.setSelection(activeWorkingSets);
+ // And open the dialog
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ // Remember the current list of recently used working sets
+ IWorkingSet[] mruWorkingSets = workingSetManager.getRecentWorkingSets();
+ // Remove the old working set instances (non-local only)
+ for (IWorkingSet workingSet : allWorkingSets) {
+ if (!isLocalWorkingSet(workingSet)) {
+ workingSetManager.removeWorkingSet(workingSet);
+ }
+ }
+ // Get the new working set list from the dialog
+ allWorkingSets = dialog.getAllWorkingSets();
+ // And add the working sets back to the manager (non-local only)
+ for (IWorkingSet workingSet : allWorkingSets) {
+ if (!isLocalWorkingSet(workingSet)) {
+ workingSetManager.addWorkingSet(workingSet);
+ }
+ // If the working set existed in the recently used working set list,
+ // restore it
+ if (exists(workingSet.getName(), mruWorkingSets)) {
+ workingSetManager.addRecentWorkingSet(workingSet);
+ }
+ }
+
+ // Update the sorted state
+ sortedWorkingSets = dialog.isSortingEnabled();
+ manager.setSortedWorkingSet(sortedWorkingSets);
+ if (!sortedWorkingSets) {
+ CustomizedOrderComparator comparator = new CustomizedOrderComparator(allWorkingSets);
+ manager.setWorkingSetComparator(comparator);
+ }
+
+ // Update the active (checked) working set list
+ IWorkingSet[] selection = dialog.getSelection();
+ List<IWorkingSet> list = new ArrayList<IWorkingSet>(Arrays.asList(selection));
+ manager.setVisibleWorkingSets(list);
+
+ // Trigger a viewer refresh to reflect the changes
+ viewer.refresh();
+ }
+ }
+
+ /**
+ * Determine if the given working set is a local working set and therefore
+ * managed by the local working set manager.
+ *
+ * @param workingSet The working set. Must not be <code>null</code>.
+ * @return <code>True</code> if the working set is a local working set, <code>false</code> otherwise.
+ */
+ private boolean isLocalWorkingSet(IWorkingSet workingSet) {
+ Assert.isNotNull(workingSet);
+
+ boolean isLocal = IWorkingSetIDs.ID_WS_OTHERS.equals(workingSet.getId());
+
+ return isLocal;
+ }
+
+ /**
+ * Judge if the working set with the specified name exists in the working set array.
+ *
+ * @param wsname The name of the working set.
+ * @param workingSets The working set array to be searched.
+ * @return true if a working set with the specified name exists.
+ */
+ private boolean exists(String wsname, IWorkingSet[] workingSets) {
+ for (IWorkingSet workingSet : workingSets) {
+ if (wsname.equals(workingSet)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/actions/WorkingSetRootModeActionGroup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionGroup.java index 8420eea34..fa560fd26 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/actions/WorkingSetRootModeActionGroup.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionGroup.java @@ -7,10 +7,11 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.ui.views.actions; +package org.eclipse.tcf.te.ui.views.workingsets.actions; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -28,6 +29,7 @@ import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetsContentProvider; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.navigator.CommonViewer; import org.eclipse.ui.navigator.IExtensionStateModel; /** @@ -41,44 +43,59 @@ import org.eclipse.ui.navigator.IExtensionStateModel; * <p> * Copied and adapted from <code>org.eclipse.ui.internal.navigator.resources.actions.WorkingSetRootModeActionGroup</code>. */ -public class WorkingSetRootModeActionGroup extends ActionGroup { +public class WorkingSetActionGroup extends ActionGroup { + private static final String WS_GROUP = "group.ws"; //$NON-NLS-1$ /* default */ IExtensionStateModel stateModel; /* default */ StructuredViewer viewer; private boolean hasContributedToViewMenu = false; private IAction workingSetsAction = null; - private IAction targetsAction = null; + private IAction elementsAction = null; /* default */ IAction[] actions; /* default */ int currentSelection; /* default */ MenuItem[] items; + /** + * Toggle action switching the top elements between working sets and elements. + */ private class TopLevelContentAction extends Action { - - private final boolean groupWorkingSets; + // If true, the action does enable working set top elements. + private final boolean showWorkingSets; /** - * Construct an Action that represents a toggle-able state between Showing top level Working - * Sets and Projects. + * Constructor * - * @param toGroupWorkingSets + * @param showWorkingSets If <code>true</code>, the action does enable working sets as top level elements, + * <code>false</code> to disable working sets as top level elements. */ public TopLevelContentAction(boolean toGroupWorkingSets) { super("", AS_RADIO_BUTTON); //$NON-NLS-1$ - groupWorkingSets = toGroupWorkingSets; + showWorkingSets = toGroupWorkingSets; } /* (non-Javadoc) * @see org.eclipse.jface.action.Action#run() */ - @Override + @SuppressWarnings("restriction") + @Override public void run() { - if (stateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS) != groupWorkingSets) { - stateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, groupWorkingSets); - + boolean isShowTopLevelWorkingSets = stateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS); + if (isShowTopLevelWorkingSets != showWorkingSets) { + // Toggle the "show working set top level elements" property. + // + // This will trigger the WorkingSetsContentProvider property change listener + // to update the target explorer view root mode. + stateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets); + + // Disable the viewer redraw, refresh the viewer, reset + // the frame list and enable redraw finally. viewer.getControl().setRedraw(false); try { viewer.refresh(); + if (viewer instanceof CommonViewer) { + ((CommonViewer)viewer).getFrameList().reset(); + } } finally { viewer.getControl().setRedraw(true); @@ -94,7 +111,7 @@ public class WorkingSetRootModeActionGroup extends ActionGroup { * @param viewer * @param stateModel */ - public WorkingSetRootModeActionGroup(StructuredViewer viewer, IExtensionStateModel stateModel) { + public WorkingSetActionGroup(StructuredViewer viewer, IExtensionStateModel stateModel) { super(); this.viewer = viewer; this.stateModel = stateModel; @@ -106,9 +123,14 @@ public class WorkingSetRootModeActionGroup extends ActionGroup { @Override public void fillActionBars(IActionBars actionBars) { if (hasContributedToViewMenu) return; - IMenuManager topLevelSubMenu = new MenuManager(Messages.WorkingSetRootModeActionGroup_Top_Level_Element); + IMenuManager topLevelSubMenu = new MenuManager(Messages.WorkingSetActionGroup_Top_Level_Element); addActions(topLevelSubMenu); - actionBars.getMenuManager().insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, topLevelSubMenu); + + IMenuManager manager = actionBars.getMenuManager(); + manager.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, new GroupMarker(WS_GROUP)); + manager.appendToGroup(WS_GROUP, topLevelSubMenu); + manager.appendToGroup(WS_GROUP, new Separator()); + manager.appendToGroup(WS_GROUP, new ConfigureWorkingSetAction(viewer)); hasContributedToViewMenu = true; } @@ -166,15 +188,15 @@ public class WorkingSetRootModeActionGroup extends ActionGroup { private IAction[] createActions() { - targetsAction = new TopLevelContentAction(false); - targetsAction.setText(Messages.WorkingSetRootModeActionGroup_Target); - targetsAction.setImageDescriptor(UIPlugin.getImageDescriptor(ImageConsts.VIEW)); + elementsAction = new TopLevelContentAction(false); + elementsAction.setText(Messages.WorkingSetActionGroup_Elements); + elementsAction.setImageDescriptor(UIPlugin.getImageDescriptor(ImageConsts.VIEW)); workingSetsAction = new TopLevelContentAction(true); - workingSetsAction.setText(Messages.WorkingSetRootModeActionGroup_Working_Set); + workingSetsAction.setText(Messages.WorkingSetActionGroup_Working_Set); workingSetsAction.setImageDescriptor(UIPlugin.getImageDescriptor(ImageConsts.WORKING_SETS)); - return new IAction[] { targetsAction, workingSetsAction }; + return new IAction[] { elementsAction, workingSetsAction }; } /** @@ -188,12 +210,13 @@ public class WorkingSetRootModeActionGroup extends ActionGroup { currentSelection = showTopLevelWorkingSets ? 1 : 0; workingSetsAction.setChecked(showTopLevelWorkingSets); - targetsAction.setChecked(!showTopLevelWorkingSets); + elementsAction.setChecked(!showTopLevelWorkingSets); if (items != null) { for (int i = 0; i < items.length; i++) { - if (items[i] != null && actions[i] != null) items[i].setSelection(actions[i] - .isChecked()); + if (items[i] != null && actions[i] != null) { + items[i].setSelection(actions[i].isChecked()); + } } } if (stateModel != null) { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java new file mode 100644 index 000000000..f67d12ad1 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/actions/WorkingSetActionProvider.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2011 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.ui.views.workingsets.actions; + +import org.eclipse.tcf.te.ui.views.workingsets.WorkingSetsContentProvider; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.CommonViewer; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.IExtensionActivationListener; +import org.eclipse.ui.navigator.IExtensionStateModel; +import org.eclipse.ui.navigator.INavigatorContentService; + +/** + * Working set action provider implementation. + */ +public class WorkingSetActionProvider extends CommonActionProvider { + // Mark if the contribution items have been added to the menu + private boolean contributedToViewMenu = false; + + /* default */ CommonViewer viewer; + /* default */ INavigatorContentService contentService; + /* default */ WorkingSetActionGroup workingSetActionGroup; + /* default */ IExtensionStateModel extensionStateModel; + + private IExtensionActivationListener activationListener = new IExtensionActivationListener() { + + @Override + public void onExtensionActivation(String viewerId, String[] extensionIds, boolean isActive) { + + for (int i = 0; i < extensionIds.length; i++) { + if (WorkingSetsContentProvider.EXTENSION_ID.equals(extensionIds[i])) { + if (isActive) { + extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID); + workingSetActionGroup.setStateModel(extensionStateModel); + } else { + workingSetActionGroup.setShowTopLevelWorkingSets(false); + } + } + } + } + + }; + + @Override + public void init(ICommonActionExtensionSite site) { + viewer = (CommonViewer) site.getStructuredViewer(); + contentService = site.getContentService(); + + extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID); + + workingSetActionGroup = new WorkingSetActionGroup(viewer, extensionStateModel); + + contentService.getActivationService().addExtensionActivationListener(activationListener); + } + + @Override + public void restoreState(final IMemento memento) { + super.restoreState(memento); + + // Need to run this asynchronous to avoid being reentered when processing a selection change + viewer.getControl().getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + boolean showWorkingSets = true; + if (memento != null) { + Integer showWorkingSetsInt = memento.getInteger(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS); + showWorkingSets = showWorkingSetsInt == null || showWorkingSetsInt.intValue() == 1; + extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets); + workingSetActionGroup.setShowTopLevelWorkingSets(showWorkingSets); + } else { + showWorkingSets = false; + + extensionStateModel.setBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets); + workingSetActionGroup.setShowTopLevelWorkingSets(showWorkingSets); + } + } + }); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonActionProvider#saveState(org.eclipse.ui.IMemento) + */ + @Override + public void saveState(IMemento memento) { + super.saveState(memento); + + if (memento != null) { + int showWorkingSets = extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS) ? 1 : 0; + memento.putInteger(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS, showWorkingSets); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + @Override + public void fillActionBars(IActionBars actionBars) { + if (!contributedToViewMenu) { + try { + super.fillActionBars(actionBars); + workingSetActionGroup.fillActionBars(actionBars); + } finally { + contributedToViewMenu = true; + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + @Override + public void dispose() { + super.dispose(); + workingSetActionGroup.dispose(); + contentService.getActivationService().removeExtensionActivationListener(activationListener); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/dialogs/WorkingSetConfigurationDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/dialogs/WorkingSetConfigurationDialog.java new file mode 100644 index 000000000..ad0dfb119 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/workingsets/dialogs/WorkingSetConfigurationDialog.java @@ -0,0 +1,598 @@ +/*******************************************************************************
+ * Copyright (c) 2011 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.ui.views.workingsets.dialogs;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+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.tcf.te.ui.views.interfaces.workingsets.IWorkingSetIDs;
+import org.eclipse.tcf.te.ui.views.nls.Messages;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
+import org.eclipse.ui.dialogs.IWorkingSetNewWizard;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.ui.internal.WorkingSetComparator;
+
+/**
+ * The working set configuration dialog used to edit the working set content and order.
+ *
+ * <p>
+ * Copied and adapted from <code>org.eclipse.cdt.internal.ui.WorkingSetConfigurationDialog</code>.
+ */
+@SuppressWarnings("restriction")
+public class WorkingSetConfigurationDialog extends SelectionDialog {
+
+ private static class WorkingSetLabelProvider extends LabelProvider {
+ private Map<ImageDescriptor, Image> fIcons;
+
+ public WorkingSetLabelProvider() {
+ fIcons = new Hashtable<ImageDescriptor, Image>();
+ }
+
+ @Override
+ public void dispose() {
+ Iterator<Image> iterator = fIcons.values().iterator();
+ while (iterator.hasNext()) {
+ Image icon = iterator.next();
+ icon.dispose();
+ }
+ super.dispose();
+ }
+
+ @Override
+ public Image getImage(Object object) {
+ Assert.isTrue(object instanceof IWorkingSet);
+ IWorkingSet workingSet = (IWorkingSet) object;
+ ImageDescriptor imageDescriptor = workingSet.getImageDescriptor();
+ if (imageDescriptor == null) return null;
+ Image icon = fIcons.get(imageDescriptor);
+ if (icon == null) {
+ icon = imageDescriptor.createImage();
+ fIcons.put(imageDescriptor, icon);
+ }
+ return icon;
+ }
+
+ @Override
+ public String getText(Object object) {
+ Assert.isTrue(object instanceof IWorkingSet);
+ IWorkingSet workingSet = (IWorkingSet) object;
+ return workingSet.getName();
+ }
+ }
+
+ List<IWorkingSet> fAllWorkingSets;
+ CheckboxTableViewer fTableViewer;
+
+ Button fNewButton;
+ Button fEditButton;
+ Button fRemoveButton;
+ Button fUpButton;
+ Button fDownButton;
+ Button fSelectAll;
+ Button fDeselectAll;
+ IWorkingSetManager workingSetManager;
+ /**
+ * Sort working sets button.
+ *
+ * @since 3.5
+ */
+ Button fSortWorkingSet;
+
+ IWorkingSet[] fResult;
+
+ int nextButtonId = IDialogConstants.CLIENT_ID + 1;
+
+ /**
+ * Value of sorted state of working sets.
+ *
+ * @since 3.5
+ */
+ boolean fIsSortingEnabled;
+
+ /**
+ * The working set comparator.
+ *
+ * @since 3.5
+ */
+ WorkingSetComparator fComparator;
+
+ public WorkingSetConfigurationDialog(IWorkingSetManager workingSetManager, Shell parentShell, IWorkingSet[] allWorkingSets, boolean isSortingEnabled) {
+ super(parentShell);
+ this.workingSetManager = workingSetManager;
+ setTitle(Messages.WorkingSetConfigurationDialog_title);
+ setMessage(Messages.WorkingSetConfigurationDialog_message);
+ fAllWorkingSets = new ArrayList<IWorkingSet>(allWorkingSets.length);
+ for (int i = 0; i < allWorkingSets.length; i++) {
+ fAllWorkingSets.add(allWorkingSets[i]);
+ }
+ fIsSortingEnabled = isSortingEnabled;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ }
+
+ /**
+ * Returns the selected working sets
+ *
+ * @return the selected working sets
+ */
+ public IWorkingSet[] getSelection() {
+ return fResult;
+ }
+
+ /**
+ * Sets the initial selection
+ *
+ * @param workingSets the initial selection
+ */
+ public void setSelection(IWorkingSet[] workingSets) {
+ fResult = workingSets;
+ setInitialSelections(workingSets);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ Control control = super.createContents(parent);
+ setInitialSelection();
+ updateButtonAvailability();
+ return control;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ createMessageArea(composite);
+ Composite inner = new Composite(composite, SWT.NONE);
+ inner.setLayoutData(new GridData(GridData.FILL_BOTH));
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ inner.setLayout(layout);
+ createTableViewer(inner);
+ createOrderButtons(inner);
+ createModifyButtons(composite);
+ if (fIsSortingEnabled) {
+ fTableViewer.setComparator(new ViewerComparator(getComparator()) {
+ /*
+ * @see ViewerComparator#compare(Viewer, Object, Object)
+ * @since 3.5
+ */
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ return getComparator().compare(e1, e2);
+ }
+ });
+ }
+ fTableViewer.setInput(fAllWorkingSets);
+ applyDialogFont(composite);
+
+ return composite;
+ }
+
+ private void createTableViewer(Composite parent) {
+ fTableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.MULTI);
+ fTableViewer.addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ updateButtonAvailability();
+ }
+ });
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = convertHeightInCharsToPixels(20);
+ data.widthHint = convertWidthInCharsToPixels(50);
+ fTableViewer.getTable().setLayoutData(data);
+
+ fTableViewer.setLabelProvider(new WorkingSetLabelProvider());
+ fTableViewer.setContentProvider(new ArrayContentProvider());
+ fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ handleSelectionChanged();
+ }
+ });
+ fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ if (fEditButton.isEnabled()) editSelectedWorkingSet();
+ }
+ });
+ }
+
+ private void createModifyButtons(Composite composite) {
+ Composite buttonComposite = new Composite(composite, SWT.RIGHT);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ buttonComposite.setLayout(layout);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
+ data.grabExcessHorizontalSpace = true;
+ composite.setData(data);
+
+ fNewButton = createButton(buttonComposite, nextButtonId++, Messages.WorkingSetConfigurationDialog_new_label, false);
+ fNewButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ createWorkingSet();
+ }
+ });
+
+ fEditButton = createButton(buttonComposite, nextButtonId++, Messages.WorkingSetConfigurationDialog_edit_label, false);
+ fEditButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ editSelectedWorkingSet();
+ }
+ });
+
+ fRemoveButton = createButton(buttonComposite, nextButtonId++, Messages.WorkingSetConfigurationDialog_remove_label, false);
+ fRemoveButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removeSelectedWorkingSets();
+ }
+ });
+ }
+
+ private void createOrderButtons(Composite parent) {
+ Composite buttons = new Composite(parent, SWT.NONE);
+ buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ buttons.setLayout(layout);
+
+ fUpButton = new Button(buttons, SWT.PUSH);
+ fUpButton.setText(Messages.WorkingSetConfigurationDialog_up_label);
+ setButtonLayoutData(fUpButton);
+ fUpButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ moveUp(((IStructuredSelection) fTableViewer.getSelection()).toList());
+ }
+ });
+
+ fDownButton = new Button(buttons, SWT.PUSH);
+ fDownButton.setText(Messages.WorkingSetConfigurationDialog_down_label);
+ setButtonLayoutData(fDownButton);
+ fDownButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ moveDown(((IStructuredSelection) fTableViewer.getSelection()).toList());
+ }
+ });
+
+ fSelectAll = new Button(buttons, SWT.PUSH);
+ fSelectAll.setText(Messages.WorkingSetConfigurationDialog_selectAll_label);
+ setButtonLayoutData(fSelectAll);
+ fSelectAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ selectAll();
+ }
+ });
+
+ fDeselectAll = new Button(buttons, SWT.PUSH);
+ fDeselectAll.setText(Messages.WorkingSetConfigurationDialog_deselectAll_label);
+ setButtonLayoutData(fDeselectAll);
+ fDeselectAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ deselectAll();
+ }
+ });
+ /**
+ * A check box that has persistence to sort the working sets alphabetically in the
+ * WorkingSetConfigurationDialog. It restores the unsorted order of the working sets when
+ * unchecked.
+ *
+ * @since 3.5
+ */
+ fSortWorkingSet = new Button(parent, SWT.CHECK);
+ fSortWorkingSet.setText(Messages.WorkingSetConfigurationDialog_sort_working_sets);
+ fSortWorkingSet.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false));
+ fSortWorkingSet.setSelection(fIsSortingEnabled);
+ fSortWorkingSet.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fIsSortingEnabled = fSortWorkingSet.getSelection();
+ if (fIsSortingEnabled) {
+ fTableViewer.setComparator(new ViewerComparator(getComparator()) {
+ /*
+ * @see ViewerComparator#compare(Viewer, Object, Object)
+ * @since 3.5
+ */
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ return getComparator().compare(e1, e2);
+ }
+ });
+ }
+ else {
+ fTableViewer.setComparator(null);
+ }
+ updateButtonAvailability();
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void okPressed() {
+ List<IWorkingSet> newResult = getResultWorkingSets();
+ fResult = newResult.toArray(new IWorkingSet[newResult.size()]);
+ if (fIsSortingEnabled) {
+ Collections.sort(fAllWorkingSets, getComparator());
+ }
+ setResult(newResult);
+ super.okPressed();
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private List<IWorkingSet> getResultWorkingSets() {
+ Object[] checked = fTableViewer.getCheckedElements();
+ return new ArrayList(Arrays.asList(checked));
+ }
+
+ private void setInitialSelection() {
+ List<Object[]> selections = getInitialElementSelections();
+ if (!selections.isEmpty()) {
+ fTableViewer.setCheckedElements(selections.toArray());
+ }
+ }
+
+ void createWorkingSet() {
+ IWorkingSetNewWizard wizard = workingSetManager.createWorkingSetNewWizard(new String[] { IWorkingSetIDs.ID_WS_TARGET_EXPLORER });
+ // the wizard can't be null since we have at least the Java working set.
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ if (dialog.open() == Window.OK) {
+ IWorkingSet workingSet = wizard.getSelection();
+ fAllWorkingSets.add(workingSet);
+ fTableViewer.add(workingSet);
+ fTableViewer.setSelection(new StructuredSelection(workingSet), true);
+ fTableViewer.setChecked(workingSet, true);
+ }
+ }
+
+ void editSelectedWorkingSet() {
+ IWorkingSet editWorkingSet = (IWorkingSet) ((IStructuredSelection) fTableViewer
+ .getSelection()).getFirstElement();
+ IWorkingSetEditWizard wizard = workingSetManager.createWorkingSetEditWizard(editWorkingSet);
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ if (dialog.open() == Window.OK) {
+ editWorkingSet = wizard.getSelection();
+ if (fIsSortingEnabled) fTableViewer.refresh();
+ else fTableViewer.update(editWorkingSet, null);
+
+ // make sure ok button is enabled when the selected working set
+ // is edited. Fixes bug 33386.
+ updateButtonAvailability();
+ }
+ }
+
+ /**
+ * Called when the selection has changed.
+ */
+ void handleSelectionChanged() {
+ updateButtonAvailability();
+ }
+
+ /**
+ * Removes the selected working sets from the workbench.
+ */
+ void removeSelectedWorkingSets() {
+ ISelection selection = fTableViewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Iterator<?> iter = ((IStructuredSelection) selection).iterator();
+ while (iter.hasNext()) {
+ IWorkingSet workingSet = (IWorkingSet) iter.next();
+ fAllWorkingSets.remove(workingSet);
+ }
+ fTableViewer.remove(((IStructuredSelection) selection).toArray());
+ }
+ }
+
+ /**
+ * Updates the modify buttons' enabled state based on the current seleciton.
+ */
+ void updateButtonAvailability() {
+ IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
+ boolean hasSelection = !selection.isEmpty();
+ boolean hasSingleSelection = selection.size() == 1;
+
+ fRemoveButton.setEnabled(hasSelection && areAllEditable(selection));
+ fEditButton.setEnabled(hasSingleSelection && ((IWorkingSet) selection.getFirstElement())
+ .isEditable());
+ if (fUpButton != null) {
+ fUpButton.setEnabled(canMoveUp());
+ }
+ if (fDownButton != null) {
+ fDownButton.setEnabled(canMoveDown());
+ }
+ }
+
+ private boolean areAllEditable(IStructuredSelection selection) {
+ for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
+ IWorkingSet workingSet = (IWorkingSet) iter.next();
+ if (!workingSet.isEditable()) return false;
+ }
+ return true;
+ }
+
+ void moveUp(List<IWorkingSet> toMoveUp) {
+ if (toMoveUp.size() > 0) {
+ setElements(moveUp(fAllWorkingSets, toMoveUp));
+ fTableViewer.reveal(toMoveUp.get(0));
+ }
+ }
+
+ void moveDown(List<IWorkingSet> toMoveDown) {
+ if (toMoveDown.size() > 0) {
+ setElements(reverse(moveUp(reverse(fAllWorkingSets), toMoveDown)));
+ fTableViewer.reveal(toMoveDown.get(toMoveDown.size() - 1));
+ }
+ }
+
+ private void setElements(List<IWorkingSet> elements) {
+ fAllWorkingSets = elements;
+ fTableViewer.setInput(fAllWorkingSets);
+ updateButtonAvailability();
+ }
+
+ private List<IWorkingSet> moveUp(List<IWorkingSet> elements, List<IWorkingSet> move) {
+ int nElements = elements.size();
+ List<IWorkingSet> res = new ArrayList<IWorkingSet>(nElements);
+ IWorkingSet floating = null;
+ for (int i = 0; i < nElements; i++) {
+ IWorkingSet curr = elements.get(i);
+ if (move.contains(curr)) {
+ res.add(curr);
+ }
+ else {
+ if (floating != null) {
+ res.add(floating);
+ }
+ floating = curr;
+ }
+ }
+ if (floating != null) {
+ res.add(floating);
+ }
+ return res;
+ }
+
+ private List<IWorkingSet> reverse(List<IWorkingSet> p) {
+ List<IWorkingSet> reverse = new ArrayList<IWorkingSet>(p.size());
+ for (int i = p.size() - 1; i >= 0; i--) {
+ reverse.add(p.get(i));
+ }
+ return reverse;
+ }
+
+ private boolean canMoveUp() {
+ if (!fIsSortingEnabled) {
+ int[] indc = fTableViewer.getTable().getSelectionIndices();
+ for (int i = 0; i < indc.length; i++) {
+ if (indc[i] != i) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean canMoveDown() {
+ if (!fIsSortingEnabled) {
+ int[] indc = fTableViewer.getTable().getSelectionIndices();
+ int k = fAllWorkingSets.size() - 1;
+ for (int i = indc.length - 1; i >= 0; i--, k--) {
+ if (indc[i] != k) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ // ---- select / deselect --------------------------------------------------
+
+ void selectAll() {
+ fTableViewer.setAllChecked(true);
+ }
+
+ void deselectAll() {
+ fTableViewer.setAllChecked(false);
+ }
+
+ /**
+ * Returns whether sorting is enabled for working sets.
+ *
+ * @return <code>true</code> if sorting is enabled, <code>false</code> otherwise
+ * @since 3.5
+ */
+ public boolean isSortingEnabled() {
+ return fIsSortingEnabled;
+ }
+
+ /**
+ * Returns the working set comparator.
+ *
+ * @return the working set comparator
+ * @since 3.5
+ */
+ WorkingSetComparator getComparator() {
+ if (fComparator == null) {
+ fComparator = new WorkingSetComparator();
+ }
+ return fComparator;
+ }
+
+ /**
+ * Returns all the working sets.
+ *
+ * @return all the working sets
+ * @since 3.7
+ */
+ public IWorkingSet[] getAllWorkingSets() {
+ return fAllWorkingSets.toArray(new IWorkingSet[fAllWorkingSets.size()]);
+ }
+}
|