Commit | Line | Data |
---|---|---|
12c155f5 FC |
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 | ||
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; | |
19 | import org.eclipse.jface.viewers.TreeSelection; | |
20 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; | |
21 | import org.eclipse.linuxtools.tmf.ui.project.wizards.NewExperimentDialog; | |
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>NewExperimentHandler</u></b> | |
30 | * <p> | |
31 | */ | |
32 | public class NewExperimentHandler extends AbstractHandler { | |
33 | ||
34 | // ------------------------------------------------------------------------ | |
35 | // Execution | |
36 | // ------------------------------------------------------------------------ | |
37 | ||
38 | @Override | |
39 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
40 | ||
41 | // Check if we are closing down | |
42 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
43 | if (window == null) | |
44 | return null; | |
45 | ||
46 | // Get the selection | |
47 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
48 | IWorkbenchPart part = page.getActivePart(); | |
49 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
50 | TmfExperimentFolder experimentFolder = null; | |
51 | if (selection instanceof TreeSelection) { | |
52 | TreeSelection sel = (TreeSelection) selection; | |
53 | Object element = sel.getFirstElement(); | |
54 | if (element instanceof TmfExperimentFolder) { | |
55 | experimentFolder = (TmfExperimentFolder) element; | |
56 | } | |
57 | } | |
58 | if (experimentFolder == null) { | |
59 | return null; | |
60 | } | |
61 | ||
62 | // Fire the New Experiment dialog | |
63 | Shell shell = window.getShell(); | |
64 | NewExperimentDialog dialog = new NewExperimentDialog(shell, experimentFolder); | |
65 | dialog.open(); | |
66 | ||
67 | return null; | |
68 | } | |
69 | ||
70 | } |