gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / 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.control.ui.views;
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.control.ui.views.model.ITraceControlComponent;
25 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponentChangedListener;
26 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceControlContentProvider;
27 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceControlLabelProvider;
28 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.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.setSystem(true);
150 myJob.schedule();
151 }
152
153 /**
154 * Sets the selected component in the tree
155 * @param component - component to select
156 */
157 public void setSelection(ITraceControlComponent component) {
158 ITraceControlComponent[] components = new ITraceControlComponent[1];
159 components[0] = component;
160 setSelection(components);
161 }
162
163 /**
164 * Sets the selected components in the tree
165 * @param components - array of components to select
166 */
167 public void setSelection(ITraceControlComponent[] components) {
168 final StructuredSelection selection = new StructuredSelection(components);
169 UIJob myJob = new UIJob("Select") { //$NON-NLS-1$
170 @Override
171 public IStatus runInUIThread(IProgressMonitor monitor) {
172 fTreeViewer.setSelection(selection);
173 return Status.OK_STATUS;
174 }
175 };
176 myJob.setUser(false);
177 myJob.schedule();
178 }
179
180 // ------------------------------------------------------------------------
181 // Helper methods
182 // ------------------------------------------------------------------------
183 /**
184 * Creates the context sensitive menu.
185 */
186 private void createContextMenu() {
187 // First we create a menu Manager
188 final MenuManager menuManager = new MenuManager();
189 final Menu menu = menuManager.createContextMenu(fTreeViewer.getTree());
190 // Set the MenuManager
191 fTreeViewer.getTree().setMenu(menu);
192 getSite().registerContextMenu(menuManager, fTreeViewer);
193 }
194 }
This page took 0.034964 seconds and 5 git commands to generate.