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
.tmf
.ui
.project
.model
.TmfExperimentElement
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectModelElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
26 import org
.eclipse
.ui
.IWorkbenchPage
;
27 import org
.eclipse
.ui
.handlers
.IHandlerService
;
29 public class OpenAction
extends Action
{
31 private static final String OPEN_TRACE_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.trace.open"; //$NON-NLS-1$
32 private static final String OPEN_EXPERIMENT_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment.open"; //$NON-NLS-1$
34 private IWorkbenchPage page
;
35 private ISelectionProvider selectionProvider
;
36 private TmfProjectModelElement element
;
40 * @param page the workbench page
41 * @param selectionProvider the selection provider
43 public OpenAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
45 this.selectionProvider
= selectionProvider
;
50 * @see org.eclipse.jface.action.Action#isEnabled()
53 public boolean isEnabled() {
54 ISelection selection
= selectionProvider
.getSelection();
55 if (!selection
.isEmpty()) {
56 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
57 if (sSelection
.size() == 1) {
58 if (sSelection
.getFirstElement() instanceof TmfTraceElement
||
59 sSelection
.getFirstElement() instanceof TmfExperimentElement
) {
60 element
= (TmfProjectModelElement
) sSelection
.getFirstElement();
70 * @see org.eclipse.jface.action.Action#run()
75 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
76 if (element
instanceof TmfTraceElement
) {
77 handlerService
.executeCommand(OPEN_TRACE_COMMAND_ID
, null);
78 } else if (element
instanceof TmfExperimentElement
) {
79 handlerService
.executeCommand(OPEN_EXPERIMENT_COMMAND_ID
, null);
81 } catch (ExecutionException e
) {
83 } catch (NotDefinedException e
) {
85 } catch (NotEnabledException e
) {
87 } catch (NotHandledException e
) {