Fix some Findbugs findings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / CopyTraceHandler.java
CommitLineData
12c155f5
FC
1/*******************************************************************************
2 * Copyright (c) 2011 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
d34665f9 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
12c155f5
FC
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.jface.viewers.ISelection;
1595249b 19import org.eclipse.jface.viewers.ISelectionProvider;
12c155f5
FC
20import org.eclipse.jface.viewers.TreeSelection;
21import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
22import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
23import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyTraceDialog;
24import org.eclipse.swt.widgets.Shell;
25import org.eclipse.ui.IWorkbenchPage;
26import org.eclipse.ui.IWorkbenchPart;
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.PlatformUI;
29
30/**
31 * <b><u>CopyTraceHandler</u></b>
32 * <p>
33 */
34public class CopyTraceHandler extends AbstractHandler {
35
36 private TmfTraceElement fTrace = null;
37
38 // ------------------------------------------------------------------------
39 // Validation
40 // ------------------------------------------------------------------------
41
42 @Override
43 public boolean isEnabled() {
44
45 // Check if we are closing down
46 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
47 if (window == null)
48 return false;
49
50 // Get the selection
51 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
52 IWorkbenchPart part = page.getActivePart();
1595249b
FC
53 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
54 if (selectionProvider == null)
55 return false;
56 ISelection selection = selectionProvider.getSelection();
12c155f5
FC
57
58 // Make sure a trace is selected
59 fTrace = null;
60 if (selection instanceof TreeSelection) {
61 TreeSelection sel = (TreeSelection) selection;
62 // There should be only one item selected as per the plugin.xml
63 Object element = sel.getFirstElement();
64 if (element instanceof TmfTraceElement) {
65 fTrace = (TmfTraceElement) element;
66 }
67 }
68
69 // We only enable opening from the Traces folder for now
70 return (fTrace != null && fTrace.getParent() instanceof TmfTraceFolder);
71 }
72
73 // ------------------------------------------------------------------------
74 // Execution
75 // ------------------------------------------------------------------------
76
77 @Override
78 public Object execute(ExecutionEvent event) throws ExecutionException {
79
80 // Check if we are closing down
81 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
82 if (window == null)
83 return null;
84
85 // Fire the Copy Experiment dialog
86 Shell shell = window.getShell();
87 CopyTraceDialog dialog = new CopyTraceDialog(shell, fTrace);
88 dialog.open();
89
90 return null;
91 }
92
93}
This page took 0.036262 seconds and 5 git commands to generate.