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