EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.internal.actions]

COVERAGE SUMMARY FOR SOURCE FILE [NewWizardShortcutAction.java]

nameclass, %method, %block, %line, %
NewWizardShortcutAction.java0%   (0/1)0%   (0/6)0%   (0/191)0%   (0/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NewWizardShortcutAction0%   (0/1)0%   (0/6)0%   (0/191)0%   (0/52)
NewWizardShortcutAction (IWorkbenchWindow, IWizardDescriptor): void 0%   (0/1)0%   (0/23)0%   (0/7)
getLocalId (): String 0%   (0/1)0%   (0/12)0%   (0/4)
getPluginContribution (): IPluginContribution 0%   (0/1)0%   (0/20)0%   (0/2)
getPluginId (): String 0%   (0/1)0%   (0/10)0%   (0/4)
getWizardDescriptor (): IWizardDescriptor 0%   (0/1)0%   (0/3)0%   (0/1)
run (): void 0%   (0/1)0%   (0/123)0%   (0/34)

1/*******************************************************************************
2 * Copyright (c) 2000, 2007 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 *******************************************************************************/
11package org.eclipse.ui.internal.actions;
12 
13import org.eclipse.core.runtime.CoreException;
14import org.eclipse.jface.action.Action;
15import org.eclipse.jface.dialogs.ErrorDialog;
16import org.eclipse.jface.viewers.ISelection;
17import org.eclipse.jface.viewers.IStructuredSelection;
18import org.eclipse.jface.viewers.StructuredSelection;
19import org.eclipse.jface.wizard.WizardDialog;
20import org.eclipse.swt.graphics.Point;
21import org.eclipse.swt.widgets.Shell;
22import org.eclipse.ui.IEditorInput;
23import org.eclipse.ui.IEditorPart;
24import org.eclipse.ui.INewWizard;
25import org.eclipse.ui.IPluginContribution;
26import org.eclipse.ui.IWorkbenchPart;
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.actions.ActionFactory;
29import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
30import org.eclipse.ui.internal.LegacyResourceSupport;
31import org.eclipse.ui.internal.WorkbenchMessages;
32import org.eclipse.ui.internal.util.Util;
33import org.eclipse.ui.wizards.IWizardDescriptor;
34 
35/**
36 * Opens a specific new wizard. 
37 */
38public class NewWizardShortcutAction extends Action implements
39        IPluginContribution {
40    private IWizardDescriptor wizardElement;
41 
42    /**
43     * The wizard dialog width
44     */
45    private static final int SIZING_WIZARD_WIDTH = 500;
46 
47    /**
48     * The wizard dialog height
49     */
50    private static final int SIZING_WIZARD_HEIGHT = 500;
51    
52    private IWorkbenchWindow window;
53 
54    /**
55     * Create an instance of this class.
56     *
57     * @param window the workbench window in which this action will appear
58     * @param wizardDesc a wizard element
59     */
60    public NewWizardShortcutAction(IWorkbenchWindow window,
61            IWizardDescriptor wizardDesc) {
62        super(wizardDesc.getLabel());
63        setToolTipText(wizardDesc.getDescription());
64        setImageDescriptor(wizardDesc.getImageDescriptor());
65        setId(ActionFactory.NEW.getId());
66        wizardElement = wizardDesc;
67        this.window = window;
68    }
69 
70    /**
71     * Get the wizard descriptor for this action.
72     * 
73     * @return the wizard descriptor 
74     */
75    public IWizardDescriptor getWizardDescriptor() {
76                return wizardElement;
77        }
78   
79    /* (non-Javadoc)
80     * @see org.eclipse.jface.action.IAction#run()
81     */
82    public void run() {
83        // create instance of target wizard
84 
85        INewWizard wizard;
86        try {
87            wizard = (INewWizard) wizardElement.createWizard();
88        } catch (CoreException e) {
89            ErrorDialog.openError(window.getShell(), WorkbenchMessages.NewWizardShortcutAction_errorTitle,
90                    WorkbenchMessages.NewWizardShortcutAction_errorMessage,
91                    e.getStatus());
92            return;
93        }
94 
95        ISelection selection = window.getSelectionService().getSelection();
96        IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
97        if (selection instanceof IStructuredSelection) {
98            selectionToPass = wizardElement
99                    .adaptedSelection((IStructuredSelection) selection);
100        } else {
101            // Build the selection from the IFile of the editor
102            IWorkbenchPart part = window.getPartService().getActivePart();
103            if (part instanceof IEditorPart) {
104                IEditorInput input = ((IEditorPart) part).getEditorInput();
105                Class fileClass = LegacyResourceSupport.getFileClass();
106                if (input != null && fileClass != null) {
107                    Object file = Util.getAdapter(input, fileClass);
108                    if (file != null) {
109                        selectionToPass = new StructuredSelection(file);
110                    }
111                }
112            }
113        }
114 
115        // even tho we MAY finish early without showing a dialog, prep the
116                // wizard with a dialog and such in case it's logic requires it
117                // - yes, it wastes a dialog but they are plentiful...
118                wizard.init(window.getWorkbench(), selectionToPass);
119 
120        Shell parent = window.getShell();
121        WizardDialog dialog = new WizardDialog(parent, wizard);
122        dialog.create();
123        Point defaultSize = dialog.getShell().getSize();
124        dialog.getShell().setSize(
125                Math.max(SIZING_WIZARD_WIDTH, defaultSize.x),
126                Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y));
127        window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
128                                IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
129        
130        // if the wizard can finish early and doesn't have any pages, just finish it.
131        if (wizardElement.canFinishEarly() && !wizardElement.hasPages()) {
132                        wizard.performFinish();
133                        dialog.close();
134                } else {
135                        dialog.open();
136                }
137    }
138 
139    /* (non-Javadoc)
140     * @see org.eclipse.ui.IPluginContribution#getLocalId()
141     */
142    public String getLocalId() {
143            IPluginContribution contribution = getPluginContribution();
144            if (contribution != null) {
145                        return contribution.getLocalId();
146                }
147            return wizardElement.getId();
148    }
149 
150    /* (non-Javadoc)
151     * @see org.eclipse.ui.IPluginContribution#getPluginId()
152     */
153    public String getPluginId() {
154            IPluginContribution contribution = getPluginContribution();
155            if (contribution != null) {
156                        return contribution.getPluginId();
157                }
158            return null;
159    }
160    
161    /**
162     * Return the plugin contribution associated with the wizard.
163     * 
164     * @return the contribution or <code>null</code>
165     * @since 3.1
166     */
167    private IPluginContribution getPluginContribution() {
168                return (IPluginContribution) Util.getAdapter(wizardElement,
169                                IPluginContribution.class);
170        }
171}

[all classes][org.eclipse.ui.internal.actions]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov