2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / NewProjectHandler.java
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
47 @Override
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 @Override
70 public Object execute(ExecutionEvent event) throws ExecutionException {
71
72 // Fire the New Project Wizard
73 Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
74 NewProjectWizard wizard = new NewProjectWizard();
75 WizardDialog dialog = new WizardDialog(shell, wizard);
76 dialog.open();
77
78 // Update the project model
79 if (dialog.getReturnCode() == Window.OK) {
80 IProject project = wizard.getProject();
81 if (project != null && fProjectRoot != null) {
82 IEclipsePreferences node = new InstanceScope().getNode(TmfUiPlugin.PLUGIN_ID);
83 node.put(TmfUiPreferenceInitializer.ACTIVE_PROJECT_PREFERENCE, project.getName());
84 try {
85 node.flush();
86 } catch (BackingStoreException e) {
87 e.printStackTrace();
88 }
89 fProjectRoot.refreshChildren();
90 fProjectRoot.refresh();
91 }
92 }
93
94 return null;
95 }
96
97 }
This page took 0.031602 seconds and 5 git commands to generate.