1 /*******************************************************************************
2 * Copyright (c) 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 * Patrick Tasse - 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
.core
.runtime
.CoreException
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
24 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
25 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceParserUpdatedSignal
;
26 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfExperimentNode
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfTraceNode
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * <b><u>OpenTraceHandler</u></b>
39 public class SelectParserHandler
extends AbstractHandler
{
41 private TmfTraceNode fTrace
= null;
42 private ProjectView fProjectView
= null;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
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
))
60 fProjectView
= (ProjectView
) page
.getActivePart();
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 @SuppressWarnings("unchecked")
78 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();
83 String parser
= event
.getParameter("org.eclipse.linuxtools.tmf.ui.commandparameter.project.trace.selectparser.parser");
85 resource
.setPersistentProperty(ParserProviderManager
.PARSER_PROPERTY
, parser
);
86 fProjectView
.broadcast(new TmfTraceParserUpdatedSignal(fProjectView
, resource
));
87 fTrace
.getProject().refresh();
89 TmfExperiment
<TmfEvent
> currentExperiment
= (TmfExperiment
<TmfEvent
>) TmfExperiment
.getCurrentExperiment();
90 if (currentExperiment
!= null) {
91 for (int i
= 0; i
< currentExperiment
.getTraces().length
; i
++) {
92 ITmfTrace trace
= currentExperiment
.getTraces()[i
];
93 if (resource
.getLocation().toOSString().equals(trace
.getPath())) {
94 ITmfTrace newTrace
= ParserProviderManager
.getTrace(resource
);
95 if (newTrace
!= null) {
96 currentExperiment
.getTraces()[i
] = newTrace
;
97 fProjectView
.broadcast(new TmfExperimentSelectedSignal
<TmfEvent
>(new Object(), currentExperiment
));
102 } catch (CoreException e
) {