Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 256603 | Differences between
and this patch

Collapse All | Expand All

(-).classpath (-1 / +1 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
7
</classpath>
(-)build.properties (-1 / +2 lines)
Lines 3-9 Link Here
3
bin.includes = META-INF/,\
3
bin.includes = META-INF/,\
4
               .,\
4
               .,\
5
               about.html,\
5
               about.html,\
6
               plugin.properties
6
               plugin.properties,\
7
               plugin.xml
7
src.includes = about.html,\
8
src.includes = about.html,\
8
               META-INF/,\
9
               META-INF/,\
9
               plugin.properties
10
               plugin.properties
(-)src/org/eclipse/ecf/internal/remoteservices/ui/Messages.java (+7 lines)
Lines 32-37 Link Here
32
	public static String MethodInvocationDialog_InvocationTypeRemoteServiceProxy;
32
	public static String MethodInvocationDialog_InvocationTypeRemoteServiceProxy;
33
	public static String MethodInvocationDialog_InvocationTypeSynchronous;
33
	public static String MethodInvocationDialog_InvocationTypeSynchronous;
34
34
35
	public static String AbstractRemoteServiceAccessHandler_DISCONNECT_MENU_TEXT;
36
	public static String AbstractRemoteServiceAccessHandler_MSG_BOX_RECEIVED_EXCEPTION_TEXT;
37
	public static String AbstractRemoteServiceAccessHandler_MSG_BOX_RECEIVED_EXCEPTION_TITLE;
38
	public static String AbstractRemoteServiceAccessHandler_MSG_BOX_RECEIVED_RESP_TEXT;
39
	public static String AbstractRemoteServiceAccessHandler_MSG_BOX_RECEIVED_RESP_TITLE;
40
	public static String AbstractRemoteServiceAccessHandler_NOT_AVAILABLE_MENU_TEXT;
41
35
	static {
42
	static {
36
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
43
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
37
	}
44
	}
(-)META-INF/MANIFEST.MF (-4 / +9 lines)
Lines 2-13 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %plugin.name
3
Bundle-Name: %plugin.name
4
Bundle-SymbolicName: org.eclipse.ecf.remoteservice.ui;singleton:=true
4
Bundle-SymbolicName: org.eclipse.ecf.remoteservice.ui;singleton:=true
5
Bundle-Version: 2.0.0.qualifier
5
Bundle-Version: 3.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: J2SE-1.4
6
Bundle-RequiredExecutionEnvironment: J2SE-1.4
7
Require-Bundle: org.eclipse.core.runtime,
7
Require-Bundle: org.eclipse.core.runtime,
8
 org.eclipse.ui
8
 org.eclipse.ui,
9
Export-Package: org.eclipse.ecf.internal.remoteservices.ui;x-internal:=true,
9
 org.eclipse.core.expressions;bundle-version="3.4.0",
10
 org.eclipse.ecf.remoteservices.ui
10
 org.eclipse.ecf;bundle-version="2.0.1",
11
 org.eclipse.ecf.remoteservice;bundle-version="2.0.0",
12
 org.eclipse.ecf.discovery;bundle-version="2.1.0",
13
 org.eclipse.ecf.discovery.ui;bundle-version="3.0.0"
14
Export-Package: org.eclipse.ecf.remoteservices.ui;version="3.0.0"
11
Bundle-ActivationPolicy: lazy
15
Bundle-ActivationPolicy: lazy
12
Bundle-Vendor: %plugin.provider
16
Bundle-Vendor: %plugin.provider
13
Bundle-Localization: plugin
17
Bundle-Localization: plugin
18
Bundle-Activator: org.eclipse.ecf.internal.remoteservices.ui.Activator
(-)src/org/eclipse/ecf/internal/remoteservices/ui/handlers/ConnectRemoteServicehandler.java (+64 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.remoteservices.ui.handlers;
12
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.ecf.core.ContainerConnectException;
21
import org.eclipse.ecf.core.IContainer;
22
import org.eclipse.ecf.core.identity.ID;
23
import org.eclipse.ecf.internal.remoteservices.ui.RemoteServiceHandlerUtil;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.swt.widgets.Display;
27
28
public class ConnectRemoteServicehandler extends AbstractHandler {
29
30
	public Object execute(final ExecutionEvent event) throws ExecutionException {
31
		final ID createConnectId = RemoteServiceHandlerUtil.getActiveConnectIDChecked(event);
32
		// decouple the long running connect call from the ui thread
33
		Job job = new Job(NLS.bind("Connecting {0}", createConnectId.getName())) {
34
			protected IStatus run(IProgressMonitor monitor) {
35
				try {
36
					final IContainer container = RemoteServiceHandlerUtil.getActiveIRemoteServiceContainerChecked(event);
37
					container.connect(createConnectId, null);
38
				} catch (ContainerConnectException e) {
39
					showException(e);
40
					return Status.CANCEL_STATUS;
41
				} catch (ExecutionException e) {
42
					showException(e);
43
					return Status.CANCEL_STATUS;
44
				}
45
				return Status.OK_STATUS;
46
			}
47
		};
48
		job.setUser(true);
49
		job.schedule();
50
		return null;
51
	}
52
53
	private void showException(final Throwable t) {
54
		Display.getDefault().asyncExec(new Runnable() {
55
			public void run() {
56
				String msg = t.toString();
57
				if (t.getCause() != null) {
58
					msg += t.getCause().toString();
59
				}
60
				MessageDialog.openError(null, t.getLocalizedMessage(), NLS.bind("Exception: {0}", msg));
61
			}
62
		});
63
	}
64
}
(-)src/org/eclipse/ecf/internal/remoteservices/ui/property/ConnectedTester.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.remoteservices.ui.property;
12
13
14
import org.eclipse.core.expressions.PropertyTester;
15
import org.eclipse.ecf.core.IContainer;
16
import org.eclipse.ecf.core.IContainerManager;
17
import org.eclipse.ecf.core.identity.ID;
18
import org.eclipse.ecf.core.identity.IDCreateException;
19
import org.eclipse.ecf.core.identity.IDFactory;
20
import org.eclipse.ecf.discovery.IServiceInfo;
21
import org.eclipse.ecf.discovery.ui.DiscoveryPropertyTesterUtil;
22
import org.eclipse.ecf.internal.remoteservices.ui.Activator;
23
import org.eclipse.ecf.remoteservice.Constants;
24
25
public class ConnectedTester extends PropertyTester {
26
	
27
	private IContainerManager containerManager;
28
29
	public ConnectedTester() {
30
		containerManager = Activator.getDefault().getContainerManager();
31
	}
32
	
33
	/* (non-Javadoc)
34
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
35
	 */
36
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
37
		// consumers expect connected or disconnected
38
		if(!(expectedValue instanceof Boolean)) {
39
			return false;
40
		}
41
		boolean expected = ((Boolean) expectedValue).booleanValue();
42
43
		// get the container instance
44
		IServiceInfo serviceInfo = DiscoveryPropertyTesterUtil.getIServiceInfoReceiver(receiver);
45
		final String connectNamespace = getConnectNamespace(serviceInfo);
46
		final String connectId = getConnectID(serviceInfo);
47
		try {
48
			ID createConnectId = IDFactory.getDefault().createID(connectNamespace, connectId);
49
			IContainer container = containerManager.getContainer(createConnectId);
50
			if(container == null) {
51
				//Trace.trace(...);
52
				return expected == false;
53
			}
54
			ID connectedId = container.getConnectedID();
55
			boolean isConnected = connectedId == null ? false : true;
56
			return expected == isConnected;
57
		} catch (IDCreateException e) {
58
			//Trace.trace(...);
59
			return expected == false;
60
		}
61
	}
62
63
	private String getConnectNamespace(IServiceInfo serviceInfo) {
64
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_CONNECT_ID_NAMESPACE_PROPERTY);
65
	}
66
67
	private String getConnectID(IServiceInfo serviceInfo) {
68
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_CONNECT_ID_PROPERTY);
69
	}
