001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.actions;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.jface.dialogs.IDialogSettings;
014: import org.eclipse.jface.viewers.ISelection;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.jface.viewers.StructuredSelection;
017: import org.eclipse.jface.wizard.WizardDialog;
018: import org.eclipse.ui.ISharedImages;
019: import org.eclipse.ui.IWorkbench;
020: import org.eclipse.ui.IWorkbenchWindow;
021: import org.eclipse.ui.PlatformUI;
022: import org.eclipse.ui.internal.dialogs.NewWizard;
023: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
024: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
025: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
026:
027: /**
028: * Standard action for launching the create project selection
029: * wizard.
030: * <p>
031: * This class may be instantiated; it is not intended to be subclassed.
032: * </p>
033: */
034: public class NewProjectAction extends Action {
035:
036: /**
037: * The wizard dialog width
038: */
039: private static final int SIZING_WIZARD_WIDTH = 500;
040:
041: /**
042: * The wizard dialog height
043: */
044: private static final int SIZING_WIZARD_HEIGHT = 500;
045:
046: /**
047: * The workbench window this action will run in
048: */
049: private IWorkbenchWindow window;
050:
051: /**
052: * This default constructor allows the the action to be called from the welcome page.
053: */
054: public NewProjectAction() {
055: this (PlatformUI.getWorkbench().getActiveWorkbenchWindow());
056: }
057:
058: /**
059: * Creates a new action for launching the new project
060: * selection wizard.
061: *
062: * @param window the workbench window to query the current
063: * selection and shell for opening the wizard.
064: */
065: public NewProjectAction(IWorkbenchWindow window) {
066: super (IDEWorkbenchMessages.NewProjectAction_text);
067: if (window == null) {
068: throw new IllegalArgumentException();
069: }
070: this .window = window;
071: ISharedImages images = PlatformUI.getWorkbench()
072: .getSharedImages();
073: setImageDescriptor(images
074: .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD));
075: setDisabledImageDescriptor(images
076: .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED));
077: setToolTipText(IDEWorkbenchMessages.NewProjectAction_toolTip);
078: PlatformUI
079: .getWorkbench()
080: .getHelpSystem()
081: .setHelp(
082: this ,
083: org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION);
084: }
085:
086: /* (non-Javadoc)
087: * Method declared on IAction.
088: */
089: public void run() {
090: // Create wizard selection wizard.
091: IWorkbench workbench = PlatformUI.getWorkbench();
092: NewWizard wizard = new NewWizard();
093: wizard.setProjectsOnly(true);
094: ISelection selection = window.getSelectionService()
095: .getSelection();
096: IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
097: if (selection instanceof IStructuredSelection) {
098: selectionToPass = (IStructuredSelection) selection;
099: }
100: wizard.init(workbench, selectionToPass);
101: IDialogSettings workbenchSettings = IDEWorkbenchPlugin
102: .getDefault().getDialogSettings();
103: IDialogSettings wizardSettings = workbenchSettings
104: .getSection("NewWizardAction");//$NON-NLS-1$
105: if (wizardSettings == null) {
106: wizardSettings = workbenchSettings
107: .addNewSection("NewWizardAction");//$NON-NLS-1$
108: }
109: wizard.setDialogSettings(wizardSettings);
110: wizard.setForcePreviousAndNextButtons(true);
111:
112: // Create wizard dialog.
113: WizardDialog dialog = new WizardDialog(null, wizard);
114: dialog.create();
115: dialog.getShell().setSize(
116: Math.max(SIZING_WIZARD_WIDTH, dialog.getShell()
117: .getSize().x), SIZING_WIZARD_HEIGHT);
118: PlatformUI.getWorkbench().getHelpSystem().setHelp(
119: dialog.getShell(),
120: IIDEHelpContextIds.NEW_PROJECT_WIZARD);
121:
122: // Open wizard.
123: dialog.open();
124: }
125: }
|