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:net.sourceforge.eclipsefrills.resource.action.OpenAllResultsAction.java

License:Open Source License

/**
 * @see IViewActionDelegate#run(IAction)
 *///from  w ww.ja  v a  2s .co  m
public void run(final IAction action) {
    final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) selection;
        if (!sel.isEmpty()) {
            final List<Object> elements = new ArrayList<Object>(sel.size());
            for (final Object obj : sel.toArray()) {
                if (!(obj instanceof IProject || obj instanceof IFolder)) {
                    elements.add(obj);
                }
            }

            final StructuredSelection selAdapter = new StructuredSelection(elements);
            if (!selAdapter.isEmpty()) {
                final OpenFileAction openAction = new OpenFileAction(
                        viewPart.getSite().getWorkbenchWindow().getActivePage());
                openAction.selectionChanged(selAdapter);
                openAction.run();
            }
        }
    }
}

From source file:net.sourceforge.eclipsefrills.workingset.action.SelectWorkingSetForResultsAction.java

License:Open Source License

@Override
public void run(final IAction action) {
    final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) selection;
        if (!sel.isEmpty()) {
            final IResource[] resources = new IResource[sel.size()];
            int i = 0;
            for (final Object obj : sel.toArray()) {
                resources[i++] = (IResource) obj;
            }/*from   w ww .  j av a 2s.c  o  m*/

            createWorkingSet(resources);
        }
    }
}

From source file:net.sourceforge.eclipsetrader.ats.ui.tradingsystem.wizards.SecuritySelectionPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(3, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    content.setLayout(gridLayout);// www .  jav a2s .c om
    content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setControl(content);

    available = new ListViewer(content, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    gridData.widthHint = 200;
    gridData.heightHint = 250;
    available.getControl().setLayoutData(gridData);
    available.setContentProvider(new ArrayContentProvider());
    available.setLabelProvider(new LabelProvider());
    available.setComparator(comparator);
    available.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            toSelected.setEnabled(event.getSelection() != null && !event.getSelection().isEmpty());
        }
    });

    Composite buttons = new Composite(content, SWT.NONE);
    gridLayout = new GridLayout(1, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    buttons.setLayout(gridLayout);
    buttons.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    toSelected = new Button(buttons, SWT.PUSH);
    toSelected.setImage(ATSPlugin.getImageDescriptor("icons/buttons16/right.gif").createImage());
    toSelected.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) available.getSelection();
            if (selection != null && !selection.isEmpty()) {
                selectedItems.addAll(selection.toList());
                availableItems.removeAll(selection.toList());
                selected.add(selection.toArray());
                available.remove(selection.toArray());
            }
        }
    });
    toSelected.setEnabled(false);

    Button button = new Button(buttons, SWT.PUSH);
    button.setImage(ATSPlugin.getImageDescriptor("icons/buttons16/all-right.gif").createImage());
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selected.add(availableItems.toArray());
            available.remove(availableItems.toArray());
            selectedItems.addAll(availableItems);
            availableItems.clear();
        }
    });

    button = new Button(buttons, SWT.PUSH);
    button.setImage(ATSPlugin.getImageDescriptor("icons/buttons16/all-left.gif").createImage());
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selected.remove(selectedItems.toArray());
            available.add(selectedItems.toArray());
            availableItems.addAll(selectedItems);
            selectedItems.clear();
        }
    });

    toAvailable = new Button(buttons, SWT.PUSH);
    toAvailable.setImage(ATSPlugin.getImageDescriptor("icons/buttons16/left.gif").createImage());
    toAvailable.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) selected.getSelection();
            if (selection != null && !selection.isEmpty()) {
                selectedItems.removeAll(selection.toList());
                availableItems.addAll(selection.toList());
                available.add(selection.toArray());
                selected.remove(selection.toArray());
            }
        }
    });
    toAvailable.setEnabled(false);

    selected = new ListViewer(content, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    gridData.widthHint = 200;
    gridData.heightHint = 250;
    selected.getControl().setLayoutData(gridData);
    selected.setContentProvider(new ArrayContentProvider());
    selected.setComparator(comparator);
    selected.setLabelProvider(new LabelProvider());
    selected.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            toAvailable.setEnabled(event.getSelection() != null && !event.getSelection().isEmpty());
        }
    });

    availableItems = new ArrayList(CorePlugin.getRepository().allSecurities());
    available.setInput(availableItems.toArray());
}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

License:Open Source License

/**
 * Returns the objects which are currently selected. NOTE this is package private and should remain that way - the
 * implementation of the ConnectionsView is now hidden from the rest of the application (see the getSelectedXxxx()
 * methods below for a structured API)/*from  w  w  w .j a v  a  2 s.c om*/
 * 
 * @return
 */
/* package */Object[] getSelected() {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return null;
    }
    Object[] result = selection.toArray();
    if (result.length == 0) {
        return null;
    }
    return result;
}

