1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 466786 added images amongst other things

Added images including the error overlay for when connections are
closed. Made the resulting label provider public so it can be reused
by the launch bar.

Fixed a bug with the JschConnection factory which was creating new
connections everytime asked resulting in great weirdness. Added getting
list of services to the IRemoteConnectionType API and separated
out the three types of services.

Added open and close connection commands for the Connections view.

Changed connection type capabilities to booleans and removed unused
ones.

Removed launch config service. Found a better way to pass targets
to launch configs that will actually work.

Change-Id: I99d85f72d496f42d6ba790bd1b91943ea869c12b
Signed-off-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
Doug Schaefer 2015-05-12 15:29:26 -04:00
parent 018403c3cc
commit a278a865a1
39 changed files with 640 additions and 252 deletions

View file

@ -14,7 +14,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0",
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.remote.core,
org.eclipse.remote.core.exception,
org.eclipse.remote.core.launch,
org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui,org.eclipse.remote.jsch.core",
org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui"
Bundle-Localization: plugin

View file

@ -8,7 +8,9 @@
<extension
point="org.eclipse.remote.core.remoteServices">
<connectionType
capabilities="0"
canAdd="false"
canEdit="false"
canRemove="false"
id="org.eclipse.remote.LocalServices"
name="Local"
scheme="file">

View file

@ -84,10 +84,24 @@
</documentation>
</annotation>
</attribute>
<attribute name="capabilities" type="string" use="required">
<attribute name="canAdd" type="boolean">
<annotation>
<documentation>
The capabilities of this connection. This an integer created by ORing the applicable capabilities as listed in IRemoteServices.
Can you add connections using the API. Default is true.
</documentation>
</annotation>
</attribute>
<attribute name="canEdit" type="boolean">
<annotation>
<documentation>
Can a connection be changed using the API. Default is true.
</documentation>
</annotation>
</attribute>
<attribute name="canRemove" type="boolean">
<annotation>
<documentation>
Can a connection be removed using the API.
</documentation>
</annotation>
</attribute>

View file

@ -38,13 +38,6 @@ public interface IRemoteConnectionType {
}
}
// Capabilities
static final int CAPABILITY_ADD_CONNECTIONS = 0x01;
static final int CAPABILITY_EDIT_CONNECTIONS = 0x02;
static final int CAPABILITY_REMOVE_CONNECTIONS = 0x04;
static final int CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING = 0x08;
static final int CAPABILITY_SUPPORTS_X11_FORWARDING = 0x10;
/**
* Get the remote services manager. This is a convenient way to get back
* to the root.
@ -75,11 +68,25 @@ public interface IRemoteConnectionType {
String getScheme();
/**
* Gets the capabilities of the remote service.
* Can you add new connections of this type using the API.
*
* @return bit-wise or of capability flag constants
* @return can add
*/
int getCapabilities();
boolean canAdd();
/**
* Can you edit connections of this type, i.e. create working copies.
*
* @return can edit
*/
boolean canEdit();
/**
* Can you remove connections of this type using the API.
*
* @return can remove
*/
boolean canRemove();
/**
* Get the service for this remote services implementation that implements the given interface.
@ -101,6 +108,13 @@ public interface IRemoteConnectionType {
*/
<T extends Service> boolean hasService(Class<T> service);
/**
* Return the list of connection type services supported by this type.
*
* @return connection type services
*/
List<String> getServices();
/**
* Do connections created by this connection type support the given service.
*
@ -110,6 +124,13 @@ public interface IRemoteConnectionType {
*/
<T extends IRemoteConnection.Service> boolean hasConnectionService(Class<T> service);
/**
* Return the list of connection services supported by connections of this type.
*
* @return connection services
*/
List<String> getConnectionServices();
/**
* Do processes created by this connection type support the given service.
*
@ -119,6 +140,13 @@ public interface IRemoteConnectionType {
*/
<T extends IRemoteProcess.Service> boolean hasProcessService(Class<T> service);
/**
* Return the list of process services supported by connections of this type.
*
* @return process services
*/
List<String> getProcessServices();
/**
* Gets the remote connection corresponding to the supplied name.
*

View file

@ -1,53 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems 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:
* QNX - initial API and implementation
*******************************************************************************/
package org.eclipse.remote.core.launch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.remote.core.IRemoteConnection;
/**
* Manages and persists the mapping between launch configurations and
* remote connections that they run on. Each launch configuration has an
* active remote connection.
*
* @since 2.0
*/
public interface IRemoteLaunchConfigService {
/**
* Sets the active remote connection for the given launch configuration.
*
* @param launchConfig launch configuration
* @param connection active remote connection
*/
void setActiveConnection(ILaunchConfiguration launchConfig, IRemoteConnection connection);
/**
* Gets the active remote connection for the given launch configuration
* @param launchConfig launch configuration
* @return active remote connection
*/
IRemoteConnection getActiveConnection(ILaunchConfiguration launchConfig);
/**
* For a given launch configuration type, get the remote connection that was last
* used by a launch configuration of that type.
*
* This is used for new launch configurations with the assumption that the user
* will want to use the same remote connection.
*
* @param launchConfigType launch configuration type
* @return last active remote configuration
*/
IRemoteConnection getLastActiveConnection(ILaunchConfigurationType launchConfigType);
}

View file

