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.core.resources.IProject; | |
19 | import org.eclipse.core.runtime.CoreException; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.project.model.ITmfProjectTreeNode; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectNode; | |
25 | import org.eclipse.ui.IWorkbenchPage; | |
26 | import org.eclipse.ui.IWorkbenchWindow; | |
27 | import org.eclipse.ui.PlatformUI; | |
28 | ||
29 | /** | |
30 | * <b><u>DeleteProjectHandler</u></b> | |
31 | * <p> | |
32 | * TODO: Implement me. Please. | |
33 | */ | |
34 | public class DeleteProjectHandler extends AbstractHandler { | |
35 | ||
36 | private TmfProjectNode fProject = null; | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Validation | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
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 | // Check if we are in the Project View | |
50 | IWorkbenchPage page = window.getActivePage(); | |
51 | if (!(page.getActivePart() instanceof ProjectView)) | |
52 | return false; | |
53 | ||
54 | // Check if a project is selected | |
55 | ISelection selection = page.getSelection(ProjectView.ID); | |
56 | if (selection instanceof StructuredSelection) { | |
57 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
58 | fProject = (element instanceof TmfProjectNode) ? (TmfProjectNode) element : null; | |
59 | } | |
60 | return (fProject != null); | |
61 | } | |
62 | ||
63 | // ------------------------------------------------------------------------ | |
64 | // Execution | |
65 | // ------------------------------------------------------------------------ | |
66 | ||
67 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
68 | ||
69 | IProject project = fProject.getProject(); | |
70 | ITmfProjectTreeNode parent = fProject.getParent(); | |
71 | try { | |
72 | parent.removeChild(fProject); | |
73 | parent.refresh(); | |
74 | project.delete(true, true, null); | |
75 | } catch (CoreException e) { | |
76 | e.printStackTrace(); | |
77 | } | |
78 | ||
79 | return null; | |
80 | } | |
81 | ||
82 | } |