**********************************************************************/
package org.eclipse.linuxtools.lttng.ui.views.control.handlers;
-import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.INewConnectionDialog;
-import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.NewConnectionDialog;
+import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.TraceControlDialogFactory;
import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent;
import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent;
import org.eclipse.rse.core.IRSESystemType;
* Command handler for creation new connection for trace control.
* </p>
*/
-public class NewConnectionHandler extends AbstractHandler {
+public class NewConnectionHandler extends BaseControlViewHandler {
// ------------------------------------------------------------------------
// Constants
IHost[] hosts = registry.getHostsBySystemType(sysType);
// Open dialog box for the node name and address
- INewConnectionDialog dialog = new NewConnectionDialog(window.getShell(), fRoot, hosts);
+ final INewConnectionDialog dialog = TraceControlDialogFactory.getInstance().getNewConnectionDialog();
+ dialog.setTraceControlParent(fRoot);
+ dialog.setHosts(hosts);
- if (dialog.open() == Window.OK) {
+ if (dialog.open() != Window.OK) {
+ return null;
+ }
+
+ String hostName = dialog.getConnectionName();
+ String hostAddress = dialog.getHostName();
- String hostName = dialog.getConnectionName();
- String hostAddress = dialog.getHostName();
+ // get the singleton RSE registry
+ IHost host = null;
- // get the singleton RSE registry
- IHost host = null;
+ for (int i = 0; i < hosts.length; i++) {
+ if (hosts[i].getAliasName().equals(hostName)) {
+ host = hosts[i];
+ break;
+ }
+ }
- for (int i = 0; i < hosts.length; i++) {
- if (hosts[i].getAliasName().equals(hostName)) {
- host = hosts[i];
- break;
- }
+ if (host == null) {
+ // if there's no host then we will create it
+ try {
+ // create the host object as an SSH Only connection
+ host = registry.createHost(
+ sysType, //System Type Name
+ hostName, //Connection name
+ hostAddress, //IP Address
+ "Connection to Host"); //description //$NON-NLS-1$
}
+ catch (Exception e) {
+ MessageDialog.openError(window.getShell(),
+ Messages.TraceControl_EclipseCommandFailure,
+ Messages.TraceControl_NewNodeCreationFailure + " (" + hostName + ", " + hostAddress + ")" + ":\n" + e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return null;
+ }
+ }
- if (host == null) {
- // if there's no host then we will create it
- try {
- // create the host object as an SSH Only connection
- host = registry.createHost(
- sysType, //System Type Name
- hostName, //Connection name
- hostAddress, //IP Address
- "Connection to Host"); //description //$NON-NLS-1$
- }
- catch (Exception e) {
- MessageDialog.openError(window.getShell(),
- Messages.TraceControl_EclipseCommandFailure,
- Messages.TraceControl_NewNodeCreationFailure + " (" + hostName + ", " + hostAddress + ")" + ":\n" + e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- return null;
- }
+ if (host != null) {
+ // successful creation of host
+ TargetNodeComponent node = null;
+ if (!fRoot.containsChild(hostName)) {
+ node = new TargetNodeComponent(hostName, fRoot, host);
+ fRoot.addChild(node);
}
-
- if (host != null) {
- // successful creation of host
- TargetNodeComponent node = null;
- if (!fRoot.containsChild(hostName)) {
- node = new TargetNodeComponent(hostName, fRoot, host);
- fRoot.addChild(node);
- }
- else {
- node = (TargetNodeComponent)fRoot.getChild(hostName);
- }
-
- node.connect();
+ else {
+ node = (TargetNodeComponent)fRoot.getChild(hostName);
}
+
+ node.connect();
}
return null;
}
*/
@Override
public boolean isEnabled() {
- fRoot = null;
-
- // Check if we are closing down
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window == null) {
+
+ // Get workbench page for the Control View
+ IWorkbenchPage page = getWorkbenchPage();
+ if (page == null) {
return false;
}
- // Check if we are in the Control View
- IWorkbenchPage page = window.getActivePage();
- if (page == null) return false;
- IWorkbenchPart part = page.getActivePart();
- if (!(part instanceof ControlView)) {
- return false;
- }
+ fRoot = null;
+ // no need to verify part because it has been already done in getWorkbenchPage()
+ IWorkbenchPart part = page.getActivePart();
fRoot = ((ControlView) part).getTraceControlRoot();
return (fRoot != null);