70
}
(-)src/org/eclipse/ecf/internal/remoteservices/ui/handlers/ReflectiveRemoteServiceHandler.java (+189 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.remoteservices.ui.handlers;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Arrays;
15
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.commands.IHandler;
20
import org.eclipse.ecf.core.IContainer;
21
import org.eclipse.ecf.core.identity.ID;
22
import org.eclipse.ecf.core.util.IAsyncResult;
23
import org.eclipse.ecf.internal.remoteservices.ui.RemoteServiceHandlerUtil;
24
import org.eclipse.ecf.remoteservice.IRemoteCall;
25
import org.eclipse.ecf.remoteservice.IRemoteCallListener;
26
import org.eclipse.ecf.remoteservice.IRemoteService;
27
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
28
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
29
import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
30
import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
31
import org.eclipse.ecf.remoteservices.ui.MethodInvocationDialog;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.jface.window.Window;
34
import org.eclipse.osgi.util.NLS;
35
import org.eclipse.swt.widgets.Display;
36
import org.eclipse.swt.widgets.Shell;
37
38
public class ReflectiveRemoteServiceHandler extends AbstractHandler implements
39
		IHandler {
40
41
	/*
42
	 * (non-Javadoc)
43
	 * @see
44
	 * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
45
	 * .ExecutionEvent)
46
	 */
47
	public Object execute(ExecutionEvent event) throws ExecutionException {
48
		final String clazz = event.getParameter("org.eclipse.ecf.remoteservices.ui.commands.reflectiveMethodDialogParameter");
49
		final IRemoteServiceContainerAdapter adapter = RemoteServiceHandlerUtil.getActiveIRemoteServiceContainerAdapterChecked(event);
50
		final IRemoteServiceReference[] references = RemoteServiceHandlerUtil.getActiveIRemoteServiceReferencesChecked(event);
51
		final IRemoteService remoteService = adapter.getRemoteService(references[0]);
52
		try {
53
			executeMethodInvocationDialog(Class.forName(clazz), remoteService);
54
		} catch (ClassNotFoundException e) {
55
			throw new ExecutionException(e.getMessage(), e);
56
		}
57
		return null;
58
	}
59
60
	private void executeMethodInvocationDialog(final Class cls, final IRemoteService remoteService) {
61
		final MethodInvocationDialog mid = new MethodInvocationDialog(
62
				(Shell) null, cls);
63
		if (mid.open() == Window.OK) {
64
			final int timeout = (mid.getTimeout() > 0) ? mid.getTimeout()
65
					: 30000;
66
			final String methodName = mid.getMethod().getName();
67
			final Object[] methodArgs = mid.getMethodArguments();
68
			final IRemoteCall remoteCall = new IRemoteCall() {
69
				public String getMethod() {
70
					return methodName;
71
				}
72
73
				public Object[] getParameters() {
74
					return methodArgs;
75
				}
76
77
				public long getTimeout() {
78
					return timeout;
79
				}
80
			};
81
			final int invokeType = mid.getInvocationType();
82
			try {
83
				switch (invokeType) {
84
				case MethodInvocationDialog.ASYNC_FIRE_AND_GO:
85
					remoteService.callAsynch(remoteCall);
86
					break;
87
				case MethodInvocationDialog.ASYNC_FUTURE_RESULT:
88
					invokeFuture(cls, remoteService, remoteCall);
89
					break;
90
				case MethodInvocationDialog.ASYNC_LISTENER:
91
					invokeAsyncListener(cls, remoteService, remoteCall);
92
					break;
93
				case MethodInvocationDialog.OSGI_SERVICE_PROXY:
94
					throw new UnsupportedOperationException();
95
					// invokeOSGiProxy(interfaceClass, remoteCall);
96
					// break;
97
				case MethodInvocationDialog.REMOTE_SERVICE_PROXY:
98
					throw new UnsupportedOperationException();
99
					// invokeProxy(interfaceClass, remoteService, remoteCall);
100
					// break;
101
				case MethodInvocationDialog.SYNCHRONOUS:
102
					throw new UnsupportedOperationException();
103
					// invokeSync(cls, remoteService, remoteCall);
104
					// break;
105
				default:
106
					break;
107
				}
108
			} catch (final Exception e) {
109
				showException(e);
110
			}
111
		}
112
	}
113
114
	protected void showException(final Throwable t, final IContainer container,
115
			ID targetID) {
116
		Display.getDefault().asyncExec(new Runnable() {
117
			public void run() {
118
				String msg = t.toString();
119
				if (t.getCause() != null) {
120
					msg += t.getCause().toString();
121
				}
122
				MessageDialog.openInformation(null, "Received Exception", NLS
123
						.bind("Exception: {0}", msg));
124
				container.disconnect();
125
			}
126
		});
127
	}
128
129
	protected void invokeFuture(Class cls, IRemoteService remoteService,
130
			IRemoteCall remoteCall) throws InterruptedException,
131
			InvocationTargetException {
132
		// Make async call with future result
133
		final IAsyncResult asyncResult = remoteService.callAsynch(remoteCall);
134
		// Call blocking get and show result
135
		showResult(cls.getName(), remoteCall, asyncResult.get());
136
	}
137
138
	private void invokeAsyncListener(final Class interfaceClass,
139
			final IRemoteService remoteService, final IRemoteCall remoteCall) {
140
		// Make async call
141
		remoteService.callAsynch(remoteCall, new IRemoteCallListener() {
142
			public void handleEvent(IRemoteCallEvent event) {
143
				if (event instanceof IRemoteCallCompleteEvent) {
144
					final IRemoteCallCompleteEvent complete = (IRemoteCallCompleteEvent) event;
145
					if (complete.hadException()) {
146
						showException(complete.getException());
147
					} else
148
						showResult(interfaceClass.getName(), remoteCall,
149
								complete.getResponse());
150
				}
151
			}
152
		});
153
	}
154
155
	protected void showException(final Throwable t) {
156
		Display.getDefault().asyncExec(new Runnable() {
157
			public void run() {
158
				String msg = t.toString();
159
				if (t.getCause() != null) {
160
					msg += t.getCause().toString();
161
				}
162
				MessageDialog.openInformation(null, "Received Exception", NLS
163
						.bind("Exception: {0}", msg));
164
			}
165
		});
166
	}
167
168
	protected void showResult(final String serviceInterface,
169
			final IRemoteCall remoteCall, final Object result) {
170
		final Object display = (result != null && result.getClass().isArray()) ? Arrays
171
				.asList((Object[]) result)
172
				: result;
173
		final Object[] bindings = new Object[] { serviceInterface,
174
				remoteCall.getMethod(),
175
				Arrays.asList(remoteCall.getParameters()), display };
176
		Display.getDefault().asyncExec(new Runnable() {
177
			public void run() {
178
				MessageDialog
179
						.openInformation(
180
								null,
181
								"Received Response",
182
								NLS
183
										.bind(
184
												"Service Interface:\n{0}\n\nMethod: {1}\nParameters: {2}\n\nResult:  {3}",
185
												bindings));
186
			}
187
		});
188
	}
189
}
(-)src/org/eclipse/ecf/internal/remoteservices/ui/Activator.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ecf.internal.remoteservices.ui;
13
14
import org.eclipse.ecf.core.IContainerManager;
15
import org.eclipse.ui.plugin.AbstractUIPlugin;
16
import org.osgi.framework.BundleContext;
17
import org.osgi.util.tracker.ServiceTracker;
18
19
public class Activator extends AbstractUIPlugin {
20
21
	private volatile ServiceTracker containerManagerTracker;
22
	// The shared instance
23
	private volatile static Activator plugin;
24
	
25
	/**
26
	 * The constructor
27
	 */
28
	public Activator() {
29
		plugin = this;
30
	}
31
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
34
	 */
35
	public void stop(BundleContext context) throws Exception {
36
		plugin = null;
37
		if(containerManagerTracker != null) {
38
			containerManagerTracker.close();
39
			containerManagerTracker = null;
40
		}
41
		super.stop(context);
42
	}
43
	
44
	/**
45
	 * Returns the shared instance
46
	 *
47
	 * @return the shared instance
48
	 */
49
	public static Activator getDefault() {
50
		return plugin;
51
	}
52
53
	public IContainerManager getContainerManager() {
54
		BundleContext context = getBundle().getBundleContext();
55
		if (containerManagerTracker == null) {
56
			containerManagerTracker = new ServiceTracker(context, IContainerManager.class.getName(), null);
57
			containerManagerTracker.open();
58
		}
59
		return (IContainerManager) containerManagerTracker.getService();
60
	}
61
}
(-)src/org/eclipse/ecf/internal/remoteservices/ui/RemoteServiceHandlerUtil.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ecf.internal.remoteservices.ui;
13
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.ecf.core.ContainerCreateException;
17
import org.eclipse.ecf.core.ContainerFactory;
18
import org.eclipse.ecf.core.IContainer;
19
import org.eclipse.ecf.core.IContainerManager;
20
import org.eclipse.ecf.core.identity.ID;
21
import org.eclipse.ecf.core.identity.IDCreateException;
22
import org.eclipse.ecf.core.identity.IDFactory;
23
import org.eclipse.ecf.discovery.IServiceInfo;
24
import org.eclipse.ecf.discovery.ui.DiscoveryHandlerUtil;
25
import org.eclipse.ecf.remoteservice.Constants;
26
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
27
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
28
import org.osgi.framework.InvalidSyntaxException;
29
30
public class RemoteServiceHandlerUtil {
31
32
	public static IRemoteServiceContainerAdapter getActiveIRemoteServiceContainerAdapterChecked(ExecutionEvent event) throws ExecutionException {
33
		final ID activeConnectId = getActiveConnectIDChecked(event);
34
		final IContainerManager containerManager = Activator.getDefault().getContainerManager();
35
		final IContainer container = containerManager.getContainer(activeConnectId);
36
		final IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
37
		return adapter;
38
	}
39
40
	public static IRemoteServiceReference[] getActiveIRemoteServiceReferencesChecked(ExecutionEvent event) throws ExecutionException {
41
		IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
42
		IRemoteServiceContainerAdapter adapter = getActiveIRemoteServiceContainerAdapterChecked(event);
43
		try {
44
			return getRemoteServiceReferencesForRemoteServiceAdapter(adapter, serviceInfo);
45
		} catch (IDCreateException e) {
46
			throw new ExecutionException(e.getMessage(), e);
47
		} catch (InvalidSyntaxException e) {
48
			throw new ExecutionException(e.getMessage(), e);
49
		}
50
	}
51
52
	public static ID getActiveConnectIDChecked(ExecutionEvent event) throws ExecutionException {
53
		IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
54
		final String connectNamespace = getConnectNamespace(serviceInfo);
55
		final String connectId = getConnectID(serviceInfo);
56
		try {
57
			return IDFactory.getDefault().createID(connectNamespace, connectId);
58
		} catch (IDCreateException e) {
59
			throw new ExecutionException(e.getMessage(), e);
60
		}
61
	}
62
63
	public static IContainer getActiveIRemoteServiceContainerChecked(ExecutionEvent event) throws ExecutionException {
64
		final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
65
		final ID createConnectId = getActiveConnectIDChecked(event);
66
		//TODO remove parameters once https://bugs.eclipse.org/bugs/show_bug.cgi?id=256586 is fixed
67
		final Object[] parameters = new Object[]{createConnectId};
68
		try {
69
			return ContainerFactory.getDefault().createContainer(getContainerFactory(serviceInfo), parameters);
70
		} catch (ContainerCreateException e) {
71
			throw new ExecutionException(e.getMessage(), e);
72
		}
73
	}
74
75
	private static IRemoteServiceReference[] getRemoteServiceReferencesForRemoteServiceAdapter(IRemoteServiceContainerAdapter adapter, IServiceInfo serviceInfo) throws InvalidSyntaxException, IDCreateException {
76
		ID serviceID = null;
77
		String serviceNamespace = getServiceNamespace(serviceInfo);
78
		String serviceid = getServiceID(serviceInfo);
79
		if (serviceNamespace != null && serviceid != null) {
80
			serviceID = IDFactory.getDefault().createID(serviceNamespace, serviceid);
81
		}
82
		ID[] targets = (serviceID == null) ? null : new ID[] {serviceID};
83
		return adapter.getRemoteServiceReferences(targets, getRemoteServiceClass(serviceInfo), getFilter(serviceInfo));
84
	}
85
	
86
	private static String getServiceNamespace(IServiceInfo serviceInfo) {
87
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_SERVICE_ID_NAMESPACE_PROPERTY);
88
	}
89
	private static String getServiceID(IServiceInfo serviceInfo) {
90
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_SERVICE_ID_PROPERTY);
91
	}
