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