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 | ||
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.StructuredSelection; | |
20 | import org.eclipse.jface.viewers.TreeSelection; | |
21 | import org.eclipse.jface.wizard.WizardDialog; | |
22 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; | |
23 | import org.eclipse.linuxtools.tmf.ui.project.wizards.ImportTraceWizard; | |
24 | import org.eclipse.swt.widgets.Shell; | |
25 | import org.eclipse.ui.IWorkbench; | |
26 | import org.eclipse.ui.IWorkbenchPage; | |
27 | import org.eclipse.ui.IWorkbenchPart; | |
28 | import org.eclipse.ui.IWorkbenchWindow; | |
29 | import org.eclipse.ui.PlatformUI; | |
30 | ||
31 | /** | |
32 | * <b><u>ImportTraceHandler</u></b> | |
33 | * <p> | |
34 | * Starts an ImportTraceWizard that will handle the lowly details. | |
35 | */ | |
36 | public class ImportTraceHandler extends AbstractHandler { | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Execution | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
42 | @Override | |
43 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
44 | ||
45 | // Check if we are closing down | |
46 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
47 | if (window == null) | |
48 | return null; | |
49 | ||
50 | // Get the selection | |
51 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
52 | IWorkbenchPart part = page.getActivePart(); | |
53 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
54 | ||
55 | TmfTraceFolder traceFolder = 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 TmfTraceFolder) { | |
61 | traceFolder = (TmfTraceFolder) element; | |
62 | } | |
63 | } | |
64 | if (traceFolder == null) | |
65 | return null; | |
66 | ||
67 | // Fire the Import Trace Wizard | |
68 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
69 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
70 | ||
71 | ImportTraceWizard wizard = new ImportTraceWizard(); | |
72 | wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder)); | |
73 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
74 | dialog.open(); | |
75 | ||
76 | traceFolder.refresh(); | |
77 | ||
78 | return null; | |
79 | } | |
80 | ||
81 | } |