2010-07-12 Francois Chouinard <fchouinar@gmail.com> Contribution for Bug319428...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / OpenTraceHandler.java
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
49 public boolean isEnabled() {
50
51 // Check if we are closing down
52 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
53 if (window == null)
54 return false;
55
56 // Check if a trace is selected
57 IWorkbenchPage page = window.getActivePage();
58 if (!(page.getActivePart() instanceof ProjectView))
59 return false;
60
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;
66 }
67
68 return (fTrace != null);
69 }
70
71 // ------------------------------------------------------------------------
72 // Execution
73 // ------------------------------------------------------------------------
74
75 public Object execute(ExecutionEvent event) throws ExecutionException {
76
77 IResource resource = fTrace.getResource();
78 if (fTrace.getParent() instanceof TmfExperimentNode) {
79 resource = fTrace.getProject().getTracesFolder().getTraceForLocation(resource.getLocation()).getResource();
80 }
81
82 ITmfTrace trace = ParserProviderManager.getTrace(resource);
83 if (trace == null) {
84 return null;
85 }
86
87 try {
88 IEditorInput editorInput = new TmfEditorInput(resource, trace);
89 IWorkbench wb = PlatformUI.getWorkbench();
90 IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
91
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);
97 } else {
98 editor = activePage.openEditor(editorInput, editorId);
99 }
100
101 } catch (PartInitException e) {
102 e.printStackTrace();
103 }
104
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));
109
110 return null;
111 }
112
113 }
This page took 0.053948 seconds and 5 git commands to generate.