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

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

Introduction

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

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:org.opentravel.schemas.utils.RCPUtils.java

License:Apache License

/**
 * @param selection// ww  w  .  j  av  a2  s  .  c o  m
 *            must by {@link StructuredSelection}.
 * @param clazz
 * @return extract object of provided type or his sub-types from selection.
 */
@SuppressWarnings("unchecked")
public static <T> List<T> extractObjects(ISelection selection, Class<T> clazz) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) selection;
        List<T> ret = new ArrayList<T>(ss.size());
        for (Object o : ss.toList()) {
            if (clazz.isAssignableFrom(o.getClass())) {
                ret.add((T) o);
            }
        }
        return ret;
    }
    return Collections.emptyList();
}

From source file:org.opentravel.schemas.wizards.NewPropertiesWizardPage.java

License:Apache License

private List<PropertyNode> getSelectedValidPropertiesFromLibraryTree() {
    final List<PropertyNode> ret = new ArrayList<PropertyNode>();
    final ISelection selection = libraryTree.getSelection();
    if (selection instanceof StructuredSelection) {
        final StructuredSelection strSel = (StructuredSelection) selection;
        for (final Object o : strSel.toList()) {
            if (o instanceof PropertyNode) {
                final PropertyNode p = (PropertyNode) o;
                if (propertyTypesOrder.contains(p.getPropertyType())) {
                    ret.add(p);/*from  w  w w  .  j  a  v a  2  s.c  o m*/
                }
            }
        }
    }
    return ret;
}

From source file:org.pentaho.pms.ui.concept.editor.AvailSecurityOwnersTableViewer.java

License:Open Source License

public SecurityOwner[] getSelectedOwners() {
    StructuredSelection selection = (StructuredSelection) getSelection();
    @SuppressWarnings("all")
    Collection<SecurityOwner> c = selection.toList();
    return c.toArray(new SecurityOwner[0]);
}

From source file:org.pentaho.pms.ui.concept.editor.SecurityTableViewer.java

License:Open Source License

@SuppressWarnings("unchecked")
public SecurityOwner[] getSelectedOwners() {
    StructuredSelection selection = (StructuredSelection) getSelection();
    return (SecurityOwner[]) selection.toList().toArray(new SecurityOwner[0]);
}

From source file:org.pentaho.pms.ui.concept.editor.SecurityTableViewer.java

License:Open Source License

public void removeSelectedOwners() {
    StructuredSelection structuredSelection = (StructuredSelection) getSelection();
    for (Iterator iterator = structuredSelection.toList().iterator(); iterator.hasNext();) {
        removeOwner((SecurityOwner) iterator.next());
    }/*  www  . jav a2  s.  c  o m*/
    setSelection(new StructuredSelection());
}

From source file:org.rssowl.ui.internal.dialogs.SearchNewsDialog.java

License:Open Source License

private ISelection convertToNews(StructuredSelection selection) {
    List<?> selectedElements = selection.toList();
    List<INews> selectedNews = new ArrayList<INews>();
    for (Object selectedElement : selectedElements) {
        ScoredNews scoredNews = (ScoredNews) selectedElement;
        selectedNews.add(scoredNews.getNews());
    }/*from   w w w  . j  a  v  a 2 s  .  c o m*/

    return new StructuredSelection(selectedNews);
}

From source file:org.savara.tools.bpmn2.actions.CreateArchitectureDesignAction.java

License:Open Source License

/**
 * This method implements the action's run method.
 * /*from w  ww  .  jav a2s  . c  om*/
 * @param action The action
 */
