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.dawb.workbench.ui.diffraction.table.DiffractionDelegate.java

License:Open Source License

/**
 * /* www. j a  v a  2s  . c o  m*/
 * @param parent
 *           composite
 * @param pathsList
 *           list of all paths images to be displayed in the table viewer
 * @param service
 *           service loader, can be null
 */
public DiffractionDelegate(Composite parent, List<String> pathsList, DiffractionDataManager manager) {

    viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    this.parent = parent;
    this.pathsList = pathsList;
    this.table = viewer.getTable();
    this.manager = manager;

    initialize();
    createColumns(viewer);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setToolTipText("How to use Diffraction Calibration View:\n"
            + "1. Drag/drop or double click your calibration file to add it.\n" + "2. Choose the calibrant\n"
            + "3. Select the rings to use.\n" + "4. Run the calibration.");

    viewer.setContentProvider(new DiffCalContentProvider());
    viewer.setLabelProvider(new DiffCalLabelProvider());
    viewer.setInput(manager);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final MenuManager mgr = new MenuManager();
    mgr.setRemoveAllWhenShown(true);
    mgr.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object[] selected = selection.toArray();
            if (selected.length > 0) {
                if (selected.length == 1) {
                    deleteAction.setText(
                            "Delete " + ((DiffractionTableData) selection.getFirstElement()).getName());
                    mgr.add(deleteAction);
                } else {
                    deleteAction.setText("Delete " + selected.length + " images selected");
                    mgr.add(deleteAction);
                }
            }
        }
    });
    viewer.getControl().setMenu(mgr.createContextMenu(viewer.getControl()));
    // add drop support
    DropTarget dt = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_DEFAULT | DND.DROP_COPY);
    dt.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance(),
            ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() });
    dt.addDropListener(dropListener);

    //      Label infoEditableLabel = new Label(parent, SWT.NONE);
    //      infoEditableLabel.setText("* Click to change value");
}

From source file:org.dawnsci.usagedata.internal.ui.preview.UploadPreview.java

License:Open Source License

String getFilterSuggestionBasedOnMultipleSelection(IStructuredSelection selection) {
    String[] names = new String[selection.size()];
    int index = 0;
    for (Object event : selection.toArray()) {
        names[index++] = ((UsageDataEventWrapper) event).getBundleId();
    }//www .j  a  v a 2s .  c om
    return FilterUtils.getFilterSuggestionBasedOnBundleIds(names);
}

From source file:org.dyno.visual.swing.base.FieldProperty.java

License:Open Source License

@Override
public void setPropertyValue(IStructuredSelection bean, Object value) {
    assert !bean.isEmpty();
    if (isEditable()) {
        try {/*from w ww . ja va  2 s  .co  m*/
            if (editorFactory != null)
                value = editorFactory.decodeValue(value);
            else {
                Class type = lastValue.getClass();
                TypeAdapter ta = ExtensionRegistry.getTypeAdapter(type);
                value = ta.getEditor().decodeValue(value);
            }
            for (Object b : bean.toArray()) {
                field.set(b, value);
                if (b instanceof Component) {
                    Component jcomp = (Component) b;
                    WidgetAdapter adapter = WidgetAdapter.getWidgetAdapter(jcomp);
                    if (adapter != null) {
                        adapter.repaintDesigner();
                    }
                }
            }
        } catch (Exception e) {
            VisualSwingPlugin.getLogger().error(e);
        }
    }
}

From source file:org.dyno.visual.swing.base.WidgetProperty.java

License:Open Source License

