tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / CopyExperimentHandler.java
CommitLineData
12c155f5 1/*******************************************************************************
c8422608 2 * Copyright (c) 2009, 2013 Ericsson
d5210347 3 *
12c155f5
FC
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
d5210347 8 *
12c155f5
FC
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.TmfExperimentElement;
22import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyExperimentDialog;
23import org.eclipse.swt.widgets.Shell;
24import org.eclipse.ui.IWorkbenchPage;
25import org.eclipse.ui.IWorkbenchPart;
26import org.eclipse.ui.IWorkbenchWindow;
27import org.eclipse.ui.PlatformUI;
28
29/**
30 * <b><u>CopyExperimentHandler</u></b>
31 * <p>
32 * TODO: Implement me. Please.
33 */
34public class CopyExperimentHandler extends AbstractHandler {
35
36 private TmfExperimentElement fExperiment = null;
37
38 // ------------------------------------------------------------------------
39 // isEnabled
40 // ------------------------------------------------------------------------
41
42 @Override
43 public boolean isEnabled() {
44
45 // Check if we are closing down
46 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
d5210347 47 if (window == null) {
12c155f5 48 return false;
d5210347 49 }
12c155f5
FC
50
51 // Get the selection
52 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
53 IWorkbenchPart part = page.getActivePart();
d5210347
PT
54 if (part == null) {
55 return false;
56 }
1595249b 57 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
c8422608 58 if (selectionProvider == null) {
1595249b 59 return false;
c8422608 60 }
1595249b 61 ISelection selection = selectionProvider.getSelection();
12c155f5
FC
62
63 // Make sure there is only selection and that it is an experiment
64 fExperiment = null;
65 if (selection instanceof TreeSelection) {
66 TreeSelection sel = (TreeSelection) selection;
67 // There should be only one item selected as per the plugin.xml
68 Object element = sel.getFirstElement();
69 if (element instanceof TmfExperimentElement) {
70 fExperiment = (TmfExperimentElement) element;
71 }
72 }
73
74 return (fExperiment != null);
75 }
76
77 // ------------------------------------------------------------------------
78 // Execution
79 // ------------------------------------------------------------------------
80
81 @Override
82 public Object execute(ExecutionEvent event) throws ExecutionException {
83
84 // Check if we are closing down
85 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
c8422608 86 if (window == null) {
12c155f5 87 return null;
c8422608 88 }
12c155f5
FC
89
90 // Fire the Copy Experiment dialog
91 Shell shell = window.getShell();
92 CopyExperimentDialog dialog = new CopyExperimentDialog(shell, fExperiment);
93 dialog.open();
94
95 return null;
96 }
97
98}
This page took 0.038661 seconds and 5 git commands to generate.