1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.tmf
.ui
.views
.project
.handlers
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.resources
.IResource
;
19 import org
.eclipse
.jface
.viewers
.ISelection
;
20 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
21 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEditorInput
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfExperimentNode
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfTraceNode
;
27 import org
.eclipse
.ui
.IEditorInput
;
28 import org
.eclipse
.ui
.IEditorPart
;
29 import org
.eclipse
.ui
.IReusableEditor
;
30 import org
.eclipse
.ui
.IWorkbench
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PartInitException
;
34 import org
.eclipse
.ui
.PlatformUI
;
37 * <b><u>OpenTraceHandler</u></b>
39 * TODO: Implement me. Please.
41 public class OpenTraceHandler
extends AbstractHandler
{
43 private TmfTraceNode fTrace
= null;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 public boolean isEnabled() {
52 // Check if we are closing down
53 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
57 // Check if a trace is selected
58 IWorkbenchPage page
= window
.getActivePage();
59 if (!(page
.getActivePart() instanceof ProjectView
))
62 // Check if a trace is selected
63 ISelection selection
= page
.getSelection(ProjectView
.ID
);
64 if (selection
instanceof StructuredSelection
) {
65 Object element
= ((StructuredSelection
) selection
).getFirstElement();
66 fTrace
= (element
instanceof TmfTraceNode
) ?
(TmfTraceNode
) element
: null;
69 return (fTrace
!= null);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
79 IResource resource
= fTrace
.getResource();
80 if (fTrace
.getParent() instanceof TmfExperimentNode
) {
81 resource
= fTrace
.getProject().getTracesFolder().getTraceForLocation(resource
.getLocation()).getResource();
84 ITmfTrace trace
= ParserProviderManager
.getTrace(resource
);
90 IEditorInput editorInput
= new TmfEditorInput(resource
, trace
);
91 IWorkbench wb
= PlatformUI
.getWorkbench();
92 IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
94 String editorId
= ParserProviderManager
.getEditorId(resource
);
95 IEditorPart editor
= activePage
.findEditor(editorInput
);
96 if (editor
!= null && editor
instanceof IReusableEditor
) {
97 activePage
.reuseEditor((IReusableEditor
)editor
, editorInput
);
98 activePage
.activate(editor
);
100 editor
= activePage
.openEditor(editorInput
, editorId
);
103 } catch (PartInitException e
) {
107 // ITmfTrace[] traces = new ITmfTrace[]{trace};
108 // TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, resource.getName(), traces, trace.getCacheSize());
109 // experiment.indexExperiment(false);
110 // TmfSignalManager.dispatchSignal(new TmfExperimentSelectedSignal<TmfEvent>(this, experiment));