Example usage for org.eclipse.jface.viewers StructuredSelection EMPTY

List of usage examples for org.eclipse.jface.viewers StructuredSelection EMPTY

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection EMPTY.

Prototype

StructuredSelection EMPTY

To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.

Click Source Link

Document

The canonical empty selection.

Usage

From source file:cn.ieclipse.adt.ext.actions.OpenWizardAction.java

License:Apache License

public void run(IAction action) {
    IWorkbench workbench = (this.mWorkbench != null) ? this.mWorkbench : PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

    ISelection selection = this.mSelection;
    if (selection == null) {
        selection = window.getSelectionService().getSelection();
    }/*from  w  ww.  j av  a 2 s  .c  o  m*/

    IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
    if (selection instanceof IStructuredSelection) {
        selectionToPass = (IStructuredSelection) selection;
    } else {
        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);
                }
            }

        }

    }

    this.mWizard = instanciateWizard(action);
    this.mWizard.init(workbench, selectionToPass);

    Shell parent = window.getShell();
    WizardDialog dialog = new WizardDialog(parent, this.mWizard);
    dialog.create();

    // Point defaultSize = dialog.getShell().getSize();
    // dialog.getShell().setSize(
    // Math.max(500, defaultSize.x),
    // Math.max(500, defaultSize.y));
    window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
            "org.eclipse.ui.new_wizard_shortcut_context");

    this.mDialogResult = dialog.open();
}

From source file:com.android.ide.eclipse.adt.internal.wizards.actions.OpenWizardAction.java

License:Open Source License

/**
 * Opens and display the Android New Project Wizard.
 * <p/>/*ww  w .  ja  va 2s  .co m*/
 * Most of this implementation is extracted from {@link NewWizardShortcutAction#run()}.
 *
 * @param action The action that got us here. Can be null when used internally.
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 */
@Override
public void run(IAction action) {

    // get the workbench and the current window
    IWorkbench workbench = mWorkbench != null ? mWorkbench : 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 = mSelection;
    if (selection == null) {
        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
    mWizard = instanciateWizard(action);
    mWizard.init(workbench, selectionToPass);

    // It's not visible yet until a dialog is created and opened
    Shell parent = window.getShell();
    WizardDialogEx dialog = new WizardDialogEx(parent, mWizard);
    dialog.create();

    if (mWizard instanceof IUpdateWizardDialog) {
        ((IUpdateWizardDialog) mWizard).updateWizardDialog(dialog);
    }

    // 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);

    mDialogResult = dialog.open();
}

From source file:com.android.ide.eclipse.adt.wizards.actions.OpenWizardAction.java

License:Open Source License

/**
 * Opens and display the Android New Project Wizard.
 * <p/>// w  w w .  ja  v a  2  s . co  m
 * Most of this implementation is extracted from {@link NewWizardShortcutAction#run()}.
 * 
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 */
public void run(IAction action) {

    // 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();
}

From source file:com.apicloud.navigator.ui.editors.APICloudWizardEditor.java

License:Open Source License

protected void registerWizardFunction(final UZWizardComposite browserComposite) {
    browserComposite.registerFunction("create", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            CreateAPICloudProjectWizard wizard = new CreateAPICloudProjectWizard();
            wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
            WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
            dialog.create();//from   w  w  w . j ava  2 s.c o m
            dialog.open();
            return null;
        }
    });

    browserComposite.registerFunction("importApp", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            ImportExportWizard wizard = new ImportExportWizard(ImportExportWizard.IMPORT);
            wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);

            IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault().getDialogSettings();
            IDialogSettings wizardSettings = workbenchSettings.getSection("ImportExportAction"); //$NON-NLS-1$
            if (wizardSettings == null) {
                wizardSettings = workbenchSettings.addNewSection("ImportExportAction"); //$NON-NLS-1$
            }
            wizard.setDialogSettings(wizardSettings);
            wizard.setForcePreviousAndNextButtons(true);

            WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
            dialog.open();
            return null;
        }
    });

    browserComposite.registerFunction("openurl", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            String url = (String) arguments[0];

            if (url != null && !url.equals("")) {
                openUrl(url);
            }

            return null;
        }

        private void openUrl(String url) {
            Desktop desktop = Desktop.getDesktop();
            if ((Desktop.isDesktopSupported()) && (desktop.isSupported(Desktop.Action.BROWSE))) {
                try {
                    URI uri = new URI(url);
                    desktop.browse(uri);
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });

}

From source file:com.appnativa.studio.properties.PropertySheetViewer.java

License:Open Source License

/**
 * The <code>PropertySheetViewer</code> implementation of this
 * <code>ISelectionProvider</code> method returns the result as a
 * <code>StructuredSelection</code>.
 * <p>/*  w  ww .  j  a  v a  2 s. c om*/
 * Note that this method only includes <code>IPropertySheetEntry</code> in
 * the selection (no categories).
 * </p>
 */
