Replace printStackTrace() with proper logging in TMF and LTTng
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / OpenAction.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
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.TmfUiPlugin;
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;
29
30 public class OpenAction extends Action {
31
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$
34
35 private IWorkbenchPage page;
36 private ISelectionProvider selectionProvider;
37 private TmfProjectModelElement element;
38
39 /**
40 * Default constructor
41 * @param page the workbench page
42 * @param selectionProvider the selection provider
43 */
44 public OpenAction(IWorkbenchPage page, ISelectionProvider selectionProvider) {
45 this.page = page;
46 this.selectionProvider = selectionProvider;
47 }
48
49 /*
50 * (non-Javadoc)
51 * @see org.eclipse.jface.action.Action#isEnabled()
52 */
53 @Override
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();
62 return true;
63 }
64 }
65 }
66 return false;
67 }
68
69 /*
70 * (non-Javadoc)
71 * @see org.eclipse.jface.action.Action#run()
72 */
73 @Override
74 public void run() {
75 try {
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);
81 }
82 } catch (ExecutionException e) {
83 TmfUiPlugin.getDefault().logError("Error opening resource " + element.getName(), e); //$NON-NLS-1$
84 } catch (NotDefinedException e) {
85 TmfUiPlugin.getDefault().logError("Error opening resource " + element.getName(), e); //$NON-NLS-1$
86 } catch (NotEnabledException e) {
87 TmfUiPlugin.getDefault().logError("Error opening resource " + element.getName(), e); //$NON-NLS-1$
88 } catch (NotHandledException e) {
89 TmfUiPlugin.getDefault().logError("Error opening resource " + element.getName(), e); //$NON-NLS-1$
90 }
91 }
92
93 }
This page took 0.034405 seconds and 6 git commands to generate.