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.swt.widgets.Shell;
019: import org.eclipse.ui.ISharedImages;
020: import org.eclipse.ui.IWorkbench;
021: import org.eclipse.ui.IWorkbenchWindow;
022: import org.eclipse.ui.PlatformUI;
023: import org.eclipse.ui.internal.dialogs.NewWizard;
024: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
025: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
026: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
027: import org.eclipse.ui.internal.registry.WizardsRegistryReader;
028:
029: /**
030: * Standard action for launching the create project selection
031: * wizard.
032: * <p>
033: * This class may be instantiated; it is not intended to be subclassed.
034: * </p>
035: */
036: public class NewExampleAction extends Action {
037:
038: /**
039: * The wizard dialog width
040: */
041: private static final int SIZING_WIZARD_WIDTH = 500;
042:
043: /**
044: * The wizard dialog height
045: */
046: private static final int SIZING_WIZARD_HEIGHT = 500;
047:
048: /**
049: * The workbench window this action will run in
050: */
051: private IWorkbenchWindow window;
052:
053: /**
054: * This default constructor allows the the action to be called from the welcome page.
055: */
056: public NewExampleAction() {
057: this (PlatformUI.getWorkbench().getActiveWorkbenchWindow());
058: }
059:
060: /**
061: * Creates a new action for launching the new project
062: * selection wizard.
063: *
064: * @param window the workbench window to query the current
065: * selection and shell for opening the wizard.
066: */
067: public NewExampleAction(IWorkbenchWindow window) {
068: super (IDEWorkbenchMessages.NewExampleAction_text);
069: if (window == null) {
070: throw new IllegalArgumentException();
071: }
072: this .window = window;
073: ISharedImages images = PlatformUI.getWorkbench()
074: .getSharedImages();
075: setImageDescriptor(images
076: .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD));
077: setDisabledImageDescriptor(images
078: .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED));
079: setToolTipText(IDEWorkbenchMessages.NewExampleAction_toolTip);
080: PlatformUI
081: .getWorkbench()
082: .getHelpSystem()
083: .setHelp(
084: this ,
085: org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION);
086: }
087:
088: /* (non-Javadoc)
089: * Method declared on IAction.
090: */
091: public void run() {
092: // Create wizard selection wizard.
093: IWorkbench workbench = PlatformUI.getWorkbench();
094: NewWizard wizard = new NewWizard();
095: wizard
096: .setCategoryId(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
097:
098: ISelection selection = window.getSelectionService()
099: .getSelection();
100: IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
101: if (selection instanceof IStructuredSelection) {
102: selectionToPass = (IStructuredSelection) selection;
103: }
104: wizard.init(workbench, selectionToPass);
105: IDialogSettings workbenchSettings = IDEWorkbenchPlugin
106: .getDefault().getDialogSettings();
107: IDialogSettings wizardSettings = workbenchSettings
108: .getSection("NewWizardAction"); //$NON-NLS-1$
109: if (wizardSettings == null) {
110: wizardSettings = workbenchSettings
111: .addNewSection("NewWizardAction"); //$NON-NLS-1$
112: }
113: wizard.setDialogSettings(wizardSettings);
114: wizard.setForcePreviousAndNextButtons(true);
115:
116: // Create wizard dialog.
117: Shell parent = window.getShell();
118: WizardDialog dialog = new WizardDialog(parent, wizard);
119: dialog.create();
120: wizard.setWindowTitle(IDEWorkbenchMessages.NewExample_title);
121: dialog.getShell().setSize(
122: Math.max(SIZING_WIZARD_WIDTH, dialog.getShell()
123: .getSize().x), SIZING_WIZARD_HEIGHT);
124: PlatformUI.getWorkbench().getHelpSystem().setHelp(
125: dialog.getShell(),
126: IIDEHelpContextIds.NEW_PROJECT_WIZARD);
127:
128: // Open wizard.
129: dialog.open();
130: }
131: }
|