public ISelection getSelection() {
    if (tree.getSelectionCount() == 0) {
        return StructuredSelection.EMPTY;
    }

    TreeItem[] sel = tree.getSelection();
    List entries = new ArrayList(sel.length);

    for (int i = 0; i < sel.length; i++) {
        TreeItem ti = sel[i];
        Object data = ti.getData();

        if (data instanceof IPropertySheetEntry) {
            entries.add(data);
        }
    }

    return new StructuredSelection(entries);
}

From source file:com.aptana.deploy.internal.ui.handlers.RunDeployWizardHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = StructuredSelection.EMPTY;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof IEditorPart) {
        IEditorInput editorInput = ((IEditorPart) activePart).getEditorInput();
        if (editorInput instanceof IFileEditorInput) {
            selection = new StructuredSelection(((IFileEditorInput) editorInput).getFile());
        }//from   w  w  w  . j  ava2s.  c o m
    } else {
        selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    }

    // Instantiates and initializes the wizard
    DeployWizard wizard = new DeployWizard();
    wizard.init(activePart.getSite().getWorkbenchWindow().getWorkbench(), selection);
    wizard.setWindowTitle(Messages.DeployHandler_Wizard_Title);
    IDialogSettings workbenchSettings = DeployUIPlugin.getDefault().getDialogSettings();
    IDialogSettings wizardSettings = workbenchSettings.getSection(DEPLOY_WIZARD_SECTION);
    if (wizardSettings == null) {
        wizardSettings = workbenchSettings.addNewSection(DEPLOY_WIZARD_SECTION);
    }
    wizard.setDialogSettings(wizardSettings);
    wizard.setForcePreviousAndNextButtons(true);

    // Instantiates the wizard container with the wizard and opens it
    Shell shell = activePart.getSite().getShell();
    if (shell == null) {
        shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    }
    // FIXME Don't use this special dialog! move ILoginValidator stuff to page change listener stuff when necessary!
    DeployWizardDialog dialog = new DeployWizardDialog(shell, wizard);
    dialog.setPageSize(350, 500);
    dialog.setHelpAvailable(false);
    dialog.create();
    dialog.open();

    return null;
}

From source file:com.aptana.editor.common.outline.CommonOutlinePage.java

License:Open Source License

@Override
public ISelection getSelection() {
    if (fTreeViewer == null) {
        return StructuredSelection.EMPTY;
    }//  ww  w.jav a 2 s  .  c o  m
    return fTreeViewer.getSelection();
}

From source file:com.aptana.editor.common.outline.CommonQuickOutlinePage.java

License:Open Source License

@Override
public ISelection getSelection() {
    if (getTreeViewer() == null) {
        return StructuredSelection.EMPTY;
    }//from   www. j a  va  2 s.com
    return getTreeViewer().getSelection();
}

From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Refreshes the dialog - has to be called in UI thread.
 *///from  www.j  av a2s  .  c  o  m
public void refresh() {
    if (list != null && !list.getTable().isDisposed()) {

        List<?> lastRefreshSelection = ((StructuredSelection) list.getSelection()).toList();

        list.setItemCount(contentProvider.getElements(null).length);
        list.refresh();

        if (list.getTable().getItemCount() > 0) {
            // preserve previous selection
            if (refreshWithLastSelection && lastRefreshSelection != null && lastRefreshSelection.size() > 0) {
                list.setSelection(new StructuredSelection(lastRefreshSelection));
            } else {
                refreshWithLastSelection = true;
                list.getTable().setSelection(0);
                list.getTable().notifyListeners(SWT.Selection, new Event());
            }
        } else {
            list.setSelection(StructuredSelection.EMPTY);
        }

    }

    scheduleProgressMessageRefresh();
}

From source file:com.aptana.explorer.internal.ui.SingleProjectView.java

License:Open Source License

/**
 * @param oldProject/* w  ww.  j a v  a 2 s.co  m*/
 * @param newProject
 */
protected void projectChanged(IProject oldProject, IProject newProject) {
    // Set project pulldown
    String newProjectName = ""; //$NON-NLS-1$
    if (newProject != null && newProject.exists()) {
        newProjectName = newProject.getName();
    }
    projectToolItem.setText(newProjectName);
    MenuItem[] menuItems = projectsMenu.getItems();
    for (MenuItem menuItem : menuItems) {
        menuItem.setSelection(menuItem.getText().equals(newProjectName));
    }
    getCommonViewer().setInput(newProject);
    if (newProject == null) {
        // Clear the selection when there is no active project so the menus
        // get updated correctly
        getCommonViewer().setSelection(StructuredSelection.EMPTY);
    }
}