001: /*******************************************************************************
002: * Copyright (c) 2003, 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.internal.navigator.wizards;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.jface.action.Action;
014: import org.eclipse.jface.dialogs.ErrorDialog;
015: import org.eclipse.jface.viewers.ISelection;
016: import org.eclipse.jface.viewers.IStructuredSelection;
017: import org.eclipse.jface.viewers.StructuredSelection;
018: import org.eclipse.jface.wizard.WizardDialog;
019: import org.eclipse.swt.widgets.Shell;
020: import org.eclipse.ui.IPluginContribution;
021: import org.eclipse.ui.IWorkbenchWindow;
022: import org.eclipse.ui.IWorkbenchWizard;
023: import org.eclipse.ui.actions.ActionFactory;
024: import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
025: import org.eclipse.ui.wizards.IWizardDescriptor;
026:
027: /**
028: * <p>
029: * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
030: * part of a work in progress. There is a guarantee neither that this API will
031: * work nor that it will remain the same. Please do not use this API without
032: * consulting with the Platform/UI team.
033: * </p>
034: *
035: * @since 3.2
036: *
037: */
038: public class WizardShortcutAction extends Action implements
039: IPluginContribution {
040: private IWizardDescriptor descriptor;
041:
042: private IWorkbenchWindow window;
043:
044: /**
045: *
046: * @param aWindow
047: * The window to use for the shell and selection service.
048: * @param aDescriptor
049: * The descriptor with information for triggering the desired
050: * wizard.
051: */
052: public WizardShortcutAction(IWorkbenchWindow aWindow,
053: IWizardDescriptor aDescriptor) {
054: super (aDescriptor.getLabel());
055: descriptor = aDescriptor;
056: setToolTipText(descriptor.getDescription());
057: setImageDescriptor(descriptor.getImageDescriptor());
058: setId(ActionFactory.NEW.getId());
059: this .window = aWindow;
060: }
061:
062: /**
063: * This action has been invoked by the user
064: */
065: public void run() {
066: // create instance of target wizard
067:
068: IWorkbenchWizard wizard;
069: try {
070: wizard = descriptor.createWizard();
071: } catch (CoreException e) {
072: ErrorDialog
073: .openError(
074: window.getShell(),
075: CommonNavigatorMessages.NewProjectWizard_errorTitle,
076: CommonNavigatorMessages.NewProjectAction_text,
077: e.getStatus());
078: return;
079: }
080:
081: ISelection selection = window.getSelectionService()
082: .getSelection();
083:
084: if (selection instanceof IStructuredSelection) {
085: wizard.init(window.getWorkbench(),
086: (IStructuredSelection) selection);
087: } else {
088: wizard.init(window.getWorkbench(),
089: StructuredSelection.EMPTY);
090: }
091:
092: Shell parent = window.getShell();
093: WizardDialog dialog = new WizardDialog(parent, wizard);
094: dialog.create();
095: // WorkbenchHelp.setHelp(dialog.getShell(),
096: // IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
097: dialog.open();
098: }
099:
100: /*
101: * (non-Javadoc)
102: *
103: * @see org.eclipse.ui.activities.support.IPluginContribution#getLocalId()
104: */
105: public String getLocalId() {
106: return descriptor.getId();
107: }
108:
109: /*
110: * (non-Javadoc)
111: *
112: * @see org.eclipse.ui.activities.support.IPluginContribution#getPluginId()
113: */
114: public String getPluginId() {
115: return descriptor.getId();
116: }
117:
118: }
|