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
CommitLineData
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
13package org.eclipse.linuxtools.tmf.ui.views.project.handlers;
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20import org.eclipse.core.runtime.preferences.InstanceScope;
21import org.eclipse.jface.window.Window;
22import org.eclipse.jface.wizard.WizardDialog;
23import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
24import org.eclipse.linuxtools.tmf.ui.TmfUiPreferenceInitializer;
25import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;
26import org.eclipse.linuxtools.tmf.ui.views.project.dialogs.NewProjectWizard;
27import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectRoot;
28import org.eclipse.swt.widgets.Shell;
29import org.eclipse.ui.IWorkbenchPart;
30import org.eclipse.ui.IWorkbenchWindow;
31import org.eclipse.ui.PlatformUI;
32import org.osgi.service.prefs.BackingStoreException;
33
34/**
35 * <b><u>NewProjectHandler</u></b>
36 * <p>
37 * TODO: Implement me. Please.
38 */
39public 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
d4011df2 69 @Override
abfad0aa
FC
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.027047 seconds and 5 git commands to generate.