Commit | Line | Data |
---|---|---|
6e512b93 ASL |
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.lttng.ui.views.project.handlers; | |
14 | ||
15 | import org.eclipse.core.commands.ExecutionEvent; | |
16 | import org.eclipse.core.commands.ExecutionException; | |
17 | import org.eclipse.core.commands.IHandler; | |
18 | import org.eclipse.core.commands.IHandlerListener; | |
19 | import org.eclipse.jface.viewers.ISelection; | |
20 | import org.eclipse.jface.viewers.StructuredSelection; | |
21 | import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngProjectNode; | |
23 | import org.eclipse.ui.IWorkbenchPage; | |
24 | import org.eclipse.ui.IWorkbenchWindow; | |
25 | import org.eclipse.ui.PlatformUI; | |
26 | ||
27 | /** | |
28 | * <b><u>OpenProjectHandler</u></b> | |
29 | * <p> | |
30 | * TODO: Implement me. Please. | |
31 | */ | |
32 | public class OpenProjectHandler implements IHandler { | |
33 | ||
34 | private LTTngProjectNode fProject = null; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Validation | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
d4011df2 | 40 | @Override |
6e512b93 ASL |
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 | // Check if we are in the Project View | |
49 | IWorkbenchPage page = window.getActivePage(); | |
50 | if (!(page.getActivePart() instanceof ProjectView)) | |
51 | return false; | |
52 | ||
53 | // Check if a project is selected | |
54 | ISelection selection = page.getSelection(ProjectView.ID); | |
55 | if (selection instanceof StructuredSelection) { | |
56 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
57 | fProject = (element instanceof LTTngProjectNode) ? (LTTngProjectNode) element : null; | |
58 | } | |
59 | return (fProject != null && !fProject.isOpen()); | |
60 | } | |
61 | ||
62 | // Handled if we are in the ProjectView | |
d4011df2 | 63 | @Override |
6e512b93 ASL |
64 | public boolean isHandled() { |
65 | return true; | |
66 | } | |
67 | ||
68 | // ------------------------------------------------------------------------ | |
69 | // Execution | |
70 | // ------------------------------------------------------------------------ | |
71 | ||
d4011df2 | 72 | @Override |
6e512b93 ASL |
73 | public Object execute(ExecutionEvent event) throws ExecutionException { |
74 | ||
75 | if (fProject != null) { | |
76 | fProject.openProject(); | |
77 | fProject.refresh(); | |
78 | } | |
79 | return null; | |
80 | } | |
81 | ||
d4011df2 | 82 | @Override |
6e512b93 ASL |
83 | public void dispose() { |
84 | // TODO Auto-generated method stub | |
85 | } | |
86 | ||
87 | // ------------------------------------------------------------------------ | |
88 | // IHandlerListener | |
89 | // ------------------------------------------------------------------------ | |
90 | ||
d4011df2 | 91 | @Override |
6e512b93 ASL |
92 | public void addHandlerListener(IHandlerListener handlerListener) { |
93 | // TODO Auto-generated method stub | |
94 | } | |
95 | ||
d4011df2 | 96 | @Override |
6e512b93 ASL |
97 | public void removeHandlerListener(IHandlerListener handlerListener) { |
98 | // TODO Auto-generated method stub | |
99 | } | |
100 | ||
101 | } |