Separate remote logic from GUI login in TerminalHandler implementation
PATCH v3 1/1 Separate remote logic from GUI login in TerminalHandler implementation
- TerminalHandler is used by both Perf and Latencytop handlers for running remote commands and for holding the settings dialog
- in order to separate the common functionality for running remote commands we need to separate the GUI from the utilitary funtions
- create DialogHandler that extends TerminalHandler to hold the GUI settings
- clean-up code in TerminalHandler:
- remove references to settings dialog
- modify execute method and keep only remote control code
- change Perf and Latencytop's parent to DialogHandler
--- .../sdk/remotetools/actions/DialogHandler.java | 40 +++++++++ .../sdk/remotetools/actions/LatencytopHandler.java | 2 +- .../yocto/sdk/remotetools/actions/PerfHandler.java | 2 +- .../sdk/remotetools/actions/TerminalHandler.java | 93 ++++++-------------- 4 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java new file +40 -0
@@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013 Intel 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; + +abstract public class DialogHandler extends TerminalHandler { + + protected BaseSettingDialog setting; + + abstract protected String getDialogTitle(); + + protected void initialize(ExecutionEvent event) throws ExecutionException{ + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + shell = window.getShell(); + setting = new SimpleSettingDialog(shell, getDialogTitle(), getConnnectionName()); + } + + @Override + public void execute(ExecutionEvent event) throws ExecutionException { + initialize(event); + + if(setting.open() == BaseSettingDialog.OK) { + IHost currentHost = setting.getHost(); + execute(currentHost); + } + } +}
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java +1 -1
@@ -11,7 +11,7 @@ package org.yocto.sdk.remotetools.actions; -public class LatencytopHandler extends TerminalHandler { +public class LatencytopHandler extends DialogHandler { private static String initCmd="export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin; cd; sudo latencytop\r";
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java +1 -1
@@ -11,7 +11,7 @@ package org.yocto.sdk.remotetools.actions; -public class PerfHandler extends TerminalHandler { +public class PerfHandler extends DialogHandler { private static String initCmd="cd; perf\r";
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java +27 -66
129 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Zhang, Jessica
AppliedMerged to eclipse-poky master.
Thanks,
Jessica
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ioana Grigoropol
Sent: Thursday, May 09, 2013 1:01 PM
To: [email protected]
Subject: [yocto] [PATCH v3] Separate remote logic from GUI login in TerminalHandler implementation
- TerminalHandler is used by both Perf and Latencytop handlers for running remote commands and for holding the settings dialog
- in order to separate the common functionality for running remote commands we need to separate the GUI from the utilitary funtions
- create DialogHandler that extends TerminalHandler to hold the GUI settings
- clean-up code in TerminalHandler:
- remove references to settings dialog
- modify execute method and keep only remote control code
- change Perf and Latencytop's parent to DialogHandler
--- .../sdk/remotetools/actions/DialogHandler.java | 40 +++++++++ .../sdk/remotetools/actions/LatencytopHandler.java | 2 +- .../yocto/sdk/remotetools/actions/PerfHandler.java | 2 +- .../sdk/remotetools/actions/TerminalHandler.java | 93 ++++++-------------- 4 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ac new file +0 -0
+++ tions/DialogHandler.java
@@ -0,0 +1,40 @@ +/**********************************************************************
+*********
+ * Copyright (c) 2013 Intel 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel - initial API and implementation
+***********************************************************************
+********/ package org.yocto.sdk.remotetools.actions;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException; +import org.eclipse.rse.core.model.IHost; import +org.eclipse.ui.IWorkbenchWindow; import +org.eclipse.ui.handlers.HandlerUtil;
+
+abstract public class DialogHandler extends TerminalHandler { +
+ protected BaseSettingDialog setting;
+
+ abstract protected String getDialogTitle();
+
+ protected void initialize(ExecutionEvent event) throws ExecutionException{
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + shell = window.getShell(); + setting = new SimpleSettingDialog(shell, getDialogTitle(), getConnnectionName());
+ }
+
+ @Override
+ public void execute(ExecutionEvent event) throws ExecutionException {
+ initialize(event);
+
+ if(setting.open() == BaseSettingDialog.OK) {
+ IHost currentHost = setting.getHost();
+ execute(currentHost);
+ }
+ }
+}
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ac renamed from plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java +0 -0
+++ tions/LatencytopHandler.java
@@ -11,7 +11,7 @@
package org.yocto.sdk.remotetools.actions;
-public class LatencytopHandler extends TerminalHandler { +public class LatencytopHandler extends DialogHandler {
private static String initCmd="export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin; cd; sudo latencytop\r";
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ac renamed from plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java +0 -0
+++ tions/PerfHandler.java
@@ -11,7 +11,7 @@
package org.yocto.sdk.remotetools.actions;
-public class PerfHandler extends TerminalHandler { +public class PerfHandler extends DialogHandler {
private static String initCmd="cd; perf\r";
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ac renamed from plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java +0 -0
+++ tions/TerminalHandler.java
@@ -11,7 +11,6 @@
package org.yocto.sdk.remotetools.actions;
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.NullProgressMonitor;
@@ -34,14 +33,11 @@ import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
-import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil;
import org.yocto.sdk.remotetools.CommonHelper;
import org.yocto.sdk.remotetools.RSEHelper;
abstract public class TerminalHandler extends AbstractHandler {
- protected BaseSettingDialog setting;
protected Shell shell;
@@ -50,11 +46,6 @@ abstract public class TerminalHandler extends AbstractHandler {
abstract protected String getInitCmd();
abstract protected String getConnnectionName();
abstract protected String getDialogTitle();
- protected void initialize(ExecutionEvent event) throws ExecutionException{
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
- shell = window.getShell();
- setting = new SimpleSettingDialog(shell, getDialogTitle(), getConnnectionName());- }
protected ITerminalShell getTerminalShellFromTab(CTabItem item) {
ITerminalShell terminalShell = null; @@ -98,70 +89,40 @@ abstract public class TerminalHandler extends AbstractHandler {
return false;
}- public Object execute(ExecutionEvent event) throws ExecutionException {
+ public void execute(IHost host) throws ExecutionException {
- initialize(event);
+ final ITerminalServiceSubSystem terminalSubSystem =
+RSEHelper.getTerminalSubSystem(host);
- if(setting.open()==BaseSettingDialog.OK) {
- IHost currentHost = setting.getHost();
- final ITerminalServiceSubSystem terminalSubSystem = RSEHelper.getTerminalSubSystem(currentHost);
-
- if (terminalSubSystem != null) {
- TerminalsUI terminalsUI = TerminalsUI.getInstance();
- TerminalViewer viewer = terminalsUI.activateTerminalsView();
- if (preProcess(terminalSubSystem)) {
- /*if (!terminalSubSystem.isConnected()) {- try {
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
- dialog.run(true, true, new IRunnableWithProgress(){
- public void run(IProgressMonitor monitor) {
- monitor.beginTask("Connecting to remote target ...", 100);
- try {
- terminalSubSystem.connect(new NullProgressMonitor(), false);
- monitor.done();
- } catch (Exception e) {- CommonHelper.showErrorDialog("Connection failure", null, e.getMessage());
- monitor.done();
- }
- }
- });
- } catch (OperationCanceledException e) {
- // user canceled, return silently
- return null;
- } catch (Exception e) {
- SystemBasePlugin.logError(e.getLocalizedMessage(), e);
- }
- }
- if (terminalSubSystem.isConnected()) {*/
- CTabItem tab = viewer.getTabFolder().createTabItem(
- terminalSubSystem.getHost(), changeTerm + getInitCmd());
- //since RSETerminalConnector not exit the shell during the diconnection,
- //we have manually exit it here
- try {- tab.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
-
- Object source = e.getSource();
- if (source instanceof CTabItem) {
- CTabItem currentItem = (CTabItem) source;
- ITerminalShell shell=getTerminalShellFromTab(currentItem);
- if(shell!=null) {
- shell.exit();
- }
+ if (terminalSubSystem != null) {
+ TerminalsUI terminalsUI = TerminalsUI.getInstance();
+ TerminalViewer viewer = terminalsUI.activateTerminalsView();
+ if (preProcess(terminalSubSystem)) {
+ CTabItem tab = viewer.getTabFolder().createTabItem(
+ terminalSubSystem.getHost(), changeTerm + getInitCmd());
+ //since RSETerminalConnector not exit the shell during the diconnection,
+ //we have manually exit it here
+ try {+ tab.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Object source = e.getSource();
+ if (source instanceof CTabItem) {
+ CTabItem currentItem = (CTabItem) source;
+ ITerminalShell shell=getTerminalShellFromTab(currentItem);
+ if(shell!=null) {
+ shell.exit();
}
}- });
- }catch(Exception e) {
- e.printStackTrace();
- }
- TerminalElement element = TerminalServiceHelper
- .createTerminalElement(tab, terminalSubSystem);
- terminalSubSystem.addChild(element);
-
+ }
+ });
+ }catch(Exception e) {
+ e.printStackTrace();
}+ TerminalElement element = TerminalServiceHelper
+ .createTerminalElement(tab, terminalSubSystem);
+ terminalSubSystem.addChild(element);
+
}
}
- return null;
} }
--
1.7.9.5
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto