Example usage for org.eclipse.jface.viewers IStructuredSelection toArray

List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection toArray.

Prototype

public Object[] toArray();

Source Link

Document

Returns the elements in this selection as an array.

Usage

From source file:org.eclipse.contribution.visualiser.internal.help.VisualiserHelp.java

License:Open Source License

/**
 * Creates and returns a help context provider for the given part.
 * /* w w  w .j  av a 2s. co m*/
 * @param part the part for which to create the help context provider
 * @param contextId   the optional context ID used to retrieve static help
 * @return the help context provider 
 */
public static IContextProvider getHelpContextProvider(IWorkbenchPart part, String contextId) {
    IStructuredSelection selection;
    try {
        selection = SelectionConverter.getStructuredSelection(part);
    } catch (JavaModelException ex) {
        selection = StructuredSelection.EMPTY;
    }
    Object[] elements = selection.toArray();
    return new XRefUIHelpContextProvider(contextId, elements);
}

From source file:org.eclipse.core.tools.runtime.ActivePluginsView.java

License:Open Source License

protected void createActions() {
    refreshAction = new Action("Refresh") { //$NON-NLS-1$
        public void run() {
            VMClassloaderInfo.refreshInfos();
            getViewer().refresh();//from w  w  w.ja  v  a2s . c o m
        }
    };
    refreshAction.setImageDescriptor(CoreToolsPlugin.createImageDescriptor("refresh.gif")); //$NON-NLS-1$
    refreshAction.setToolTipText("Refresh the data"); //$NON-NLS-1$
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);

    displayClassesInfoAction = new Action("Classes") { //$NON-NLS-1$
        public void run() {
            try {
                LoadedClassesView view = (LoadedClassesView) getSite().getPage()
                        .showView(LoadedClassesView.VIEW_ID);
                IStructuredSelection selection = ((IStructuredSelection) getViewer().getSelection());
                if (selection == null)
                    return;

                view.setInput(selection.toArray());

            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
    };
    displayClassesInfoAction.setToolTipText("Display classes loaded by the selected plug-in"); //$NON-NLS-1$
    displayClassesInfoAction.setImageDescriptor(CoreToolsPlugin.createImageDescriptor("classes.gif")); //$NON-NLS-1$

    displayStackAction = new Action("Stack &Trace") { //$NON-NLS-1$
        public void run() {
            try {
                StackTraceView view = (StackTraceView) getSite().getPage().showView(StackTraceView.VIEW_ID);
                BundleStats info = (BundleStats) ((IStructuredSelection) getViewer().getSelection())
                        .getFirstElement();
                if (info == null)
                    return;
                view.setInput(StatsManager.TRACE_FILENAME, info.getTraceStart(), info.getTraceEnd());
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
    };
    displayStackAction.setToolTipText("Display the plug-in activation stack trace"); //$NON-NLS-1$
    displayStackAction.setImageDescriptor(CoreToolsPlugin.createImageDescriptor("trace.gif")); //$NON-NLS-1$
}

From source file:org.eclipse.datatools.sqltools.result.internal.ui.actions.SaveResultInstanceAction.java

License:Open Source License

public void update() {
    IStructuredSelection selection = (IStructuredSelection) _provider.getSelection();
    if (selection == null) {
        setEnabled(false);//from   w  ww.j av a 2 s.c  o  m
        return;
    }
    Object[] obj = selection.toArray();
    if (obj == null || obj.length == 0 || obj.length > 1) {
        setEnabled(false);
        return;
    }
    if (!(obj[0] instanceof IResultInstance)) {
        setEnabled(false);
        return;
    }
    setEnabled(true);
}

From source file:org.eclipse.datatools.sqltools.result.internal.ui.actions.SaveResultInstanceAction.java

License:Open Source License

public void run() {
    IStructuredSelection selection = (IStructuredSelection) _provider.getSelection();
    Object[] obj = selection.toArray();
    if (obj == null || obj.length == 0 || obj.length > 1) {
        // should not happen
        return;//from www . j a va2 s .  c om
    }
    IResultInstance instance = (IResultInstance) obj[0];
    FileDialog dialog = new FileDialog(_shell, SWT.SAVE);
    dialog.setText(Messages.SaveResultInstanceAction_save_hisotry_title);

    String filename = ""; //$NON-NLS-1$
    boolean selectAgain = false;
    do {
        filename = dialog.open();
        if (filename == null) {
            return;
        }
        File file = new File(filename);
        if (file.exists()) {
            String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL,
                    IDialogConstants.get().CANCEL_LABEL };
            String question = NLS.bind(Messages.ResultExportWizard_overwrite, new Object[] { filename });
            MessageDialog d = new MessageDialog(_shell, Messages.ResultExportWizard_question, null, question,
                    MessageDialog.QUESTION, buttons, 0);
            int overwrite = d.open();
            switch (overwrite) {
            case 0: // Yes
                selectAgain = false;
                break;
            case 1: // No
                selectAgain = true;
                break;
            case 2: // Cancel
            default:
                return;
            }
        }
    } while (selectAgain);

    try {
        FileOutputStream fos = new FileOutputStream(new File(filename));
        PrintWriter w = new PrintWriter(new BufferedWriter((new OutputStreamWriter(fos, "UTF-8"))));
        printResultInstance(w, instance, "", true);
        w.close();
    } catch (IOException ex) {
        _log.error("SaveResultInstanceAction_cant_export_result_log", ex); //$NON-NLS-1$
        ErrorDialog.openError(_shell, Messages.SaveResultInstanceAction_save_error,
                Messages.SaveResultInstanceAction_can_not_save,
                new Status(IStatus.ERROR, ResultsViewUIPlugin.PLUGIN_ID, 0, ex.getMessage(), ex));
    }
}

From source file:org.eclipse.datatools.sqltools.result.internal.ui.actions.TerminateInstanceAction.java

License:Open Source License

protected boolean updateSelection(IStructuredSelection selection) {
    if (selection == null)
        return false;
    Object[] obj = selection.toArray();
    if (obj == null || obj.length == 0) {
        return false;
    } else {/*from   w w w.  j a va 2s. c  o m*/
        for (int i = 0; i < obj.length; i++) {
            if (obj[i] instanceof IResultInstance) {
                if (((IResultInstance) obj[i])
                        .isFinished()/* || !((IResultInstance) obj[i]).hasTerminateHandler() */) {
                    // finished results
                    return false;
                }
            } else {
                return false;
            }
        }
        // all are running.
        return true;
    }
}

From source file:org.eclipse.datatools.sqltools.result.internal.ui.actions.TerminateInstanceAction.java

License:Open Source License

public void run() {
    IStructuredSelection sel = this.getStructuredSelection();
    if (sel == null) {
        return;/*w  w  w  . ja  va 2  s. co  m*/
    }

    Object[] objs = sel.toArray();
    if (objs != null) {
        for (int i = 0; i < objs.length; i++) {
            if (objs[i] instanceof IResultInstance) {
                ((IResultInstance) objs[i]).terminate();
            }
        }
    }
}

From source file:org.eclipse.datatools.sqltools.sqlbuilder.examples.actions.SQLBuilderDialogDialectTestEditorInputAction.java

License:Open Source License

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 */// ww w .j ava  2s .  c  om
public void selectionChanged(IAction action, ISelection selection) {
    _selectedFile1 = null;
    _selectedFile2 = null;
    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) selection;
        Object[] objs = iss.toArray();
        if (objs.length == 2) {
            if (objs[0] != null && objs[0] instanceof IFile) {
                _selectedFile1 = (IFile) objs[0];
            }
            if (objs[1] != null && objs[1] instanceof IFile) {
                _selectedFile2 = (IFile) objs[1];
            }
        }
    }
}

