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 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
12c155f5 FC |
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; | |
1595249b | 19 | import org.eclipse.jface.viewers.ISelectionProvider; |
12c155f5 FC |
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.RenameExperimentDialog; | |
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>RenameExperimentHandler</u></b> | |
31 | * <p> | |
32 | */ | |
33 | public class RenameExperimentHandler 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(); | |
1595249b FC |
52 | ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); |
53 | if (selectionProvider == null) | |
54 | return false; | |
55 | ISelection selection = selectionProvider.getSelection(); | |
12c155f5 FC |
56 | |
57 | // Make sure there is only selection and that it is an experiment | |
58 | fExperiment = null; | |
59 | if (selection instanceof TreeSelection) { | |
60 | TreeSelection sel = (TreeSelection) selection; | |
61 | Object element = sel.getFirstElement(); | |
62 | if (element instanceof TmfExperimentElement) { | |
63 | fExperiment = (TmfExperimentElement) element; | |
64 | } | |
65 | } | |
66 | ||
67 | return (fExperiment != null); | |
68 | } | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Execution | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
74 | @Override | |
75 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
76 | ||
77 | // Check if we are closing down | |
78 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
79 | if (window == null) | |
80 | return null; | |
81 | ||
82 | // Fire the Rename Experiment dialog | |
83 | Shell shell = window.getShell(); | |
84 | RenameExperimentDialog dialog = new RenameExperimentDialog(shell, fExperiment); | |
85 | dialog.open(); | |
86 | ||
87 | return null; | |
88 | } | |
89 | ||
90 | } |