1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.handlers
;
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
;
35 * <b><u>NewProjectHandler</u></b>
37 * TODO: Implement me. Please.
39 public class NewProjectHandler
extends AbstractHandler
{
41 private TmfProjectRoot fProjectRoot
= null;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
48 public boolean isEnabled() {
50 // Check if we are closing down
51 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
55 // Check if we are in the Project View
56 IWorkbenchPart part
= window
.getActivePage().getActivePart();
57 if (!(part
instanceof ProjectView
))
60 fProjectRoot
= ((ProjectView
) part
).getRoot();
62 return (fProjectRoot
!= null);
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
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
);
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());
85 } catch (BackingStoreException e
) {
88 fProjectRoot
.refreshChildren();
89 fProjectRoot
.refresh();