From source file:net.sourceforge.taggerplugin.action.AddNewTagAssociationAction.java

License:Open Source License

/**
 * Used to extract the taggable items from the selection.
 *
 * @param sel the selection// ww w . j a v a 2  s. c o m
 * @return the taggable items selected
 */
private ITaggable[] extractTaggables(IStructuredSelection sel) {
    final Object[] resources = sel.toArray();
    final ITaggable[] taggables = new ITaggable[resources.length];
    for (int i = 0; i < resources.length; i++) {
        taggables[i] = (ITaggable) ((IResource) (resources[i])).getAdapter(ITaggable.class);
    }
    return (taggables);
}

From source file:net.sourceforge.taggerplugin.action.ClearTagAssociationsAction.java

License:Open Source License

/**
 * @see IObjectActionDelegate#run(IAction)
 *//*from  www .  ja  v a2s. com*/
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) selection;
        if (!sel.isEmpty()) {
            final Object[] selectedObjs = sel.toArray();
            if (deleteConfirmed(selectedObjs.length)) {
                try {
                    for (Object obj : selectedObjs) {
                        final IResource resource = (IResource) obj;
                        final ITaggable taggable = (ITaggable) resource.getAdapter(ITaggable.class);
                        taggable.clearTags();
                    }
                } catch (TagAssociationException tae) {
                    ExceptionDialogFactory.create(workbenchPart.getSite().getShell(), tae).open();
                }
            }
        }
    }
}

From source file:net.sourceforge.taggerplugin.action.CreateWorkingSetFromResultsAction.java

License:Open Source License

/**
 * @see IViewActionDelegate#run(IAction)
 *//*from   w  w  w .j a  v a2  s .  c  om*/
public void run(IAction action) {
    final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) selection;
        if (!sel.isEmpty()) {
            final IResource[] resources = new IResource[sel.size()];
            int i = 0;
            for (Object obj : sel.toArray()) {
                resources[i++] = (IResource) obj;
            }

            createWorkingSet(resources);
        }
    }
}

From source file:net.sourceforge.taggerplugin.action.OpenAllResultsAction.java

License:Open Source License

/**
 * @see IViewActionDelegate#run(IAction)
 *///from   w w  w  . j  a va  2 s  .  c  o m
@SuppressWarnings("unchecked")
public void run(IAction action) {
    final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) selection;
        if (!sel.isEmpty()) {
            final List elements = new ArrayList(sel.size());
            for (Object obj : sel.toArray()) {
                if (!(obj instanceof IProject || obj instanceof IFolder)) {
                    elements.add(obj);
                }
            }

            final StructuredSelection selAdapter = new StructuredSelection(elements);
            if (!selAdapter.isEmpty()) {
                final OpenFileAction openAction = new OpenFileAction(
                        viewPart.getSite().getWorkbenchWindow().getActivePage());
                openAction.selectionChanged(selAdapter);
                openAction.run();
            }
        }
    }
}

From source file:net.sourceforge.taggerplugin.search.TagSearchInput.java

License:Open Source License

TagSearchInput(String[] tagIds, boolean required, final ISearchPageContainer container) {
    super();/* w  ww  .j a  v a2s . c  o  m*/
    this.tagIds = tagIds;
    this.required = required;

    this.scope = container.getSelectedScope();
    if (scope == ISearchPageContainer.SELECTED_PROJECTS_SCOPE) {
        this.projectNames = container.getSelectedProjectNames();
    } else if (scope == ISearchPageContainer.WORKING_SET_SCOPE) {
        this.workingSets = container.getSelectedWorkingSets();
    } else if (scope == ISearchPageContainer.SELECTION_SCOPE) {
        final ISelection selection = container.getSelection();
        if (selection instanceof IStructuredSelection) {
            final IStructuredSelection iss = (IStructuredSelection) selection;
            this.selectedResources = new IResource[iss.size()];
            int i = 0;
            for (Object obj : iss.toArray()) {
                selectedResources[i++] = (IResource) obj;
            }
        }
    } else {
        // workspace scope -- nothing special
    }
}

From source file:net.sourceforge.tagsea.core.ui.waypoints.OpenWaypointDialog.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {

    IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
    Object[] selection = structuredSelection.toArray();

    if (selection.length > 0) {
        selectedWaypoints = new IWaypoint[selection.length];

        for (int i = 0; i < selection.length; i++) {
            if (selection[i] instanceof IWaypoint)
                selectedWaypoints[i] = (IWaypoint) selection[i];
            else if (selection[i] instanceof WaypointWrapper) {
                selectedWaypoints[i] = (IWaypoint) ((WaypointWrapper) (selection[i]))
                        .getAdapter(IWaypoint.class);
            }/*from  ww  w .j ava  2  s .  co m*/
        }
    } else {
        selectedWaypoints = null;
    }
}