1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
;
15 import java
.io
.FileNotFoundException
;
17 import org
.eclipse
.core
.resources
.IResource
;
18 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
19 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
20 import org
.eclipse
.core
.resources
.IWorkspace
;
21 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
22 import org
.eclipse
.jface
.action
.IMenuListener
;
23 import org
.eclipse
.jface
.action
.IMenuManager
;
24 import org
.eclipse
.jface
.action
.MenuManager
;
25 import org
.eclipse
.jface
.viewers
.TreeSelection
;
26 import org
.eclipse
.jface
.viewers
.TreeViewer
;
27 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
28 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTrace
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
.LTTngExperimentEntry
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
.LTTngTraceEntry
;
31 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
32 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperimentSelectedSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.events
.MouseAdapter
;
37 import org
.eclipse
.swt
.events
.MouseEvent
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Menu
;
40 import org
.eclipse
.swt
.widgets
.Tree
;
43 * <b><u>ProjectView</u></b>
45 * The ProjectView keeps track of the LTTng projects in the workspace.
47 * TODO: Implement me. Please.
48 * TODO: Put all actions in a context menu
49 * TODO: Identify LTTng traces vs. experiments and hook doubleClick properly
50 * TODO: Handle multiple traces
52 public class ProjectView
extends TmfView
{
54 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.project";
56 private final IWorkspace fWorkspace
;
57 private final IResourceChangeListener fResourceChangeListener
;
58 private TreeViewer fViewer
;
59 private TmfExperiment
<LttngEvent
> fExperiment
= null;
60 // private Object fSelection = null;
62 // To perform updates on the UI thread
63 private Runnable fViewRefresher
= new Runnable() {
70 // ========================================================================
71 // Constructor/Destructor
72 // ========================================================================
75 * This view needs to react to workspace resource changes
77 public ProjectView() {
79 // TmfTraceContext.init();
81 fWorkspace
= ResourcesPlugin
.getWorkspace();
82 fResourceChangeListener
= new IResourceChangeListener() {
83 public void resourceChanged(IResourceChangeEvent event
) {
84 if (event
.getType() == IResourceChangeEvent
.POST_CHANGE
) {
85 Tree tree
= fViewer
.getTree();
86 if (tree
!= null && !tree
.isDisposed())
87 tree
.getDisplay().asyncExec(fViewRefresher
);
91 fWorkspace
.addResourceChangeListener(fResourceChangeListener
);
98 public void dispose() {
99 fWorkspace
.removeResourceChangeListener(fResourceChangeListener
);
103 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
106 public void createPartControl(Composite parent
) {
108 fViewer
= new TreeViewer(parent
, SWT
.SINGLE
);
109 fViewer
.setLabelProvider(new LTTngProjectLabelProvider());
110 fViewer
.setContentProvider(new LTTngProjectContentProvider());
111 fViewer
.setInput(ResourcesPlugin
.getWorkspace().getRoot());
121 private void hookMouse() {
122 fViewer
.getTree().addMouseListener(new MouseAdapter() {
124 public void mouseDoubleClick(MouseEvent event
) {
125 TreeSelection selection
= (TreeSelection
) fViewer
.getSelection();
126 Object element
= selection
.getFirstElement();
127 if (element
instanceof LTTngExperimentEntry
) {
128 LTTngExperimentEntry experiment
= (LTTngExperimentEntry
) element
;
129 selectExperiment(experiment
);
135 private void hookDragAndDrop() {
136 new TraceDragSource(fViewer
);
137 new TraceDropTarget(fViewer
);
143 * TODO: Tie the proper parser to the trace
145 // FIXME: Troubleshooting hack - start
146 private boolean waitForCompletion
= true;
147 // FIXME: Troubleshooting hack - end
149 private void selectExperiment(LTTngExperimentEntry experiment
) {
150 String expId
= experiment
.getName();
151 if (fExperiment
!= null)
152 fExperiment
.deregister();
154 LTTngTraceEntry
[] traceEntries
= experiment
.getTraces();
155 int nbTraces
= traceEntries
.length
;
156 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
157 for (int i
= 0; i
< nbTraces
; i
++) {
158 IResource res
= traceEntries
[i
].getResource();
159 String location
= res
.getLocation().toOSString();
160 ITmfTrace trace
= new LTTngTrace(location
, waitForCompletion
);
163 fExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class, expId
, traces
);
164 fExperiment
.indexExperiment(waitForCompletion
);
165 broadcast(new TmfExperimentSelectedSignal(this, fExperiment
));
166 } catch (FileNotFoundException e
) {
167 // TODO: Why not tell the user? He would appreciate...
168 // e.printStackTrace();
170 } catch (Exception e
) {
178 private void createContextMenu() {
179 MenuManager menuManager
= new MenuManager("#PopupMenu");
180 menuManager
.setRemoveAllWhenShown(true);
181 menuManager
.addMenuListener(new IMenuListener() {
182 public void menuAboutToShow(IMenuManager manager
) {
183 ProjectView
.this.fillContextMenu(manager
);
187 Menu menu
= menuManager
.createContextMenu(fViewer
.getControl());
188 fViewer
.getControl().setMenu(menu
);
189 getSite().registerContextMenu(menuManager
, fViewer
);
195 private void fillContextMenu(IMenuManager manager
) {
199 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
202 public void setFocus() {
203 // TODO Auto-generated method stub
207 * @see java.lang.Object#toString()
210 public String
toString() {
211 return "[ProjectView]";