FileDocCategorySizeDatePackage
OpenWizardAction.javaAPI DocAndroid 1.5 API5431Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt.wizards.actions

OpenWizardAction

public abstract class OpenWizardAction extends Object implements org.eclipse.ui.IWorkbenchWindowActionDelegate
An abstract action that displays one of our wizards. Derived classes must provide the actual wizard to display.

Fields Summary
private static final int
SIZING_WIZARD_WIDTH
The wizard dialog width, extracted from {@link NewWizardShortcutAction}
private static final int
SIZING_WIZARD_HEIGHT
The wizard dialog height, extracted from {@link NewWizardShortcutAction}
Constructors Summary
Methods Summary
public voiddispose()


    
    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
     */
       
        // pass
    
public voidinit(org.eclipse.ui.IWorkbenchWindow window)

        // pass
    
protected abstract org.eclipse.ui.IWorkbenchWizardinstanciateWizard(org.eclipse.jface.action.IAction action)
Called by {@link #run(IAction)} to instantiate the actual wizard.

param
action The action parameter from {@link #run(IAction)}.
return
A new wizard instance. Must not be null.

public voidrun(org.eclipse.jface.action.IAction action)
Opens and display the Android New Project Wizard.

Most of this implementation is extracted from {@link NewWizardShortcutAction#run()}.

see
org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)


        // get the workbench and the current window
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        
        // This code from NewWizardShortcutAction#run() gets the current window selection
        // and converts it to a workbench structured selection for the wizard, if possible.
        ISelection selection = window.getSelectionService().getSelection();
        IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
        if (selection instanceof IStructuredSelection) {
            selectionToPass = (IStructuredSelection) selection;
        } else {
            // Build the selection from the IFile of the editor
            IWorkbenchPart part = window.getPartService().getActivePart();
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                Class<?> fileClass = LegacyResourceSupport.getFileClass();
                if (input != null && fileClass != null) {
                    Object file = Util.getAdapter(input, fileClass);
                    if (file != null) {
                        selectionToPass = new StructuredSelection(file);
                    }
                }
            }
        }

        // Create the wizard and initialize it with the selection
        IWorkbenchWizard wizard = instanciateWizard(action);
        wizard.init(workbench, selectionToPass);
        
        // It's not visible yet until a dialog is created and opened
        Shell parent = window.getShell();
        WizardDialog dialog = new WizardDialog(parent, wizard);
        dialog.create();
        
        // This code comes straight from NewWizardShortcutAction#run()
        Point defaultSize = dialog.getShell().getSize();
        dialog.getShell().setSize(
                Math.max(SIZING_WIZARD_WIDTH, defaultSize.x),
                Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y));
        window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
                IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
        
        dialog.open();
    
public voidselectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection)

        // pass