@ -39,7 +39,7 @@ public class RemoteConnection implements IRemoteConnection {
private final RemoteConnectionType connectionType;
private String name;
private final Map<String, Object> servicesMap = new HashMap<>();
private final Map<Class<? extends Service>, Service> servicesMap = new HashMap<>();
private final ListenerList fListeners = new ListenerList();
@ -69,15 +69,15 @@ public class RemoteConnection implements IRemoteConnection {
@Override
public <T extends Service> T getService(Class<T> service) {
String serviceName = service.getName();
Object obj = servicesMap.get(serviceName);
T obj = (T) servicesMap.get(serviceName);
if (obj == null) {
obj = connectionType.getConnectionService(this, service);
if (obj != null) {
servicesMap.put(serviceName, obj);
servicesMap.put(service, obj);
}
}
return (T) obj;
return obj;
}
/*

View file

@ -39,10 +39,14 @@ public class RemoteConnectionType implements IRemoteConnectionType {
private final String id;
private final String name;
private final String scheme;
private final int capabilities;
private final boolean canAdd;
private final boolean canEdit;
private final boolean canRemove;
private final Map<String, Object> serviceMap = new HashMap<>();
private final Map<Class<? extends Service>, Object> serviceMap = new HashMap<>();
private final Map<String, IConfigurationElement> serviceDefinitionMap = new HashMap<>();
private final Map<String, IConfigurationElement> connectionServiceDefinitionMap = new HashMap<>();
private final Map<String, IConfigurationElement> processServiceDefinitionMap = new HashMap<>();
private final Map<String, RemoteConnection> connections = new HashMap<>();
@ -52,22 +56,23 @@ public class RemoteConnectionType implements IRemoteConnectionType {
name = ce.getAttribute("name"); //$NON-NLS-1$
scheme = ce.getAttribute("scheme"); //$NON-NLS-1$
String caps = ce.getAttribute("capabilities"); //$NON-NLS-1$
if (caps != null) {
capabilities = Integer.parseInt(caps);
} else {
capabilities = 0;
}
// capabilities, default is true for all of these
String canAddStr = ce.getAttribute("canAdd"); //$NON-NLS-1$
canAdd = canAddStr != null ? Boolean.parseBoolean(canAddStr) : true;
String canEditStr = ce.getAttribute("canEdit"); //$NON-NLS-1$
canEdit = canEditStr != null ? Boolean.parseBoolean(canEditStr) : true;
String canRemoveStr = ce.getAttribute("canRemove"); //$NON-NLS-1$
canRemove = canRemoveStr != null ? Boolean.parseBoolean(canRemoveStr) : true;
// load up existing connections
synchronized (connections) {
try {
for (String connectionName : getPreferenceNode().childrenNames()) {
connections.put(connectionName, new RemoteConnection(this, connectionName));
}
} catch (BackingStoreException e) {
RemoteCorePlugin.log(e);
try {
for (String connectionName : getPreferenceNode().childrenNames()) {
connections.put(connectionName, new RemoteConnection(this, connectionName));
}
} catch (BackingStoreException e) {
RemoteCorePlugin.log(e);
}
}
@ -119,14 +124,19 @@ public class RemoteConnectionType implements IRemoteConnectionType {
return scheme;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionType#getCapabilities()
*/
@Override
public int getCapabilities() {
return capabilities;
public boolean canAdd() {
return canAdd;
}
@Override
public boolean canEdit() {
return canEdit;
}
@Override
public boolean canRemove() {
return canRemove;
}
/*
@ -136,18 +146,16 @@ public class RemoteConnectionType implements IRemoteConnectionType {
*/
@Override
public <T extends Service> T getService(Class<T> service) {
String serviceName = service.getName();
@SuppressWarnings("unchecked")
T obj = (T) serviceMap.get(serviceName);
T obj = (T) serviceMap.get(service);
if (obj == null) {
IConfigurationElement ce = serviceDefinitionMap.get(serviceName);
IConfigurationElement ce = serviceDefinitionMap.get(service.getName());
if (ce != null) {
try {
Service.Factory factory = (Service.Factory) ce.createExecutableExtension("factory"); //$NON-NLS-1$
if (factory != null) {
obj = factory.getService(this, service);
serviceMap.put(serviceName, obj);
serviceDefinitionMap.remove(serviceName);
serviceMap.put(service, obj);
}
} catch (CoreException e) {
RemoteCorePlugin.log(e.getStatus());
@ -157,6 +165,11 @@ public class RemoteConnectionType implements IRemoteConnectionType {
return obj;
}
@Override
public List<String> getServices() {
return new ArrayList<>(serviceDefinitionMap.keySet());
}
/*
* (non-Javadoc)
*
@ -164,8 +177,7 @@ public class RemoteConnectionType implements IRemoteConnectionType {
*/
@Override
public <T extends Service> boolean hasService(Class<T> service) {
String serviceName = service.getName();
return serviceMap.get(serviceName) != null || serviceDefinitionMap.get(service) != null;
return serviceDefinitionMap.get(service.getName()) != null;
}
/**
@ -179,9 +191,7 @@ public class RemoteConnectionType implements IRemoteConnectionType {
* @throws CoreException
*/
public <T extends IRemoteConnection.Service> T getConnectionService(IRemoteConnection connection, Class<T> service) {
// Both top level and connection services are stored in the serviceDefinitionMap.
// In theory the two sets of interfaces can't collide.
IConfigurationElement ce = serviceDefinitionMap.get(service.getName());
IConfigurationElement ce = connectionServiceDefinitionMap.get(service.getName());
if (ce != null) {
try {
IRemoteConnection.Service.Factory factory = (IRemoteConnection.Service.Factory) ce
@ -197,6 +207,11 @@ public class RemoteConnectionType implements IRemoteConnectionType {
return null;
}
@Override
public List<String> getConnectionServices() {
return new ArrayList<>(connectionServiceDefinitionMap.keySet());
}
/*
* (non-Javadoc)
*
@ -204,7 +219,7 @@ public class RemoteConnectionType implements IRemoteConnectionType {
*/
@Override
public <T extends IRemoteConnection.Service> boolean hasConnectionService(Class<T> service) {
return serviceDefinitionMap.get(service.getName()) != null;
return connectionServiceDefinitionMap.get(service.getName()) != null;
}
/**
@ -218,9 +233,7 @@ public class RemoteConnectionType implements IRemoteConnectionType {
* @throws CoreException
*/
public <T extends IRemoteProcess.Service> T getProcessService(IRemoteProcess process, Class<T> service) {
// Both top level and connection services are stored in the serviceDefinitionMap.
// In theory the two sets of interfaces can't collide.
IConfigurationElement ce = serviceDefinitionMap.get(service.getName());
IConfigurationElement ce = processServiceDefinitionMap.get(service.getName());
if (ce != null) {
try {
IRemoteProcess.Service.Factory factory = (IRemoteProcess.Service.Factory) ce.createExecutableExtension("factory"); //$NON-NLS-1$
@ -235,6 +248,11 @@ public class RemoteConnectionType implements IRemoteConnectionType {
return null;
}
@Override
public List<String> getProcessServices() {
return new ArrayList<>(processServiceDefinitionMap.keySet());
}
/*
* (non-Javadoc)
*
@ -242,7 +260,7 @@ public class RemoteConnectionType implements IRemoteConnectionType {
*/
@Override
public <T extends IRemoteProcess.Service> boolean hasProcessService(Class<T> service) {
return serviceDefinitionMap.get(service.getName()) != null;
return processServiceDefinitionMap.get(service.getName()) != null;
}
/**
@ -253,8 +271,19 @@ public class RemoteConnectionType implements IRemoteConnectionType {
* the extension element defining the service
*/
public void addService(IConfigurationElement ce) {
String service = ce.getAttribute("service"); //$NON-NLS-1$
serviceDefinitionMap.put(service, ce);
String serviceName = ce.getAttribute("service"); //$NON-NLS-1$
String name = ce.getName();
switch (name) {
case "connectionTypeService": //$NON-NLS-1$
serviceDefinitionMap.put(serviceName, ce);
break;
case "connectionService": //$NON-NLS-1$
connectionServiceDefinitionMap.put(serviceName, ce);
break;
case "processService": //$NON-NLS-1$
processServiceDefinitionMap.put(serviceName, ce);
break;
}
}
/**
@ -298,13 +327,13 @@ public class RemoteConnectionType implements IRemoteConnectionType {
if (connection != null) {
return connection;
}
// If it's a file: scheme we must be the local connection type, just return our
// hopefully one connection, the Local connection.
if (uri.getScheme().equals("file") && !connections.isEmpty()) { //$NON-NLS-1$
return connections.values().iterator().next();
}
return null;
}
}

View file

@ -18,8 +18,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
import org.eclipse.remote.internal.core.launch.RemoteLaunchConfigService;
import org.eclipse.remote.internal.core.preferences.Preferences;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@ -110,7 +108,6 @@ public class RemoteCorePlugin extends Plugin {
super.start(context);
plugin = this;
context.registerService(IRemoteServicesManager.class, new RemoteServicesManager(), null);
context.registerService(IRemoteLaunchConfigService.class, new RemoteLaunchConfigService(), null);
RemoteDebugOptions.configure(context);
ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() {
@Override

View file

@ -24,7 +24,7 @@ import org.eclipse.remote.core.IRemoteProcessControlService;
* Standard root class for remote processes.
*/
public class RemoteProcess extends Process implements IRemoteProcess {
private final Map<String, Object> servicesMap = new HashMap<>();
private final Map<Class<? extends Service>, Service> servicesMap = new HashMap<>();
private final IRemoteConnection connection;
private final IRemoteProcessBuilder builder;
@ -111,16 +111,15 @@ public class RemoteProcess extends Process implements IRemoteProcess {
@SuppressWarnings("unchecked")
@Override
public <T extends Service> T getService(Class<T> service) {
String serviceName = service.getName();
Object obj = servicesMap.get(serviceName);
T obj = (T) servicesMap.get(service);
if (obj == null) {
obj = getConnectionType().getProcessService(this, service);
if (obj != null) {
servicesMap.put(serviceName, obj);
servicesMap.put(service, obj);
}
}
return (T) obj;
return obj;
}
/**

View file

@ -218,7 +218,6 @@ public class RemoteServicesManager implements IRemoteServicesManager {
*/
@Override
public List<IRemoteConnection> getAllRemoteConnections() {
// TODO do this without getting the connection managers and force loading the plugins
List<IRemoteConnection> connections = new ArrayList<>();
for (IRemoteConnectionType connType : getAllConnectionTypes()) {
connections.addAll(connType.getConnections());

View file

@ -1,65 +0,0 @@
package org.eclipse.remote.internal.core.launch;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
import org.eclipse.remote.internal.core.RemoteCorePlugin;
import org.osgi.service.prefs.Preferences;
public class RemoteLaunchConfigService implements IRemoteLaunchConfigService {
private static final String REMOTE_LAUNCH_CONFIG = "remoteLaunchConfig"; //$NON-NLS-1$
private static final String REMOTE_LAUNCH_TYPE = "remoteLaunchType"; //$NON-NLS-1$
private Preferences getPreferences(String node) {
return InstanceScope.INSTANCE.getNode(RemoteCorePlugin.getUniqueIdentifier()).node(node);
}
private IRemoteConnection getRemoteConnection(String remoteId) {
if (remoteId == null) {
return null;
}
String[] ids = remoteId.split(":"); //$NON-NLS-1$
if (ids.length < 2) {
return null;
}
IRemoteServicesManager manager = RemoteCorePlugin.getService(IRemoteServicesManager.class);
IRemoteConnectionType connectionType = manager.getConnectionType(ids[0]);
if (connectionType == null) {
return null;
}
return connectionType.getConnection(ids[1]);
}
@Override
public void setActiveConnection(ILaunchConfiguration launchConfig, IRemoteConnection connection) {
String remoteId = connection.getConnectionType().getId() + ":" + connection.getName(); //$NON-NLS-1$
getPreferences(REMOTE_LAUNCH_CONFIG).put(launchConfig.getName(), remoteId);
try {
getPreferences(REMOTE_LAUNCH_TYPE).put(launchConfig.getType().getIdentifier(), remoteId);
} catch (CoreException e) {
RemoteCorePlugin.log(e.getStatus());
}
}
@Override
public IRemoteConnection getActiveConnection(ILaunchConfiguration launchConfig) {
String remoteId = getPreferences(REMOTE_LAUNCH_CONFIG).get(launchConfig.getName(), null);
return getRemoteConnection(remoteId);
}
@Override
public IRemoteConnection getLastActiveConnection(ILaunchConfigurationType launchConfigType) {
String remoteId = getPreferences(REMOTE_LAUNCH_TYPE).get(launchConfigType.getIdentifier(), null);
return getRemoteConnection(remoteId);
}
}

View file

@ -4,7 +4,6 @@
<extension
point="org.eclipse.remote.core.remoteServices">
<connectionType
capabilities="31"
id="org.eclipse.remote.JSch"
name="SSH"
scheme="ssh">

View file

@ -24,6 +24,7 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jsch.core.IJSchService;
import org.eclipse.osgi.util.NLS;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
import org.eclipse.remote.core.IRemoteConnectionControlService;
import org.eclipse.remote.core.IRemoteConnectionHostService;
import org.eclipse.remote.core.IRemoteConnectionPropertyService;
@ -52,7 +53,7 @@ import com.jcraft.jsch.UserInfo;
* @since 5.0
*/
public class JSchConnection implements IRemoteConnectionControlService, IRemoteConnectionPropertyService,
IRemotePortForwardingService, IRemoteProcessService, IRemoteConnectionHostService {
IRemotePortForwardingService, IRemoteProcessService, IRemoteConnectionHostService, IRemoteConnectionChangeListener {
// Connection Type ID
public static final String JSCH_ID = "org.eclipse.remote.JSch"; //$NON-NLS-1$
@ -255,9 +256,21 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
private ChannelSftp fSftpChannel;
private boolean isFullySetup; // including sftp channel and environment
private static final Map<IRemoteConnection, JSchConnection> connectionMap = new HashMap<>();
public JSchConnection(IRemoteConnection connection) {
fRemoteConnection = connection;
fJSchService = Activator.getDefault().getService();
connection.addConnectionChangeListener(this);
}
@Override
public void connectionChanged(RemoteConnectionChangeEvent event) {
if (event.getType() == RemoteConnectionChangeEvent.CONNECTION_REMOVED) {
synchronized (connectionMap) {
connectionMap.remove(event.getConnection());
}
}
}
/*
@ -286,7 +299,14 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
// As a side effect, it makes this class a service too which can be used
// by the this plug-in
if (JSchConnection.class.equals(service)) {
return (T) new JSchConnection(connection);
synchronized (connectionMap) {
JSchConnection jschConnection = connectionMap.get(connection);
if (jschConnection == null) {
jschConnection = new JSchConnection(connection);
connectionMap.put(connection, jschConnection);
}
return (T) jschConnection;
}
} else if (IRemoteConnectionControlService.class.equals(service)
|| IRemoteConnectionPropertyService.class.equals(service) || IRemotePortForwardingService.class.equals(service)
|| IRemoteProcessService.class.equals(service) || IRemoteConnectionHostService.class.equals(service)) {
@ -338,13 +358,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionControlService#close()
*/
@Override
public synchronized void close() {
private synchronized void cleanup() {
if (fSftpChannel != null) {
if (fSftpChannel.isConnected()) {
fSftpChannel.disconnect();
@ -357,6 +371,16 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
fSessions.clear();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionControlService#close()
*/
@Override
public synchronized void close() {
cleanup();
fRemoteConnection.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_CLOSED);
}
@ -714,7 +738,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
if (!hasOpenSession) {
close(); // Cleanup if session is closed
cleanup(); // Cleanup if session is closed
}
return hasOpenSession;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

View file

@ -1,20 +1,23 @@
package org.eclipse.remote.internal.jsch.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jsch.core.IJSchService;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends Plugin {
public class Activator extends AbstractUIPlugin {
// The plug-in ID
private static final String PLUGIN_ID = "org.eclipse.remote.jsch.ui"; //$NON-NLS-1$
// Image Keys
public static final String IMG_CONNECTION_TYPE = PLUGIN_ID + ".connectionType"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
@ -107,6 +110,7 @@ public class Activator extends Plugin {
plugin = this;
ServiceReference<IJSchService> reference = context.getServiceReference(IJSchService.class);
fJSchService = context.getService(reference);
getImageRegistry().put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "/icons/ssh.png")); //$NON-NLS-1$
}
/*

View file

@ -19,18 +19,20 @@ import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteConnectionType.Service;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.internal.jsch.ui.messages.Messages;
import org.eclipse.remote.internal.jsch.ui.wizards.JSchConnectionWizard;
import org.eclipse.remote.ui.AbstractRemoteUIConnectionManager;
import org.eclipse.remote.ui.AbstractRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
public class JSchUIConnectionService extends AbstractRemoteUIConnectionManager {
public class JSchUIConnectionService extends AbstractRemoteUIConnectionService {
private final IRemoteConnectionType fConnectionType;
@ -53,7 +55,7 @@ public class JSchUIConnectionService extends AbstractRemoteUIConnectionManager {
public IRemoteConnectionType getConnectionType() {
return fConnectionType;
}
@Override
public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) {
return new JSchConnectionWizard(shell, fConnectionType);
@ -92,4 +94,15 @@ public class JSchUIConnectionService extends AbstractRemoteUIConnectionManager {
}
}
}
@Override
public ILabelProvider getLabelProvider() {
return new DefaultLabelProvider() {
@Override
public Image getImage(Object element) {
return Activator.getDefault().getImageRegistry().get(Activator.IMG_CONNECTION_TYPE);
}
};
}
}

View file

@ -4,7 +4,6 @@
<extension
point="org.eclipse.remote.core.remoteServices">
<connectionType
capabilities="7"
id="org.eclipse.remote.serial.core.connectionType"
name="Serial Port">
</connectionType>

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

View file

@ -25,13 +25,16 @@ public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.remote.serial.ui"; //$NON-NLS-1$
// Image keys
public static final String IMG_CONNECTION_TYPE = PLUGIN_ID + ".connectionType"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
getImageRegistry().put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "/icons/serial.png")); //$NON-NLS-1$
}
public void stop(BundleContext context) throws Exception {

View file

@ -15,15 +15,18 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteConnectionType.Service;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.ui.AbstractRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
public class SerialPortConnectionsUI implements IRemoteUIConnectionService {
public class SerialPortConnectionsUI extends AbstractRemoteUIConnectionService {
private final IRemoteConnectionType connectionType;
@ -70,4 +73,14 @@ public class SerialPortConnectionsUI implements IRemoteUIConnectionService {
}
}
@Override
public ILabelProvider getLabelProvider() {
return new DefaultLabelProvider() {
@Override
public Image getImage(Object element) {
return Activator.getDefault().getImageRegistry().get(Activator.IMG_CONNECTION_TYPE);
}
};
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

View file

@ -17,3 +17,5 @@ ConnectionsContent.name=Connections
NewConnectionCommand.name=New Connection
DeleteConnectionCommand.name=Delete Connection
ConnectionProperties.name=Connection
OpenConnectionCommand.name=Open Connection
CloseConnectionCommand.name=Close Connection

View file

@ -36,6 +36,11 @@
factory="org.eclipse.remote.internal.ui.services.local.LocalUIFileService$Factory"
service="org.eclipse.remote.ui.IRemoteUIFileService">
</connectionTypeService>
<connectionTypeService
connectionTypeId="org.eclipse.remote.LocalServices"
factory="org.eclipse.remote.internal.ui.services.local.LocalUIConnectionService$Factory"
service="org.eclipse.remote.ui.IRemoteUIConnectionService">
</connectionTypeService>
</extension>
<extension
point="org.eclipse.ui.views">
@ -46,6 +51,7 @@
<view
category="org.eclipse.remote.ui.view.category.connections"
class="org.eclipse.remote.internal.ui.views.RemoteConnectionsView"
icon="icons/connection.gif"
id="org.eclipse.remote.ui.view.connections"
name="%ConnectionsView.name"
restorable="true">
@ -57,7 +63,7 @@
activeByDefault="true"
contentProvider="org.eclipse.remote.internal.ui.views.RemoteConnectionsContentProvider"
id="org.eclipse.remote.ui.navigatorContent.connections"
labelProvider="org.eclipse.remote.internal.ui.views.RemoteConnectionsLabelProvider"
labelProvider="org.eclipse.remote.ui.RemoteConnectionsLabelProvider"
name="%ConnectionsContent.name">
<triggerPoints>
<instanceof
@ -121,6 +127,16 @@
id="org.eclipse.remote.ui.command.deleteConnection"
name="%DeleteConnectionCommand.name">
</command>
<command
defaultHandler="org.eclipse.remote.internal.ui.views.OpenConnectionHandler"
id="org.eclipse.remote.ui.command.openConnection"
name="%OpenConnectionCommand.name">
</command>
<command
defaultHandler="org.eclipse.remote.internal.ui.views.CloseConnectionHandler"
id="org.eclipse.remote.ui.command.closeConnection"
name="%CloseConnectionCommand.name">
</command>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
@ -128,7 +144,7 @@
class="org.eclipse.remote.internal.ui.ServicePropertyTester"
id="org.eclipse.remote.ui.propertyTester.hasService"
namespace="org.eclipse.remote.ui"
properties="hasConnectionTypeService,hasConnectionService,canDelete"
properties="hasConnectionTypeService,hasConnectionService,canDelete,canOpen,canClose"
type="org.eclipse.remote.core.IRemoteConnection">
</propertyTester>
</extension>
@ -147,6 +163,38 @@
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.remote.ui.view.connections">
<command
commandId="org.eclipse.remote.ui.command.openConnection"
label="%OpenConnectionCommand.name"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<iterate>
<test
property="org.eclipse.remote.ui.canOpen">
</test>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.remote.ui.command.closeConnection"
label="%CloseConnectionCommand.name"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<iterate>
<test
property="org.eclipse.remote.ui.canClose">
</test>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.remote.ui.command.deleteConnection"
label="%DeleteConnectionCommand.name"

View file

@ -41,6 +41,8 @@ public class RemoteUIImages {
public static final String IMG_OVR_SYMLINK = NAME_PREFIX + T_OVR + ".symlink_ovr.gif"; //$NON-NLS-1$
public static final String IMG_ELCL_NEW_FOLDER = NAME_PREFIX + T_ELCL + ".new_folder.gif"; //$NON-NLS-1$
public static final String IMG_DLCL_NEW_FOLDER = NAME_PREFIX + T_DLCL + ".new_folder.gif"; //$NON-NLS-1$
public static final String IMG_DEFAULT_TYPE = NAME_PREFIX + "defaultType"; //$NON-NLS-1$
/*
* Set of predefined Image Descriptors.
*/
@ -49,6 +51,7 @@ public class RemoteUIImages {
public static final ImageDescriptor DESC_OVR_SYMLINK = createManaged(T_OVR, "symlink_ovr.gif", IMG_OVR_SYMLINK); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_NEW_FOLDER = createManaged(T_ELCL, "new_folder.gif", IMG_ELCL_NEW_FOLDER); //$NON-NLS-1$
public static final ImageDescriptor DESC_DLCL_NEW_FOLDER = createManaged(T_DLCL, "new_folder.gif", IMG_DLCL_NEW_FOLDER); //$NON-NLS-1$
public static final ImageDescriptor DESC_DEFAULT_TYPE = createManaged(ICONS_PATH.append("console.png"), IMG_DEFAULT_TYPE); //$NON-NLS-1$
/**
* Returns the image managed under the given key in this registry.
@ -104,6 +107,12 @@ public class RemoteUIImages {
action.setImageDescriptor(descriptor);
}
private static ImageDescriptor createManaged(IPath path, String key) {
ImageDescriptor desc = createImageDescriptor(RemoteUIPlugin.getDefault().getBundle(), path, true);
fgImageRegistry.put(key, desc);
return desc;
}
private static ImageDescriptor createManaged(String prefix, String name, String key) {
ImageDescriptor image = create(prefix, name, true);
fgImageRegistry.put(key, image);
@ -139,4 +148,5 @@ public class RemoteUIImages {
}
return null;
}
}

View file

@ -2,6 +2,7 @@ package org.eclipse.remote.internal.ui;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionControlService;
import org.eclipse.remote.core.IRemoteConnectionType;
public class ServicePropertyTester extends PropertyTester {
@ -32,7 +33,21 @@ public class ServicePropertyTester extends PropertyTester {
}
}
} else if (property.equals("canDelete")) { //$NON-NLS-1$
return (connection.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0;
return connection.getConnectionType().canRemove();
} else if (property.equals("canOpen")) { //$NON-NLS-1$
IRemoteConnectionControlService controlService = connection.getService(IRemoteConnectionControlService.class);
if (controlService != null) {
return !connection.isOpen();
} else {
return false;
}
} else if (property.equals("canClose")) { //$NON-NLS-1$
IRemoteConnectionControlService controlService = connection.getService(IRemoteConnectionControlService.class);
if (controlService != null) {
return connection.isOpen();
} else {
return false;
}
}
}
return false;

View file

@ -506,7 +506,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
fUIConnectionManager = fConnectionType.getService(IRemoteUIConnectionService.class);
initWorkingConnections();
fConnectionViewer.refresh();
fAddButton.setEnabled((fConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0);
fAddButton.setEnabled(fConnectionType.canAdd());
}
fIsDirty = false;
}
@ -596,16 +596,16 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
if (conn.hasService(IRemoteConnectionControlService.class)) {
if (!conn.isOpen()) {
fEditButton
.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_EDIT_CONNECTIONS) != 0);
.setEnabled(conn.getConnectionType().canEdit());
fRemoveButton
.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0);
.setEnabled(conn.getConnectionType().canRemove());
fOpenButton.setEnabled(true);
} else {
fCloseButton.setEnabled(true);
}
} else {
fEditButton
.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_EDIT_CONNECTIONS) != 0);
.setEnabled(conn.getConnectionType().canEdit());
}
}
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems 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:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.remote.internal.ui.services.local;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteConnectionType.Service;
import org.eclipse.remote.ui.AbstractRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.swt.widgets.Shell;
public class LocalUIConnectionService extends AbstractRemoteUIConnectionService {
private IRemoteConnectionType connectionType;
public LocalUIConnectionService(IRemoteConnectionType connectionType) {
this.connectionType = connectionType;
}
@Override
public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) {
// we don't do this
return null;
}
public static class Factory implements IRemoteConnectionType.Service.Factory {
@SuppressWarnings("unchecked")
@Override
public <T extends Service> T getService(IRemoteConnectionType connectionType, Class<T> service) {
if (IRemoteUIConnectionService.class.equals(service)) {
return (T) new LocalUIConnectionService(connectionType);
}
return null;
}
}
@Override
public IRemoteConnectionType getConnectionType() {
return connectionType;
}
}

View file

@ -0,0 +1,61 @@
package org.eclipse.remote.internal.ui.views;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionControlService;
import org.eclipse.remote.internal.ui.RemoteUIPlugin;
import org.eclipse.ui.handlers.HandlerUtil;
public class CloseConnectionHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
// Get the manageable connections from the selection
final List<IRemoteConnection> connections = new ArrayList<IRemoteConnection>();
@SuppressWarnings("unchecked")
Iterator<Object> i = ((IStructuredSelection) selection).iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof IRemoteConnection) {
IRemoteConnection connection = (IRemoteConnection) obj;
connections.add(connection);
}
}
new Job(Messages.CloseConnectionHandler_0) {
protected IStatus run(IProgressMonitor monitor) {
List<IStatus> status = new ArrayList<>();
for (IRemoteConnection connection : connections) {
IRemoteConnectionControlService controlService = connection.getService(IRemoteConnectionControlService.class);
if (controlService != null) {
controlService.close();
}
}
if (status.isEmpty()) {
return Status.OK_STATUS;
} else {
return new MultiStatus(RemoteUIPlugin.PLUGIN_ID, 1, status.toArray(new IStatus[status.size()]), Messages.CloseConnectionHandler_1, null);
}
}
}.schedule();
}
return Status.OK_STATUS;
}
}

View file

@ -43,7 +43,7 @@ public class DeleteRemoteConnectionHandler extends AbstractHandler {
if (obj instanceof IRemoteConnection) {
IRemoteConnection connection = (IRemoteConnection) obj;
IRemoteConnectionType connectionType = connection.getConnectionType();
if ((connectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0) {
if (connectionType.canRemove()) {
connections.add(connection);
}
}

View file

@ -4,8 +4,12 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.remote.internal.ui.views.messages"; //$NON-NLS-1$
public static String CloseConnectionHandler_0;
public static String CloseConnectionHandler_1;
public static String DeleteRemoteConnectionHandler_ConfirmDeleteMessage;
public static String DeleteRemoteConnectionHandler_DeleteConnectionTitle;
public static String OpenConnectionHandler_0;
public static String OpenConnectionHandler_1;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems 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:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.remote.internal.ui.views;
import org.eclipse.jface.wizard.IWizardPage;
@ -9,6 +19,7 @@ import org.eclipse.remote.internal.ui.RemoteUIPlugin;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -46,25 +57,25 @@ public class NewRemoteConnectionTypePage extends WizardPage {
IRemoteServicesManager remoteManager = RemoteUIPlugin.getService(IRemoteServicesManager.class);
for (IRemoteConnectionType connectionType : remoteManager.getAllConnectionTypes()) {
if ((connectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) == 0)
if (!connectionType.canAdd())
continue;
IRemoteUIConnectionService connManager = connectionType.getService(IRemoteUIConnectionService.class);
if (connManager == null)
IRemoteUIConnectionService connService = connectionType.getService(IRemoteUIConnectionService.class);
if (connService == null)
continue;
IRemoteUIConnectionWizard wizard = connManager.getConnectionWizard(parent.getShell());
IRemoteUIConnectionWizard wizard = connService.getConnectionWizard(parent.getShell());
if (wizard == null)
continue;
TableItem item = new TableItem(table, SWT.NONE);
item.setText(connectionType.getName());
item.setData(wizard);
// TODO connection type icons somehow
// Image icon = ui.getIcon();
// if (icon != null) {
// item.setImage(icon);
// }
Image icon = connService.getLabelProvider().getImage(connectionType);
if (icon != null) {
item.setImage(icon);
}
// TODO select the last selected entry
table.select(0);

View file

@ -0,0 +1,66 @@
package org.eclipse.remote.internal.ui.views;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionControlService;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.internal.ui.RemoteUIPlugin;
import org.eclipse.ui.handlers.HandlerUtil;
public class OpenConnectionHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
// Get the manageable connections from the selection
final List<IRemoteConnection> connections = new ArrayList<IRemoteConnection>();
@SuppressWarnings("unchecked")
Iterator<Object> i = ((IStructuredSelection) selection).iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof IRemoteConnection) {
IRemoteConnection connection = (IRemoteConnection) obj;
connections.add(connection);
}
}
new Job(Messages.OpenConnectionHandler_0) {
protected IStatus run(IProgressMonitor monitor) {
List<IStatus> status = new ArrayList<>();
for (IRemoteConnection connection : connections) {
IRemoteConnectionControlService controlService = connection.getService(IRemoteConnectionControlService.class);
if (controlService != null) {
try {
controlService.open(monitor);
} catch (RemoteConnectionException e) {
status.add(e.getStatus());
}
}
}
if (status.isEmpty()) {
return Status.OK_STATUS;
} else {
return new MultiStatus(RemoteUIPlugin.PLUGIN_ID, 1, status.toArray(new IStatus[status.size()]), Messages.OpenConnectionHandler_1, null);
}
}
}.schedule();
}
return Status.OK_STATUS;
}
}

View file

@ -1,24 +0,0 @@
package org.eclipse.remote.internal.ui.views;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.swt.graphics.Image;
public class RemoteConnectionsLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
if (element instanceof IRemoteConnection) {
return ((IRemoteConnection) element).getName();
} else {
return super.getText(element);
}
}
@Override
public Image getImage(Object element) {
// TODO Need a method to get icons for the UI connection managers.
return super.getImage(element);
}
}

View file

@ -1,2 +1,6 @@
CloseConnectionHandler_0=Closing connections
CloseConnectionHandler_1=Error closing connections
DeleteRemoteConnectionHandler_ConfirmDeleteMessage=Delete connection
DeleteRemoteConnectionHandler_DeleteConnectionTitle=Delete Connection
OpenConnectionHandler_0=Openning connections
OpenConnectionHandler_1=Error openning connections

View file

@ -19,20 +19,28 @@ import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.internal.ui.RemoteUIImages;
import org.eclipse.remote.internal.ui.RemoteUIPlugin;
import org.eclipse.remote.internal.ui.messages.Messages;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
/**
* Abstract base class for providing UI connection manager services.
* @since 2.0
*/
public abstract class AbstractRemoteUIConnectionManager implements IRemoteUIConnectionService {
public abstract class AbstractRemoteUIConnectionService implements IRemoteUIConnectionService {
@Override
public void openConnectionWithProgress(final Shell shell, IRunnableContext context, final IRemoteConnection connection) {
if (!connection.isOpen()) {
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
connection.open(monitor);
@ -62,4 +70,30 @@ public abstract class AbstractRemoteUIConnectionManager implements IRemoteUIConn
}
}
protected static class DefaultLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
if (element instanceof IRemoteConnection) {
return ((IRemoteConnection) element).getName();
} else if (element instanceof IRemoteConnectionType) {
return ((IRemoteConnectionType) element).getName();
} else {
return super.getText(element);
}
}
@Override
public Image getImage(Object element) {
if (element instanceof IRemoteConnection || element instanceof IRemoteConnectionType) {
return RemoteUIImages.get(RemoteUIImages.IMG_DEFAULT_TYPE);
}
return super.getImage(element);
}
}
@Override
public ILabelProvider getLabelProvider() {
return new DefaultLabelProvider();
}
}

View file

@ -11,6 +11,7 @@
package org.eclipse.remote.ui;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.swt.widgets.Shell;
@ -21,6 +22,12 @@ import org.eclipse.swt.widgets.Shell;
* @since 2.0
*/
public interface IRemoteUIConnectionService extends IRemoteConnectionType.Service {
/**
* ID for the command to start the new connection wizard.
*/
public static final String NEW_CONNECTION_COMMAND = "org.eclipse.remote.ui.command.newConnection"; //$NON-NLS-1$
/**
* Create a wizard for adding or editing connections. The implementation can choose to do this in any way, but typically will
* use a dialog or wizard.
@ -42,7 +49,15 @@ public interface IRemoteUIConnectionService extends IRemoteConnectionType.Servic
* runnable context for displaying progress indicator. Can be null.
* @param connection
* connection to open
* @since 5.0
*/
public void openConnectionWithProgress(Shell shell, IRunnableContext context, IRemoteConnection connection);
/**
* Return the label provider that provides the text and base image for the connection type
* and connections of that type.
*
* @return label provider
*/
public ILabelProvider getLabelProvider();
}

View file

@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems 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:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.remote.ui;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.internal.ui.RemoteUIPlugin;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
/**
* A label provider to show the test and base image for remote connections.
* It calls out to the connection type services to get the text and images for
* the types of the connections.
*
* @since 2.0
*/
public class RemoteConnectionsLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
if (element instanceof IRemoteConnection) {
IRemoteConnectionType type = ((IRemoteConnection) element).getConnectionType();
IRemoteUIConnectionService uiService = type.getService(IRemoteUIConnectionService.class);
if (uiService != null) {
return uiService.getLabelProvider().getText(element);
} else {
return ((IRemoteConnection) element).getName();
}
} else {
return super.getText(element);
}
}
@Override
public Image getImage(Object element) {
if (element instanceof IRemoteConnection) {
IRemoteConnection connection = (IRemoteConnection) element;
IRemoteConnectionType type = connection.getConnectionType();
IRemoteUIConnectionService uiService = type.getService(IRemoteUIConnectionService.class);
if (uiService != null) {
final Image baseImage = uiService.getLabelProvider().getImage(element);
if (connection.isOpen()) {
return baseImage;
} else {
String closedId = "closed." + type.getId(); //$NON-NLS-1$
Image closedImage = RemoteUIPlugin.getDefault().getImageRegistry().get(closedId);
if (closedImage == null) {
final Image errorImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR);
ImageDescriptor desc = new CompositeImageDescriptor() {
@Override
protected Point getSize() {
Rectangle bounds = baseImage.getBounds();
return new Point(bounds.width, bounds.height);
}
@Override
protected void drawCompositeImage(int width, int height) {
drawImage(baseImage.getImageData(), 0, 0);
int y = baseImage.getBounds().height - errorImage.getBounds().height;
drawImage(errorImage.getImageData(), 0, y);
}
};
closedImage = desc.createImage();
RemoteUIPlugin.getDefault().getImageRegistry().put(closedId, closedImage);
}
return closedImage;
}
}
}
return super.getImage(element);
}
}

View file

@ -521,7 +521,7 @@ public class RemoteConnectionWidget extends Composite {
* Enable 'new' button if new connections are supported
*/
fNewConnectionButton
.setEnabled((selectedConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0);
.setEnabled(selectedConnectionType.canAdd());
}
} finally {
fWidgetListener.setEnabled(enabled);
@ -652,12 +652,12 @@ public class RemoteConnectionWidget extends Composite {
}
fConnectionCombo.setEnabled(fEnabled && isRemote);
fNewConnectionButton.setEnabled(fEnabled && isRemote
&& (fDefaultConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0);
&& fDefaultConnectionType.canAdd());
} else {
IRemoteConnectionType services = getSelectedConnectionType();
fConnectionCombo.setEnabled(fEnabled && services != null);
fNewConnectionButton.setEnabled(fEnabled && services != null
&& (services.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0);
&& services.canAdd());
fConnectionTypeCombo.setEnabled(fEnabled);
}
}