public void run(IAction action) {
    if (m_selection instanceof StructuredSelection) {
        StructuredSelection sel = (StructuredSelection) m_selection;

        FeedbackHandlerDialog handler = new FeedbackHandlerDialog(m_targetPart.getSite().getShell());

        java.util.Map<String, java.util.List<ProtocolModel>> messageTraces = new java.util.HashMap<String, java.util.List<ProtocolModel>>();

        ArchitectureDesignDialog d = new ArchitectureDesignDialog(m_targetPart.getSite().getShell());

        Object firstSelection = sel.toList().iterator().next();
        if (firstSelection instanceof IFile) {
            d.setFolder(((IFile) firstSelection).getParent().getLocation().toFile());
        }

        if (d.open() == InputDialog.OK) {
            java.io.File container = d.getFolder();

            for (Object res : sel.toList()) {
                if (res instanceof IFile) {
                    if (container == null) {
                        container = ((IFile) res).getParent().getLocation().toFile();
                    }

                    deriveMessageTrace((IFile) res, messageTraces, handler, d.getNamespace());
                }
            }

            if (handler.hasErrors()) {
                handler.show();
            } else {
                java.util.List<ProtocolModel> localModels = new java.util.Vector<ProtocolModel>();

                for (String roleName : messageTraces.keySet()) {
                    ProtocolModel lm = PA.aggregateLocalModel(d.getModelName(), messageTraces.get(roleName),
                            handler);

                    if (lm != null) {
                        generateBPMN2ProcessModel(container, lm, handler);

                        localModels.add(lm);
                    } else {
                        handler.error(MessageFormatter.format(
                                java.util.PropertyResourceBundle.getBundle("org.savara.tools.bpmn2.Messages"),
                                "SAVARA-BPMN2TOOLS-00005", roleName), null);
                    }
                }

                // If multiple local models
                ProtocolModel globalModel = PA.aggregateGlobalModel(d.getModelName(), d.getNamespace(),
                        localModels, handler);

                if (globalModel != null) {
                    generateBPMN2ChoreographyModel(container, globalModel, handler);
                } else {
                    handler.error(
                            MessageFormatter.format(java.util.PropertyResourceBundle
                                    .getBundle("org.savara.tools.bpmn2.Messages"), "SAVARA-BPMN2TOOLS-00006"),
                            null);
                }

                if (handler.hasErrors()) {
                    handler.show();
                }
            }
        }
    }
}

From source file:org.savara.tools.bpmn2.actions.CreateChoreographyAction.java

License:Open Source License

/**
 * {@inheritDoc}/*ww w. j a  v a  2  s. c om*/
 */
public void run(IAction action) {
    if (_selection instanceof StructuredSelection) {
        StructuredSelection sel = (StructuredSelection) _selection;

        FeedbackHandlerDialog handler = new FeedbackHandlerDialog(_targetPart.getSite().getShell());

        IContainer container = null;
        java.util.List<ProtocolModel> localModels = new java.util.Vector<ProtocolModel>();

        for (Object res : sel.toList()) {
            if (res instanceof IFile) {
                if (container == null) {
                    container = ((IFile) res).getParent();
                }

                try {
                    Content content = new ResourceContent(((IFile) res).getRawLocationURI());

                    DefaultProtocolContext context = new DefaultProtocolContext(
                            ProtocolServices.getParserManager(), new DefaultResourceLocator(
                                    ((IFile) res).getRawLocation().toFile().getParentFile()));

                    ProtocolModel model = ProtocolServices.getParserManager().parse(context, content,
                            new JournalProxy(handler));

                    if (model == null || !model.isLocated()) {
                        handler.error(MessageFormatter.format(
                                java.util.PropertyResourceBundle.getBundle("org.savara.tools.bpmn2.Messages"),
                                "SAVARA-BPMN2TOOLS-00008", ((IFile) res).getRawLocationURI()), null);
                    } else {
                        localModels.add(model);
                    }
                } catch (Exception e) {
                    e.printStackTrace();

                    String mesg = MessageFormatter.format(
                            java.util.PropertyResourceBundle.getBundle("org.savara.tools.bpmn2.Messages"),
                            "SAVARA-BPMN2TOOLS-00007", ((IFile) res).getRawLocationURI());

                    handler.error(mesg, null);

                    LOG.log(Level.SEVERE, mesg, e);
                }
            }
        }

        if (handler.hasErrors()) {
            handler.show();
        } else {
            InputDialog dialog = new InputDialog(_targetPart.getSite().getShell(), "Choreography Model",
                    "Enter the model name", null, null);

            if (dialog.open() == InputDialog.OK) {
                String modelName = dialog.getValue();

                // If multiple local models
                ProtocolModel globalModel = PA.aggregateGlobalModel(modelName, null, localModels, handler);

                if (globalModel != null) {
                    generateBPMN2ChoreographyModel(container, globalModel, handler);
                } else {
                    handler.error(
                            MessageFormatter.format(java.util.PropertyResourceBundle
                                    .getBundle("org.savara.tools.bpmn2.Messages"), "SAVARA-BPMN2TOOLS-00006"),
                            null);
                }

                if (handler.hasErrors()) {
                    handler.show();
                }
            }
        }
    }
}

