2010-07-28 Francois Chouinard <fchouinard@gmail.com> Fix for Bug316349 + a bunch...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / OpenTraceHandler.java
CommitLineData
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
13package org.eclipse.linuxtools.tmf.ui.views.project.handlers;
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.resources.IResource;
19import org.eclipse.jface.viewers.ISelection;
20import org.eclipse.jface.viewers.StructuredSelection;
21import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
22import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput;
23import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager;
24import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;
25import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode;
26import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfTraceNode;
27import org.eclipse.ui.IEditorInput;
28import org.eclipse.ui.IEditorPart;
29import org.eclipse.ui.IReusableEditor;
30import org.eclipse.ui.IWorkbench;
31import org.eclipse.ui.IWorkbenchPage;
32import org.eclipse.ui.IWorkbenchWindow;
33import org.eclipse.ui.PartInitException;
34import org.eclipse.ui.PlatformUI;
35
36/**
37 * <b><u>OpenTraceHandler</u></b>
38 * <p>
39 * TODO: Implement me. Please.
40 */
41public 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
76 public Object execute(ExecutionEvent event) throws ExecutionException {
77
78 IResource resource = fTrace.getResource();
79 if (fTrace.getParent() instanceof TmfExperimentNode) {
80 resource = fTrace.getProject().getTracesFolder().getTraceForLocation(resource.getLocation()).getResource();
81 }
82
83 ITmfTrace trace = ParserProviderManager.getTrace(resource);
84 if (trace == null) {
85 return null;
86 }
87
88 try {
89 IEditorInput editorInput = new TmfEditorInput(resource, trace);
90 IWorkbench wb = PlatformUI.getWorkbench();
91 IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
92
93 String editorId = ParserProviderManager.getEditorId(resource);
94 IEditorPart editor = activePage.findEditor(editorInput);
95 if (editor != null && editor instanceof IReusableEditor) {
96 activePage.reuseEditor((IReusableEditor)editor, editorInput);
97 activePage.activate(editor);
98 } else {
99 editor = activePage.openEditor(editorInput, editorId);
100 }
101
102 } catch (PartInitException e) {
103 e.printStackTrace();
104 }
105
106// ITmfTrace[] traces = new ITmfTrace[]{trace};
107// TmfExperiment<TmfEvent> experiment = new TmfExperiment<TmfEvent>(TmfEvent.class, resource.getName(), traces, trace.getCacheSize());
108// experiment.indexExperiment(false);
109// TmfSignalManager.dispatchSignal(new TmfExperimentSelectedSignal<TmfEvent>(this, experiment));
110
111 return null;
112 }
113
114}
This page took 0.032536 seconds and 5 git commands to generate.