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