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