Commit | Line | Data |
---|---|---|
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 | ||
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.RenameExperimentDialog; | |
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>RenameExperimentHandler</u></b> | |
30 | * <p> | |
31 | */ | |
32 | public class RenameExperimentHandler extends AbstractHandler { | |
33 | ||
34 | private TmfExperimentElement fExperiment = null; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // isEnabled | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | @Override | |
41 | public boolean isEnabled() { | |
42 | ||
43 | // Check if we are closing down | |
44 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
45 | if (window == null) | |
46 | return false; | |
47 | ||
48 | // Get the selection | |
49 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
50 | IWorkbenchPart part = page.getActivePart(); | |
51 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
52 | ||
53 | // Make sure there is only selection and that it is an experiment | |
54 | fExperiment = null; | |
55 | if (selection instanceof TreeSelection) { | |
56 | TreeSelection sel = (TreeSelection) selection; | |
57 | Object element = sel.getFirstElement(); | |
58 | if (element instanceof TmfExperimentElement) { | |
59 | fExperiment = (TmfExperimentElement) element; | |
60 | } | |
61 | } | |
62 | ||
63 | return (fExperiment != null); | |
64 | } | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Execution | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | @Override | |
71 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
72 | ||
73 | // Check if we are closing down | |
74 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
75 | if (window == null) | |
76 | return null; | |
77 | ||
78 | // Fire the Rename Experiment dialog | |
79 | Shell shell = window.getShell(); | |
80 | RenameExperimentDialog dialog = new RenameExperimentDialog(shell, fExperiment); | |
81 | dialog.open(); | |
82 | ||
83 | return null; | |
84 | } | |
85 | ||
86 | } |