1 /*******************************************************************************
2 * Copyright (c) 2012 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
.internal
.tmf
.ui
.project
.handlers
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.NotEnabledException
;
17 import org
.eclipse
.core
.commands
.NotHandledException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.jface
.action
.Action
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectModelElement
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
28 import org
.eclipse
.ui
.handlers
.IHandlerService
;
30 public class OpenAction
extends Action
{
32 private static final String OPEN_TRACE_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.trace.open"; //$NON-NLS-1$
33 private static final String OPEN_EXPERIMENT_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment.open"; //$NON-NLS-1$
35 private IWorkbenchPage page
;
36 private ISelectionProvider selectionProvider
;
37 private TmfProjectModelElement element
;
41 * @param page the workbench page
42 * @param selectionProvider the selection provider
44 public OpenAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
46 this.selectionProvider
= selectionProvider
;
51 * @see org.eclipse.jface.action.Action#isEnabled()
54 public boolean isEnabled() {
55 ISelection selection
= selectionProvider
.getSelection();
56 if (!selection
.isEmpty()) {
57 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
58 if (sSelection
.size() == 1) {
59 if (sSelection
.getFirstElement() instanceof TmfTraceElement
||
60 sSelection
.getFirstElement() instanceof TmfExperimentElement
) {
61 element
= (TmfProjectModelElement
) sSelection
.getFirstElement();
71 * @see org.eclipse.jface.action.Action#run()
76 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
77 if (element
instanceof TmfTraceElement
) {
78 handlerService
.executeCommand(OPEN_TRACE_COMMAND_ID
, null);
79 } else if (element
instanceof TmfExperimentElement
) {
80 handlerService
.executeCommand(OPEN_EXPERIMENT_COMMAND_ID
, null);
82 } catch (ExecutionException e
) {
83 Activator
.getDefault().logError("Error opening resource " + element
.getName(), e
); //$NON-NLS-1$
84 } catch (NotDefinedException e
) {
85 Activator
.getDefault().logError("Error opening resource " + element
.getName(), e
); //$NON-NLS-1$
86 } catch (NotEnabledException e
) {
87 Activator
.getDefault().logError("Error opening resource " + element
.getName(), e
); //$NON-NLS-1$
88 } catch (NotHandledException e
) {
89 Activator
.getDefault().logError("Error opening resource " + element
.getName(), e
); //$NON-NLS-1$