diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-10 03:49:30 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-10 03:49:30 +0200 |
commit | ede215cf93ba81c963ae62d665d0f32c9407551c (patch) | |
tree | 4a6dc80f259bccb8ff8b76d31e6cc8794bd97a2b /plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views | |
download | eclipse-poky-kepler-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views')
3 files changed, 736 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java new file mode 100644 index 0000000..a5801c7 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/BaseFileView.java | |||
@@ -0,0 +1,140 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 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.sdk.remotetools.views; | ||
12 | |||
13 | |||
14 | import java.io.BufferedReader; | ||
15 | import java.io.FileReader; | ||
16 | import java.util.ArrayList; | ||
17 | |||
18 | import org.eclipse.swt.widgets.Composite; | ||
19 | import org.eclipse.ui.part.*; | ||
20 | import org.eclipse.jface.viewers.*; | ||
21 | import org.eclipse.swt.graphics.Image; | ||
22 | import org.eclipse.ui.*; | ||
23 | import org.eclipse.swt.SWT; | ||
24 | |||
25 | |||
26 | /** | ||
27 | * This sample class demonstrates how to plug-in a new | ||
28 | * workbench view. The view shows data obtained from the | ||
29 | * model. The sample creates a dummy model on the fly, | ||
30 | * but a real implementation would connect to the model | ||
31 | * available either in this or another plug-in (e.g. the workspace). | ||
32 | * The view is connected to the model using a content provider. | ||
33 | * <p> | ||
34 | * The view uses a label provider to define how model | ||
35 | * objects should be presented in the view. Each | ||
36 | * view can present the same model objects using | ||
37 | * different labels and icons, if needed. Alternatively, | ||
38 | * a single label provider can be shared between views | ||
39 | * in order to ensure that objects of the same type are | ||
40 | * presented in the same way everywhere. | ||
41 | * <p> | ||
42 | */ | ||
43 | |||
44 | public class BaseFileView extends ViewPart { | ||
45 | |||
46 | /** | ||
47 | * The ID of the view as specified by the extension. | ||
48 | */ | ||
49 | public static final String ID = "org.yocto.sdk.remotetools.views.BaseFileView"; | ||
50 | |||
51 | private TableViewer viewer; | ||
52 | |||
53 | private String filename; | ||
54 | |||
55 | /* | ||
56 | * The content provider class is responsible for | ||
57 | * providing objects to the view. It can wrap | ||
58 | * existing objects in adapters or simply return | ||
59 | * objects as-is. These objects may be sensitive | ||
60 | * to the current input of the view, or ignore | ||
61 | * it and always show the same content | ||
62 | * (like Task List, for example). | ||
63 | */ | ||
64 | |||
65 | class ViewContentProvider implements IStructuredContentProvider { | ||
66 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { | ||
67 | if(newInput instanceof String) | ||
68 | filename=(String)newInput; | ||
69 | } | ||
70 | public void dispose() { | ||
71 | } | ||
72 | public Object[] getElements(Object parent) { | ||
73 | ArrayList <String> elements=new ArrayList <String>(); | ||
74 | BufferedReader in; | ||
75 | String line; | ||
76 | try { | ||
77 | in=new BufferedReader(new FileReader(filename)); | ||
78 | }catch (Exception e) { | ||
79 | return new String [] {"Invalid file " + filename}; | ||
80 | } | ||
81 | |||
82 | try { | ||
83 | do { | ||
84 | line=in.readLine(); | ||
85 | if(line!=null) | ||
86 | elements.add(line); | ||
87 | }while(line!=null); | ||
88 | }catch (Exception e) { | ||
89 | e.printStackTrace(); | ||
90 | } | ||
91 | return (String[]) elements.toArray(new String[elements.size()]); | ||
92 | } | ||
93 | } | ||
94 | class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { | ||
95 | public String getColumnText(Object obj, int index) { | ||
96 | return getText(obj); | ||
97 | } | ||
98 | public Image getColumnImage(Object obj, int index) { | ||
99 | //return getImage(obj); | ||
100 | return null; | ||
101 | } | ||
102 | public Image getImage(Object obj) { | ||
103 | return PlatformUI.getWorkbench(). | ||
104 | getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * The constructor. | ||
110 | */ | ||
111 | public BaseFileView() { | ||
112 | } | ||
113 | |||
114 | public BaseFileView(String file) { | ||
115 | this(); | ||
116 | this.filename=file; | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * This is a callback that will allow us | ||
121 | * to create the viewer and initialize it. | ||
122 | */ | ||
123 | public void createPartControl(Composite parent) { | ||
124 | viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); | ||
125 | viewer.setContentProvider(new ViewContentProvider()); | ||
126 | viewer.setLabelProvider(new ViewLabelProvider()); | ||
127 | viewer.setInput(filename); | ||
128 | } | ||
129 | |||
130 | public void setInput(String filename) { | ||
131 | viewer.setInput(filename); | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * Passing the focus request to the viewer's control. | ||
136 | */ | ||
137 | public void setFocus() { | ||
138 | viewer.getControl().setFocus(); | ||
139 | } | ||
140 | } \ No newline at end of file | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java new file mode 100644 index 0000000..bbb2d02 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewTab.java | |||
@@ -0,0 +1,457 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2002, 2009 IBM Corporation and others. | ||
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 | * Initial Contributors: | ||
9 | * The following IBM employees contributed to the Remote System Explorer | ||
10 | * component that contains this file: David McKnight, Kushal Munir, | ||
11 | * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, | ||
12 | * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. | ||
13 | * | ||
14 | * Contributors: | ||
15 | * David McKnight (IBM) - [165680] "Show in Remote Shell View" does not work | ||
16 | * Yu-Fen Kuo (MontaVista) - Adapted from CommandsViewWorkbook | ||
17 | * Anna Dushistova (MontaVista) - Adapted from CommandsViewWorkbook | ||
18 | * Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits | ||
19 | * Martin Oberhuber (Wind River) - [227571] RSE Terminal should honor Encoding set on the IHost | ||
20 | * Michael Scharf (Wind River) - [236203] [rseterminal] Potentially UI blocking code in TerminalViewTab.createTabItem | ||
21 | * Anna Dushistova (MontaVista) - [244437] [rseterminal] Possible race condition when multiple Terminals are launched after each other | ||
22 | * Martin Oberhuber (Wind River) - [247700] Terminal uses ugly fonts in JEE package | ||
23 | * Anna Dushistova (MontaVista) - [267609] [rseterminal] The first "Launch Terminal" command creates no terminal tab | ||
24 | ********************************************************************************/ | ||
25 | package org.yocto.sdk.remotetools.views; | ||
26 | |||
27 | import java.io.UnsupportedEncodingException; | ||
28 | |||
29 | import org.eclipse.core.runtime.IAdaptable; | ||
30 | import org.eclipse.jface.action.IMenuListener; | ||
31 | import org.eclipse.jface.action.IMenuManager; | ||
32 | import org.eclipse.jface.action.MenuManager; | ||
33 | import org.eclipse.jface.action.Separator; | ||
34 | import org.eclipse.jface.resource.FontRegistry; | ||
35 | import org.eclipse.jface.util.IPropertyChangeListener; | ||
36 | import org.eclipse.jface.util.PropertyChangeEvent; | ||
37 | import org.eclipse.rse.core.model.IHost; | ||
38 | import org.eclipse.swt.SWT; | ||
39 | import org.eclipse.swt.custom.CTabFolder; | ||
40 | import org.eclipse.swt.custom.CTabItem; | ||
41 | import org.eclipse.swt.events.DisposeEvent; | ||
42 | import org.eclipse.swt.events.DisposeListener; | ||
43 | import org.eclipse.swt.events.MenuEvent; | ||
44 | import org.eclipse.swt.events.MenuListener; | ||
45 | import org.eclipse.swt.graphics.Font; | ||
46 | import org.eclipse.swt.layout.FillLayout; | ||
47 | import org.eclipse.swt.layout.GridData; | ||
48 | import org.eclipse.swt.widgets.Composite; | ||
49 | import org.eclipse.swt.widgets.Control; | ||
50 | import org.eclipse.swt.widgets.Display; | ||
51 | import org.eclipse.swt.widgets.Menu; | ||
52 | import org.eclipse.tm.internal.terminal.control.ITerminalListener; | ||
53 | import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; | ||
54 | import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory; | ||
55 | import org.eclipse.tm.internal.terminal.control.actions.TerminalActionClearAll; | ||
56 | import org.eclipse.tm.internal.terminal.control.actions.TerminalActionCopy; | ||
57 | import org.eclipse.tm.internal.terminal.control.actions.TerminalActionCut; | ||
58 | import org.eclipse.tm.internal.terminal.control.actions.TerminalActionPaste; | ||
59 | import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll; | ||
60 | import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; | ||
61 | import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; | ||
62 | import org.eclipse.ui.PlatformUI; | ||
63 | import org.eclipse.ui.themes.IThemeManager; | ||
64 | |||
65 | /** | ||
66 | * This is the desktop view wrapper of the System View viewer. | ||
67 | */ | ||
68 | public class TerminalViewTab extends Composite { | ||
69 | |||
70 | public static String DATA_KEY_CONTROL = "$_control_$"; //$NON-NLS-1$ | ||
71 | |||
72 | private final CTabFolder tabFolder; | ||
73 | |||
74 | private IPropertyChangeListener propertyChangeListener; | ||
75 | |||
76 | private Menu menu; | ||
77 | |||
78 | private boolean fMenuAboutToShow; | ||
79 | |||
80 | private TerminalActionCopy fActionEditCopy; | ||
81 | |||
82 | private TerminalActionCut fActionEditCut; | ||
83 | |||
84 | private TerminalActionPaste fActionEditPaste; | ||
85 | |||
86 | private TerminalActionClearAll fActionEditClearAll; | ||
87 | |||
88 | private TerminalActionSelectAll fActionEditSelectAll; | ||
89 | |||
90 | protected class TerminalContextMenuHandler implements MenuListener, | ||
91 | IMenuListener { | ||
92 | public void menuHidden(MenuEvent event) { | ||
93 | fMenuAboutToShow = false; | ||
94 | fActionEditCopy.updateAction(fMenuAboutToShow); | ||
95 | } | ||
96 | |||
97 | public void menuShown(MenuEvent e) { | ||
98 | |||
99 | } | ||
100 | |||
101 | public void menuAboutToShow(IMenuManager menuMgr) { | ||
102 | fMenuAboutToShow = true; | ||
103 | fActionEditCopy.updateAction(fMenuAboutToShow); | ||
104 | fActionEditCut.updateAction(fMenuAboutToShow); | ||
105 | fActionEditSelectAll.updateAction(fMenuAboutToShow); | ||
106 | fActionEditPaste.updateAction(fMenuAboutToShow); | ||
107 | fActionEditClearAll.updateAction(fMenuAboutToShow); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | public TerminalViewTab(final Composite parent, TerminalViewer viewer) { | ||
112 | super(parent, SWT.NONE); | ||
113 | tabFolder = new CTabFolder(this, SWT.NONE); | ||
114 | tabFolder.setLayout(new FillLayout()); | ||
115 | tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
116 | setLayout(new FillLayout()); | ||
117 | tabFolder.setBackground(parent.getBackground()); | ||
118 | tabFolder.setSimple(false); | ||
119 | tabFolder.setUnselectedImageVisible(false); | ||
120 | tabFolder.setUnselectedCloseVisible(false); | ||
121 | |||
122 | tabFolder.setMinimizeVisible(false); | ||
123 | tabFolder.setMaximizeVisible(false); | ||
124 | //TODO setupActions(); | ||
125 | } | ||
126 | |||
127 | public void dispose() { | ||
128 | if (propertyChangeListener != null) { | ||
129 | IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); | ||
130 | mgr.removePropertyChangeListener(propertyChangeListener); | ||
131 | propertyChangeListener = null; | ||
132 | } | ||
133 | if (!tabFolder.isDisposed()) { | ||
134 | tabFolder.dispose(); | ||
135 | } | ||
136 | super.dispose(); | ||
137 | } | ||
138 | |||
139 | public CTabFolder getFolder() { | ||
140 | return tabFolder; | ||
141 | } | ||
142 | |||
143 | public void remove(Object root) { | ||
144 | |||
145 | } | ||
146 | |||
147 | public int getItemCount(){ | ||
148 | return tabFolder.getItemCount(); | ||
149 | } | ||
150 | |||
151 | public CTabItem getSelectedTab() { | ||
152 | if (tabFolder.getItemCount() > 0) { | ||
153 | int index = tabFolder.getSelectionIndex(); | ||
154 | CTabItem item = tabFolder.getItem(index); | ||
155 | return item; | ||
156 | } | ||
157 | |||
158 | return null; | ||
159 | } | ||
160 | |||
161 | public void showCurrentPage() { | ||
162 | tabFolder.setFocus(); | ||
163 | } | ||
164 | |||
165 | public void showPageFor(Object root) { | ||
166 | for (int i = 0; i < tabFolder.getItemCount(); i++) { | ||
167 | CTabItem item = tabFolder.getItem(i); | ||
168 | if (item.getData() == root) { | ||
169 | tabFolder.setSelection(item); | ||
170 | } | ||
171 | |||
172 | } | ||
173 | } | ||
174 | |||
175 | public void showPageFor(String tabName) { | ||
176 | for (int i = 0; i < tabFolder.getItemCount(); i++) { | ||
177 | CTabItem item = tabFolder.getItem(i); | ||
178 | if (item.getText().equals(tabName)) { | ||
179 | tabFolder.setSelection(item); | ||
180 | return; | ||
181 | } | ||
182 | |||
183 | } | ||
184 | } | ||
185 | |||
186 | public void disposePageFor(String tabName) { | ||
187 | for (int i = 0; i < tabFolder.getItemCount(); i++) { | ||
188 | CTabItem item = tabFolder.getItem(i); | ||
189 | if (item.getText().equals(tabName)) { | ||
190 | item.dispose(); | ||
191 | return; | ||
192 | } | ||
193 | |||
194 | } | ||
195 | } | ||
196 | |||
197 | public void propertyChange(PropertyChangeEvent e) { | ||
198 | // for now always update | ||
199 | if (tabFolder!=null) { | ||
200 | CTabItem[] items = tabFolder.getItems(); | ||
201 | for (int i=0; i<items.length; i++) { | ||
202 | Object control = items[i].getData(DATA_KEY_CONTROL); | ||
203 | if (control instanceof ITerminalViewControl) { | ||
204 | updateTheme((ITerminalViewControl) control); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public void updateTheme(final ITerminalViewControl control) { | ||
211 | if (control != null) { | ||
212 | IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); | ||
213 | Font font; | ||
214 | FontRegistry fr = mgr.getCurrentTheme().getFontRegistry(); | ||
215 | if (fr.hasValueFor("terminal.views.view.font.definition")) { //$NON-NLS-1$ | ||
216 | //Terminal View font if available | ||
217 | font = fr.get("terminal.views.view.font.definition"); //$NON-NLS-1$ | ||
218 | } else if (fr.hasValueFor("REMOTE_COMMANDS_VIEW_FONT")) { //$NON-NLS-1$ | ||
219 | //fallback: "Remote Shell Font" | ||
220 | font = fr.get("REMOTE_COMMANDS_VIEW_FONT"); //$NON-NLS-1$ | ||
221 | } else { | ||
222 | //fallback: "Basic Text Font" | ||
223 | font = fr.get("org.eclipse.jface.textfont"); //$NON-NLS-1$ | ||
224 | } | ||
225 | control.setFont(font); | ||
226 | if (propertyChangeListener == null) { | ||
227 | final TerminalViewTab myself = this; | ||
228 | propertyChangeListener = new IPropertyChangeListener() { | ||
229 | public void propertyChange(PropertyChangeEvent event) { | ||
230 | myself.propertyChange(event); | ||
231 | } | ||
232 | }; | ||
233 | mgr.addPropertyChangeListener(propertyChangeListener); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | /* TODO | ||
238 | public CTabItem createTabItem(IAdaptable root, | ||
239 | final String initialWorkingDirCmd,final String initialCmd) { | ||
240 | final CTabItem item = new CTabItem(tabFolder, SWT.CLOSE); | ||
241 | setTabTitle(root, item); | ||
242 | |||
243 | item.setData(root); | ||
244 | Composite c = new Composite(tabFolder, SWT.NONE); | ||
245 | c.setLayout(new FillLayout()); | ||
246 | |||
247 | tabFolder.getParent().layout(true); | ||
248 | if (root instanceof IHost) { | ||
249 | final IHost host = (IHost) root; | ||
250 | |||
251 | ITerminalConnector connector = new TCFTerminalConnector(host); | ||
252 | ITerminalViewControl terminalControl = TerminalViewControlFactory | ||
253 | .makeControl(new ITerminalListener() | ||
254 | { | ||
255 | |||
256 | public void setState(final TerminalState state) { | ||
257 | if (state == TerminalState.CLOSED | ||
258 | || state == TerminalState.CONNECTED) { | ||
259 | Display.getDefault().asyncExec(new Runnable() { | ||
260 | public void run() { | ||
261 | if (!item.isDisposed()) { | ||
262 | final ITerminalServiceSubSystem terminalServiceSubSystem = TerminalServiceHelper | ||
263 | .getTerminalSubSystem(host); | ||
264 | |||
265 | if (state == TerminalState.CONNECTED) | ||
266 | TerminalServiceHelper | ||
267 | .updateTerminalShellForTerminalElement(item); | ||
268 | |||
269 | setTabImage(host, item); | ||
270 | ISystemRegistry registry = RSECorePlugin | ||
271 | .getTheSystemRegistry(); | ||
272 | registry | ||
273 | .fireEvent(new SystemResourceChangeEvent( | ||
274 | terminalServiceSubSystem, | ||
275 | ISystemResourceChangeEvents.EVENT_REFRESH, | ||
276 | terminalServiceSubSystem)); | ||
277 | } | ||
278 | if (state == TerminalState.CONNECTED) { | ||
279 | |||
280 | if (initialWorkingDirCmd != null) { | ||
281 | Object data = item | ||
282 | .getData(DATA_KEY_CONTROL); | ||
283 | if (data instanceof ITerminalViewControl) | ||
284 | ((ITerminalViewControl) data) | ||
285 | .pasteString(initialWorkingDirCmd); | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | }); | ||
290 | } | ||
291 | |||
292 | } | ||
293 | |||
294 | public void setTerminalTitle(String title) { | ||
295 | |||
296 | } | ||
297 | }, | ||
298 | c, new ITerminalConnector[] { connector }); | ||
299 | // Specify Encoding for Terminal | ||
300 | try { | ||
301 | terminalControl.setEncoding(host.getDefaultEncoding(true)); | ||
302 | } catch (UnsupportedEncodingException e) { | ||
303 | // ignore and allow fallback to default encoding | ||
304 | } | ||
305 | terminalControl.setConnector(connector); | ||
306 | item.setData(DATA_KEY_CONTROL, terminalControl); | ||
307 | updateTheme(terminalControl); | ||
308 | terminalControl.connectTerminal(); | ||
309 | } | ||
310 | item.setControl(c); | ||
311 | tabFolder.setSelection(item); | ||
312 | item.addDisposeListener(new DisposeListener() { | ||
313 | |||
314 | public void widgetDisposed(DisposeEvent e) { | ||
315 | Object source = e.getSource(); | ||
316 | if (source instanceof CTabItem) { | ||
317 | CTabItem currentItem = (CTabItem) source; | ||
318 | Object data = currentItem.getData(DATA_KEY_CONTROL); | ||
319 | if (data instanceof ITerminalViewControl) { | ||
320 | ((ITerminalViewControl) data).disposeTerminal(); | ||
321 | } | ||
322 | data = currentItem.getData(); | ||
323 | if (data instanceof IHost) { | ||
324 | TerminalServiceHelper.removeTerminalElementFromHost( | ||
325 | currentItem, (IHost) data); | ||
326 | } | ||
327 | } | ||
328 | |||
329 | } | ||
330 | |||
331 | }); | ||
332 | |||
333 | setupContextMenus(); | ||
334 | return item; | ||
335 | |||
336 | } | ||
337 | |||
338 | protected void setupActions() { | ||
339 | fActionEditCopy = new TerminalActionCopy() { | ||
340 | protected ITerminalViewControl getTarget() { | ||
341 | return getCurrentTerminalViewControl(); | ||
342 | } | ||
343 | }; | ||
344 | fActionEditCut = new TerminalActionCut() { | ||
345 | protected ITerminalViewControl getTarget() { | ||
346 | return getCurrentTerminalViewControl(); | ||
347 | } | ||
348 | }; | ||
349 | fActionEditPaste = new TerminalActionPaste() { | ||
350 | protected ITerminalViewControl getTarget() { | ||
351 | return getCurrentTerminalViewControl(); | ||
352 | } | ||
353 | }; | ||
354 | fActionEditClearAll = new TerminalActionClearAll() { | ||
355 | protected ITerminalViewControl getTarget() { | ||
356 | return getCurrentTerminalViewControl(); | ||
357 | } | ||
358 | }; | ||
359 | fActionEditSelectAll = new TerminalActionSelectAll() { | ||
360 | protected ITerminalViewControl getTarget() { | ||
361 | return getCurrentTerminalViewControl(); | ||
362 | } | ||
363 | }; | ||
364 | } | ||
365 | |||
366 | protected void setupContextMenus() { | ||
367 | ITerminalViewControl terminalViewControl = getCurrentTerminalViewControl(); | ||
368 | if (terminalViewControl == null) | ||
369 | return; | ||
370 | |||
371 | if (menu == null) { | ||
372 | MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ | ||
373 | menu = menuMgr.createContextMenu(tabFolder); | ||
374 | loadContextMenus(menuMgr); | ||
375 | TerminalContextMenuHandler contextMenuHandler = new TerminalContextMenuHandler(); | ||
376 | menuMgr.addMenuListener(contextMenuHandler); | ||
377 | menu.addMenuListener(contextMenuHandler); | ||
378 | } | ||
379 | Control ctlText = terminalViewControl.getControl(); | ||
380 | ctlText.setMenu(menu); | ||
381 | } | ||
382 | |||
383 | protected void loadContextMenus(IMenuManager menuMgr) { | ||
384 | menuMgr.add(fActionEditCopy); | ||
385 | menuMgr.add(fActionEditPaste); | ||
386 | menuMgr.add(new Separator()); | ||
387 | menuMgr.add(fActionEditClearAll); | ||
388 | menuMgr.add(fActionEditSelectAll); | ||
389 | menuMgr.add(new Separator()); | ||
390 | |||
391 | // Other plug-ins can contribute there actions here | ||
392 | menuMgr.add(new Separator("Additions")); //$NON-NLS-1$ | ||
393 | } | ||
394 | |||
395 | private void setTabTitle(IAdaptable root, CTabItem titem) { | ||
396 | ISystemViewElementAdapter va = (ISystemViewElementAdapter) root | ||
397 | .getAdapter(ISystemViewElementAdapter.class); | ||
398 | if (va != null) { | ||
399 | updateWithUniqueTitle(va.getName(root), titem); | ||
400 | setTabImage(root, titem); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | private void setTabImage(IAdaptable root, CTabItem titem) { | ||
405 | ISystemViewElementAdapter va = (ISystemViewElementAdapter) root | ||
406 | .getAdapter(ISystemViewElementAdapter.class); | ||
407 | if (va != null) { | ||
408 | if (root instanceof IHost) { | ||
409 | ITerminalServiceSubSystem terminalServiceSubSystem = TerminalServiceHelper | ||
410 | .getTerminalSubSystem((IHost) root); | ||
411 | TerminalElement element = terminalServiceSubSystem | ||
412 | .getChild(titem.getText()); | ||
413 | if (element != null) { | ||
414 | va = (ISystemViewElementAdapter) element | ||
415 | .getAdapter(ISystemViewElementAdapter.class); | ||
416 | titem | ||
417 | .setImage(va.getImageDescriptor(element) | ||
418 | .createImage()); | ||
419 | return; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | titem.setImage(va.getImageDescriptor(root).createImage()); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | private void updateWithUniqueTitle(String title, CTabItem currentItem) { | ||
428 | CTabItem[] items = tabFolder.getItems(); | ||
429 | int increment = 1; | ||
430 | String temp = title; | ||
431 | for (int i = 0; i < items.length; i++) { | ||
432 | if (items[i] != currentItem) { | ||
433 | String name = items[i].getText(); | ||
434 | if (name != null) { | ||
435 | if (name.equals(temp)) { | ||
436 | temp = title + " " + increment++; //$NON-NLS-1$ | ||
437 | } | ||
438 | } | ||
439 | |||
440 | } | ||
441 | } | ||
442 | currentItem.setText(temp); | ||
443 | } | ||
444 | |||
445 | private ITerminalViewControl getCurrentTerminalViewControl() { | ||
446 | if (tabFolder != null && !tabFolder.isDisposed()) { | ||
447 | CTabItem item = tabFolder.getSelection(); | ||
448 | if (item != null && !item.isDisposed()) { | ||
449 | Object data = item.getData(DATA_KEY_CONTROL); | ||
450 | if (data instanceof ITerminalViewControl) | ||
451 | return ((ITerminalViewControl) data); | ||
452 | } | ||
453 | } | ||
454 | return null; | ||
455 | } | ||
456 | */ | ||
457 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewer.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewer.java new file mode 100644 index 0000000..65a562b --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TerminalViewer.java | |||
@@ -0,0 +1,139 @@ | |||
1 | /******************************************************************************** | ||
2 | * Copyright (c) 2002, 2009 IBM Corporation and others. All rights reserved. | ||
3 | * This program and the accompanying materials are made available under the terms | ||
4 | * of the Eclipse Public License v1.0 which accompanies this distribution, and is | ||
5 | * available at http://www.eclipse.org/legal/epl-v10.html | ||
6 | * | ||
7 | * Initial Contributors: | ||
8 | * The following IBM employees contributed to the Remote System Explorer | ||
9 | * component that contains this file: David McKnight, Kushal Munir, | ||
10 | * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, | ||
11 | * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. | ||
12 | * | ||
13 | * Contributors: | ||
14 | * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType | ||
15 | * Martin Oberhuber (Wind River) - [168975] Move RSE Events API to Core | ||
16 | * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API | ||
17 | * Martin Oberhuber (Wind River) - [174945] Remove obsolete icons from rse.shells.ui | ||
18 | * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() | ||
19 | * David McKnight (IBM) - [165680] "Show in Remote Shell View" does not work | ||
20 | * Kevin Doyle (IBM) - [198534] Shell Menu Enablement Issue's | ||
21 | * Radoslav Gerganov(ProSyst) - [181563] Fix hardcoded Ctrl+Space for remote shell content assist | ||
22 | * Yu-Fen Kuo (MontaVista) - Adapted from SystemCommandsViewPart | ||
23 | * Anna Dushistova (MontaVista) - Adapted from SystemCommandsViewPart | ||
24 | * Yu-Fen Kuo (MontaVista) - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits | ||
25 | * Anna Dushistova (MontaVista) - [228577] [rseterminal] Clean up RSE Terminal impl | ||
26 | * Anna Dushistova (MontaVista) - [238257] Request a help text when no tab is open in "Remote Shell", "Remote Monitor" and "Terminals" views | ||
27 | * Anna Dushistova (MontaVista) - [235097] [rseterminal] Cannot activate RSE Terminals View with the keyboard | ||
28 | * Anna Dushistova (MontaVista) - [267609] [rseterminal] The first "Launch Terminal" command creates no terminal tab | ||
29 | *********************************************************************************/ | ||
30 | package org.yocto.sdk.remotetools.views; | ||
31 | |||
32 | import org.yocto.sdk.remotetools.Messages; | ||
33 | |||
34 | import org.eclipse.jface.action.IMenuManager; | ||
35 | import org.eclipse.jface.viewers.ISelection; | ||
36 | import org.eclipse.jface.viewers.ISelectionChangedListener; | ||
37 | import org.eclipse.jface.viewers.SelectionChangedEvent; | ||
38 | import org.eclipse.swt.SWT; | ||
39 | import org.eclipse.swt.events.SelectionEvent; | ||
40 | import org.eclipse.swt.events.SelectionListener; | ||
41 | import org.eclipse.swt.widgets.Composite; | ||
42 | import org.eclipse.swt.widgets.Label; | ||
43 | import org.eclipse.ui.ISelectionListener; | ||
44 | import org.eclipse.ui.ISelectionService; | ||
45 | import org.eclipse.ui.IWorkbenchPart; | ||
46 | import org.eclipse.ui.part.PageBook; | ||
47 | import org.eclipse.ui.part.ViewPart; | ||
48 | |||
49 | public class TerminalViewer extends ViewPart implements ISelectionListener, | ||
50 | SelectionListener, ISelectionChangedListener/*, | ||
51 | ISystemResourceChangeListener,*/{ | ||
52 | |||
53 | private TerminalViewTab tabFolder; | ||
54 | |||
55 | private PageBook pagebook; | ||
56 | |||
57 | private Label noTabShownLabel; | ||
58 | |||
59 | public static String VIEW_ID = "org.eclipse.rse.terminals.ui.view.TerminalView"; //$NON-NLS-1$ | ||
60 | |||
61 | public void createPartControl(Composite parent) { | ||
62 | pagebook = new PageBook(parent, SWT.NONE); | ||
63 | |||
64 | tabFolder = new TerminalViewTab(pagebook, this); | ||
65 | tabFolder.getFolder().addSelectionListener(this); | ||
66 | |||
67 | // Page 2: Nothing selected | ||
68 | noTabShownLabel = new Label(pagebook, SWT.TOP + SWT.LEFT + SWT.WRAP); | ||
69 | noTabShownLabel.setText(Messages.TerminalViewer_text); | ||
70 | showEmptyPage(); | ||
71 | |||
72 | |||
73 | ISelectionService selectionService = getSite().getWorkbenchWindow() | ||
74 | .getSelectionService(); | ||
75 | selectionService.addSelectionListener(this); | ||
76 | /* | ||
77 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | ||
78 | |||
79 | registry.addSystemResourceChangeListener(this); | ||
80 | */ | ||
81 | } | ||
82 | |||
83 | public void setFocus() { | ||
84 | tabFolder.setFocus(); | ||
85 | } | ||
86 | |||
87 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { | ||
88 | // TODO Auto-generated method stub | ||
89 | |||
90 | } | ||
91 | |||
92 | public void widgetDefaultSelected(SelectionEvent e) { | ||
93 | // TODO Auto-generated method stub | ||
94 | |||
95 | } | ||
96 | |||
97 | public void widgetSelected(SelectionEvent e) { | ||
98 | // TODO Auto-generated method stub | ||
99 | |||
100 | } | ||
101 | |||
102 | public void selectionChanged(SelectionChangedEvent event) { | ||
103 | // TODO Auto-generated method stub | ||
104 | |||
105 | } | ||
106 | /* | ||
107 | public void systemResourceChanged(ISystemResourceChangeEvent event) { | ||
108 | if (event.getType() == ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED) { | ||
109 | Object source = event.getSource(); | ||
110 | if (source instanceof TerminalElement) { | ||
111 | tabFolder.disposePageFor(((TerminalElement) source).getName()); | ||
112 | } | ||
113 | }else if(event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH){ | ||
114 | if(tabFolder.getItemCount() == 0) | ||
115 | showEmptyPage(); | ||
116 | else | ||
117 | showTabsPage(); | ||
118 | } | ||
119 | } | ||
120 | */ | ||
121 | |||
122 | public void menuAboutToShow(IMenuManager manager) { | ||
123 | // TODO Auto-generated method stub | ||
124 | |||
125 | } | ||
126 | |||
127 | public TerminalViewTab getTabFolder() { | ||
128 | return tabFolder; | ||
129 | } | ||
130 | |||
131 | private void showEmptyPage() { | ||
132 | pagebook.showPage(noTabShownLabel); | ||
133 | } | ||
134 | |||
135 | private void showTabsPage(){ | ||
136 | pagebook.showPage(tabFolder); | ||
137 | } | ||
138 | |||
139 | } \ No newline at end of file | ||