a9761986ceba752cc6fba88a7b84a9801fe90951
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / CopyExperimentHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 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
13 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.TreeSelection;
21 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
22 import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyExperimentDialog;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.IWorkbenchPage;
25 import org.eclipse.ui.IWorkbenchPart;
26 import org.eclipse.ui.IWorkbenchWindow;
27 import org.eclipse.ui.PlatformUI;
28
29 /**
30 * <b><u>CopyExperimentHandler</u></b>
31 * <p>
32 * TODO: Implement me. Please.
33 */
34 public 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();
47 if (window == null) {
48 return false;
49 }
50
51 // Get the selection
52 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
53 IWorkbenchPart part = page.getActivePart();
54 if (part == null) {
55 return false;
56 }
57 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
58 if (selectionProvider == null)
59 return false;
60 ISelection selection = selectionProvider.getSelection();
61
62 // Make sure there is only selection and that it is an experiment
63 fExperiment = null;
64 if (selection instanceof TreeSelection) {
65 TreeSelection sel = (TreeSelection) selection;
66 // There should be only one item selected as per the plugin.xml
67 Object element = sel.getFirstElement();
68 if (element instanceof TmfExperimentElement) {
69 fExperiment = (TmfExperimentElement) element;
70 }
71 }
72
73 return (fExperiment != null);
74 }
75
76 // ------------------------------------------------------------------------
77 // Execution
78 // ------------------------------------------------------------------------
79
80 @Override
81 public Object execute(ExecutionEvent event) throws ExecutionException {
82
83 // Check if we are closing down
84 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
85 if (window == null)
86 return null;
87
88 // Fire the Copy Experiment dialog
89 Shell shell = window.getShell();
90 CopyExperimentDialog dialog = new CopyExperimentDialog(shell, fExperiment);
91 dialog.open();
92
93 return null;
94 }
95
96 }
This page took 0.032045 seconds and 5 git commands to generate.