diff --git a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java index 9f522a9a9c4..031e6258e45 100644 --- a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java +++ b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java @@ -9,6 +9,7 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteFileManager; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; @@ -126,9 +127,11 @@ public class ConnectionTests extends TestCase { fail(e.getMessage()); } assertNotNull(fRemoteConnection); - fRemoteConnection.setAddress(HOST); - fRemoteConnection.setUsername(USERNAME); - fRemoteConnection.setPassword(PASSWORD); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setAddress(HOST); + wc.setUsername(USERNAME); + wc.setPassword(PASSWORD); + wc.save(); try { fRemoteConnection.open(new NullProgressMonitor()); diff --git a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java index d23b4bc4211..bae01de8c66 100644 --- a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java +++ b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteFileManager; import org.eclipse.remote.core.IRemoteServices; import org.eclipse.remote.core.RemoteServices; @@ -133,9 +134,11 @@ public class FileStoreTests extends TestCase { fail(e.getMessage()); } assertNotNull(fRemoteConnection); - fRemoteConnection.setAddress(HOST); - fRemoteConnection.setUsername(USERNAME); - fRemoteConnection.setPassword(PASSWORD); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setAddress(HOST); + wc.setUsername(USERNAME); + wc.setPassword(PASSWORD); + wc.save(); try { fRemoteConnection.open(new NullProgressMonitor()); diff --git a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java index 9bac29e3f1b..1f7957ef6fd 100644 --- a/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java +++ b/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java @@ -12,6 +12,7 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; import org.eclipse.remote.core.IRemoteServices; @@ -113,9 +114,11 @@ public class ProcessTests extends TestCase { fail(e.getLocalizedMessage()); } assertNotNull(fRemoteConnection); - fRemoteConnection.setAddress(HOST); - fRemoteConnection.setUsername(USERNAME); - fRemoteConnection.setPassword(PASSWORD); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setAddress(HOST); + wc.setUsername(USERNAME); + wc.setPassword(PASSWORD); + wc.save(); try { fRemoteConnection.open(new NullProgressMonitor()); diff --git a/org.eclipse.remote.core/META-INF/MANIFEST.MF b/org.eclipse.remote.core/META-INF/MANIFEST.MF index 15c66ed122e..205e65902b7 100644 --- a/org.eclipse.remote.core/META-INF/MANIFEST.MF +++ b/org.eclipse.remote.core/META-INF/MANIFEST.MF @@ -18,3 +18,4 @@ Export-Package: org.eclipse.internal.remote.core;x-friends:="org.eclipse.remote. org.eclipse.remote.core.exception Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.equinox.security.storage diff --git a/org.eclipse.remote.core/plugin.xml b/org.eclipse.remote.core/plugin.xml index e629b9f19b3..ed73df73c25 100644 --- a/org.eclipse.remote.core/plugin.xml +++ b/org.eclipse.remote.core/plugin.xml @@ -10,7 +10,6 @@ class="org.eclipse.internal.remote.core.services.local.LocalServicesFactory" id="org.eclipse.remote.LocalServices" name="Local" - newConnections="false" scheme="file"> diff --git a/org.eclipse.remote.core/schema/remoteServices.exsd b/org.eclipse.remote.core/schema/remoteServices.exsd index f7e30e2bd97..c474783d1b5 100644 --- a/org.eclipse.remote.core/schema/remoteServices.exsd +++ b/org.eclipse.remote.core/schema/remoteServices.exsd @@ -88,16 +88,10 @@ - - - - Indicates if this service supports the creation of new connections. - - - + @@ -107,7 +101,6 @@ - @@ -120,7 +113,6 @@ class="org.eclipse.internal.remote.core.services.local.LocalServicesFactory" id="org.eclipse.ptp.remote.LocalServices" name="Local" - newConnections="false" scheme="file"> </remoteServices> </extension> diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteCorePlugin.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteCorePlugin.java index b79e853a991..295b5f6d193 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteCorePlugin.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteCorePlugin.java @@ -96,7 +96,7 @@ public class RemoteCorePlugin extends Plugin { ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() { @Override public void saving(ISaveContext saveContext) throws CoreException { - Preferences.savePreferences(getUniqueIdentifier()); + Preferences.savePreferences(); } @Override @@ -123,7 +123,7 @@ public class RemoteCorePlugin extends Plugin { */ @Override public void stop(BundleContext context) throws Exception { - Preferences.savePreferences(getUniqueIdentifier()); + Preferences.savePreferences(); plugin = null; super.stop(context); } diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesProxy.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesDescriptor.java similarity index 77% rename from org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesProxy.java rename to org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesDescriptor.java index 43ab85094d9..683b5efd034 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesProxy.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesDescriptor.java @@ -17,20 +17,11 @@ import org.eclipse.remote.core.IRemoteServices; import org.eclipse.remote.core.IRemoteServicesDescriptor; import org.eclipse.remote.core.IRemoteServicesFactory; -public class RemoteServicesProxy implements IRemoteServicesDescriptor { +public class RemoteServicesDescriptor implements IRemoteServicesDescriptor { private static final String ATTR_ID = "id"; //$NON-NLS-1$ private static final String ATTR_NAME = "name"; //$NON-NLS-1$ private static final String ATTR_SCHEME = "scheme"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - private static final String ATTR_NEWCONNECTIONS = "newConnections"; //$NON-NLS-1$ - - private static boolean getAttribute(IConfigurationElement configElement, String name, boolean defaultValue) { - String attr = configElement.getAttribute(name); - if (attr != null) { - return Boolean.parseBoolean(attr); - } - return defaultValue; - } private static String getAttribute(IConfigurationElement configElement, String name, String defaultValue) { String value = configElement.getAttribute(name); @@ -48,16 +39,14 @@ public class RemoteServicesProxy implements IRemoteServicesDescriptor { private final String fId; private final String fName; private final String fScheme; - private final boolean fNewConnections; private IRemoteServicesFactory fFactory; private IRemoteServices fDelegate = null; - public RemoteServicesProxy(IConfigurationElement configElement) { + public RemoteServicesDescriptor(IConfigurationElement configElement) { fConfigElement = configElement; fId = getAttribute(configElement, ATTR_ID, null); fName = getAttribute(configElement, ATTR_NAME, fId); fScheme = getAttribute(configElement, ATTR_SCHEME, null); - fNewConnections = getAttribute(configElement, ATTR_NEWCONNECTIONS, false); getAttribute(configElement, ATTR_CLASS, null); fFactory = null; } @@ -65,13 +54,11 @@ public class RemoteServicesProxy implements IRemoteServicesDescriptor { /* * (non-Javadoc) * - * @see - * org.eclipse.remote.core.IRemoteServicesDescriptor#canCreateConnections - * () + * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override - public boolean canCreateConnections() { - return fNewConnections; + public int compareTo(IRemoteServicesDescriptor arg0) { + return getName().compareTo(arg0.getName()); } /** @@ -86,9 +73,8 @@ public class RemoteServicesProxy implements IRemoteServicesDescriptor { try { fFactory = (IRemoteServicesFactory) fConfigElement.createExecutableExtension(ATTR_CLASS); } catch (Exception e) { - RemoteCorePlugin - .log(NLS.bind(Messages.RemoteServicesProxy_1, new Object[] { fConfigElement.getAttribute(ATTR_CLASS), fId, - fConfigElement.getDeclaringExtension().getNamespaceIdentifier() })); + RemoteCorePlugin.log(NLS.bind(Messages.RemoteServicesProxy_1, new Object[] { fConfigElement.getAttribute(ATTR_CLASS), + fId, fConfigElement.getDeclaringExtension().getNamespaceIdentifier() })); } return fFactory; } diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesImpl.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesImpl.java index 4b5330002f5..6d283189687 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesImpl.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/RemoteServicesImpl.java @@ -13,7 +13,6 @@ package org.eclipse.internal.remote.core; import java.net.URI; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,28 +32,21 @@ public class RemoteServicesImpl { public static final String REMOTE_SERVICES_EXTENSION_POINT_ID = "remoteServices"; //$NON-NLS-1$ // Active remote services plugins (not necessarily loaded) - private static final Map fRemoteServicesById = Collections - .synchronizedMap(new HashMap()); - private static final Map fRemoteServicesByScheme = Collections - .synchronizedMap(new HashMap()); + private static final Map fRemoteServicesById = Collections + .synchronizedMap(new HashMap()); + private static final Map fRemoteServicesByScheme = Collections + .synchronizedMap(new HashMap()); private RemoteServicesImpl() { // Hide constructor } - private static class RemoteServicesSorter implements Comparator { - @Override - public int compare(RemoteServicesProxy o1, RemoteServicesProxy o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); - } - } - - public static RemoteServicesProxy getRemoteServiceProxyById(String id) { + public static RemoteServicesDescriptor getRemoteServiceDescriptorById(String id) { retrieveRemoteServices(); return fRemoteServicesById.get(id); } - public static RemoteServicesProxy getRemoteServiceProxyByURI(URI uri) { + public static RemoteServicesDescriptor getRemoteServiceDescriptorByURI(URI uri) { String scheme = uri.getScheme(); if (scheme != null) { retrieveRemoteServices(); @@ -64,18 +56,18 @@ public class RemoteServicesImpl { } /** - * Retrieve a sorted list of remote service proxies. + * Retrieve a sorted list of remote service descriptors. * - * @return remote service proxies + * @return remote service descriptors */ - public static RemoteServicesProxy[] getRemoteServiceProxies() { + public static List getRemoteServiceDescriptors() { retrieveRemoteServices(); - List services = new ArrayList(); - for (RemoteServicesProxy proxy : fRemoteServicesById.values()) { - services.add(proxy); + List descriptors = new ArrayList(); + for (RemoteServicesDescriptor descriptor : fRemoteServicesById.values()) { + descriptors.add(descriptor); } - Collections.sort(services, new RemoteServicesSorter()); - return services.toArray(new RemoteServicesProxy[0]); + Collections.sort(descriptors); + return descriptors; } /** @@ -92,7 +84,7 @@ public class RemoteServicesImpl { final IConfigurationElement[] elements = ext.getConfigurationElements(); for (IConfigurationElement ce : elements) { - RemoteServicesProxy proxy = new RemoteServicesProxy(ce); + RemoteServicesDescriptor proxy = new RemoteServicesDescriptor(ce); fRemoteServicesById.put(proxy.getId(), proxy); fRemoteServicesByScheme.put(proxy.getScheme(), proxy); } diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/PreferenceInitializer.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/PreferenceInitializer.java index 14bfd28f54d..bd8572de647 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/PreferenceInitializer.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/PreferenceInitializer.java @@ -12,7 +12,6 @@ package org.eclipse.internal.remote.core.preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.internal.remote.core.RemoteCorePlugin; import org.eclipse.remote.core.IRemotePreferenceConstants; /** @@ -24,7 +23,6 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { @Override public void initializeDefaultPreferences() { - Preferences.setDefaultString(RemoteCorePlugin.getUniqueIdentifier(), IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID, - IRemotePreferenceConstants.REMOTE_TOOLS_REMOTE_SERVICES_ID); + Preferences.setDefaultString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID, "org.eclipse.remote.JSch"); //$NON-NLS-1$ } } diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/Preferences.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/Preferences.java index 03a3259d2ba..ff45e927c9a 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/Preferences.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/preferences/Preferences.java @@ -20,8 +20,8 @@ import org.eclipse.internal.remote.core.RemoteCorePlugin; import org.osgi.service.prefs.BackingStoreException; /** - * Convenience class to facilitate using the new {@link IEclipsePreferences} - * story. Adapted from org.eclipse.debug.internal.core.Preferences. + * Convenience class to facilitate using the new {@link IEclipsePreferences} story. Adapted from + * org.eclipse.debug.internal.core.Preferences. * * @since 5.0 * @noinstantiate This class is not intended to be instantiated by clients. @@ -33,28 +33,27 @@ public final class Preferences { private static final int DEFAULT_CONTEXT = 0; private static final int INSTANCE_CONTEXT = 1; + private static final String fQualifier = RemoteCorePlugin.getUniqueIdentifier(); + /** - * Adds the given preference listener to the {@link DefaultScope} and the - * {@link InstanceScope} + * Adds the given preference listener to the {@link DefaultScope} and the {@link InstanceScope} * - * @param qualifier * @param listener */ - public static void addPreferenceChangeListener(String qualifier, IPreferenceChangeListener listener) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).addPreferenceChangeListener(listener); - contexts[INSTANCE_CONTEXT].getNode(qualifier).addPreferenceChangeListener(listener); + public static void addPreferenceChangeListener(IPreferenceChangeListener listener) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).addPreferenceChangeListener(listener); + contexts[INSTANCE_CONTEXT].getNode(fQualifier).addPreferenceChangeListener(listener); } /** * Returns whether the named preference is know in the preference store. * - * @param qualifier * @param name * @return */ - public static boolean contains(String qualifier, String name) { - return (contexts[INSTANCE_CONTEXT].getNode(qualifier).get(name, null) != null || contexts[DEFAULT_CONTEXT].getNode( - qualifier).get(name, null) != null); + public static boolean contains(String name) { + return (contexts[INSTANCE_CONTEXT].getNode(fQualifier).get(name, null) != null || contexts[DEFAULT_CONTEXT].getNode( + fQualifier).get(name, null) != null); } /** @@ -62,14 +61,13 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static boolean getBoolean(String qualifier, String key) { - return Platform.getPreferencesService().getBoolean(qualifier, key, false, null); + public static boolean getBoolean(String key) { + return Platform.getPreferencesService().getBoolean(fQualifier, key, false, null); } /** @@ -77,14 +75,13 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static byte[] getByteArray(String qualifier, String key) { - return Platform.getPreferencesService().getByteArray(qualifier, key, null, null); + public static byte[] getByteArray(String key) { + return Platform.getPreferencesService().getByteArray(fQualifier, key, null, null); } /** @@ -92,31 +89,29 @@ public final class Preferences { * the given key or the specified default value if the key does not appear * in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the boolean value set in the {@link DefaultScope} for the given * key, or the specified default value. */ - public static synchronized boolean getDefaultBoolean(String qualifier, String key, boolean defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getBoolean(key, defaultvalue); + public static synchronized boolean getDefaultBoolean(String key, boolean defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getBoolean(key, defaultvalue); } /** - * Returns the default byte array value stored in the {@link DefaultScope} - * for the given key or the specified default value if the key does not + * Returns the default byte array value stored in the {@link DefaultScope} for the given key or the specified default value if + * the key does not * appear in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the byte array value set in the {@link DefaultScope} for the * given key, or the specified default value. */ - public static synchronized byte[] getDefaultByteArray(String qualifier, String key, byte[] defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getByteArray(key, defaultvalue); + public static synchronized byte[] getDefaultByteArray(String key, byte[] defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getByteArray(key, defaultvalue); } /** @@ -124,15 +119,14 @@ public final class Preferences { * the given key or the specified default value if the key does not appear * in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the double value set in the {@link DefaultScope} for the given * key, or the specified default value. */ - public static synchronized double getDefaultDouble(String qualifier, String key, double defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getDouble(key, defaultvalue); + public static synchronized double getDefaultDouble(String key, double defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getDouble(key, defaultvalue); } /** @@ -140,15 +134,14 @@ public final class Preferences { * the given key or the specified default value if the key does not appear * in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the float value set in the {@link DefaultScope} for the given * key, or the specified default value. */ - public static synchronized float getDefaultFloat(String qualifier, String key, float defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getFloat(key, defaultvalue); + public static synchronized float getDefaultFloat(String key, float defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getFloat(key, defaultvalue); } /** @@ -156,15 +149,14 @@ public final class Preferences { * the given key or the specified default value if the key does not appear * in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the integer value set in the {@link DefaultScope} for the given * key, or the specified default value. */ - public static synchronized int getDefaultInt(String qualifier, String key, int defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getInt(key, defaultvalue); + public static synchronized int getDefaultInt(String key, int defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getInt(key, defaultvalue); } /** @@ -172,15 +164,14 @@ public final class Preferences { * given key or the specified default value if the key does not appear in * the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the long value set in the {@link DefaultScope} for the given key, * or the specified default value. */ - public static synchronized long getDefaultLong(String qualifier, String key, long defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).getLong(key, defaultvalue); + public static synchronized long getDefaultLong(String key, long defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).getLong(key, defaultvalue); } /** @@ -188,15 +179,14 @@ public final class Preferences { * the given key or the specified default value if the key does not appear * in the {@link DefaultScope} * - * @param qualifier * @param key * @param defaultvalue * * @return the string value set in the {@link DefaultScope} for the given * key, or the specified default value. */ - public static synchronized String getDefaultString(String qualifier, String key, String defaultvalue) { - return contexts[DEFAULT_CONTEXT].getNode(qualifier).get(key, defaultvalue); + public static synchronized String getDefaultString(String key, String defaultvalue) { + return contexts[DEFAULT_CONTEXT].getNode(fQualifier).get(key, defaultvalue); } /** @@ -204,14 +194,13 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static double getDouble(String qualifier, String key) { - return Platform.getPreferencesService().getDouble(qualifier, key, 0.0, null); + public static double getDouble(String key) { + return Platform.getPreferencesService().getDouble(fQualifier, key, 0.0, null); } /** @@ -219,14 +208,14 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier + * @param fQualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static float getFloat(String qualifier, String key) { - return Platform.getPreferencesService().getFloat(qualifier, key, 0.0f, null); + public static float getFloat(String key) { + return Platform.getPreferencesService().getFloat(fQualifier, key, 0.0f, null); } /** @@ -234,14 +223,14 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier + * @param fQualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static int getInt(String qualifier, String key) { - return Platform.getPreferencesService().getInt(qualifier, key, 0, null); + public static int getInt(String key) { + return Platform.getPreferencesService().getInt(fQualifier, key, 0, null); } /** @@ -249,14 +238,13 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static long getLong(String qualifier, String key) { - return Platform.getPreferencesService().getLong(qualifier, key, 0L, null); + public static long getLong(String key) { + return Platform.getPreferencesService().getLong(fQualifier, key, 0L, null); } /** @@ -264,27 +252,25 @@ public final class Preferences { * is not defined then return the default value. Use the canonical scope * lookup order for finding the preference value. * - * @param qualifier * @param key * @param defaultvalue * * @return the value of the preference or the given default value */ - public static String getString(String qualifier, String key) { - return Platform.getPreferencesService().getString(qualifier, key, null, null); + public static String getString(String key) { + return Platform.getPreferencesService().getString(fQualifier, key, null, null); } /** * Returns true if the named preference has the default value. * - * @param qualifier * @param name * @return */ - public static boolean isDefault(String qualifier, String name) { - String defVal = contexts[DEFAULT_CONTEXT].getNode(qualifier).get(name, null); + public static boolean isDefault(String name) { + String defVal = contexts[DEFAULT_CONTEXT].getNode(fQualifier).get(name, null); if (defVal != null) { - String val = contexts[INSTANCE_CONTEXT].getNode(qualifier).get(name, null); + String val = contexts[INSTANCE_CONTEXT].getNode(fQualifier).get(name, null); return (val != null && val.equals(defVal)); } return false; @@ -294,24 +280,21 @@ public final class Preferences { * Removes the given preference listener from the {@link DefaultScope} and * the {@link InstanceScope} * - * @param qualifier * @param listener */ - public static void removePreferenceChangeListener(String qualifier, IPreferenceChangeListener listener) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).removePreferenceChangeListener(listener); - contexts[INSTANCE_CONTEXT].getNode(qualifier).removePreferenceChangeListener(listener); + public static void removePreferenceChangeListener(IPreferenceChangeListener listener) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).removePreferenceChangeListener(listener); + contexts[INSTANCE_CONTEXT].getNode(fQualifier).removePreferenceChangeListener(listener); } /** * Save the preferences for the given plugin identifier. It should be noted * that all pending preference changes will be flushed with this method. - * - * @param qualifier */ - public static synchronized void savePreferences(String qualifier) { + public static synchronized void savePreferences() { try { - contexts[DEFAULT_CONTEXT].getNode(qualifier).flush(); - contexts[INSTANCE_CONTEXT].getNode(qualifier).flush(); + contexts[DEFAULT_CONTEXT].getNode(fQualifier).flush(); + contexts[INSTANCE_CONTEXT].getNode(fQualifier).flush(); } catch (BackingStoreException bse) { RemoteCorePlugin.log(bse); } @@ -320,183 +303,169 @@ public final class Preferences { /** * Sets a boolean preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setBoolean(String qualifier, String key, boolean value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putBoolean(key, value); + public static synchronized void setBoolean(String key, boolean value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putBoolean(key, value); } /** * Sets a byte array preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setByteArray(String qualifier, String key, byte[] value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putByteArray(key, value); + public static synchronized void setByteArray(String key, byte[] value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putByteArray(key, value); } /** * Sets a boolean in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultBoolean(String qualifier, String key, boolean value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putBoolean(key, value); + public static synchronized void setDefaultBoolean(String key, boolean value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putBoolean(key, value); } /** * Sets a byte array in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultByteArray(String qualifier, String key, byte[] value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putByteArray(key, value); + public static synchronized void setDefaultByteArray(String key, byte[] value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putByteArray(key, value); } /** * Sets a double in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultDouble(String qualifier, String key, double value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putDouble(key, value); + public static synchronized void setDefaultDouble(String key, double value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putDouble(key, value); } /** * Sets a float in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultFloat(String qualifier, String key, float value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putFloat(key, value); + public static synchronized void setDefaultFloat(String key, float value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putFloat(key, value); } /** * Sets a integer in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultInt(String qualifier, String key, int value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putInt(key, value); + public static synchronized void setDefaultInt(String key, int value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putInt(key, value); } /** * Sets a long in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultLong(String qualifier, String key, long value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).putLong(key, value); + public static synchronized void setDefaultLong(String key, long value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).putLong(key, value); } /** * Sets a string in the {@link DefaultScope} * - * @param qualifier * @param key * the key * @param value * the new value */ - public static synchronized void setDefaultString(String qualifier, String key, String value) { - contexts[DEFAULT_CONTEXT].getNode(qualifier).put(key, value); + public static synchronized void setDefaultString(String key, String value) { + contexts[DEFAULT_CONTEXT].getNode(fQualifier).put(key, value); } /** * Sets a double preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setDouble(String qualifier, String key, double value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putDouble(key, value); + public static synchronized void setDouble(String key, double value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putDouble(key, value); } /** * Sets a float preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setFloat(String qualifier, String key, float value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putFloat(key, value); + public static synchronized void setFloat(String key, float value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putFloat(key, value); } /** * Sets a integer preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setInt(String qualifier, String key, int value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putInt(key, value); + public static synchronized void setInt(String key, int value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putInt(key, value); } /** * Sets a long preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setLong(String qualifier, String key, long value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).putLong(key, value); + public static synchronized void setLong(String key, long value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).putLong(key, value); } /** * Sets a string preference in the {@link InstanceScope}. * - * @param qualifier * @param key * the key * @param value * the value */ - public static synchronized void setString(String qualifier, String key, String value) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).put(key, value); + public static synchronized void setString(String key, String value) { + contexts[INSTANCE_CONTEXT].getNode(fQualifier).put(key, value); } /** @@ -504,13 +473,12 @@ public final class Preferences { * any set value from the {@link InstanceScope}. Has no effect if the given * key is null. * - * @param qualifier * @param key * the key for the preference */ - public static synchronized void setToDefault(String qualifier, String key) { + public static synchronized void setToDefault(String key) { if (key != null) { - contexts[INSTANCE_CONTEXT].getNode(qualifier).remove(key); + contexts[INSTANCE_CONTEXT].getNode(fQualifier).remove(key); } } diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnection.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnection.java index 1702baa65b0..503e1c34e39 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnection.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnection.java @@ -24,6 +24,7 @@ import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionChangeEvent; import org.eclipse.remote.core.IRemoteConnectionChangeListener; import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteFileManager; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; @@ -33,9 +34,9 @@ import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.core.exception.UnableToForwardPortException; public class LocalConnection implements IRemoteConnection { - private String fName = IRemoteConnectionManager.LOCAL_CONNECTION_NAME; - private String fAddress = Messages.LocalConnection_1; - private String fUsername = System.getProperty("user.name"); //$NON-NLS-1$ + private final String fName = IRemoteConnectionManager.LOCAL_CONNECTION_NAME; + private final String fAddress = Messages.LocalConnection_1; + private final String fUsername = System.getProperty("user.name"); //$NON-NLS-1$ private boolean fConnected = true; private IPath fWorkingDir = null; @@ -73,12 +74,23 @@ public class LocalConnection implements IRemoteConnection { } } + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(IRemoteConnection connection) { + return getName().compareTo(connection.getName()); + } + /** * Notify all listeners when this connection's status changes. * * @param event */ - private void fireConnectionChangeEvent(final int type) { + @Override + public void fireConnectionChangeEvent(final int type) { IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() { @Override public IRemoteConnection getConnection() { @@ -274,6 +286,16 @@ public class LocalConnection implements IRemoteConnection { return fUsername; } + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() + */ + @Override + public IRemoteConnectionWorkingCopy getWorkingCopy() { + return new LocalConnectionWorkingCopy(this); + } + /* * (non-Javadoc) * @@ -364,76 +386,6 @@ public class LocalConnection implements IRemoteConnection { // Do nothing } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#setAddress(java.lang.String - * ) - */ - @Override - public void setAddress(String address) { - fAddress = address; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#setAttribute(java.lang. - * String, java.lang.String) - */ - @Override - public void setAttribute(String key, String value) { - // Not supported - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#setName(java.lang.String) - */ - @Override - public void setName(String name) { - fName = name; - fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_RENAMED); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#setPassword(java.lang.String - * ) - */ - @Override - public void setPassword(String password) { - // Not supported - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setPort(int) - */ - @Override - public void setPort(int port) { - // Not supported - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#setUsername(java.lang.String - * ) - */ - @Override - public void setUsername(String username) { - fUsername = username; - } - /* * (non-Javadoc) * diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionManager.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionManager.java index 3d0a1af526f..01ff833f02f 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionManager.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionManager.java @@ -11,6 +11,8 @@ package org.eclipse.internal.remote.core.services.local; import java.net.URI; +import java.util.HashSet; +import java.util.Set; import org.eclipse.core.filesystem.EFS; import org.eclipse.remote.core.IRemoteConnection; @@ -62,8 +64,10 @@ public class LocalConnectionManager implements IRemoteConnectionManager { * org.eclipse.remote.core.IRemoteConnectionManager#getConnections() */ @Override - public IRemoteConnection[] getConnections() { - return new IRemoteConnection[] { fLocalConnection }; + public Set getConnections() { + Set set = new HashSet(); + set.add(fLocalConnection); + return set; } /* diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionWorkingCopy.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionWorkingCopy.java new file mode 100644 index 00000000000..6c295bb9007 --- /dev/null +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalConnectionWorkingCopy.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2013 IBM Corporation 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: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.internal.remote.core.services.local; + +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; + +public class LocalConnectionWorkingCopy extends LocalConnection implements IRemoteConnectionWorkingCopy { + + public LocalConnectionWorkingCopy(LocalConnection connection) { + super(connection.getRemoteServices()); + } + + @Override + public void setAddress(String address) { + // Do nothing + } + + @Override + public void setAttribute(String key, String value) { + // Do nothing + } + + @Override + public void setName(String name) { + // Do nothing + } + + @Override + public void setPassword(String password) { + // Do nothing + } + + @Override + public void setPort(int port) { + // Do nothing + } + + @Override + public void setUsername(String username) { + // Do nothing + } + + @Override + public void save() { + // Do nothing + } +} diff --git a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalServices.java b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalServices.java index 8055433c1ee..8a1ddb4b4bb 100644 --- a/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalServices.java +++ b/org.eclipse.remote.core/src/org/eclipse/internal/remote/core/services/local/LocalServices.java @@ -11,30 +11,27 @@ package org.eclipse.internal.remote.core.services.local; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.remote.core.AbstractRemoteServices; import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteServices; import org.eclipse.remote.core.IRemoteServicesDescriptor; -public class LocalServices implements IRemoteServices { +public class LocalServices extends AbstractRemoteServices { public static final String LocalServicesId = "org.eclipse.remote.LocalServices"; //$NON-NLS-1$ private final IRemoteConnectionManager fConnMgr = new LocalConnectionManager(this); - private final IRemoteServicesDescriptor fDescriptor; public LocalServices(IRemoteServicesDescriptor descriptor) { - fDescriptor = descriptor; + super(descriptor); } /* * (non-Javadoc) * - * @see - * org.eclipse.remote.core.IRemoteServicesDescriptor#canCreateConnections - * () + * @see org.eclipse.remote.core.IRemoteServices#getCapabilities() */ @Override - public boolean canCreateConnections() { - return fDescriptor.canCreateConnections(); + public int getCapabilities() { + return 0; } /* @@ -49,36 +46,6 @@ public class LocalServices implements IRemoteServices { return fConnMgr; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getId() - */ - @Override - public String getId() { - return fDescriptor.getId(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getName() - */ - @Override - public String getName() { - return fDescriptor.getName(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getScheme() - */ - @Override - public String getScheme() { - return fDescriptor.getScheme(); - } - /* * (non-Javadoc) * diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java index 0f9e40f9dd1..da4adc4704e 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java @@ -27,13 +27,11 @@ public abstract class AbstractRemoteServices implements IRemoteServices { /* * (non-Javadoc) * - * @see - * org.eclipse.remote.core.IRemoteServicesDescriptor#canCreateConnections - * () + * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override - public boolean canCreateConnections() { - return fDescriptor.canCreateConnections(); + public int compareTo(IRemoteServicesDescriptor o) { + return fDescriptor.compareTo(o); } /* diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java index ccd482b172b..aabb544a98b 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java @@ -22,7 +22,7 @@ import org.eclipse.remote.core.exception.RemoteConnectionException; * then call the {{@link #open(IProgressMonitor)} method. Once the connection is completed, call the {@link #close()} method to * terminate the connection. */ -public interface IRemoteConnection { +public interface IRemoteConnection extends Comparable { public final static String OS_NAME_PROPERTY = "os.name"; //$NON-NLS-1$ public final static String OS_VERSION_PROPERTY = "os.version"; //$NON-NLS-1$ public final static String OS_ARCH_PROPERTY = "os.arch"; //$NON-NLS-1$ @@ -55,6 +55,15 @@ public interface IRemoteConnection { */ public void close(); + /** + * Notify all listeners when this connection's status changes. See {{@link IRemoteConnectionChangeEvent} for a list of event + * types. + * + * @param event + * event type indicating the nature of the event + */ + public void fireConnectionChangeEvent(int type); + /** * Forward local port localPort to remote port fwdPort on remote machine fwdAddress. If this IRemoteConnection is not to * fwdAddress, the port will be routed via the connection machine to fwdAddress. @@ -239,6 +248,8 @@ public interface IRemoteConnection { */ public String getUsername(); + public IRemoteConnectionWorkingCopy getWorkingCopy(); + /** * Get the working directory. Relative paths will be resolved using this path. * @@ -310,58 +321,10 @@ public interface IRemoteConnection { public void removeRemotePortForwarding(int port) throws RemoteConnectionException; /** - * Set the address for this connection + * Set the working directory while the connection is open. The working directory will revert to the default when the connection + * is closed then subsequently reopened. * - * @param address - */ - public void setAddress(String address); - - /** - * Set an implementation dependent attribute for the connection. Attributes keys supported by the connection can be obtained - * using {@link #getAttributes()} - * - * @param key - * attribute key - * @param value - * attribute value - * @since 5.0 - */ - public void setAttribute(String key, String value); - - /** - * Set the name for this connection - * - * @param name - */ - public void setName(String name); - - /** - * Set the password for this connection - * - * @param password - * @since 5.0 - */ - public void setPassword(String password); - - /** - * Set the port used for this connection. Only valid if supported by the underlying service provider. - * - * @param port - * port number for the connection - * @since 5.0 - */ - public void setPort(int port); - - /** - * Set the username for this connection - * - * @param username - */ - public void setUsername(String username); - - /** - * Set the working directory. Relative paths will be resolved using this path. The path must be valid and absolute for any - * changes to be made. + * Relative paths will be resolved using this path. The path must be valid and absolute for any changes to be made. * * @param path * String representing the current working directory diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java index a51bd4522b9..1bebd0d899d 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java @@ -11,6 +11,7 @@ package org.eclipse.remote.core; import java.net.URI; +import java.util.Set; import org.eclipse.remote.core.exception.RemoteConnectionException; @@ -50,7 +51,7 @@ public interface IRemoteConnectionManager { * * @return connections that we know about */ - public IRemoteConnection[] getConnections(); + public Set getConnections(); /** * Creates a new remote connection named with supplied name. The connection diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java new file mode 100644 index 00000000000..d5f3cb85f8e --- /dev/null +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation 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: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.remote.core; + +public interface IRemoteConnectionWorkingCopy extends IRemoteConnection { + /** + * Set the address for this connection + * + * @param address + */ + public void setAddress(String address); + + /** + * Set an implementation dependent attribute for the connection. Attributes keys supported by the connection can be obtained + * using {@link #getAttributes()}. Attributes are persisted along with connection information. + * + * @param key + * attribute key + * @param value + * attribute value + * @since 5.0 + */ + public void setAttribute(String key, String value); + + /** + * Set the name for this connection + * + * @param name + */ + public void setName(String name); + + /** + * Set the password for this connection + * + * @param password + * @since 5.0 + */ + public void setPassword(String password); + + /** + * Set the port used for this connection. Only valid if supported by the underlying service provider. + * + * @param port + * port number for the connection + * @since 5.0 + */ + public void setPort(int port); + + /** + * Set the username for this connection + * + * @param username + */ + public void setUsername(String username); + + public void save(); +} diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePreferenceConstants.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePreferenceConstants.java index 806959f295f..969fdd446db 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePreferenceConstants.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePreferenceConstants.java @@ -21,18 +21,4 @@ public interface IRemotePreferenceConstants { * has been set, and if so, what the provider ID is. */ public static final String PREF_REMOTE_SERVICES_ID = "remoteServicesId"; //$NON-NLS-1$ - - /** - * ID of the Remote Tools provider - * - * @since 6.0 - */ - public static final String REMOTE_TOOLS_REMOTE_SERVICES_ID = "org.eclipse.ptp.remote.RemoteTools"; //$NON-NLS-1$ - - /** - * ID of the RSE provider - * - * @since 6.0 - */ - public static final String RSE_REMOTE_SERVICES_ID = "org.eclipse.ptp.remote.RSERemoteServices"; //$NON-NLS-1$ } diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java index f9f177a75a8..19b46fdeea0 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2013 IBM Corporation 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 @@ -17,6 +17,12 @@ import org.eclipse.core.runtime.IProgressMonitor; * {@link RemoteServices}. The methods on this interface can then be used to access the full range of remote services provided. */ public interface IRemoteServices extends IRemoteServicesDescriptor { + public static final int CAPABILITY_ADD_CONNECTIONS = 0x01; + public static final int CAPABILITY_EDIT_CONNECTIONS = 0x02; + public static final int CAPABILITY_REMOVE_CONNECTIONS = 0x04; + public static final int CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING = 0x08; + public static final int CAPABILITY_SUPPORTS_X11_FORWARDING = 0x10; + /** * Get a connection manager for managing remote connections. * @@ -31,4 +37,11 @@ public interface IRemoteServices extends IRemoteServicesDescriptor { * @since 7.0 */ public boolean initialize(IProgressMonitor monitor); + + /** + * Gets the capabilities of the remote service. + * + * @return bit-wise or of capability flag constants + */ + public int getCapabilities(); } diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java index c3f51fa33e8..970fed1bbcc 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java @@ -14,15 +14,7 @@ package org.eclipse.remote.core; * Interface representing a remote services provider extension. Clients can use this to find out information about the extension * without loading it. */ -public interface IRemoteServicesDescriptor { - /** - * Test if this provider can create connections. - * - * @return true if new connections can be created - * @since 5.0 - */ - public boolean canCreateConnections(); - +public interface IRemoteServicesDescriptor extends Comparable { /** * Get unique ID of this service. Can be used as a lookup key. * diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java index e77cf0b9dc9..5acc1c672ae 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java @@ -14,7 +14,7 @@ import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.internal.remote.core.RemoteServicesImpl; -import org.eclipse.internal.remote.core.RemoteServicesProxy; +import org.eclipse.internal.remote.core.RemoteServicesDescriptor; import org.eclipse.internal.remote.core.services.local.LocalServices; /** @@ -61,7 +61,7 @@ public class RemoteServices { * @since 5.0 */ public static IRemoteServices getRemoteServices(String id, IProgressMonitor monitor) { - RemoteServicesProxy proxy = RemoteServicesImpl.getRemoteServiceProxyById(id); + RemoteServicesDescriptor proxy = RemoteServicesImpl.getRemoteServiceDescriptorById(id); if (proxy != null) { IRemoteServices service = proxy.getServices(); if (service.initialize(monitor)) { @@ -94,7 +94,7 @@ public class RemoteServices { * @since 5.0 */ public static IRemoteServices getRemoteServices(URI uri, IProgressMonitor monitor) { - RemoteServicesProxy proxy = RemoteServicesImpl.getRemoteServiceProxyByURI(uri); + RemoteServicesDescriptor proxy = RemoteServicesImpl.getRemoteServiceDescriptorByURI(uri); if (proxy != null) { IRemoteServices service = proxy.getServices(); if (service.initialize(monitor)) { diff --git a/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java b/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java index 7ba3677b04a..299575e3143 100644 --- a/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java +++ b/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java @@ -17,9 +17,8 @@ import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.internal.remote.core.RemoteCorePlugin; +import org.eclipse.internal.remote.core.RemoteServicesDescriptor; import org.eclipse.internal.remote.core.RemoteServicesImpl; -import org.eclipse.internal.remote.core.RemoteServicesProxy; import org.eclipse.internal.remote.core.preferences.Preferences; /** @@ -108,8 +107,7 @@ public class RemoteServicesUtils { services = RemoteServices.getRemoteServices(parts[0]); connName = parts[1]; } else if (parts.length == 1) { - String id = Preferences.getString(RemoteCorePlugin.getUniqueIdentifier(), - IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); + String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); if (id != null) { services = RemoteServices.getRemoteServices(id); } @@ -124,7 +122,7 @@ public class RemoteServicesUtils { if (services != null) { conn = services.getConnectionManager().getConnection(connName); } else if (connName != null) { - for (RemoteServicesProxy proxy : RemoteServicesImpl.getRemoteServiceProxies()) { + for (RemoteServicesDescriptor proxy : RemoteServicesImpl.getRemoteServiceDescriptors()) { conn = proxy.getServices().getConnectionManager().getConnection(connName); if (conn != null) { break; diff --git a/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF b/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF index 9c936736bd5..7113028a02a 100644 --- a/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF +++ b/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF @@ -9,9 +9,10 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.filesystem, org.eclipse.remote.core, org.eclipse.jsch.core, - com.jcraft.jsch + com.jcraft.jsch, + org.eclipse.equinox.security Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.internal.remote.jsch.core;x-internal:=true, +Export-Package: org.eclipse.internal.remote.jsch.core;x-friends:="org.eclipse.remote.jsch.ui", org.eclipse.internal.remote.jsch.core.messages;x-internal:=true Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/org.eclipse.remote.jsch.core/plugin.properties b/org.eclipse.remote.jsch.core/plugin.properties index 131882605c6..dac4334a1ed 100644 --- a/org.eclipse.remote.jsch.core/plugin.properties +++ b/org.eclipse.remote.jsch.core/plugin.properties @@ -7,5 +7,5 @@ # ############################################################################### -pluginName=PTP JSch Support +pluginName=JSch Remote Support pluginProvider=Eclipse PTP diff --git a/org.eclipse.remote.jsch.core/plugin.xml b/org.eclipse.remote.jsch.core/plugin.xml index 20a92e43ad2..0ff64312250 100644 --- a/org.eclipse.remote.jsch.core/plugin.xml +++ b/org.eclipse.remote.jsch.core/plugin.xml @@ -7,7 +7,6 @@ class="org.eclipse.internal.remote.jsch.core.JSchServicesFactory" id="org.eclipse.remote.JSch" name="JSch" - newConnections="true" scheme="ssh"> diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/Activator.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/Activator.java index 2529a64964f..ed84c5d75ea 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/Activator.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/Activator.java @@ -13,10 +13,7 @@ import org.osgi.framework.ServiceReference; public class Activator extends Plugin { // The plug-in ID - private static final String PLUGIN_ID = "org.eclipse.ptp.remote.core.remotetools"; //$NON-NLS-1$ - - // The remote services ID - public static final String SERVICES_ID = "org.eclipse.ptp.remote.RemoteTools"; //$NON-NLS-1$ + public static final String PLUGIN_ID = "org.eclipse.remote.jsch.core"; //$NON-NLS-1$ // The shared instance private static Activator plugin; diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnection.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnection.java index 63947e1ec8e..f04f889bf15 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnection.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnection.java @@ -29,6 +29,7 @@ import org.eclipse.jsch.core.IJSchService; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionChangeEvent; import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteFileManager; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; @@ -48,19 +49,20 @@ import com.jcraft.jsch.UserInfo; * @since 5.0 */ public class JSchConnection implements IRemoteConnection { - private static int DEFAULT_PORT = 22; + protected static final int DEFAULT_PORT = 22; + protected static final int DEFAULT_TIMEOUT = 5; + protected static final boolean DEFAULT_IS_PASSWORD = true; + protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ private String fWorkingDir; - private final Map fEnv = new HashMap(); - private final Map fProperties = new HashMap(); - private String fHost; - private String fUsername; - private String fPassword; - private int fPort = DEFAULT_PORT; - private String fConnName; private boolean fIsOpen; + private final IJSchService fJSchService; + private final JSchConnectionAttributes fAttributes; + private final JSchConnectionManager fManager; + private final Map fEnv = new HashMap(); + private final Map fProperties = new HashMap(); private final IRemoteServices fRemoteServices; private final ListenerList fListeners = new ListenerList(); private final List fSessions = new ArrayList(); @@ -68,8 +70,9 @@ public class JSchConnection implements IRemoteConnection { private ChannelSftp fSftpChannel; public JSchConnection(String name, IRemoteServices services) { - fConnName = name; fRemoteServices = services; + fManager = (JSchConnectionManager) services.getConnectionManager(); + fAttributes = new JSchConnectionAttributes(name); fJSchService = Activator.getDefault().getService(); } @@ -116,10 +119,10 @@ public class JSchConnection implements IRemoteConnection { * @throws RemoteConnectionException */ private void checkIsConfigured() throws RemoteConnectionException { - if (fHost == null) { + if (fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, null) == null) { throw new RemoteConnectionException(Messages.JSchConnection_remote_address_must_be_set); } - if (fUsername == null) { + if (fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, null) == null) { throw new RemoteConnectionException(Messages.JSchConnection_username_must_be_set); } } @@ -140,16 +143,26 @@ public class JSchConnection implements IRemoteConnection { } } fIsOpen = false; - fireConnectionChangeEvent(this, IRemoteConnectionChangeEvent.CONNECTION_CLOSED); + fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_CLOSED); } } + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(IRemoteConnection o) { + return getName().compareTo(o.getName()); + } + /** * Notify all fListeners when this connection's status changes. * * @param event */ - public void fireConnectionChangeEvent(final IRemoteConnection connection, final int type) { + public void fireConnectionChangeEvent(final int type) { + final IRemoteConnection connection = this; IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() { public IRemoteConnection getConnection() { return connection; @@ -271,7 +284,7 @@ public class JSchConnection implements IRemoteConnection { * @see org.eclipse.remote.core.IRemoteConnection#getAddress() */ public String getAddress() { - return fHost; + return fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING); } /* @@ -280,7 +293,7 @@ public class JSchConnection implements IRemoteConnection { * @see org.eclipse.remote.core.IRemoteConnection#getAttributes() */ public Map getAttributes() { - return Collections.unmodifiableMap(fProperties); + return Collections.unmodifiableMap(fAttributes.getAttributes()); } /* @@ -292,6 +305,22 @@ public class JSchConnection implements IRemoteConnection { throw new IOException("Not currently implemented"); //$NON-NLS-1$ } + /** + * Get the result of executing a pwd command. + * + * @return current working directory + */ + private String getCwd(IProgressMonitor monitor) { + SubMonitor subMon = SubMonitor.convert(monitor, 10); + ExecCommand exec = new ExecCommand(this); + try { + return exec.setCommand("pwd").getResult(subMon.newChild(10)).trim(); //$NON-NLS-1$ + } catch (RemoteConnectionException e) { + // Ignore + } + return null; + } + /* * (non-Javadoc) * @@ -335,13 +364,33 @@ public class JSchConnection implements IRemoteConnection { return new JSchFileManager(this); } + public JSchConnectionAttributes getInfo() { + return fAttributes; + } + + public String getKeyFile() { + return fAttributes.getAttribute(JSchConnectionAttributes.KEYFILE_ATTR, EMPTY_STRING); + } + + public JSchConnectionManager getManager() { + return fManager; + } + /* * (non-Javadoc) * * @see org.eclipse.remote.core.IRemoteConnection#getName() */ public String getName() { - return fConnName; + return fAttributes.getName(); + } + + public String getPassphrase() { + return fAttributes.getSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, EMPTY_STRING); + } + + public String getPassword() { + return fAttributes.getSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, EMPTY_STRING); } /* @@ -350,7 +399,7 @@ public class JSchConnection implements IRemoteConnection { * @see org.eclipse.remote.core.IRemoteConnection#getPort() */ public int getPort() { - return fPort; + return fAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT); } /* @@ -380,15 +429,6 @@ public class JSchConnection implements IRemoteConnection { return fProperties.get(key); } - /** - * Get the result of executing a pwd command. - * - * @return current working directory - */ - private String getPwd() { - return null; // TODO: implement - } - /* * (non-Javadoc) * @@ -419,13 +459,26 @@ public class JSchConnection implements IRemoteConnection { return fSftpChannel; } + public int getTimeout() { + return fAttributes.getInt(JSchConnectionAttributes.TIMEOUT_ATTR, DEFAULT_TIMEOUT); + } + /* * (non-Javadoc) * * @see org.eclipse.remote.core.IRemoteConnection#getUsername() */ public String getUsername() { - return fUsername; + return fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() + */ + public IRemoteConnectionWorkingCopy getWorkingCopy() { + return new JSchConnectionWorkingCopy(this); } /* @@ -438,10 +491,7 @@ public class JSchConnection implements IRemoteConnection { return "/"; //$NON-NLS-1$ } if (fWorkingDir == null) { - fWorkingDir = getPwd(); - if (fWorkingDir == null) { - return "/"; //$NON-NLS-1$ - } + return "/"; //$NON-NLS-1$ } return fWorkingDir; } @@ -455,6 +505,10 @@ public class JSchConnection implements IRemoteConnection { return fIsOpen; } + public boolean isPasswordAuth() { + return fAttributes.getBoolean(JSchConnectionAttributes.IS_PASSWORD_ATTR, DEFAULT_IS_PASSWORD); + } + private void loadEnv(IProgressMonitor monitor) throws RemoteConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 10); ExecCommand exec = new ExecCommand(this); @@ -523,7 +577,7 @@ public class JSchConnection implements IRemoteConnection { fProperties.put(FILE_SEPARATOR_PROPERTY, "/"); //$NON-NLS-1$ fProperties.put(PATH_SEPARATOR_PROPERTY, ":"); //$NON-NLS-1$ fProperties.put(LINE_SEPARATOR_PROPERTY, "\n"); //$NON-NLS-1$ - fProperties.put(USER_HOME_PROPERTY, getPwd()); + fProperties.put(USER_HOME_PROPERTY, getWorkingDirectory()); ExecCommand exec = new ExecCommand(this); String osVersion; @@ -566,8 +620,8 @@ public class JSchConnection implements IRemoteConnection { private Session newSession(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException { SubMonitor progress = SubMonitor.convert(monitor, 10); try { - final IJSchLocation location = fJSchService.getLocation(fUsername, fHost, fPort); - location.setPassword(fPassword); + final IJSchLocation location = fJSchService.getLocation(getUsername(), getAddress(), getPort()); + location.setPassword(getPassword()); UserInfo userInfo = null; if (authenticator != null) { userInfo = new UserInfo() { @@ -607,7 +661,7 @@ public class JSchConnection implements IRemoteConnection { }; } Session session = fJSchService.createSession(location, userInfo); - session.setPassword(fPassword); + session.setPassword(getPassword()); fJSchService.connect(session, 0, progress.newChild(10)); if (!progress.isCanceled()) { fSessions.add(session); @@ -637,16 +691,17 @@ public class JSchConnection implements IRemoteConnection { public void open(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException { if (!isOpen()) { checkIsConfigured(); - SubMonitor subMon = SubMonitor.convert(monitor, 30); + SubMonitor subMon = SubMonitor.convert(monitor, 70); Session session = newSession(authenticator, subMon.newChild(10)); if (!subMon.isCanceled()) { if (!checkConfiguration(session, subMon.newChild(20))) { newSession(authenticator, subMon.newChild(10)); loadEnv(subMon.newChild(10)); } + fWorkingDir = getCwd(subMon.newChild(10)); loadProperties(subMon.newChild(10)); fIsOpen = true; - fireConnectionChangeEvent(this, IRemoteConnectionChangeEvent.CONNECTION_OPENED); + fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED); } } } @@ -703,61 +758,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setAddress(java.lang.String ) - */ - public void setAddress(String address) { - fHost = address; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setAttribute(java.lang. String, java.lang.String) - */ - public void setAttribute(String key, String value) { - fProperties.put(key, value); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setName(java.lang.String) - */ - public void setName(String name) { - fConnName = name; - fireConnectionChangeEvent(this, IRemoteConnectionChangeEvent.CONNECTION_RENAMED); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setPassword(java.lang.String ) - */ - public void setPassword(String password) { - fPassword = password; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setPort(int) - */ - public void setPort(int port) { - fPort = port; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setUsername(java.lang.String ) - */ - public void setUsername(String userName) { - fUsername = userName; - } - /* * (non-Javadoc) * diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionAttributes.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionAttributes.java new file mode 100644 index 00000000000..19d83a621bc --- /dev/null +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionAttributes.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2013 IBM Corporation 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: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.internal.remote.jsch.core; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.SecurePreferencesFactory; +import org.eclipse.equinox.security.storage.StorageException; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +public class JSchConnectionAttributes { + public static final String CONNECTIONS_KEY = "connections"; //$NON-NLS-1$ + + public static final String ADDRESS_ATTR = "JSCH_ADDRESS_ATTR"; //$NON-NLS-1$ + public static final String USERNAME_ATTR = "JSCH_USERNAME_ATTR"; //$NON-NLS-1$ + public static final String PASSWORD_ATTR = "JSCH_PASSWORD_ATTR"; //$NON-NLS-1$ + public static final String PORT_ATTR = "JSCH_PORT_ATTR"; //$NON-NLS-1$ + public static final String IS_PASSWORD_ATTR = "JSCH_IS_PASSWORD_ATTR"; //$NON-NLS-1$ + public static final String PASSPHRASE_ATTR = "JSCH_PASSPHRASE_ATTR"; //$NON-NLS-1$ + public static final String KEYFILE_ATTR = "JSCH_KEYFILE_ATTR"; //$NON-NLS-1$ + public static final String TIMEOUT_ATTR = "JSCH_TIMEOUT_ATTR"; //$NON-NLS-1$ + + private String fName; + private String fNewName; + + private final Map fAttributes = Collections.synchronizedMap(new HashMap()); + private final Map fSecureAttributes = Collections.synchronizedMap(new HashMap()); + + public JSchConnectionAttributes(String name) { + fName = name; + load(); + } + + private void clearPreferences() { + try { + getPreferences().clear(); + } catch (BackingStoreException e) { + Activator.log(e.getMessage()); + } + getSecurePreferences().clear(); + } + + public JSchConnectionAttributes copy() { + JSchConnectionAttributes copy = new JSchConnectionAttributes(fName); + copy.getAttributes().putAll(fAttributes); + copy.getSecureAttributes().putAll(fSecureAttributes); + return copy; + } + + private void flushPreferences() { + try { + getPreferences().flush(); + } catch (BackingStoreException e) { + Activator.log(e.getMessage()); + } + try { + getSecurePreferences().flush(); + } catch (IOException e) { + Activator.log(e.getMessage()); + } + } + + public String getAttribute(String key, String def) { + if (fAttributes.containsKey(key)) { + return fAttributes.get(key); + } + return def; + } + + public Map getAttributes() { + return fAttributes; + } + + public String getName() { + if (fNewName == null) { + return fName; + } + return fNewName; + } + + private Preferences getPreferences() { + IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); + Preferences connections = root.node(CONNECTIONS_KEY); + return connections.node(fName); + } + + public String getSecureAttribute(String key, String def) { + if (fSecureAttributes.containsKey(key)) { + return fSecureAttributes.get(key); + } + return def; + } + + public int getInt(String key, int def) { + try { + return Integer.parseInt(fAttributes.get(key)); + } catch (NumberFormatException e) { + return def; + } + } + + public boolean getBoolean(String key, boolean def) { + if (fAttributes.containsKey(key)) { + return Boolean.parseBoolean(fAttributes.get(key)); + } + return def; + } + + public Map getSecureAttributes() { + return fSecureAttributes; + } + + private ISecurePreferences getSecurePreferences() { + ISecurePreferences secRoot = SecurePreferencesFactory.getDefault(); + ISecurePreferences secConnections = secRoot.node(CONNECTIONS_KEY); + return secConnections.node(fName); + } + + private void load() { + IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); + Preferences connections = root.node(CONNECTIONS_KEY); + Preferences nodes = connections.node(fName); + try { + loadAttributes(nodes); + } catch (BackingStoreException e) { + Activator.log(e.getMessage()); + } + ISecurePreferences secRoot = SecurePreferencesFactory.getDefault(); + ISecurePreferences secConnections = secRoot.node(CONNECTIONS_KEY); + ISecurePreferences secNode = secConnections.node(fName); + try { + loadAuthAttributes(secNode); + } catch (StorageException e) { + Activator.log(e.getMessage()); + } + } + + private void loadAttributes(Preferences node) throws BackingStoreException { + fAttributes.clear(); + for (String key : node.keys()) { + fAttributes.put(key, node.get(key, null)); + } + } + + private void loadAuthAttributes(ISecurePreferences node) throws StorageException { + fSecureAttributes.clear(); + for (String key : node.keys()) { + fSecureAttributes.put(key, node.get(key, null)); + } + } + + public void save() { + clearPreferences(); + if (fNewName != null) { + fName = fNewName; + fNewName = null; + } + savePreferences(); + flushPreferences(); + } + + public void remove() { + clearPreferences(); + flushPreferences(); + } + + private void savePreferences() { + Preferences node = getPreferences(); + synchronized (fAttributes) { + for (Entry entry : fAttributes.entrySet()) { + node.put(entry.getKey(), entry.getValue()); + } + } + try { + ISecurePreferences secNode = getSecurePreferences(); + synchronized (fSecureAttributes) { + for (Entry entry : fSecureAttributes.entrySet()) { + secNode.put(entry.getKey(), entry.getValue(), true); + } + } + } catch (StorageException e) { + Activator.log(e.getMessage()); + } + } + + public void setAttribute(String key, String value) { + fAttributes.put(key, value); + } + + public void setName(String name) { + fNewName = name; + } + + public void setSecureAttribute(String key, String value) { + fSecureAttributes.put(key, value); + } +} diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionManager.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionManager.java index 2b28e0e8e46..328451c77cf 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionManager.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionManager.java @@ -13,18 +13,23 @@ package org.eclipse.internal.remote.jsch.core; import java.net.URI; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.internal.remote.jsch.core.messages.Messages; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionManager; import org.eclipse.remote.core.IRemoteServices; import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; public class JSchConnectionManager implements IRemoteConnectionManager { private final IRemoteServices fRemoteServices; - private final Map fConnections = Collections - .synchronizedMap(new HashMap()); + private Map fConnections; /** * @since 4.0 @@ -41,6 +46,7 @@ public class JSchConnectionManager implements IRemoteConnectionManager { * .lang.String) */ public IRemoteConnection getConnection(String name) { + loadConnections(); return fConnections.get(name); } @@ -62,14 +68,53 @@ public class JSchConnectionManager implements IRemoteConnectionManager { return null; } + public JSchConnection createConnection(String name) { + return new JSchConnection(name, fRemoteServices); + } + /* * (non-Javadoc) * * @see * org.eclipse.remote.core.IRemoteConnectionManager#getConnections() */ - public IRemoteConnection[] getConnections() { - return fConnections.values().toArray(new IRemoteConnection[fConnections.size()]); + public Set getConnections() { + loadConnections(); + Set set = new HashSet(); + set.addAll(fConnections.values()); + return set; + } + + // private void loadAuth(ISecurePreferences node) throws StorageException { + // JSchConnection connection = fConnections.get(node.name()); + // if (connection != null) { + // boolean isPasswordAuth = node.getBoolean(IS_PASSWORD_AUTH_KEY, true); + // connection.setIsPasswordAuth(isPasswordAuth); + // if (isPasswordAuth) { + // connection.setPassword(node.get(PASSWORD_KEY, null)); + // } else { + // connection.setPassphrase(node.get(PASSPHRASE_KEY, null)); + // connection.setKeyFile(node.get(KEYFILE_KEY, null)); + // } + // } else { + // node.removeNode(); + // } + // } + + private synchronized void loadConnections() { + if (fConnections == null) { + fConnections = Collections.synchronizedMap(new HashMap()); + IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); + Preferences connections = root.node(JSchConnectionAttributes.CONNECTIONS_KEY); + try { + for (String name : connections.childrenNames()) { + JSchConnection connection = new JSchConnection(name, fRemoteServices); + fConnections.put(name, connection); + } + } catch (BackingStoreException e) { + Activator.log(e.getMessage()); + } + } } /* @@ -86,9 +131,19 @@ public class JSchConnectionManager implements IRemoteConnectionManager { if (getConnection(name) != null) { throw new RemoteConnectionException(Messages.JSchConnectionManager_connection_with_this_name_exists); } - IRemoteConnection connection = new JSchConnection(name, fRemoteServices); - fConnections.put(name, connection); - return connection; + return createConnection(name); + } + + public void add(JSchConnection conn) { + if (!fConnections.containsKey(conn.getName())) { + fConnections.put(conn.getName(), conn); + } + } + + public void remove(JSchConnection conn) { + if (fConnections.containsKey(conn.getName())) { + fConnections.remove(conn.getName()); + } } /* @@ -105,6 +160,62 @@ public class JSchConnectionManager implements IRemoteConnectionManager { if (conn.isOpen()) { throw new RemoteConnectionException(Messages.JSchConnectionManager_cannotRemoveOpenConnection); } + ((JSchConnection) conn).getInfo().remove(); fConnections.remove(conn.getName()); } + + // private void saveAuth(JSchConnection conn, ISecurePreferences node) throws StorageException { + // boolean isPasswordAuth = conn.isPasswordAuth(); + // node.putBoolean(IS_PASSWORD_AUTH_KEY, isPasswordAuth, false); + // if (isPasswordAuth) { + // node.put(PASSWORD_KEY, conn.getPassword(), true); + // } else { + // node.put(PASSPHRASE_KEY, conn.getPassphrase(), true); + // node.put(KEYFILE_KEY, conn.getKeyFile(), false); + // } + // } + // + // private void saveConnection(JSchConnection conn, Preferences node) { + // node.put(HOST_KEY, conn.getAddress()); + // node.put(USER_KEY, conn.getUsername()); + // node.putInt(PORT_KEY, conn.getPort()); + // node.putInt(TIMEOUT_KEY, conn.getTimeout()); + // } + // + // public synchronized void saveConnections() { + // if (fConnections != null) { + // IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); + // Preferences connections = root.node(CONNECTIONS_KEY); + // try { + // connections.clear(); + // } catch (BackingStoreException e) { + // Activator.log(e.getMessage()); + // } + // for (JSchConnection conn : fConnections.values()) { + // Preferences node = connections.node(conn.getName()); + // saveConnection(conn, node); + // } + // ISecurePreferences secRoot = SecurePreferencesFactory.getDefault(); + // ISecurePreferences secConnections = secRoot.node("org.eclipse.remote.jsch.connections"); + // secConnections.clear(); + // try { + // for (JSchConnection conn : fConnections.values()) { + // ISecurePreferences secNode = secConnections.node(conn.getName()); + // saveAuth(conn, secNode); + // } + // } catch (StorageException e) { + // Activator.log(e.getMessage()); + // } + // try { + // root.flush(); + // } catch (BackingStoreException e) { + // Activator.log(e.getMessage()); + // } + // try { + // secRoot.flush(); + // } catch (IOException e) { + // Activator.log(e.getMessage()); + // } + // } + // } } diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionWorkingCopy.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionWorkingCopy.java new file mode 100644 index 00000000000..48cffcd7fa2 --- /dev/null +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchConnectionWorkingCopy.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 IBM Corporation 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: + * IBM Corporation - Initial API and implementation + *******************************************************************************/ +package org.eclipse.internal.remote.jsch.core; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.remote.core.IRemoteConnectionChangeEvent; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; + +/** + * @since 5.0 + */ +public class JSchConnectionWorkingCopy extends JSchConnection implements IRemoteConnectionWorkingCopy { + private final JSchConnectionAttributes fWorkingAttributes; + private final JSchConnection fOriginal; + + public JSchConnectionWorkingCopy(JSchConnection connection) { + super(connection.getName(), connection.getRemoteServices()); + fWorkingAttributes = connection.getInfo().copy(); + fOriginal = connection; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getAddress() + */ + @Override + public String getAddress() { + return fWorkingAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getAttributes() + */ + @Override + public Map getAttributes() { + return Collections.unmodifiableMap(fWorkingAttributes.getAttributes()); + } + + @Override + public String getKeyFile() { + return fWorkingAttributes.getAttribute(JSchConnectionAttributes.KEYFILE_ATTR, EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getName() + */ + @Override + public String getName() { + return fWorkingAttributes.getName(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.internal.remote.jsch.core.JSchConnection#getPassphrase() + */ + @Override + public String getPassphrase() { + return fWorkingAttributes.getSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.internal.remote.jsch.core.JSchConnection#getPassword() + */ + @Override + public String getPassword() { + return fWorkingAttributes.getSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getPort() + */ + @Override + public int getPort() { + return fWorkingAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.internal.remote.jsch.core.JSchConnection#getTimeout() + */ + @Override + public int getTimeout() { + return fWorkingAttributes.getInt(JSchConnectionAttributes.TIMEOUT_ATTR, DEFAULT_TIMEOUT); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getUsername() + */ + @Override + public String getUsername() { + return fWorkingAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, JSchConnection.EMPTY_STRING); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() + */ + @Override + public IRemoteConnectionWorkingCopy getWorkingCopy() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.internal.remote.jsch.core.JSchConnection#isPasswordAuth() + */ + @Override + public boolean isPasswordAuth() { + return fWorkingAttributes.getBoolean(JSchConnectionAttributes.IS_PASSWORD_ATTR, DEFAULT_IS_PASSWORD); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#save() + */ + public void save() { + JSchConnectionAttributes info = fOriginal.getInfo(); + info.getAttributes().clear(); + info.getAttributes().putAll(fWorkingAttributes.getAttributes()); + info.getSecureAttributes().clear(); + info.getSecureAttributes().putAll(fWorkingAttributes.getSecureAttributes()); + if (!getName().equals(info.getName())) { + info.setName(getName()); + getManager().remove(fOriginal); + fOriginal.fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_RENAMED); + } + info.save(); + getManager().add(fOriginal); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String) + */ + public void setAddress(String address) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.ADDRESS_ATTR, address); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String) + */ + public void setAttribute(String key, String value) { + fWorkingAttributes.setAttribute(key, value); + } + + public void setIsPasswordAuth(boolean isPasswordAuth) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(isPasswordAuth)); + } + + public void setKeyFile(String keyFile) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.KEYFILE_ATTR, keyFile); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) + */ + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) + */ + public void setName(String name) { + fWorkingAttributes.setName(name); + } + + public void setPassphrase(String passphrase) { + fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, passphrase); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String) + */ + public void setPassword(String password) { + fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, password); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int) + */ + public void setPort(int port) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.PORT_ATTR, Integer.toString(port)); + } + + public void setTimeout(int timeout) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.TIMEOUT_ATTR, Integer.toString(timeout)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String) + */ + public void setUsername(String userName) { + fWorkingAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, userName); + } +} diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchServices.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchServices.java index 3bbf838a4ec..e98ea486878 100644 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchServices.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/JSchServices.java @@ -43,4 +43,9 @@ public class JSchServices extends AbstractRemoteServices { public boolean initialize(IProgressMonitor monitor) { return true; } + + public int getCapabilities() { + return CAPABILITY_ADD_CONNECTIONS | CAPABILITY_EDIT_CONNECTIONS | CAPABILITY_REMOVE_CONNECTIONS + | CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING | CAPABILITY_SUPPORTS_X11_FORWARDING; + } } diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java index 0572559e072..dbab2f913eb 100755 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/Messages.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2006 IBM Corporation. + * Copyright (c) 2013 IBM Corporation. * 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 @@ -13,11 +13,6 @@ package org.eclipse.internal.remote.jsch.core.messages; import org.eclipse.osgi.util.NLS; -/** - * @author Daniel Felix Ferber - * - * @since 3.0 - */ public class Messages extends NLS { private static final String BUNDLE_ID = "org.eclipse.internal.remote.jsch.core.messages.messages"; //$NON-NLS-1$ diff --git a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties index 2ecadb540cd..e59cad73185 100755 --- a/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties +++ b/org.eclipse.remote.jsch.core/src/org/eclipse/internal/remote/jsch/core/messages/messages.properties @@ -1,7 +1,5 @@ -AbstractRemoteCommand_Get_symlink_target=Get symlink target -AbstractRemoteCommand_Operation_cancelled_by_user=Operation cancelled by user ############################################################################### -# Copyright (c) 2006 IBM Corporation. +# Copyright (c) 2013 IBM Corporation. # 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 @@ -10,6 +8,8 @@ AbstractRemoteCommand_Operation_cancelled_by_user=Operation cancelled by user # Contributors: # IBM Corporation - initial implementation ############################################################################### +AbstractRemoteCommand_Get_symlink_target=Get symlink target +AbstractRemoteCommand_Operation_cancelled_by_user=Operation cancelled by user AbstractRemoteCommand_Execution_exception=Execution exception AuthInfo_Authentication_message=Authentication Message ChildInfosCommand_Get_file_attributes=Get file attributes diff --git a/org.eclipse.remote.ui/META-INF/MANIFEST.MF b/org.eclipse.remote.ui/META-INF/MANIFEST.MF index 96a7a6df6dd..52c193acd1e 100644 --- a/org.eclipse.remote.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.remote.ui/META-INF/MANIFEST.MF @@ -7,6 +7,7 @@ Bundle-Activator: org.eclipse.internal.remote.ui.RemoteUIPlugin Bundle-Vendor: %pluginProvider Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide, + org.eclipse.ui.forms, org.eclipse.core.runtime, org.eclipse.remote.core, org.eclipse.core.filesystem, diff --git a/org.eclipse.remote.ui/plugin.properties b/org.eclipse.remote.ui/plugin.properties index 0f6683bd6ec..48b46ffa883 100644 --- a/org.eclipse.remote.ui/plugin.properties +++ b/org.eclipse.remote.ui/plugin.properties @@ -9,4 +9,5 @@ pluginName=PTP Remote UI pluginProvider=Eclipse PTP -RemoteDevPrefPage.name=Remote Development \ No newline at end of file +RemoteDevPrefPage.name=Remote Development +ConnectionsPreferencePage.name=Connections \ No newline at end of file diff --git a/org.eclipse.remote.ui/plugin.xml b/org.eclipse.remote.ui/plugin.xml index b9e258db99b..f3c965aa9e5 100644 --- a/org.eclipse.remote.ui/plugin.xml +++ b/org.eclipse.remote.ui/plugin.xml @@ -6,17 +6,26 @@ point="org.eclipse.remote.ui.remoteUIServices"> - - + + + + + diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/Messages.java b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/Messages.java index fdf7df9f065..d6806e54495 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/Messages.java +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/Messages.java @@ -20,6 +20,20 @@ public class Messages extends NLS { public static String AbstractRemoteUIConnectionManager_Could_not_open_connection; + public static String ConnectionsPreferencePage_Add; + + public static String ConnectionsPreferencePage_Connection_Name; + + public static String ConnectionsPreferencePage_Edit; + + public static String ConnectionsPreferencePage_Host; + + public static String ConnectionsPreferencePage_Remote_Services; + + public static String ConnectionsPreferencePage_Remove; + + public static String ConnectionsPreferencePage_User; + public static String LocalUIConnectionManager_0; public static String LocalUIConnectionManager_1; public static String LocalUIConnectionManager_2; @@ -44,6 +58,14 @@ public class Messages extends NLS { public static String RemoteDirectoryWidget_2; public static String RemoteDirectoryWidget_3; + public static String RemoteFileWidget_Browse; + + public static String RemoteFileWidget_File; + + public static String RemoteFileWidget_Restore_Default; + + public static String RemoteFileWidget_Select_File; + public static String RemoteResourceBrowser_resourceTitle; public static String RemoteResourceBrowser_fileTitle; public static String RemoteResourceBrowser_directoryTitle; diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/messages.properties b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/messages.properties index 70f035eebbf..a9ad1a40690 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/messages.properties +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/messages/messages.properties @@ -7,6 +7,13 @@ AbstractRemoteUIConnectionManager_Could_not_open_connection=Could not open conne # http://www.eclipse.org/legal/epl-v10.html ############################################################################### AbstractRemoteUIConnectionManager_Connection_Error=Connection Error +ConnectionsPreferencePage_Add=Add +ConnectionsPreferencePage_Connection_Name=Connection Name +ConnectionsPreferencePage_Edit=Edit +ConnectionsPreferencePage_Host=Host +ConnectionsPreferencePage_Remote_Services=Remote Services: +ConnectionsPreferencePage_Remove=Remove +ConnectionsPreferencePage_User=User LocalUIConnectionManager_0=Connection Error LocalUIConnectionManager_1=Could not open connection LocalUIConnectionManager_2=Can not create local connection @@ -26,6 +33,10 @@ RemoteDirectoryWidget_0=Select Directory RemoteDirectoryWidget_1=Directory: RemoteDirectoryWidget_2=Browse... RemoteDirectoryWidget_3=Restore Default +RemoteFileWidget_Browse=Browse... +RemoteFileWidget_File=File: +RemoteFileWidget_Restore_Default=Restore Default +RemoteFileWidget_Select_File=Select File RemoteResourceBrowser_resourceTitle=Browse Resource RemoteResourceBrowser_fileTitle=Browse File RemoteResourceBrowser_directoryTitle=Browse Directory diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/ConnectionsPreferencePage.java b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/ConnectionsPreferencePage.java new file mode 100644 index 00000000000..a6af6d630bd --- /dev/null +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/ConnectionsPreferencePage.java @@ -0,0 +1,410 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.internal.remote.ui.preferences; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.internal.remote.core.RemoteServicesDescriptor; +import org.eclipse.internal.remote.core.RemoteServicesImpl; +import org.eclipse.internal.remote.core.preferences.Preferences; +import org.eclipse.internal.remote.ui.messages.Messages; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ColumnLayoutData; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemotePreferenceConstants; +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.ui.IRemoteUIConnectionManager; +import org.eclipse.remote.ui.RemoteUIServices; +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.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * This class implements a preference page which can be used to view a list of + * JSch connections, create new connections or to delete existing connections. + * + */ +public class ConnectionsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + /** + * Handle widget selection events for this page + * + */ + private class EventHandler extends SelectionAdapter { + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + Object source; + + source = e.getSource(); + if (source == fAddButton) { + addConnection(); + } else if (source == fEditButton) { + editConnection(); + } else if (source == fRemoveButton) { + removeConnections(); + } else if (source == fConnectionTable) { + selectConnection(); + } else if (source == fServicesCombo) { + String id = fServiceIDs[fServicesCombo.getSelectionIndex()]; + selectServices(id); + } + } + + } + + private class ConnectionContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + return fWorkingCopies.values().toArray(new IRemoteConnection[fWorkingCopies.size()]); + } + + public void dispose() { + // Nothing to do + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // Nothing to do + } + + } + + private class ConnectionLabelProvider implements ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + IRemoteConnection connection = (IRemoteConnection) element; + switch (columnIndex) { + case 0: + return connection.getName(); + case 1: + return connection.getAddress(); + case 2: + return connection.getUsername(); + } + return null; + } + + public void addListener(ILabelProviderListener listener) { + // Nothing to do + } + + public void dispose() { + // Nothing to do + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + // Nothing to do + } + + } + + private final String[] fTableColumnHeaders = { Messages.ConnectionsPreferencePage_Connection_Name, Messages.ConnectionsPreferencePage_Host, Messages.ConnectionsPreferencePage_User }; + + private final ColumnLayoutData[] fTableColumnLayouts = { new ColumnWeightData(30), new ColumnWeightData(50), + new ColumnWeightData(20) }; + + private Combo fServicesCombo; + private Button fAddButton; + private Button fEditButton; + private Button fRemoveButton; + private Table fConnectionTable; + private TableViewer fConnectionViewer; + private EventHandler fEventHandler; + + private String[] fServiceIDs; + private boolean fIsDirty; + private IRemoteConnection fSelectedConnection; + private IRemoteConnectionManager fConnectionManager; + private IRemoteUIConnectionManager fUIConnectionManager; + + private final Map fWorkingCopies = new HashMap(); + + public ConnectionsPreferencePage() { + super(); + } + + public ConnectionsPreferencePage(String title) { + super(title); + } + + public ConnectionsPreferencePage(String title, ImageDescriptor image) { + super(title, image); + } + + public void init(IWorkbench workbench) { + // Do nothing + } + + private void initWorkingConnections() { + fWorkingCopies.clear(); + for (IRemoteConnection conn : fConnectionManager.getConnections()) { + fWorkingCopies.put(conn.getName(), conn); + } + } + + /** + * Delete service configurations when Ok button is pressed + * + * @return Status from superclass indicating if Ok processing is to continue + */ + @Override + public boolean performOk() { + if (fIsDirty) { + updateConnections(); + fIsDirty = false; + } + return super.performOk(); + } + + /** + * Add a service configuration to the set of service configurations + */ + private void addConnection() { + IRemoteConnectionWorkingCopy conn = fUIConnectionManager.newConnection(getShell(), null, null); + if (conn != null) { + fWorkingCopies.put(conn.getName(), conn); + fConnectionViewer.refresh(); + fIsDirty = true; + } + } + + /** + * Create the widgets for this page + * + * @param parent + * The parent widget for the client area + * @return + */ + private Control createWidgets(Composite parent) { + fEventHandler = new EventHandler(); + + Composite selectComp = new Composite(parent, SWT.NONE); + selectComp.setLayout(new GridLayout(2, false)); + selectComp.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + + Label label = new Label(selectComp, SWT.NONE); + label.setText(Messages.ConnectionsPreferencePage_Remote_Services); + label.setLayoutData(new GridData()); + fServicesCombo = new Combo(selectComp, SWT.READ_ONLY); + label.setLayoutData(new GridData()); + List descriptors = RemoteServicesImpl.getRemoteServiceDescriptors(); + String[] names = new String[descriptors.size()]; + fServiceIDs = new String[descriptors.size()]; + for (int i = 0; i < descriptors.size(); i++) { + names[i] = descriptors.get(i).getName(); + fServiceIDs[i] = descriptors.get(i).getId(); + } + fServicesCombo.addSelectionListener(fEventHandler); + fServicesCombo.setItems(names); + + Composite preferencePane = new Composite(parent, SWT.NONE); + preferencePane.setLayout(new GridLayout(2, false)); + + fConnectionTable = new Table(preferencePane, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); + GridData data = new GridData(GridData.FILL_BOTH); + data.widthHint = 425; + data.heightHint = fConnectionTable.getItemHeight(); + data.horizontalSpan = 1; + fConnectionTable.setLayoutData(data); + fConnectionTable.setFont(parent.getFont()); + fConnectionTable.addSelectionListener(fEventHandler); + + TableLayout tableLayout = new TableLayout(); + fConnectionTable.setLayout(tableLayout); + fConnectionTable.setHeaderVisible(true); + fConnectionTable.setLinesVisible(true); + + for (int i = 0; i < fTableColumnHeaders.length; i++) { + tableLayout.addColumnData(fTableColumnLayouts[i]); + TableColumn column = new TableColumn(fConnectionTable, SWT.NONE, i); + column.setResizable(fTableColumnLayouts[i].resizable); + column.setText(fTableColumnHeaders[i]); + } + fConnectionViewer = new TableViewer(fConnectionTable); + fConnectionViewer.setContentProvider(new ConnectionContentProvider()); + fConnectionViewer.setLabelProvider(new ConnectionLabelProvider()); + fConnectionViewer.setInput(this); + + Composite buttonPane = new Composite(preferencePane, SWT.NONE); + buttonPane.setLayout(new GridLayout(1, false)); + buttonPane.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + buttonPane.setFont(preferencePane.getFont()); + + fAddButton = new Button(buttonPane, SWT.PUSH); + setButtonLayoutData(fAddButton); + fAddButton.setText(Messages.ConnectionsPreferencePage_Add); + fAddButton.addSelectionListener(fEventHandler); + fEditButton = new Button(buttonPane, SWT.PUSH); + setButtonLayoutData(fEditButton); + fEditButton.setText(Messages.ConnectionsPreferencePage_Edit); + fEditButton.addSelectionListener(fEventHandler); + fEditButton.setEnabled(false); + fRemoveButton = new Button(buttonPane, SWT.PUSH); + setButtonLayoutData(fRemoveButton); + fRemoveButton.setText(Messages.ConnectionsPreferencePage_Remove); + fRemoveButton.addSelectionListener(fEventHandler); + fRemoveButton.setEnabled(false); + + String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); + if ("".equals(id)) { //$NON-NLS-1$ + id = fServiceIDs[0]; + } + for (int i = 0; i < fServiceIDs.length; i++) { + if (id.equals(fServiceIDs[i])) { + fServicesCombo.select(i); + } + } + selectServices(id); + + return preferencePane; + } + + /** + * Edit an existing service configuration + */ + private void editConnection() { + if (fSelectedConnection != null) { + IRemoteConnectionWorkingCopy copy = fSelectedConnection.getWorkingCopy(); + if (fUIConnectionManager.updateConnection(getShell(), copy)) { + fWorkingCopies.put(copy.getName(), copy); + fConnectionViewer.refresh(); + fIsDirty = true; + } + } + } + + /** + * Remove the selected service configuration from the set of service + * configurations + */ + private void removeConnections() { + TableItem[] items = fConnectionTable.getSelection(); + if (items.length > 0) { + for (TableItem item : items) { + fWorkingCopies.remove(((IRemoteConnection) item.getData()).getName()); + } + fConnectionViewer.refresh(); + fIsDirty = true; + } + } + + /** + * Record the selected connection and enable the buttons. + */ + private void selectConnection() { + TableItem[] selection = fConnectionTable.getSelection(); + fEditButton.setEnabled(false); + fRemoveButton.setEnabled(false); + if (selection.length > 0) { + fSelectedConnection = (IRemoteConnection) selection[0].getData(); + IRemoteServices services = fSelectedConnection.getRemoteServices(); + fEditButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0); + fRemoveButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0); + } + } + + private void selectServices(String id) { + IRemoteServices services = RemoteServices.getRemoteServices(id); + if (services != null) { + fConnectionManager = services.getConnectionManager(); + fUIConnectionManager = RemoteUIServices.getRemoteUIServices(services).getUIConnectionManager(); + initWorkingConnections(); + fConnectionViewer.refresh(); + fAddButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); + } + fIsDirty = false; + } + + /** + * Update the connection manager with changes to the connections. + */ + private void updateConnections() { + /* + * Remove any deleted connections + */ + for (IRemoteConnection conn : fConnectionManager.getConnections()) { + if (!fWorkingCopies.containsKey(conn.getName()) && !conn.isOpen()) { + try { + fConnectionManager.removeConnection(conn); + } catch (RemoteConnectionException e) { + // Ignore + } + } + } + /* + * Save any added/edited connections + */ + for (IRemoteConnection conn : fWorkingCopies.values()) { + if (conn instanceof IRemoteConnectionWorkingCopy) { + ((IRemoteConnectionWorkingCopy) conn).save(); + } + } + initWorkingConnections(); + } + + /** + * Create the contents for this page + * + * @param parent + * - The parent widget for the client area + */ + @Override + protected Control createContents(Composite parent) { + return createWidgets(parent); + } + + @Override + protected void performDefaults() { + initWorkingConnections(); + fIsDirty = false; + super.performDefaults(); + } +} diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/PreferencesAdapter.java b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/PreferencesAdapter.java index 718dbd2e40d..3777515b5c3 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/PreferencesAdapter.java +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/PreferencesAdapter.java @@ -48,8 +48,6 @@ public class PreferencesAdapter implements IPreferenceStore { /** Listener on the adapted Preferences */ private final PreferenceChangeListener fListener = new PreferenceChangeListener(); - private final String fPrefsQualifier; - /** True iff no events should be forwarded */ private boolean fSilent; @@ -63,9 +61,8 @@ public class PreferencesAdapter implements IPreferenceStore { * The preferences to wrap. * @since 4.0 */ - public PreferencesAdapter(String qualifier) { - fPrefsQualifier = qualifier; - Preferences.addPreferenceChangeListener(fPrefsQualifier, fListener); + public PreferencesAdapter() { + Preferences.addPreferenceChangeListener(fListener); } /** @@ -86,7 +83,7 @@ public class PreferencesAdapter implements IPreferenceStore { * {@inheritDoc} */ public boolean contains(String name) { - return Preferences.contains(fPrefsQualifier, name); + return Preferences.contains(name); } /** @@ -107,91 +104,91 @@ public class PreferencesAdapter implements IPreferenceStore { * {@inheritDoc} */ public boolean getBoolean(String name) { - return Preferences.getBoolean(fPrefsQualifier, name); + return Preferences.getBoolean(name); } /** * {@inheritDoc} */ public boolean getDefaultBoolean(String name) { - return Preferences.getDefaultBoolean(fPrefsQualifier, name, false); + return Preferences.getDefaultBoolean(name, false); } /** * {@inheritDoc} */ public double getDefaultDouble(String name) { - return Preferences.getDefaultDouble(fPrefsQualifier, name, 0.0); + return Preferences.getDefaultDouble(name, 0.0); } /** * {@inheritDoc} */ public float getDefaultFloat(String name) { - return Preferences.getDefaultFloat(fPrefsQualifier, name, 0.0f); + return Preferences.getDefaultFloat(name, 0.0f); } /** * {@inheritDoc} */ public int getDefaultInt(String name) { - return Preferences.getDefaultInt(fPrefsQualifier, name, 0); + return Preferences.getDefaultInt(name, 0); } /** * {@inheritDoc} */ public long getDefaultLong(String name) { - return Preferences.getDefaultLong(fPrefsQualifier, name, 0L); + return Preferences.getDefaultLong(name, 0L); } /** * {@inheritDoc} */ public String getDefaultString(String name) { - return Preferences.getDefaultString(fPrefsQualifier, name, ""); //$NON-NLS-1$ + return Preferences.getDefaultString(name, ""); //$NON-NLS-1$ } /** * {@inheritDoc} */ public double getDouble(String name) { - return Preferences.getDouble(fPrefsQualifier, name); + return Preferences.getDouble(name); } /** * {@inheritDoc} */ public float getFloat(String name) { - return Preferences.getFloat(fPrefsQualifier, name); + return Preferences.getFloat(name); } /** * {@inheritDoc} */ public int getInt(String name) { - return Preferences.getInt(fPrefsQualifier, name); + return Preferences.getInt(name); } /** * {@inheritDoc} */ public long getLong(String name) { - return Preferences.getLong(fPrefsQualifier, name); + return Preferences.getLong(name); } /** * {@inheritDoc} */ public String getString(String name) { - return Preferences.getString(fPrefsQualifier, name); + return Preferences.getString(name); } /** * {@inheritDoc} */ public boolean isDefault(String name) { - return Preferences.isDefault(fPrefsQualifier, name); + return Preferences.isDefault(name); } /** @@ -207,7 +204,7 @@ public class PreferencesAdapter implements IPreferenceStore { public void putValue(String name, String value) { try { fSilent = true; - Preferences.setString(fPrefsQualifier, name, value); + Preferences.setString(name, value); } finally { fSilent = false; } @@ -217,90 +214,90 @@ public class PreferencesAdapter implements IPreferenceStore { * {@inheritDoc} */ public void setDefault(String name, double value) { - Preferences.setDefaultDouble(fPrefsQualifier, name, value); + Preferences.setDefaultDouble(name, value); } /** * {@inheritDoc} */ public void setDefault(String name, float value) { - Preferences.setDefaultFloat(fPrefsQualifier, name, value); + Preferences.setDefaultFloat(name, value); } /** * {@inheritDoc} */ public void setDefault(String name, int value) { - Preferences.setDefaultInt(fPrefsQualifier, name, value); + Preferences.setDefaultInt(name, value); } /** * {@inheritDoc} */ public void setDefault(String name, long value) { - Preferences.setDefaultLong(fPrefsQualifier, name, value); + Preferences.setDefaultLong(name, value); } /** * {@inheritDoc} */ public void setDefault(String name, String defaultObject) { - Preferences.setDefaultString(fPrefsQualifier, name, defaultObject); + Preferences.setDefaultString(name, defaultObject); } /** * {@inheritDoc} */ public void setDefault(String name, boolean value) { - Preferences.setDefaultBoolean(fPrefsQualifier, name, value); + Preferences.setDefaultBoolean(name, value); } /** * {@inheritDoc} */ public void setToDefault(String name) { - Preferences.setToDefault(fPrefsQualifier, name); + Preferences.setToDefault(name); } /** * {@inheritDoc} */ public void setValue(String name, double value) { - Preferences.setDouble(fPrefsQualifier, name, value); + Preferences.setDouble(name, value); } /** * {@inheritDoc} */ public void setValue(String name, float value) { - Preferences.setFloat(fPrefsQualifier, name, value); + Preferences.setFloat(name, value); } /** * {@inheritDoc} */ public void setValue(String name, int value) { - Preferences.setInt(fPrefsQualifier, name, value); + Preferences.setInt(name, value); } /** * {@inheritDoc} */ public void setValue(String name, long value) { - Preferences.setLong(fPrefsQualifier, name, value); + Preferences.setLong(name, value); } /** * {@inheritDoc} */ public void setValue(String name, String value) { - Preferences.setString(fPrefsQualifier, name, value); + Preferences.setString(name, value); } /** * {@inheritDoc} */ public void setValue(String name, boolean value) { - Preferences.setBoolean(fPrefsQualifier, name, value); + Preferences.setBoolean(name, value); } } diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/RemoteDevelopmentPreferencePage.java b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/RemoteDevelopmentPreferencePage.java index 9e2b56a4d86..0e837874e9a 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/RemoteDevelopmentPreferencePage.java +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/preferences/RemoteDevelopmentPreferencePage.java @@ -14,9 +14,8 @@ package org.eclipse.internal.remote.ui.preferences; import java.util.ArrayList; import java.util.List; -import org.eclipse.internal.remote.core.RemoteCorePlugin; +import org.eclipse.internal.remote.core.RemoteServicesDescriptor; import org.eclipse.internal.remote.core.RemoteServicesImpl; -import org.eclipse.internal.remote.core.RemoteServicesProxy; import org.eclipse.internal.remote.ui.messages.Messages; import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; @@ -32,7 +31,7 @@ public class RemoteDevelopmentPreferencePage extends FieldEditorPreferencePage i public RemoteDevelopmentPreferencePage() { super(GRID); - setPreferenceStore(new PreferencesAdapter(RemoteCorePlugin.getUniqueIdentifier())); + setPreferenceStore(new PreferencesAdapter()); } public void init(IWorkbench workbench) { @@ -42,9 +41,13 @@ public class RemoteDevelopmentPreferencePage extends FieldEditorPreferencePage i @Override protected void createFieldEditors() { List namesAndValues = new ArrayList(); + String[] nameAndValue = new String[2]; + nameAndValue[0] = "None"; //$NON-NLS-1$ + nameAndValue[1] = ""; //$NON-NLS-1$ + namesAndValues.add(nameAndValue); - for (RemoteServicesProxy service : RemoteServicesImpl.getRemoteServiceProxies()) { - String[] nameAndValue = new String[2]; + for (RemoteServicesDescriptor service : RemoteServicesImpl.getRemoteServiceDescriptors()) { + nameAndValue = new String[2]; nameAndValue[0] = service.getName(); nameAndValue[1] = service.getId(); namesAndValues.add(nameAndValue); diff --git a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/services/local/LocalUIConnectionManager.java b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/services/local/LocalUIConnectionManager.java index 34c18294ec7..6458d62d78d 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/services/local/LocalUIConnectionManager.java +++ b/org.eclipse.remote.ui/src/org/eclipse/internal/remote/ui/services/local/LocalUIConnectionManager.java @@ -23,6 +23,7 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.ui.IRemoteUIConnectionManager; import org.eclipse.swt.widgets.Shell; @@ -34,7 +35,7 @@ public class LocalUIConnectionManager implements IRemoteUIConnectionManager { * @see * org.eclipse.remote.core.IRemoteUIConnectionManager#newConnection() */ - public IRemoteConnection newConnection(Shell shell) { + public IRemoteConnectionWorkingCopy newConnection(Shell shell) { MessageDialog.openInformation(shell, Messages.LocalUIConnectionManager_2, Messages.LocalUIConnectionManager_3); return null; } @@ -46,7 +47,7 @@ public class LocalUIConnectionManager implements IRemoteUIConnectionManager { * org.eclipse.remote.ui.IRemoteUIConnectionManager#newConnection(org * .eclipse.swt.widgets.Shell, java.lang.String[], java.lang.String[]) */ - public IRemoteConnection newConnection(Shell shell, String[] attrHints, String[] attrHintValues) { + public IRemoteConnectionWorkingCopy newConnection(Shell shell, String[] attrHints, String[] attrHintValues) { return newConnection(shell); } @@ -89,13 +90,10 @@ public class LocalUIConnectionManager implements IRemoteUIConnectionManager { /* * (non-Javadoc) * - * @see - * org.eclipse.remote.ui.IRemoteUIConnectionManager#updateConnection - * (org.eclipse.swt.widgets.Shell, - * org.eclipse.remote.core.IRemoteConnection) + * @see org.eclipse.remote.ui.IRemoteUIConnectionManager#updateConnection(org.eclipse.swt.widgets.Shell, + * org.eclipse.remote.core.IRemoteConnectionWorkingCopy) */ - public void updateConnection(Shell shell, IRemoteConnection connection) { - // TODO Auto-generated method stub - + public boolean updateConnection(Shell shell, IRemoteConnectionWorkingCopy connection) { + return false; } } diff --git a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java index f1f05921c40..581fd268623 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java +++ b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java @@ -12,6 +12,7 @@ package org.eclipse.remote.ui; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.swt.widgets.Shell; /** @@ -37,20 +38,23 @@ public interface IRemoteUIConnectionManager { public static String LOGIN_USERNAME_HINT = "LOGIN_USERNAME_HINT"; //$NON-NLS-1$ /** - * Create a new connection. The implementation can choose to do this in any - * way, but typically will use a dialog or wizard. + * Create a new connection. The implementation can choose to do this in any way, but typically will use a dialog or wizard. + * + * Returns a working copy of the remote connection. Callers must call {@link IRemoteConnectionWorkingCopy#save()} before the + * connection can be used. * * @param shell * shell used to display dialogs - * @return newly created remote connection or null if none created + * @return newly created remote connection working copy or null if none created */ - public IRemoteConnection newConnection(Shell shell); + public IRemoteConnectionWorkingCopy newConnection(Shell shell); /** - * Create a new connection using the remote service provider new connection - * dialog. If attrHints and attrHintValues are provided then the dialog will - * attempt to use these values as the default values for the appropriate - * dialog fields. + * Create a new connection using the remote service provider new connection dialog. If attrHints and attrHintValues are provided + * then the dialog will attempt to use these values as the default values for the appropriate dialog fields. + * + * Returns a working copy of the remote connection. Callers must call {@link IRemoteConnectionWorkingCopy#save()} before the + * connection can be used. * * @param shell * shell used to display dialog @@ -59,10 +63,10 @@ public interface IRemoteUIConnectionManager { * @param attrHintValues * array containing default values for each attribute specified * in attrHints - * @return the newly created connection or null if none created + * @return the newly created connection working copy or null if none created * @since 5.0 */ - public IRemoteConnection newConnection(Shell shell, String[] attrHints, String[] attrHintValues); + public IRemoteConnectionWorkingCopy newConnection(Shell shell, String[] attrHints, String[] attrHintValues); /** * Attempt to open a connection using a progress monitor. Can be called on either open or closed connections, and will @@ -80,13 +84,14 @@ public interface IRemoteUIConnectionManager { public void openConnectionWithProgress(Shell shell, IRunnableContext context, IRemoteConnection connection); /** - * Change a connection configuration. The implementation can chose to do - * this in any way, but typically will use a dialog or wizard. + * Change a connection configuration. The implementation can chose to do this in any way, but typically will use a dialog or + * wizard. Callers must call {@link IRemoteConnectionWorkingCopy#save()} on the working copy for the changes to be saved. * * @param shell * shell used to display dialogs * @param connection - * connection to modify + * working copy of the connection to modify + * @return true if the connection information was changed */ - public void updateConnection(Shell shell, IRemoteConnection connection); + public boolean updateConnection(Shell shell, IRemoteConnectionWorkingCopy connection); } diff --git a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java index 00e780370bc..a7c93022f64 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java +++ b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java @@ -10,13 +10,13 @@ *******************************************************************************/ package org.eclipse.remote.ui.widgets; -import java.util.Arrays; -import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.internal.remote.core.RemoteCorePlugin; +import org.eclipse.internal.remote.core.RemoteServicesDescriptor; import org.eclipse.internal.remote.core.RemoteServicesImpl; -import org.eclipse.internal.remote.core.RemoteServicesProxy; import org.eclipse.internal.remote.core.preferences.Preferences; import org.eclipse.internal.remote.ui.messages.Messages; import org.eclipse.jface.operation.IRunnableContext; @@ -135,7 +135,7 @@ public class RemoteConnectionWidget extends Composite { private final Combo fConnectionCombo; private final Button fNewConnectionButton; - private final RemoteServicesProxy[] fRemoteServices; + private final List fRemoteServices; private IRemoteConnection fSelectedConnection; private IRemoteServices fDefaultServices; private boolean fSelectionListernersEnabled = true; @@ -195,8 +195,7 @@ public class RemoteConnectionWidget extends Composite { * Check if we need a remote services combo, or we should just use the default provider */ if ((flags & FLAG_FORCE_PROVIDER_SELECTION) == 0) { - String id = Preferences.getString(RemoteCorePlugin.getUniqueIdentifier(), - IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); + String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); if (id != null) { fDefaultServices = getRemoteServices(id); } @@ -258,7 +257,7 @@ public class RemoteConnectionWidget extends Composite { fNewConnectionButton.setLayoutData(gd); fNewConnectionButton.addSelectionListener(fWidgetListener); - fRemoteServices = RemoteServicesImpl.getRemoteServiceProxies(); + fRemoteServices = RemoteServicesImpl.getRemoteServiceDescriptors(); if (fServicesCombo != null) { initializeRemoteServicesCombo(null); @@ -339,8 +338,8 @@ public class RemoteConnectionWidget extends Composite { return fDefaultServices; } int selectionIndex = fServicesCombo.getSelectionIndex(); - if (fRemoteServices.length > 0 && selectionIndex > 0) { - return RemoteServices.getRemoteServices(fRemoteServices[selectionIndex - 1].getId()); + if (fRemoteServices.size() > 0 && selectionIndex > 0) { + return RemoteServices.getRemoteServices(fRemoteServices.get(selectionIndex - 1).getId()); } return null; } @@ -428,8 +427,8 @@ public class RemoteConnectionWidget extends Composite { * service. */ if (fDefaultServices == null && conn != null) { - for (int index = 0; index < fRemoteServices.length; index++) { - if (fRemoteServices[index].getId().equals(selectedServices.getId())) { + for (int index = 0; index < fRemoteServices.size(); index++) { + if (fRemoteServices.get(index).getId().equals(selectedServices.getId())) { fServicesCombo.select(index + 1); break; } @@ -451,20 +450,17 @@ public class RemoteConnectionWidget extends Composite { /* * Populate the connection combo and select the connection */ - IRemoteConnection[] connections = connectionManager.getConnections(); - Arrays.sort(connections, new Comparator() { - public int compare(IRemoteConnection c1, IRemoteConnection c2) { - return c1.getName().compareToIgnoreCase(c2.getName()); - } - }); int selected = 0; int offset = 1; - for (int i = 0; i < connections.length; i++) { - fConnectionCombo.add(connections[i].getName()); - if (conn != null && connections[i].getName().equals(conn.getName())) { - selected = i + offset; + Set sorted = new TreeSet(connectionManager.getConnections()); + + for (IRemoteConnection s : sorted) { + fConnectionCombo.add(s.getName()); + if (conn != null && s.getName().equals(conn.getName())) { + selected = offset; } + offset++; } fConnectionCombo.select(selected); @@ -473,7 +469,8 @@ public class RemoteConnectionWidget extends Composite { /* * Enable 'new' button if new connections are supported */ - fNewConnectionButton.setEnabled(selectedServices.canCreateConnections()); + fNewConnectionButton + .setEnabled((selectedServices.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); } } finally { fWidgetListener.setEnabled(enabled); @@ -493,22 +490,17 @@ public class RemoteConnectionWidget extends Composite { if (id != null) { defService = getRemoteServices(id); } - Arrays.sort(fRemoteServices, new Comparator() { - public int compare(RemoteServicesProxy c1, RemoteServicesProxy c2) { - return c1.getName().compareToIgnoreCase(c2.getName()); - } - }); fServicesCombo.removeAll(); int offset = 1; int defIndex = 0; fServicesCombo.add(Messages.RemoteConnectionWidget_selectRemoteProvider); - for (int i = 0; i < fRemoteServices.length; i++) { - fServicesCombo.add(fRemoteServices[i].getName()); - if (defService != null && fRemoteServices[i].equals(defService)) { + for (int i = 0; i < fRemoteServices.size(); i++) { + fServicesCombo.add(fRemoteServices.get(i).getName()); + if (defService != null && fRemoteServices.get(i).equals(defService)) { defIndex = i + offset; } } - if (fRemoteServices.length > 0) { + if (fRemoteServices.size() > 0) { fServicesCombo.select(defIndex); } fWidgetListener.setEnabled(enabled); @@ -611,11 +603,13 @@ public class RemoteConnectionWidget extends Composite { isRemote = !fLocalButton.getSelection(); } fConnectionCombo.setEnabled(fEnabled && isRemote); - fNewConnectionButton.setEnabled(fEnabled && isRemote && fDefaultServices.canCreateConnections()); + fNewConnectionButton.setEnabled(fEnabled && isRemote + && (fDefaultServices.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); } else { IRemoteServices services = getSelectedServices(); fConnectionCombo.setEnabled(fEnabled && services != null); - fNewConnectionButton.setEnabled(fEnabled && services != null && services.canCreateConnections()); + fNewConnectionButton.setEnabled(fEnabled && services != null + && (services.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); fServicesCombo.setEnabled(fEnabled); } } diff --git a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java index 63ebd702129..a10358ca3a9 100644 --- a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java +++ b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java @@ -43,10 +43,8 @@ import org.eclipse.swt.widgets.Text; * */ public class RemoteDirectoryWidget extends Composite { - // /private final Label label; private final Text text; private final Button browseButton; - // private final Button validateButton; private final Button defaultButton; private final String fDefaultPath = null; diff --git a/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java new file mode 100644 index 00000000000..79eef5b7589 --- /dev/null +++ b/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation 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: + * Mike Kucera (IBM) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.remote.ui.widgets; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.internal.remote.ui.messages.Messages; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.ui.IRemoteUIConnectionManager; +import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * Widget to allow the user to select a remote file. Provides a "Browse" + * button that uses the currently specified connection and a "Restore Default" + * button to revert to the initial setting. + * + * If title is supplied then the widget will be placed in a group. + * + * The browse message can be modified using {@link #setBrowseMessage(String)} + * + */ +public class RemoteFileWidget extends Composite { + public static int GROUP_FLAG = 0x01; + public static int RESTORE_BUTTON_FLAG = 0x02; + + private final Label fLabel; + private final Text fText; + private final Button fBrowseButton; + + private Button fDefaultButton; + private String fDefaultPath; + private String fBrowseMessage = Messages.RemoteFileWidget_Select_File; + private IRemoteConnection fRemoteConnection; + + private final ListenerList fModifyListeners = new ListenerList(); + private final Map fPreviousSelections = new HashMap(); + + public RemoteFileWidget(Composite parent, int style, int flags, String title, String defaultPath) { + super(parent, style); + + GridLayout layout = new GridLayout(4, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + setLayout(layout); + + Composite body = this; + + if ((flags & GROUP_FLAG) != 0) { + Group group = new Group(this, SWT.NONE); + group.setText(title); + group.setLayout(new GridLayout(1, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + body = group; + } + + // Composite textComp = new Composite(body, SWT.NONE); + // textComp.setLayout(new GridLayout(2, false)); + // textComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + fLabel = new Label(body, SWT.NONE); + fLabel.setText(Messages.RemoteFileWidget_File); + fLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + fText = new Text(body, SWT.BORDER); + fText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String path = fText.getText(); + setSavedPath(path); + notifyListeners(e); + } + }); + + // Composite buttonComp = new Composite(body, SWT.NONE); + // buttonComp.setLayout(new GridLayout(2, true)); + // GridData buttonCompData = new GridData(SWT.FILL, SWT.FILL, false, false); + // buttonCompData.horizontalAlignment = SWT.END; + // buttonComp.setLayoutData(buttonCompData); + + fBrowseButton = new Button(body, SWT.NONE); + fBrowseButton.setText(Messages.RemoteFileWidget_Browse); + GridData browseButtonData = new GridData(SWT.LEFT, SWT.CENTER, false, false); + browseButtonData.widthHint = 110; + fBrowseButton.setLayoutData(browseButtonData); + fBrowseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + browse(); + } + }); + + if ((flags & RESTORE_BUTTON_FLAG) != 0) { + fDefaultButton = new Button(body, SWT.NONE); + fDefaultButton.setText(Messages.RemoteFileWidget_Restore_Default); + GridData defaultButtonData = new GridData(SWT.LEFT, SWT.CENTER, false, false); + defaultButtonData.widthHint = 110; + fDefaultButton.setLayoutData(defaultButtonData); + fDefaultButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + restoreDefault(fDefaultPath); + } + }); + } + if (defaultPath != null) { + fDefaultPath = defaultPath; + fText.setText(defaultPath); + } + updateBrowseButton(); + } + + /** + * Add a listener that will be notified when the file path is modified. + * + * @param listener + * listener to add + */ + public void addModifyListener(ModifyListener listener) { + fModifyListeners.add(listener); + } + + private void browse() { + IRemoteUIConnectionManager connMgr = getUIConnectionManager(); + if (connMgr != null) { + connMgr.openConnectionWithProgress(getShell(), null, fRemoteConnection); + if (fRemoteConnection.isOpen()) { + IRemoteUIFileManager fileMgr = getUIFileManager(); + if (fileMgr != null) { + fileMgr.setConnection(fRemoteConnection); + String path = fileMgr.browseFile(getShell(), fBrowseMessage, "", 0); //$NON-NLS-1$ + if (path != null) { + setLocationPath(path); + } + } + } + } + } + + /** + * Get the file location path. This path will be relative to the remote + * machine. + * + * @return file location path + */ + public String getLocationPath() { + return fText.getText(); + } + + private String getSavedPath() { + if (fRemoteConnection != null) { + return fPreviousSelections.get(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName()); //$NON-NLS-1$ + } + return null; + } + + private IRemoteUIConnectionManager getUIConnectionManager() { + if (fRemoteConnection != null) { + return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIConnectionManager(); + } + return null; + } + + private IRemoteUIFileManager getUIFileManager() { + if (fRemoteConnection != null) { + return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIFileManager(); + } + return null; + } + + private void notifyListeners(ModifyEvent e) { + for (Object listener : fModifyListeners.getListeners()) { + ((ModifyListener) listener).modifyText(e); + } + } + + /** + * Remove a listener that will be notified when the file path is + * modified. + * + * @param listener + * listener to remove + */ + public void removeModifyListener(ModifyListener listener) { + fModifyListeners.remove(listener); + } + + private void restoreDefault(String path) { + if (path == null && fRemoteConnection != null) { + path = fRemoteConnection.getWorkingDirectory().toString(); + } + if (path == null) { + path = ""; //$NON-NLS-1$ + } + setLocationPath(path); // modify event listener updates map + } + + /** + * Set the message that will be displayed in the remote file browser + * dialog. + * + * @param message + * message to be displayed + */ + public void setBrowseMessage(String message) { + fBrowseMessage = message; + } + + /** + * Set the remote connection to use for browsing for the remote file. + * + * @param conn + * remote connection + * @since 4.0 + */ + public void setConnection(IRemoteConnection conn) { + if (conn == null) { + throw new NullPointerException(); + } + + if (!conn.equals(fRemoteConnection)) { + fRemoteConnection = conn; + String path = getSavedPath(); + restoreDefault(path); + updateBrowseButton(); + } + } + + @Override + public void setEnabled(boolean enabled) { + if (!fText.isDisposed()) { + fText.setEnabled(enabled); + } + if (!fBrowseButton.isDisposed()) { + fBrowseButton.setEnabled(enabled); + } + } + + /** + * Set the label to be displayed + * + * @param label + */ + public void setLabel(String label) { + if (fLabel != null && !fLabel.isDisposed()) { + fLabel.setText(label); + } + } + + /** + * Set the initial remote location that will be displayed in the widget. + * + * @param path + */ + public void setLocationPath(String path) { + if (path != null && !path.equals(getLocationPath())) { + fText.setText(path); + } + } + + private void setSavedPath(String path) { + if (fRemoteConnection != null) { + fPreviousSelections.put(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName(), path); //$NON-NLS-1$ + } + } + + private void updateBrowseButton() { + fBrowseButton.setEnabled(getUIFileManager() != null); + } +}