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:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.CutAction.java

License:Open Source License

@Override
public void run(IStructuredSelection selection) {
    try {/*from   www .  j  a v a 2  s  .  c o  m*/
        selectionChanged(selection);
        if (isEnabled()) {
            fCopyToClipboardAction.run(selection);
            RefactoringExecutionStarter.startCutRefactoring(selection.toArray(), getShell());
        }
    } catch (InterruptedException e) {
        //OK
    } catch (InvocationTargetException e) {
        ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring,
                RefactoringMessages.OpenRefactoringWizardAction_exception);
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteAction.java

License:Open Source License

@Override
public void selectionChanged(IStructuredSelection selection) {
    if (ReorgUtils.containsOnlyProjects(selection.toList())) {
        setEnabled(createWorkbenchAction(selection).isEnabled());
        return;/*from   w  ww .  ja  v  a2  s.co  m*/
    }
    setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray()));
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteAction.java

License:Open Source License

@Override
public void run(IStructuredSelection selection) {
    if (ReorgUtils.containsOnlyProjects(selection.toList())) {
        createWorkbenchAction(selection).run();
        return;//w  w  w .  ja v  a 2  s  .co  m
    }
    if (ReorgUtils.containsOnlyWorkingSets(selection.toList())) {
        deleteWorkingSets(selection);
        return;
    }
    try {
        RefactoringExecutionStarter.startDeleteRefactoring(selection.toArray(), getShell());
    } catch (CoreException e) {
        ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring,
                RefactoringMessages.OpenRefactoringWizardAction_exception);
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.RenameSelectionState.java

License:Open Source License

public void restore(Object newElement) {
    if (fDisplay == null)
        return;//  w ww.  j  a v  a  2  s  .  c om
    for (int i = 0; i < fParts.size(); i++) {
        IStructuredSelection currentSelection = fSelections.get(i);
        boolean changed = false;
        final ISetSelectionTarget target = (ISetSelectionTarget) fParts.get(i);
        final IStructuredSelection[] newSelection = new IStructuredSelection[1];
        newSelection[0] = currentSelection;
        if (currentSelection instanceof TreeSelection) {
            TreeSelection treeSelection = (TreeSelection) currentSelection;
            TreePath[] paths = treeSelection.getPaths();
            for (int p = 0; p < paths.length; p++) {
                TreePath path = paths[p];
                if (path.getSegmentCount() > 0 && path.getLastSegment().equals(fElement)) {
                    paths[p] = createTreePath(path, newElement);
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new TreeSelection(paths, treeSelection.getElementComparer());
            }
        } else {
            Object[] elements = currentSelection.toArray();
            for (int e = 0; e < elements.length; e++) {
                if (elements[e].equals(fElement)) {
                    elements[e] = newElement;
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new StructuredSelection(elements);
            }
        }
        if (changed) {
            fDisplay.asyncExec(new Runnable() {
                public void run() {
                    target.selectReveal(newSelection[0]);
                }
            });
        }
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.workingsets.AbstractWorkingSetWizardPage.java

License:Open Source License

/**
 * Moves selected elements in the tree into the table
 *///from  w  w w  .jav  a  2s. c  o m
private void addTreeSelection() {
    IStructuredSelection selection = (IStructuredSelection) fTree.getSelection();
    fSelectedElements.addAll(selection.toList());
    Object[] selectedElements = selection.toArray();
    fTable.add(selectedElements);
    fTree.remove(selectedElements);
    fTable.setSelection(selection);
    fTable.getControl().setFocus();
    validateInput();
}

From source file:ext.org.eclipse.jdt.internal.ui.workingsets.AbstractWorkingSetWizardPage.java

License:Open Source License

/**
 * Moves the selected elements in the table into the tree
 *///www  .  j  a v  a 2 s  .co  m
private void removeTableSelection() {
    IStructuredSelection selection = (IStructuredSelection) fTable.getSelection();
    fSelectedElements.removeAll(selection.toList());
    Object[] selectedElements = selection.toArray();
    fTable.remove(selectedElements);
    try {
        fTree.getTree().setRedraw(false);
        for (int i = 0; i < selectedElements.length; i++) {
            fTree.refresh(fTreeContentProvider.getParent(selectedElements[i]), true);
        }
    } finally {
        fTree.getTree().setRedraw(true);
    }
    fTree.setSelection(selection);
    fTree.getControl().setFocus();
    validateInput();
}

From source file:ext.org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetPage.java

License:Open Source License

private Object[] getInitialTreeSelection() {
    final Object[][] result = new Object[1][];
    BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
        public void run() {
            IStructuredSelection selection = fInitialSelection;
            if (selection == null) {

                IWorkbenchPage page = JavaPlugin.getActivePage();
                if (page == null)
                    return;

                IWorkbenchPart part = page.getActivePart();
                if (part == null)
                    return;

                try {
                    selection = SelectionConverter.getStructuredSelection(part);
                } catch (JavaModelException e) {
                    return;
                }//from w  w  w .  j  a  va2  s . co m
            }

            Object[] elements = selection.toArray();
            for (int i = 0; i < elements.length; i++) {
                if (elements[i] instanceof IResource) {
                    IJavaElement je = (IJavaElement) ((IResource) elements[i]).getAdapter(IJavaElement.class);
                    if (je != null && je.exists() && je.getJavaProject().isOnClasspath((IResource) elements[i]))
                        elements[i] = je;
                }
            }
            result[0] = elements;
        }
    });

    if (result[0] == null)
        return new Object[0];

    return result[0];
}

From source file:fable.framework.ui.editors.ColumnFilePlotEditor.java

License:Open Source License

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (part != this) {
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection sSelection = (IStructuredSelection) selection;

            Object first = sSelection.getFirstElement();
            Object[] list = sSelection.toArray();
            // System.out.println("user has selected: " + first);
            if (first instanceof float[]) {
                float[] r = (float[]) first;
                double[] indices = null;
                if (columnInput.getColumn() != null) {
                    int indexColumnId = columnInput.getColumn().getColumnIDIndex();
                    if (list.length > 1 && indexColumnId >= 0) {

                        indices = new double[list.length];

                        for (int j = 0; j < list.length; j++) {

                            indices[j] = (double) ((float[]) list[j])[indexColumnId];
                        }/*from  w w  w .jav  a 2  s . c  o m*/
                    } else if (indexColumnId >= 0) {
                        indices = new double[1];
                        indices[0] = (double) r[indexColumnId];

                    }

                    // Now you have to color the selected spot
                    // get its spot_id
                    if (indices != null && indices.length > 0) {
                        xyplot.markSelectedRows(indices, columnInput.getColumn().getColumnfileId());
                    }
                }
            }

        }
    }

}

From source file:fable.imageviewer.component.ImageComponent.java

License:Open Source License

/**
 * This method receives selectionEvents from the workbench. This is
 * currently used for PeakSearch and its spt output file. When a user
 * selects a peak in a TableViewer and if the selection is a instance of
 * <code>PeakSearchSpt</code> or an instance of <code>Peak</code>, spots are
 * displayed in the image.//from   ww  w . j  a  va  2 s. c  om
 * 
 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
 *      org.eclipse.jface.viewers.ISelection)
 */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    // DEBUG
    // System.out.println("\n>>>Entering selectionChanged");
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        Object first = sSelection.getFirstElement();
        Object[] selections = sSelection.toArray();
        // DEBUG
        // System.out.println("Check selection");
        if (first instanceof PeakSearchSpt) {
            // Only do this for the main or zoom secondaryId
            String id2 = getSecondaryId();
            if (id2 == null
                    || (!id2.equals(ImageComponent.SECONDARY_ID_MAIN) && !id2.equals(SECONDARY_ID_ZOOM))) {
                return;
            }
            PeakSearchSpt peakFile = ((PeakSearchSpt) first);
            if (peakFile.getImageFile() != null) {
                if (id2.equals(SECONDARY_ID_MAIN)) {
                    try {
                        this.loadModel(ImageModelFactory.getImageModel(peakFile.getImageFile()));
                    } catch (Throwable e) {
                        FableLogger.error("Cannot load file " + peakFile.getFabioFileName(), e);
                    }
                }
                setPeaksOn(true);
                image.displayImage();
                // Show peaks if there are some peaks
                Vector<Float> vals = peakFile.getTabChildren();
                if (vals != null) {
                    setPeaks(vals);
                    image.showPeaks();
                }
            }
        } else if (first instanceof Peak) {
            // Only do this for the main or zoom secondaryId
            String id2 = getSecondaryId();
            if (id2 == null || (!id2.equals(SECONDARY_ID_MAIN) && !id2.equals(SECONDARY_ID_ZOOM))) {
                return;
            }
            PeakSearchSpt parent = ((Peak) first).getParent();
            int nPeaksToDisplay = selections.length;

            float[] coloredPeak = new float[nPeaksToDisplay * 2];
            int j;
            int k = 0;
            for (int ip = 0; ip < selections.length; ip++) {
                Peak peak = (Peak) selections[ip];
                if (peak.isVisible()) {
                    j = k + 1;
                    coloredPeak[k] = Float.valueOf(peak.getS());
                    coloredPeak[j] = Float.valueOf(peak.getF());
                    k += 2;
                }
            }
            Vector<Float> vals = parent.getTabChildren();
            if (vals != null) {
                setPeaks(vals);
            }
            setPeaksOn(true);
            // Draw peaks in red with selected peaks in green
            image.showSelectedPeaks(coloredPeak);
        }
    }

}

From source file:fede.workspace.tool.view.actions.AddLink.java

License:Apache License

public void selectionChanged(IAction action, ISelection selection) {
    item_source = null;//from   w w  w. jav a  2  s . c o m
    item_dest = null;
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() != 2)
            return;
        Object obj[] = ssel.toArray();
        if (obj[0] instanceof ItemInViewer) {
            this.item_source = ((ItemInViewer) obj[0]);
        }
        if (obj[1] instanceof ItemInViewer) {
            this.item_dest = ((ItemInViewer) obj[1]);
        }
    }
    action.setEnabled(item_source != null && item_source.getItem() != null && item_dest != null
            && item_dest.getItem() != null
            && !(item_source.getItem().isReadOnly() && item_dest.getItem().isReadOnly()));
}