@Override
public void setPropertyValue(IStructuredSelection bean, Object value) {
    assert !bean.isEmpty();
    if (isEditable()) {
        try {/*w w  w  .  j  av a2  s . co m*/
            if (editorFactory != null)
                value = editorFactory.decodeValue(value);
            else {
                Class type = lastValue.getClass();
                TypeAdapter ta = ExtensionRegistry.getTypeAdapter(type);
                value = ta.getEditor().decodeValue(value);
            }
            for (Object b : bean.toArray()) {
                IUndoableOperation operation = new SetValueOperation(b, this, value);
                IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport()
                        .getOperationHistory();
                if (b instanceof Component) {
                    Component jcomp = (Component) b;
                    WidgetAdapter adapter = WidgetAdapter.getWidgetAdapter(jcomp);
                    if (adapter != null) {
                        operation.addContext(adapter.getUndoContext());
                    }
                }
                operationHistory.execute(operation, null, null);
            }
        } catch (Exception e) {
            VisualSwingPlugin.getLogger().error(e);
        }
    }
}

From source file:org.ebayopensource.vjet.eclipse.internal.ui.actions.AddVjoNatureAction.java

License:Open Source License

private void doAddNature() {
    if (!(selection instanceof IStructuredSelection))
        return;// w  w w .  j  a  v  a2s . c  o  m

    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Object[] selectionElements = structuredSelection.toArray();
    for (int i = 0; i < selectionElements.length; i++) {
        Object selectionElement = selectionElements[i];
        if (selectionElement instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) selectionElement;
            IProject project = (IProject) adaptable.getAdapter(IProject.class);
            if (project == null)
                continue;

            //fetch the corresponding adding vjo nature policy implementation
            IAddVjoNaturePolicy policy = AddVjoNaturePolicyManager.getInstance().getPolicy(project);
            policy.addVjoNature(project);
        }
    }

}

From source file:org.ebayopensource.vjet.eclipse.internal.ui.actions.VjoValidationAction.java

License:Open Source License

public void run(IAction action) {
    if (!(selection instanceof IStructuredSelection))
        return;/*ww  w. j  ava 2s.c o m*/

    if (!TypeSpaceMgr.getInstance().isLoaded())
        return;

    ScriptProject sProject = null;

    for (IProject project : this.m_project) {
        sProject = CodeassistUtils.getScriptProject(project.getName());
        if (sProject == null)
            return;
        ArrayList<ISourceModule> selectedSourceModules = new ArrayList<ISourceModule>();
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object[] selectionElements = structuredSelection.toArray();
        for (int i = 0; i < selectionElements.length; i++) {
            Object selectionElement = selectionElements[i];
            if (selectionElement instanceof IFile) {
                addSourceModules(selectedSourceModules, (IResource) selectionElement, sProject);
            } else if (selectionElement instanceof IFolder) {
                getFilesFromFolder(selectedSourceModules, (IFolder) selectionElement, sProject);
            } else {
                getAllFilesFromProject(selectedSourceModules, sProject);
            }
        }

        new VJetValidateBuildJob(DLTKUIMessages.CoreUtility_job_title, project, selectedSourceModules)
                .schedule();
    }
}

From source file:org.eclipse.ajdt.internal.ui.editor.actions.AJOrganizeImportsAction.java

License:Open Source License

private ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) {
    HashSet result = new HashSet();
    Object[] selected = selection.toArray();
    for (int i = 0; i < selected.length; i++) {
        try {// w w w.j  av  a  2 s.  c  o  m
            if (selected[i] instanceof IJavaElement) {
                IJavaElement elem = (IJavaElement) selected[i];
                if (elem.exists()) {

                    switch (elem.getElementType()) {
                    case IJavaElement.TYPE:
                        if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
                            result.add(elem.getParent());
                        }
                        break;
                    case IJavaElement.COMPILATION_UNIT:
                        result.add(elem);
                        break;
                    case IJavaElement.IMPORT_CONTAINER:
                        result.add(elem.getParent());
                        break;
                    case IJavaElement.PACKAGE_FRAGMENT:
                        collectCompilationUnits((IPackageFragment) elem, result);
                        break;
                    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                        collectCompilationUnits((IPackageFragmentRoot) elem, result);
                        break;
                    case IJavaElement.JAVA_PROJECT:
                        IPackageFragmentRoot[] roots = ((IJavaProject) elem).getPackageFragmentRoots();
                        for (int k = 0; k < roots.length; k++) {
                            collectCompilationUnits(roots[k], result);
                        }
                        break;
                    }
                }
            } else if (selected[i] instanceof LogicalPackage) {
                IPackageFragment[] packageFragments = ((LogicalPackage) selected[i]).getFragments();
                for (int k = 0; k < packageFragments.length; k++) {
                    IPackageFragment pack = packageFragments[k];
                    if (pack.exists()) {
                        collectCompilationUnits(pack, result);
                    }
                }
            }
        } catch (JavaModelException e) {
            if (JavaModelUtil.isExceptionToBeLogged(e))
                JavaPlugin.log(e);
        }
    }
    return (ICompilationUnit[]) result.toArray(new ICompilationUnit[result.size()]);
}