92
	private static String getRemoteServiceClass(IServiceInfo serviceInfo) {
93
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_OBJECTCLASS_PROPERTY);
94
	}
95
	private static String getFilter(IServiceInfo serviceInfo) {
96
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_FILTER_PROPERTY);
97
	}
98
	private static String getConnectNamespace(IServiceInfo serviceInfo) {
99
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_CONNECT_ID_NAMESPACE_PROPERTY);
100
	}
101
	private static String getConnectID(IServiceInfo serviceInfo) {
102
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_CONNECT_ID_PROPERTY);
103
	}
104
	private static String getContainerFactory(IServiceInfo serviceInfo) {
105
		return serviceInfo.getServiceProperties().getPropertyString(Constants.DISCOVERY_CONTAINER_FACTORY_PROPERTY);
106
	}
107
}
(-)plugin.xml (+63 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.2"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.commands">
6
      <command
7
            defaultHandler="org.eclipse.ecf.internal.remoteservices.ui.handlers.ConnectRemoteServicehandler"
8
            id="org.eclipse.ecf.remoteservices.ui.commands.connectCommand"
9
            name="Connect Command">
10
      </command>
11
      <command
12
            defaultHandler="org.eclipse.ecf.internal.remoteservices.ui.handlers.ReflectiveRemoteServiceHandler"
13
            id="org.eclipse.ecf.remoteservices.ui.commands.reflectiveMethodDialogHandler"
14
            name="Reflective Method Invocation Command">
15
         <commandParameter
16
               id="org.eclipse.ecf.remoteservices.ui.commands.reflectiveMethodDialogParameter"
17
               name="name"
18
               optional="true">
19
         </commandParameter>
20
      </command>
21
   </extension>
22
   <extension
23
         point="org.eclipse.ui.menus">
24
      <menuContribution
25
            locationURI="popup:org.eclipse.ecf.discovery.ui.DiscoveryView?after=additions">
26
         <command
27
               commandId="org.eclipse.ecf.remoteservices.ui.commands.connectCommand"
28
               id="org.eclipse.ecf.remoteservices.ui.menus.connectCommand"
29
               mnemonic="S">
30
            <visibleWhen>
31
               <with
32
                     variable="activeMenuSelection">
33
                  <iterate
34
                        ifEmpty="false"
35
                        operator="and">
36
                     <test
37
                           args="remotesvcs"
38
                           property="org.eclipse.ecf.discovery.isServiceType"
39
                           value="true">
40
                     </test>
41
                     <test
42
                           property="org.eclipse.ecf.remoteservices.isConnected"
43
                           value="false">
44
                     </test>
45
                  </iterate>
46
               </with>
47
            </visibleWhen>
48
         </command>
49
      </menuContribution>
50
   </extension>
51
52
	 <extension
53
         point="org.eclipse.core.expressions.propertyTesters">
54
      <propertyTester
55
            class="org.eclipse.ecf.internal.remoteservices.ui.property.ConnectedTester"
56
            id="org.eclipse.ecf.remoteservices.ui.property.ConnectedPropertyTester"
57
            namespace="org.eclipse.ecf.remoteservices"
58
            properties="isConnected"
59
            type="org.eclipse.ecf.discovery.model.IServiceInfo">
60
      </propertyTester>
61
   </extension>
62
63
</plugin>

Return to bug 256603