From source file:org.eclipse.debug.internal.ui.actions.breakpointGroups.GroupBreakpointsByDialog.java

License:Open Source License

/**
 * Moves each selected item down in the tree of selected containers
 *//*from   ww w . j  a  v  a 2 s .c om*/
public void handleMoveDownPressed() {
    IStructuredSelection selection = (IStructuredSelection) fSelectedViewer.getSelection();
    Object[] elements = selection.toArray();
    for (int i = elements.length - 1; i >= 0; i--) {
        fSelectedOrganizersProvider.moveDown(elements[i]);
    }
    updateViewers();
}

From source file:org.eclipse.debug.internal.ui.commands.actions.TerminateAndRemoveAction.java

License:Open Source License

public void runWithEvent(Event event) {
    if (fCanTerminate) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
            if (!MessageDialog.openQuestion(window.getShell(),
                    DebugUIViewsMessages.LaunchView_Terminate_and_Remove_1,
                    DebugUIViewsMessages.LaunchView_Terminate_and_remove_selected__2)) {
                return;
            }/*from  ww  w. j  a v  a 2  s .co m*/
        }
        super.runWithEvent(event);
    } else {
        // don't terminate, just remove
        // TODO: make #getContext() API in next release
        ISelection sel = null;
        if (fMyPart != null) {
            sel = getDebugContextService().getActiveContext(fMyPart.getSite().getId());
        } else {
            sel = getDebugContextService().getActiveContext();
        }
        if (sel instanceof IStructuredSelection) {
            IStructuredSelection ss = (IStructuredSelection) sel;
            postExecute(new Request(), ss.toArray());
        }
    }
}

From source file:org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsViewer.java

License:Open Source License

/**
  * Performs the actual addition of the selected breakpoints to the specified target
  * @param target the target to add the selection of breakpoints to
  * @param selection the selection of breakpoints
  * @return true if the drop occurred, false otherwise
  * @since 3.3/*from   w  w  w .  j a  v a  2 s .c  om*/
  */
public boolean performDrop(Item target, IStructuredSelection selection) {
    if (target == null || selection == null) {
        return false;
    }
    IBreakpoint breakpoint = null;
    Object element = target.getData();
    IBreakpointContainer container = (element instanceof IBreakpointContainer ? (IBreakpointContainer) element
            : getAddableContainer(target));
    if (container == null) {
        return false;
    }
    IBreakpointOrganizer organizer = container.getOrganizer();
    if (organizer instanceof IBreakpointOrganizerDelegateExtension) {
        IBreakpointOrganizerDelegateExtension extension = (IBreakpointOrganizerDelegateExtension) organizer;
        Object[] array = selection.toArray();
        IBreakpoint[] breakpoints = new IBreakpoint[array.length];
        System.arraycopy(array, 0, breakpoints, 0, array.length);
        extension.addBreakpoints(breakpoints, container.getCategory());
    } else {
        for (Iterator iter = selection.iterator(); iter.hasNext();) {
            breakpoint = (IBreakpoint) iter.next();
            organizer.addBreakpoint(breakpoint, container.getCategory());
        }
    }
    expandToLevel(target.getData(), ALL_LEVELS);
    return true;
}