Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
eb1bab5b | 2 | * Copyright (c) 2009, 2012 Ericsson |
6e512b93 ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
eb1bab5b | 11 | * Bernd Hufmann - Filled with content |
6e512b93 ASL |
12 | *******************************************************************************/ |
13 | ||
115b4a01 | 14 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control; |
6e512b93 | 15 | |
b957fb8c BH |
16 | import org.eclipse.core.runtime.IProgressMonitor; |
17 | import org.eclipse.core.runtime.IStatus; | |
18 | import org.eclipse.core.runtime.Status; | |
eb1bab5b BH |
19 | import org.eclipse.jface.action.MenuManager; |
20 | import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; | |
21 | import org.eclipse.jface.viewers.ISelection; | |
d132bcc7 | 22 | import org.eclipse.jface.viewers.StructuredSelection; |
eb1bab5b | 23 | import org.eclipse.jface.viewers.TreeViewer; |
115b4a01 BH |
24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener; | |
9315aeee BH |
26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlContentProvider; |
27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlLabelProvider; | |
115b4a01 | 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlRoot; |
5f1f22f8 | 29 | import org.eclipse.rse.core.RSECorePlugin; |
eb1bab5b | 30 | import org.eclipse.swt.SWT; |
6e512b93 | 31 | import org.eclipse.swt.widgets.Composite; |
eb1bab5b | 32 | import org.eclipse.swt.widgets.Menu; |
6e512b93 | 33 | import org.eclipse.ui.part.ViewPart; |
b957fb8c | 34 | import org.eclipse.ui.progress.UIJob; |
6e512b93 ASL |
35 | |
36 | /** | |
37 | * <b><u>ControlView</u></b> | |
38 | * <p> | |
eb1bab5b BH |
39 | * View implementation for Trace Control. |
40 | * </p> | |
6e512b93 | 41 | */ |
eb1bab5b | 42 | public class ControlView extends ViewPart implements ITraceControlComponentChangedListener { |
6e512b93 | 43 | |
eb1bab5b BH |
44 | // ------------------------------------------------------------------------ |
45 | // Constants | |
46 | // ------------------------------------------------------------------------ | |
47 | /** | |
48 | * View ID. | |
49 | */ | |
115b4a01 | 50 | public static final String ID = "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$ |
6e512b93 | 51 | |
eb1bab5b BH |
52 | // ------------------------------------------------------------------------ |
53 | // Attributes | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
56 | /** | |
57 | * The tree viewer. | |
58 | */ | |
59 | private TreeViewer fTreeViewer = null; | |
60 | ||
61 | /** | |
62 | * The trace control root node. This provides access to the whole model. | |
63 | */ | |
64 | private ITraceControlComponent fRoot = null; | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Constructors | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Accessors | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
12c155f5 | 74 | /** |
eb1bab5b BH |
75 | * @return returns the trace control tree node (model). |
76 | */ | |
77 | public ITraceControlComponent getTraceControlRoot() { | |
78 | return fRoot; | |
12c155f5 FC |
79 | } |
80 | ||
eb1bab5b BH |
81 | // ------------------------------------------------------------------------ |
82 | // Operations | |
83 | // ------------------------------------------------------------------------ | |
84 | ||
12c155f5 FC |
85 | /* |
86 | * (non-Javadoc) | |
87 | * | |
88 | * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) | |
89 | */ | |
90 | @Override | |
91 | public void createPartControl(Composite parent) { | |
eb1bab5b | 92 | // Create tree viewer |
bbb3538a | 93 | fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
eb1bab5b BH |
94 | ColumnViewerToolTipSupport.enableFor(fTreeViewer); |
95 | ||
96 | fTreeViewer.setContentProvider(new TraceControlContentProvider()); | |
97 | fTreeViewer.setLabelProvider(new TraceControlLabelProvider()); | |
98 | ||
99 | // Create model root | |
100 | fRoot = new TraceControlRoot(); | |
101 | fRoot.addComponentListener(this); | |
102 | fTreeViewer.setInput(fRoot); | |
12c155f5 | 103 | |
eb1bab5b BH |
104 | // Create context menu for the tree viewer |
105 | createContextMenu(); | |
106 | ||
107 | getSite().setSelectionProvider(fTreeViewer); | |
5f1f22f8 BH |
108 | |
109 | RSECorePlugin.getTheSystemRegistry(); // to load RSE | |
12c155f5 FC |
110 | } |
111 | ||
112 | /* | |
113 | * (non-Javadoc) | |
114 | * | |
115 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
116 | */ | |
117 | @Override | |
118 | public void setFocus() { | |
eb1bab5b | 119 | fTreeViewer.getControl().setFocus(); |
eb1bab5b BH |
120 | } |
121 | ||
122 | /* | |
123 | * (non-Javadoc) | |
115b4a01 | 124 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentAdded(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent) |
eb1bab5b BH |
125 | */ |
126 | @Override | |
127 | public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) { | |
b957fb8c | 128 | componentChanged(parent); |
eb1bab5b | 129 | } |
12c155f5 | 130 | |
eb1bab5b BH |
131 | /* |
132 | * (non-Javadoc) | |
115b4a01 | 133 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentRemoved(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent) |
eb1bab5b BH |
134 | */ |
135 | @Override | |
136 | public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) { | |
b957fb8c | 137 | componentChanged(parent); |
12c155f5 | 138 | } |
6e512b93 | 139 | |
eb1bab5b BH |
140 | /* |
141 | * (non-Javadoc) | |
115b4a01 | 142 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent) |
eb1bab5b BH |
143 | */ |
144 | @Override | |
b957fb8c | 145 | public void componentChanged(final ITraceControlComponent component) { |
eb1bab5b BH |
146 | if (fTreeViewer.getTree().isDisposed()) { |
147 | return; | |
148 | } | |
149 | ||
b957fb8c | 150 | UIJob myJob = new UIJob("Refresh") { //$NON-NLS-1$ |
eb1bab5b | 151 | @Override |
b957fb8c | 152 | public IStatus runInUIThread(IProgressMonitor monitor) { |
eb1bab5b | 153 | if (fTreeViewer.getTree().isDisposed()) { |
b957fb8c | 154 | return Status.OK_STATUS; |
eb1bab5b | 155 | } |
5293eb3f | 156 | |
b957fb8c BH |
157 | fTreeViewer.refresh(component); |
158 | ||
eb1bab5b BH |
159 | // Change selection needed |
160 | final ISelection sel = fTreeViewer.getSelection(); | |
161 | fTreeViewer.setSelection(null); | |
162 | fTreeViewer.setSelection(sel); | |
b957fb8c | 163 | |
5293eb3f BH |
164 | // Show component that was changed |
165 | fTreeViewer.reveal(component); | |
166 | ||
b957fb8c | 167 | return Status.OK_STATUS; |
eb1bab5b | 168 | } |
b957fb8c BH |
169 | }; |
170 | myJob.setUser(false); | |
171 | myJob.schedule(); | |
eb1bab5b | 172 | } |
d132bcc7 BH |
173 | |
174 | /** | |
175 | * Sets the selected component in the tree | |
176 | * @param component - component to select | |
177 | */ | |
178 | public void setSelection(ITraceControlComponent component) { | |
b957fb8c BH |
179 | ITraceControlComponent[] components = new ITraceControlComponent[1]; |
180 | components[0] = component; | |
181 | setSelection(components); | |
d132bcc7 BH |
182 | } |
183 | ||
184 | /** | |
185 | * Sets the selected components in the tree | |
186 | * @param component - array of components to select | |
187 | */ | |
188 | public void setSelection(ITraceControlComponent[] components) { | |
b957fb8c BH |
189 | final StructuredSelection selection = new StructuredSelection(components); |
190 | UIJob myJob = new UIJob("Select") { //$NON-NLS-1$ | |
191 | @Override | |
192 | public IStatus runInUIThread(IProgressMonitor monitor) { | |
193 | fTreeViewer.setSelection(selection); | |
194 | return Status.OK_STATUS; | |
195 | } | |
196 | }; | |
197 | myJob.setUser(false); | |
198 | myJob.schedule(); | |
d132bcc7 BH |
199 | } |
200 | ||
eb1bab5b BH |
201 | // ------------------------------------------------------------------------ |
202 | // Helper methods | |
203 | // ------------------------------------------------------------------------ | |
c5f68877 BH |
204 | /** |
205 | * Creates the context sensitive menu. | |
206 | */ | |
eb1bab5b | 207 | private void createContextMenu() { |
eb1bab5b BH |
208 | // First we create a menu Manager |
209 | final MenuManager menuManager = new MenuManager(); | |
210 | final Menu menu = menuManager.createContextMenu(fTreeViewer.getTree()); | |
211 | // Set the MenuManager | |
212 | fTreeViewer.getTree().setMenu(menu); | |
213 | getSite().registerContextMenu(menuManager, fTreeViewer); | |
214 | } | |
6e512b93 | 215 | } |