Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 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.views.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.window.Window; | |
21 | import org.eclipse.jface.wizard.WizardDialog; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.project.dialogs.ImportTraceWizard; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.project.model.ITmfProjectTreeNode; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectNode; | |
26 | import org.eclipse.swt.widgets.Shell; | |
27 | import org.eclipse.ui.IWorkbench; | |
28 | import org.eclipse.ui.IWorkbenchPage; | |
29 | import org.eclipse.ui.IWorkbenchWindow; | |
30 | import org.eclipse.ui.PlatformUI; | |
31 | ||
32 | /** | |
33 | * <b><u>ImportTraceHandler</u></b> | |
34 | * <p> | |
35 | * TODO: Implement me. Please. | |
36 | */ | |
37 | public class ImportTraceHandler extends AbstractHandler { | |
38 | ||
39 | private TmfProjectNode fProject = null; | |
40 | ||
41 | // ------------------------------------------------------------------------ | |
42 | // Validation | |
43 | // ------------------------------------------------------------------------ | |
44 | ||
9ccc6d01 | 45 | @Override |
abfad0aa FC |
46 | public boolean isEnabled() { |
47 | ||
48 | // Check if we are closing down | |
49 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
50 | if (window == null) | |
51 | return false; | |
52 | ||
53 | // Check if we are in the Project View | |
54 | IWorkbenchPage page = window.getActivePage(); | |
55 | if (!(page.getActivePart() instanceof ProjectView)) | |
56 | return false; | |
57 | ||
58 | // Check if a project is selected | |
59 | ISelection selection = page.getSelection(ProjectView.ID); | |
60 | if (selection instanceof StructuredSelection) { | |
61 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
62 | if (element instanceof ITmfProjectTreeNode) { | |
63 | ITmfProjectTreeNode node = (ITmfProjectTreeNode) element; | |
64 | while (node != null && !(node instanceof TmfProjectNode)) { | |
65 | node = node.getParent(); | |
66 | } | |
67 | fProject = (node instanceof TmfProjectNode) ? (TmfProjectNode) node : null; | |
68 | } | |
69 | } | |
70 | ||
71 | return (fProject != null && fProject.isOpen() && fProject.isTmfProject()); | |
72 | } | |
73 | ||
74 | // ------------------------------------------------------------------------ | |
75 | // Execution | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
79 | ||
80 | // Set the selection to the project | |
81 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
82 | ProjectView view = (ProjectView) page.getActivePart(); | |
83 | view.setSelection(fProject); | |
84 | ||
85 | // Fire the Import Trace Wizard | |
86 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
87 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
88 | ||
89 | ImportTraceWizard wizard = new ImportTraceWizard(); | |
90 | wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(fProject)); | |
91 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
92 | dialog.open(); | |
93 | ||
94 | if (dialog.getReturnCode() == Window.OK && fProject != null) { | |
95 | fProject.refreshChildren(); | |
96 | fProject.refresh(); | |
97 | } | |
98 | ||
99 | return null; | |
100 | } | |
101 | ||
102 | } |