From source file:org.eclipse.ajdt.internal.ui.editor.actions.AJOrganizeImportsAction.java

License:Open Source License

private boolean isEnabled(IStructuredSelection selection) {
    Object[] selected = selection.toArray();
    for (int i = 0; i < selected.length; i++) {
        try {//from  w w  w.  j a  v  a2  s  . c o  m
            if (selected[i] instanceof IJavaElement) {
                IJavaElement elem = (IJavaElement) selected[i];
                if (elem.exists()) {
                    switch (elem.getElementType()) {
                    case IJavaElement.TYPE:
                        return elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT; // for browsing perspective
                    case IJavaElement.COMPILATION_UNIT:
                        return true;
                    case IJavaElement.IMPORT_CONTAINER:
                        return true;
                    case IJavaElement.PACKAGE_FRAGMENT:
                    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                        IPackageFragmentRoot root = (IPackageFragmentRoot) elem
                                .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
                        return (root.getKind() == IPackageFragmentRoot.K_SOURCE);
                    case IJavaElement.JAVA_PROJECT:
                        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638
                        return true;
                    }
                }
            } else if (selected[i] instanceof LogicalPackage) {
                return true;
            }
        } catch (JavaModelException e) {
            if (!e.isDoesNotExist()) {
                JavaPlugin.log(e);
            }
        }
    }
    return false;
}

From source file:org.eclipse.ajdt.internal.ui.help.AspectJUIHelp.java

License:Open Source License

/**
 * Creates and returns a help context provider for the given part.
 * //from  w w  w .  j  av  a2 s. c o 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 AspectJUIHelpContextProvider(contextId, elements);
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoringAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    currStatus = new RefactoringStatus();
    currSelection = new PullOutRefactoring();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection extended = (IStructuredSelection) selection;
        Object[] elements = extended.toArray();
        for (int i = 0; i < elements.length; i++) {
            if (elements[i] instanceof IMethod || elements[i] instanceof IField) {
                currSelection.addMember((IMember) elements[i], currStatus);
            }/* w ww.  j a v  a 2 s  .  c  o  m*/
        }
    } else if (selection instanceof ITextSelection) {
        if (editor != null) {
            ITextSelection textSel = (ITextSelection) selection;
            CompilationUnitDocumentProvider provider = (CompilationUnitDocumentProvider) editor
                    .getDocumentProvider();
            ICompilationUnit unit = provider.getWorkingCopy(editor.getEditorInput());
            if (unit != null) {
                List<IJavaElement> candidates = SelectionUtil.findSelectedElements(unit, textSel);
                for (IJavaElement candidate : candidates) {
                    if (candidate != null && (candidate instanceof IMethod || candidate instanceof IField)) {
                        currSelection.addMember((IMember) candidate, currStatus);
                    }
                }
            }
        }
    }
    action.setEnabled(currSelection.hasMembers());
    if (window == null) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        window = workbench.getActiveWorkbenchWindow();
    }
}