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

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

Introduction

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

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:net.bioclipse.qsar.ui.editors.DescriptorsPage.java

License:Open Source License

/**
 * Handle the case when users press the ADD button next to moleculeviewer
 *//*from   ww  w. j ava  2s.  c o  m*/
protected void addSelectedDescriptors() {

    List<String> errorList = new ArrayList<String>();

    IStructuredSelection ssel = (IStructuredSelection) descViewer.getSelection();
    for (Object obj : ssel.toList()) {

        if (obj instanceof Descriptor) {
            Descriptor desc = (Descriptor) obj;

            //Find out impl
            //            DescriptorImpl impl2 = qsar.getDescriptorByID(desc.getId());
            DescriptorImpl impl = qsar.getPreferredImpl(desc.getId());
            if (impl != null) {

                QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();
                qsar.addDescriptorToModel(qsarModel, editingDomain, desc, impl);

            } else {
                errorList.add("No implementation available for descriptor: " + desc);
            }
        }
    }

    if (errorList.size() > 0) {
        String errormsgs = "The following errors occured:\n\n";
        for (String str : errorList) {
            errormsgs = errormsgs + str + "\n";
        }
    }

    //       rightViewer.setInput(descriptorList.eContents().toArray());

}

From source file:net.bioclipse.qsar.ui.editors.DescriptorsPage.java

License:Open Source License

/**
  * Handle the case when users press the Remove button next to moleculeviewer
  * or presses the delete button on something
  *//*from w ww.  ja  v a 2 s. c  o  m*/
protected void deleteSelectedDescriptors() {

    IStructuredSelection ssel = (IStructuredSelection) rightViewer.getSelection();

    QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();
    qsar.removeDescriptorsFromModel(qsarModel, editingDomain, ssel.toList());

}

From source file:net.bioclipse.qsar.ui.editors.MoleculesPage.java

License:Open Source License

private void addDragAndDrop() {
    int ops = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() };
    molViewer.addDropSupport(ops, transfers, new ViewerDropAdapter(molViewer) {

        @Override//w  w  w. j  av  a  2s  .  co m
        public boolean performDrop(Object data) {

            if (!((data instanceof String[]) || (data instanceof IStructuredSelection))) {
                return false;
            }

            final Object indata = data;

            WorkspaceJob job = new WorkspaceJob("Adding resources to QSAR project") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

                    List<IResource> resources = new ArrayList<IResource>();

                    //Handle selections within Bioclipse
                    if (indata instanceof String[]) {

                        List<IResource> newRes = handleDropOfFiles((String[]) indata, monitor);
                        if (newRes != null && newRes.size() > 0)
                            resources.addAll(newRes);
                    }

                    //Handle selections within Bioclipse
                    else if (indata instanceof IStructuredSelection) {

                        IStructuredSelection ssel = (IStructuredSelection) indata;
                        for (Object obj : ssel.toList()) {
                            if (obj instanceof IResource) {
                                IResource res = (IResource) obj;
                                resources.add(res);
                            }
                        }
                    }

                    //If none, return error
                    if (resources.size() <= 0)
                        return Status.CANCEL_STATUS;

                    //Add resources to model and molecules folder is necessary
                    try {
                        addResources(resources.toArray(new IResource[0]), monitor);
                    } catch (final UnsupportedOperationException e) {
                        Display.getDefault().syncExec(new Runnable() {
                            public void run() {
                                showError("Error adding files: " + e.getMessage());
                            }
                        });
                    }

                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            molViewer.getTable().setFocus();
                        }

                    });
                    return Status.OK_STATUS;

                }

            };

            job.setUser(true);
            job.schedule();

            return true;

        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            return true;
        }
    });
}

From source file:net.bioclipse.qsar.ui.editors.MoleculesPage.java

License:Open Source License

/**
 * Handle the case when users press the Remove button next to moleculeviewer
 * or presses the delete button on something
 *//*www .j a v a 2s .  c  o m*/
@SuppressWarnings("unchecked")
protected void deleteSelectedMolecules() {

    IStructuredSelection ssel = (IStructuredSelection) molViewer.getSelection();
    if (ssel == null) {
        showMessage("Please select a molecule to remove");
        return;
    }

    QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();
    qsar.removeResourcesFromModel(qsarModel, editingDomain, ssel.toList());

    molViewer.refresh();
}

From source file:net.bioclipse.qsar.ui.wizards.ExportQsarWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {

    if (selection == null)
        dispose();//from   w  w w .j  av a2  s  .c  o m

    List<IProject> qsarProjects = new ArrayList<IProject>();
    for (Object obj : selection.toList()) {
        if (obj instanceof IResource) {
            IResource res = (IResource) obj;
            System.out.println("Res: " + res.getName());

            IProjectNature nat = null;
            try {
                nat = res.getProject().getNature(QSARNature.NATURE_ID);
            } catch (CoreException e) {
            }
            if (nat != null)
                qsarProjects.add(res.getProject());
        }
    }
    if (qsarProjects.size() <= 0) {
        System.out.println("No qsar projects in selection");
    } else if (qsarProjects.size() == 1) {
        page = new ExportQsarWizardFilePage("Export QSAR project");
        page.setTitle("Export QSAR project");
        page.setDescription("Export QSAR project to file");
    } else {
        showMessage("You have selected resources from more than one project. "
                + "Please only select a single object for export.");
    }

}

