lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / ControlView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
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
11 * Bernd Hufmann - Filled with content
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.ui.views.control;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jface.action.MenuManager;
20 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.jface.viewers.TreeViewer;
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.TraceControlContentProvider;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlLabelProvider;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlRoot;
29 import org.eclipse.rse.core.RSECorePlugin;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Menu;
33 import org.eclipse.ui.part.ViewPart;
34 import org.eclipse.ui.progress.UIJob;
35
36 /**
37 * <p>
38 * View implementation for Trace Control.
39 * </p>
40 *
41 * @author Bernd Hufmann
42 */
43 public class ControlView extends ViewPart implements ITraceControlComponentChangedListener {
44
45 // ------------------------------------------------------------------------
46 // Constants
47 // ------------------------------------------------------------------------
48
49 /**
50 * View ID.
51 */
52 public static final String ID = "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
53
54 // ------------------------------------------------------------------------
55 // Attributes
56 // ------------------------------------------------------------------------
57
58 /**
59 * The tree viewer.
60 */
61 private TreeViewer fTreeViewer = null;
62
63 /**
64 * The trace control root node. This provides access to the whole model.
65 */
66 private ITraceControlComponent fRoot = null;
67
68 // ------------------------------------------------------------------------
69 // Accessors
70 // ------------------------------------------------------------------------
71
72 /**
73 * Returns the trace control tree node (model)
74 *
75 * @return the trace control tree node (model).
76 */
77 public ITraceControlComponent getTraceControlRoot() {
78 return fRoot;
79 }
80
81 // ------------------------------------------------------------------------
82 // Operations
83 // ------------------------------------------------------------------------
84
85 @Override
86 public void createPartControl(Composite parent) {
87 // Create tree viewer
88 fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
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);
98
99 // Create context menu for the tree viewer
100 createContextMenu();
101
102 getSite().setSelectionProvider(fTreeViewer);
103
104 RSECorePlugin.getTheSystemRegistry(); // to load RSE
105 }
106
107 @Override
108 public void setFocus() {
109 fTreeViewer.getControl().setFocus();
110 }
111
112 @Override
113 public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) {
114 componentChanged(parent);
115 }
116
117 @Override
118 public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) {
119 componentChanged(parent);
120 }
121
122 @Override
123 public void componentChanged(final ITraceControlComponent component) {
124 if (fTreeViewer.getTree().isDisposed()) {
125 return;
126 }
127
128 UIJob myJob = new UIJob("Refresh") { //$NON-NLS-1$
129 @Override
130 public IStatus runInUIThread(IProgressMonitor monitor) {
131 if (fTreeViewer.getTree().isDisposed()) {
132 return Status.OK_STATUS;
133 }
134
135 fTreeViewer.refresh(component);
136
137 // Change selection needed
138 final ISelection sel = fTreeViewer.getSelection();
139 fTreeViewer.setSelection(null);
140 fTreeViewer.setSelection(sel);
141
142 // Show component that was changed
143 fTreeViewer.reveal(component);
144
145 return Status.OK_STATUS;
146 }
147 };
148 myJob.setUser(false);
149 myJob.schedule();
150 }
151
152 /**
153 * Sets the selected component in the tree
154 * @param component - component to select
155 */
156 public void setSelection(ITraceControlComponent component) {
157 ITraceControlComponent[] components = new ITraceControlComponent[1];
158 components[0] = component;
159 setSelection(components);
160 }
161
162 /**
163 * Sets the selected components in the tree
164 * @param components - array of components to select
165 */
166 public void setSelection(ITraceControlComponent[] components) {
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();
177 }
178
179 // ------------------------------------------------------------------------
180 // Helper methods
181 // ------------------------------------------------------------------------
182 /**
183 * Creates the context sensitive menu.
184 */
185 private void createContextMenu() {
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 }
193 }
This page took 0.039023 seconds and 5 git commands to generate.