diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java | |
download | eclipse-poky-juno-master.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java')
-rw-r--r-- | plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java new file mode 100644 index 0000000..d4798c2 --- /dev/null +++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java | |||
@@ -0,0 +1,132 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.remote.utils; | ||
12 | |||
13 | import org.eclipse.core.commands.AbstractHandler; | ||
14 | import org.eclipse.core.commands.ExecutionException; | ||
15 | import org.eclipse.core.runtime.IProgressMonitor; | ||
16 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
17 | import org.eclipse.core.runtime.OperationCanceledException; | ||
18 | import org.eclipse.jface.dialogs.ProgressMonitorDialog; | ||
19 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
20 | import org.eclipse.rse.core.model.IHost; | ||
21 | import org.eclipse.rse.internal.terminals.ui.TerminalServiceHelper; | ||
22 | import org.eclipse.rse.internal.terminals.ui.views.RSETerminalConnector; | ||
23 | import org.eclipse.rse.internal.terminals.ui.views.TerminalViewTab; | ||
24 | import org.eclipse.rse.internal.terminals.ui.views.TerminalViewer; | ||
25 | import org.eclipse.rse.internal.terminals.ui.views.TerminalsUI; | ||
26 | import org.eclipse.rse.services.terminals.ITerminalShell; | ||
27 | import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem; | ||
28 | import org.eclipse.rse.subsystems.terminals.core.elements.TerminalElement; | ||
29 | import org.eclipse.rse.ui.SystemBasePlugin; | ||
30 | import org.eclipse.swt.custom.CTabItem; | ||
31 | import org.eclipse.swt.events.DisposeEvent; | ||
32 | import org.eclipse.swt.events.DisposeListener; | ||
33 | import org.eclipse.swt.widgets.Shell; | ||
34 | import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; | ||
35 | import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; | ||
36 | |||
37 | abstract public class TerminalHandler extends AbstractHandler { | ||
38 | |||
39 | |||
40 | protected Shell shell; | ||
41 | |||
42 | protected String changeTerm = "export TERM=vt100;"; | ||
43 | |||
44 | abstract protected String getInitCmd(); | ||
45 | abstract protected String getConnnectionName(); | ||
46 | abstract protected String getDialogTitle(); | ||
47 | |||
48 | protected String changeTerm() { | ||
49 | return changeTerm; | ||
50 | } | ||
51 | |||
52 | protected ITerminalShell getTerminalShellFromTab(CTabItem item) { | ||
53 | ITerminalShell terminalShell = null; | ||
54 | ITerminalViewControl terminalViewControl = (ITerminalViewControl) item | ||
55 | .getData(TerminalViewTab.DATA_KEY_CONTROL); | ||
56 | ITerminalConnector terminalConnector = terminalViewControl | ||
57 | .getTerminalConnector(); | ||
58 | if (terminalConnector instanceof RSETerminalConnector) { | ||
59 | RSETerminalConnector rseTerminalConnector = (RSETerminalConnector) terminalConnector; | ||
60 | terminalShell = rseTerminalConnector.getTerminalHostShell(); | ||
61 | } | ||
62 | return terminalShell; | ||
63 | } | ||
64 | |||
65 | protected boolean preProcess(final ITerminalServiceSubSystem terminalSubSystem) { | ||
66 | if (!terminalSubSystem.isConnected()) { | ||
67 | try { | ||
68 | ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); | ||
69 | dialog.run(true, true, new IRunnableWithProgress(){ | ||
70 | @Override | ||
71 | public void run(IProgressMonitor monitor) { | ||
72 | monitor.beginTask("Connecting to remote target ...", 100); | ||
73 | try { | ||
74 | terminalSubSystem.connect(new NullProgressMonitor(), false); | ||
75 | monitor.done(); | ||
76 | } catch (Exception e) { | ||
77 | CommonHelper.showErrorDialog("Connection failure", null, e.getMessage()); | ||
78 | monitor.done(); | ||
79 | |||
80 | } | ||
81 | } | ||
82 | }); | ||
83 | } catch (OperationCanceledException e) { | ||
84 | // user canceled, return silently | ||
85 | return false; | ||
86 | } catch (Exception e) { | ||
87 | SystemBasePlugin.logError(e.getLocalizedMessage(), e); | ||
88 | return false; | ||
89 | } | ||
90 | } else | ||
91 | return true; | ||
92 | return false; | ||
93 | } | ||
94 | |||
95 | public void execute(IHost host) throws ExecutionException { | ||
96 | |||
97 | final ITerminalServiceSubSystem terminalSubSystem = RSEHelper.getTerminalSubSystem(host); | ||
98 | |||
99 | if (terminalSubSystem != null) { | ||
100 | TerminalsUI terminalsUI = TerminalsUI.getInstance(); | ||
101 | TerminalViewer viewer = terminalsUI.activateTerminalsView(); | ||
102 | if (preProcess(terminalSubSystem)) { | ||
103 | CTabItem tab = viewer.getTabFolder().createTabItem( | ||
104 | terminalSubSystem.getHost(), changeTerm() + getInitCmd()); | ||
105 | //since RSETerminalConnector not exit the shell during the diconnection, | ||
106 | //we have manually exit it here | ||
107 | try { | ||
108 | tab.addDisposeListener(new DisposeListener() { | ||
109 | @Override | ||
110 | public void widgetDisposed(DisposeEvent e) { | ||
111 | Object source = e.getSource(); | ||
112 | if (source instanceof CTabItem) { | ||
113 | CTabItem currentItem = (CTabItem) source; | ||
114 | ITerminalShell shell=getTerminalShellFromTab(currentItem); | ||
115 | if(shell!=null) { | ||
116 | shell.exit(); | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | }); | ||
121 | }catch(Exception e) { | ||
122 | e.printStackTrace(); | ||
123 | } | ||
124 | TerminalElement element = TerminalServiceHelper | ||
125 | .createTerminalElement(tab, terminalSubSystem); | ||
126 | terminalSubSystem.addChild(element); | ||
127 | |||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | } | ||