Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.project.handlers; | |
14 | ||
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; | |
35 | ||
36 | /** | |
37 | * <b><u>OpenTraceHandler</u></b> | |
38 | * <p> | |
39 | * TODO: Implement me. Please. | |
40 | */ | |
41 | public class OpenTraceHandler extends AbstractHandler { | |
42 | ||
43 | private TmfTraceNode fTrace = null; | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Validation | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
9ccc6d01 | 49 | @Override |
abfad0aa FC |
50 | public boolean isEnabled() { |
51 | ||
52 | // Check if we are closing down | |
53 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
54 | if (window == null) | |
55 | return false; | |
56 | ||
57 | // Check if a trace is selected | |
58 | IWorkbenchPage page = window.getActivePage(); | |
59 | if (!(page.getActivePart() instanceof ProjectView)) | |
60 | return false; | |
61 | ||
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; | |
67 | } | |
68 | ||
69 | return (fTrace != null); | |
70 | } | |
71 | ||
72 | // ------------------------------------------------------------------------ | |
73 | // Execution | |
74 | // ------------------------------------------------------------------------ | |
75 | ||
d4011df2 | 76 | @Override |
abfad0aa FC |
77 | public Object execute(ExecutionEvent event) throws ExecutionException { |
78 | ||
79 | IResource resource = fTrace.getResource(); | |
80 | if (fTrace.getParent() instanceof TmfExperimentNode) { | |
81 | resource = fTrace.getProject().getTracesFolder().getTraceForLocation(resource.getLocation()).getResource(); | |
82 | } | |
83 | ||
84 | ITmfTrace trace = ParserProviderManager.getTrace(resource); | |
85 | if (trace == null) { | |
86 | return null; | |
87 | } | |
88 | ||
89 | try { | |
90 | IEditorInput editorInput = new TmfEditorInput(resource, trace); | |
91 | IWorkbench wb = PlatformUI.getWorkbench(); | |
92 | IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); | |
93 | ||
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); | |
99 | } else { | |
100 | editor = activePage.openEditor(editorInput, editorId); | |
101 | } | |
102 | ||
103 | } catch (PartInitException e) { | |
104 | e.printStackTrace(); | |
105 | } | |
106 | ||
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)); | |
111 | ||
112 | return null; | |
113 | } | |
114 | ||
115 | } |