KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > NewProjectAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.actions;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.StructuredSelection;
18 import org.eclipse.jface.wizard.WizardDialog;
19 import org.eclipse.ui.ISharedImages;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.internal.dialogs.NewWizard;
24 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
25 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
26 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
27
28 /**
29  * Standard action for launching the create project selection
30  * wizard.
31  * <p>
32  * This class may be instantiated; it is not intended to be subclassed.
33  * </p>
34  */

35 public class NewProjectAction extends Action {
36
37     /**
38      * The wizard dialog width
39      */

40     private static final int SIZING_WIZARD_WIDTH = 500;
41
42     /**
43      * The wizard dialog height
44      */

45     private static final int SIZING_WIZARD_HEIGHT = 500;
46
47     /**
48      * The workbench window this action will run in
49      */

50     private IWorkbenchWindow window;
51
52     /**
53      * This default constructor allows the the action to be called from the welcome page.
54      */

55     public NewProjectAction() {
56         this(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
57     }
58
59     /**
60      * Creates a new action for launching the new project
61      * selection wizard.
62      *
63      * @param window the workbench window to query the current
64      * selection and shell for opening the wizard.
65      */

66     public NewProjectAction(IWorkbenchWindow window) {
67         super(IDEWorkbenchMessages.NewProjectAction_text);
68         if (window == null) {
69             throw new IllegalArgumentException JavaDoc();
70         }
71         this.window = window;
72         ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
73         setImageDescriptor(images
74                 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD));
75         setDisabledImageDescriptor(images
76                 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED));
77         setToolTipText(IDEWorkbenchMessages.NewProjectAction_toolTip);
78         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
79                 org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION);
80     }
81
82     /* (non-Javadoc)
83      * Method declared on IAction.
84      */

85     public void run() {
86         // Create wizard selection wizard.
87
IWorkbench workbench = PlatformUI.getWorkbench();
88         NewWizard wizard = new NewWizard();
89         wizard.setProjectsOnly(true);
90         ISelection selection = window.getSelectionService().getSelection();
91         IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
92         if (selection instanceof IStructuredSelection) {
93             selectionToPass = (IStructuredSelection) selection;
94         }
95         wizard.init(workbench, selectionToPass);
96         IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault()
97                 .getDialogSettings();
98         IDialogSettings wizardSettings = workbenchSettings
99                 .getSection("NewWizardAction");//$NON-NLS-1$
100
if (wizardSettings == null) {
101             wizardSettings = workbenchSettings.addNewSection("NewWizardAction");//$NON-NLS-1$
102
}
103         wizard.setDialogSettings(wizardSettings);
104         wizard.setForcePreviousAndNextButtons(true);
105
106         // Create wizard dialog.
107
WizardDialog dialog = new WizardDialog(null, wizard);
108         dialog.create();
109         dialog.getShell().setSize(
110                 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x),
111                 SIZING_WIZARD_HEIGHT);
112         PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
113                 IIDEHelpContextIds.NEW_PROJECT_WIZARD);
114
115         // Open wizard.
116
dialog.open();
117     }
118 }
119
Popular Tags