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