From source file:net.certiv.fluentmark.outline.dnd.OutlineDropTargetListener.java

License:Open Source License

/**
 * get the outline items being dropped, or null if there are none or if the event does not
 * qualify for a drop.//  w ww .  ja va  2  s. co  m
 */
@SuppressWarnings("unchecked")
private List<PagePart> getDropItems(DropTargetEvent event) {
    if (event.operations == DND.DROP_NONE || event.item == null) {
        return null;
    }
    Object targetData = event.item.getData();
    if (!(targetData instanceof PagePart)) {
        return null;
    }

    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        List<?> list = structuredSelection.toList();
        if (!list.isEmpty()) {
            for (Object i : list) {
                if (!(i instanceof PagePart))
                    return null;
            }
            return (List<PagePart>) list;
        }
    }
    return null;
}

From source file:net.certiv.fluentmark.outline.FluentOutlinePage.java

License:Open Source License

public void select(ISourceReference reference) {
    if (viewer != null) {
        ISelection sel = viewer.getSelection();
        if (sel instanceof IStructuredSelection) {
            IStructuredSelection ssel = (IStructuredSelection) sel;
            List<?> elements = ssel.toList();
            if (!elements.contains(reference)) {
                sel = reference == null ? StructuredSelection.EMPTY : new StructuredSelection(reference);
                viewer.setSelection(sel, true);
            }/*from w w  w . ja  v  a 2  s .  c o  m*/
        }
    }
}

From source file:net.enilink.komma.edit.ui.action.CommandActionHandler.java

License:Open Source License

/**
 * When the selection changes, this will call {@link #createCommand} with
 * the appropriate collection of selected objects.
 *///from  w  ww. j av  a2 s . co  m
protected boolean updateSelection(IStructuredSelection selection) {
    if (selection == null) {
        return false;
    }
    List<?> list = selection.toList();
    Collection<Object> collection = new ArrayList<Object>(list);
    command = createCommand(collection);
    return command.canExecute();
}

From source file:net.enilink.komma.edit.ui.action.StaticSelectionCommandAction.java

License:Open Source License

/**
 * This extracts the objects from selection, invokes createActionCommand to
 * create the command, and then configures the action based on the result.
 *//*w  ww . j  a  v  a2 s .  co m*/
@Override
public void refresh() {
    // only handle structured selections
    if (!(getSelection() instanceof IStructuredSelection)) {
        disable();
    } else {
        // convert the selection to a collection of the selected objects
        IStructuredSelection sselection = getStructuredSelection();
        List<?> list = sselection.toList();
        Collection<Object> collection = new ArrayList<Object>(list);

        // if the editing domain wasn't given by the workbench part, try to
        // get
        // it from the selection
        if (editingDomain == null) {
            for (Object o : collection) {
                editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(o);
                if (editingDomain != null) {
                    break;
                }
            }
        }

        // if we found an editing domain, create command
        if (editingDomain != null) {
            command = createActionCommand(editingDomain, collection);
            setEnabled(command.canExecute());
        }

        // give up if we couldn't create the command; otherwise, use a
        // CommandActionDelegate to set the action's text, tool-tip, icon,
        // etc. or just use the default icon
        if (command == null || command == UnexecutableCommand.INSTANCE) {
            disable();
        } else if (!(command instanceof ICommandActionDelegate)) {
            if (getDefaultImageDescriptor() != null) {
                setImageDescriptor(getDefaultImageDescriptor());
            }
        } else {
            ICommandActionDelegate commandActionDelegate = (ICommandActionDelegate) command;

            ImageDescriptor imageDescriptor = objectToImageDescriptor(commandActionDelegate.getImage());
            if (imageDescriptor != null) {
                setImageDescriptor(imageDescriptor);
            } else if (getDefaultImageDescriptor() != null) {
                setImageDescriptor(getDefaultImageDescriptor());
            }

            if (commandActionDelegate.getText() != null) {
                setText(commandActionDelegate.getText());
            }

            if (commandActionDelegate.getDescription() != null) {
                setDescription(commandActionDelegate.getDescription());
            }

            if (commandActionDelegate.getToolTipText() != null) {
                setToolTipText(commandActionDelegate.getToolTipText());
            }
        }
    }
}

From source file:net.refractions.udig.project.ui.internal.ProjectExplorerDropAdapter.java

License:Open Source License

private List<Layer> getLayers(Object data) {
    List<Object> resources = new ArrayList<Object>();

    if (data instanceof String || data instanceof String[]) {
        if (data instanceof String) {
            resources.addAll(CorePlugin.stringsToURLs((String) data));
        } else {/*from  w ww . j a  va  2  s  .  c  o m*/
            resources.addAll(CorePlugin.stringsToURLs((String[]) data));
        }
    } else if (data instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) data;

        resources.addAll(selection.toList());
    } else {
        resources.add(data);
    }

    return MapFactory.instance().processResources(null, resources);
}