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