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.preferences.IEclipsePreferences; | |
20 | import org.eclipse.core.runtime.preferences.InstanceScope; | |
21 | import org.eclipse.jface.window.Window; | |
22 | import org.eclipse.jface.wizard.WizardDialog; | |
23 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; | |
24 | import org.eclipse.linuxtools.tmf.ui.TmfUiPreferenceInitializer; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.project.dialogs.NewProjectWizard; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectRoot; | |
28 | import org.eclipse.swt.widgets.Shell; | |
29 | import org.eclipse.ui.IWorkbenchPart; | |
30 | import org.eclipse.ui.IWorkbenchWindow; | |
31 | import org.eclipse.ui.PlatformUI; | |
32 | import org.osgi.service.prefs.BackingStoreException; | |
33 | ||
34 | /** | |
35 | * <b><u>NewProjectHandler</u></b> | |
36 | * <p> | |
37 | * TODO: Implement me. Please. | |
38 | */ | |
39 | public class NewProjectHandler extends AbstractHandler { | |
40 | ||
41 | private TmfProjectRoot fProjectRoot = null; | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Validation | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
9ccc6d01 | 47 | @Override |
abfad0aa FC |
48 | public boolean isEnabled() { |
49 | ||
50 | // Check if we are closing down | |
51 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
52 | if (window == null) | |
53 | return false; | |
54 | ||
55 | // Check if we are in the Project View | |
56 | IWorkbenchPart part = window.getActivePage().getActivePart(); | |
57 | if (!(part instanceof ProjectView)) | |
58 | return false; | |
59 | ||
60 | fProjectRoot = ((ProjectView) part).getRoot(); | |
61 | ||
62 | return (fProjectRoot != null); | |
63 | } | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Execution | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
70 | ||
71 | // Fire the New Project Wizard | |
72 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | |
73 | NewProjectWizard wizard = new NewProjectWizard(); | |
74 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
75 | dialog.open(); | |
76 | ||
77 | // Update the project model | |
78 | if (dialog.getReturnCode() == Window.OK) { | |
79 | IProject project = wizard.getProject(); | |
80 | if (project != null && fProjectRoot != null) { | |
81 | IEclipsePreferences node = new InstanceScope().getNode(TmfUiPlugin.PLUGIN_ID); | |
82 | node.put(TmfUiPreferenceInitializer.ACTIVE_PROJECT_PREFERENCE, project.getName()); | |
83 | try { | |
84 | node.flush(); | |
85 | } catch (BackingStoreException e) { | |
86 | e.printStackTrace(); | |
87 | } | |
88 | fProjectRoot.refreshChildren(); | |
89 | fProjectRoot.refresh(); | |
90 | } | |
91 | } | |
92 | ||
93 | return null; | |
94 | } | |
95 | ||
96 | } |