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 // ------------------------------------------------------------------------
49 public boolean isEnabled() {
51 // Check if we are closing down
52 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
56 // Check if a trace is selected
57 IWorkbenchPage page
= window
.getActivePage();
58 if (!(page
.getActivePart() instanceof ProjectView
))
61 // Check if a trace is selected
62 ISelection selection
= page
.getSelection(ProjectView
.ID
);
63 if (selection
instanceof StructuredSelection
) {
64 Object element
= ((StructuredSelection
) selection
).getFirstElement();
65 fTrace
= (element
instanceof TmfTraceNode
) ?
(TmfTraceNode
) element
: null;
68 return (fTrace
!= null);
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
77 IResource resource
= fTrace
.getResource();
78 if (fTrace
.getParent() instanceof TmfExperimentNode
) {
79 resource
= fTrace
.getProject().getTracesFolder().getTraceForLocation(resource
.getLocation()).getResource();
82 ITmfTrace trace
= ParserProviderManager
.getTrace(resource
);
88 IEditorInput editorInput
= new TmfEditorInput(resource
, trace
);
89 IWorkbench wb
= PlatformUI
.getWorkbench();
90 IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
92 String editorId
= ParserProviderManager
.getEditorId(resource
);
93 IEditorPart editor
= activePage
.findEditor(editorInput
);
94 if (editor
!= null && editor
instanceof IReusableEditor
) {
95 activePage
.reuseEditor((IReusableEditor
)editor
, editorInput
);
96 activePage
.activate(editor
);
98 editor
= activePage
.openEditor(editorInput
, editorId
);
101 } catch (PartInitException e
) {
105 // ITmfTrace[] traces = new ITmfTrace[]{trace};
106 // TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, resource.getName(), traces, trace.getCacheSize());
107 // experiment.indexExperiment(false);
108 // TmfSignalManager.dispatchSignal(new TmfExperimentSelectedSignal<TmfEvent>(this, experiment));