ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / RenameExperimentHandler.java
CommitLineData
12c155f5 1/*******************************************************************************
c8422608 2 * Copyright (c) 2011, 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.RenameExperimentDialog;
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>RenameExperimentHandler</u></b>
31 * <p>
32 */
33public class RenameExperimentHandler extends AbstractHandler {
34
d5efe032 35 private TmfExperimentElement fExperiment = null;
d5210347 36
d5efe032 37 // ------------------------------------------------------------------------
12c155f5
FC
38 // isEnabled
39 // ------------------------------------------------------------------------
40
41 @Override
42 public boolean isEnabled() {
43
44 // Check if we are closing down
45 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
d5210347 46 if (window == null) {
12c155f5 47 return false;
d5210347 48 }
12c155f5
FC
49
50 // Get the selection
51 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
52 IWorkbenchPart part = page.getActivePart();
d5210347
PT
53 if (part == null) {
54 return false;
55 }
1595249b 56 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
d5210347 57 if (selectionProvider == null) {
1595249b 58 return false;
d5210347 59 }
1595249b 60 ISelection selection = selectionProvider.getSelection();
12c155f5
FC
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 Object element = sel.getFirstElement();
67 if (element instanceof TmfExperimentElement) {
d5efe032 68 fExperiment = (TmfExperimentElement) element;
12c155f5
FC
69 }
70 }
71
72 return (fExperiment != null);
73 }
74
75 // ------------------------------------------------------------------------
76 // Execution
77 // ------------------------------------------------------------------------
78
79 @Override
80 public Object execute(ExecutionEvent event) throws ExecutionException {
81
82 // Check if we are closing down
83 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
d5210347 84 if (window == null) {
12c155f5 85 return null;
d5210347 86 }
12c155f5
FC
87
88 // Fire the Rename Experiment dialog
89 Shell shell = window.getShell();
90 RenameExperimentDialog dialog = new RenameExperimentDialog(shell, fExperiment);
91 dialog.open();
92
93 return null;
94 }
95
96}
This page took 0.058525 seconds and 5 git commands to generate.