1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc-Andre Laperle - Initial API and implementation
11 * Bernd Hufmann - Add connection handling
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
;
17 import java
.net
.URISyntaxException
;
18 import java
.text
.MessageFormat
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.URIUtil
;
25 import org
.eclipse
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.remote
.core
.exception
.RemoteConnectionException
;
27 import org
.eclipse
.swt
.graphics
.Image
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.Activator
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.messages
.RemoteMessages
;
30 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageElement
;
31 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
32 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
35 * An RemoteImportConnectionNodeElement representing a connection node.
37 * @author Marc-Andre Laperle
39 public class RemoteImportConnectionNodeElement
extends TracePackageElement
{
41 private static final String IMAGE_PATH
= "icons/obj/connection_node.gif"; //$NON-NLS-1$
45 private RemoteSystemProxy fRemoteProxy
;
48 * Constructs an instance of RemoteImportConnectionNodeElement.
51 * the parent of this element, can be set to null
55 * the URI in string form to connect to the node
57 public RemoteImportConnectionNodeElement(TracePackageElement parent
,
58 String name
, String uri
) {
65 public String
getText() {
66 return fName
+ " (" + fURI
+ ")"; //$NON-NLS-1$//$NON-NLS-2$
70 public Image
getImage() {
71 return Activator
.getDefault().getImageFromImageRegistry(IMAGE_PATH
);
75 * Get the name of the connection.
77 * @return the name of the connection
79 public String
getName() {
84 * Set the name of the connection.
86 * @param name the name of the connection
88 public void setName(String name
) {
93 * Get the URI of the connection.
95 * @return the URI of the connection
97 public String
getURI() {
102 * Set the URI of the connection.
104 * @param uri the URI of the connection
106 public void setURI(String uri
) {
111 * Connects to the remote host
116 * @return status of the executions
118 public IStatus
connect(@NonNull IProgressMonitor monitor
) {
119 // Use local variables to avoid null annotation warning
120 RemoteSystemProxy proxy
= fRemoteProxy
;
123 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, RemoteMessages
.RemoteImportConnectionNodeElement_NodeNameNullError
);
128 hostUri
= URIUtil
.fromString(fURI
);
129 if (hostUri
== null) {
130 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, RemoteMessages
.RemoteImportConnectionNodeElement_UriNullError
);
132 proxy
= new RemoteSystemProxy(TmfRemoteConnectionFactory
.createConnection(hostUri
, name
));
133 fRemoteProxy
= proxy
;
134 } catch (URISyntaxException e
) {
135 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, MessageFormat
.format(RemoteMessages
.RemoteImportConnectionNodeElement_InvalidUriString
, fURI
), e
);
136 } catch (RemoteConnectionException e
) {
137 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, MessageFormat
.format(RemoteMessages
.RemoteImportConnectionNodeElement_ConnectionFailure
, fURI
), e
);
141 proxy
.connect(monitor
);
142 return Status
.OK_STATUS
;
143 } catch (ExecutionException e
) {
144 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, MessageFormat
.format(RemoteMessages
.RemoteImportConnectionNodeElement_ConnectionFailure
, fURI
), e
);
149 * Disconnects the remote host
151 public void disconnect() {
152 if (fRemoteProxy
!= null) {
153 fRemoteProxy
.disconnect();
158 * Returns the remote system proxy implementation
160 * @return the remote system proxy or null
162 public RemoteSystemProxy
getRemoteSystemProxy() {