From source file:org.springsource.ide.eclipse.commons.quicksearch.ui.QuickSearchDialog.java

License:Open Source License

/**
 * Returns the current selection./*from  w  w  w. j  a  v a  2s  . co m*/
 *
 * @return the current selection
 */
protected StructuredSelection getSelectedItems() {

    StructuredSelection selection = (StructuredSelection) list.getSelection();

    List selectedItems = selection.toList();

    return new StructuredSelection(selectedItems);
}

From source file:org.talend.dataprofiler.core.ui.editor.composite.ComparisonTableViewerDNDDecorate.java

License:Open Source License

/**
 * Install a drag&drop function for target table viewer.
 * /*from w w  w.ja v  a2  s.c  om*/
 * @param targetViewer the target table viewer for installing drag&drop, it's input value must a <code>List</code>
 * type.
 * @param installDragListener decide to whether install a drag listener for targetViewer: if true, will install the
 * listener; else, will not install.
 * @param validateType
 * @see ComparisonTableViewerDNDDecorate#NON_VALIDATETYPE
 * @see ComparisonTableViewerDNDDecorate#COLUMN_VALIDATETYPE
 */
public void installDND(final TableViewer targetViewer, final boolean installDragListener,
        final int validateType, final boolean isLeftPart) {
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    if (installDragListener) {
        installDragListener(targetViewer, operations);
    }
    DropTarget dropTarget = new DropTarget(targetViewer.getTable(), operations);
    dropTarget.setTransfer(transferTypes);
    DropTargetListener dndListener = new AbstractSelectionReceiver(targetViewer.getTable(), null) {

        @Override
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event, LocalSelectionTransfer transfer) {
            List inputElements = (List) targetViewer.getInput();
            // MOD mzhao bug:12766,Avoid an null pointer exception error.
            if (inputElements == null) {
                inputElements = new ArrayList();
            }
            if (dragSelectedElement != null) {
                TableItem item = (TableItem) event.item;
                TableItem[] items = targetViewer.getTable().getItems();
                int index = 0;
                for (int i = 0; i < items.length; i++) {
                    if (items[i] == item) {
                        index = i;
                        break;
                    }
                }
                inputElements.remove(dragSelectedElement);
                inputElements.add(index, dragSelectedElement);
                dragSelectedElement = null;
            } else {
                StructuredSelection selection = (StructuredSelection) transfer.getSelection();
                List selectionElements = selection.toList();
                inputElements.addAll(selectionElements);
            }
            targetViewer.setInput(inputElements);
            // Update connection widget.
            compareTreeViewer.updateBindConnection(masterPage, tableViewerPosStack);
            compareTreeViewer.setDirty(true);
            // TDQ-11606 msjian: when add a column, will update the datapreview part
            compareTreeViewer.computeRefreshDataPreviewPart(isLeftPart, inputElements, targetViewer);
        }

        @Override
        public boolean doDropValidation(DropTargetEvent event, LocalSelectionTransfer transfer) {
            StructuredSelection selection = (StructuredSelection) transfer.getSelection();

            if (dragSelectedElement != null && selection != null) {
                return true;
            }
            // boolean doDropValidation = super.doDropValidation(event, transfer);
            boolean doDropValidation = false;
            // if (doDropValidation) {
            switch (validateType) {
            case COLUMN_VALIDATETYPE:

                doDropValidation = validateColumnType(selection, targetViewer);
                break;
            default:
                doDropValidation = true;
            }
            // }
            return doDropValidation;
        }

    };
    dropTarget.addDropListener(dndListener);
}