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.eclipse.gemoc.execution.concurrent.ccsljavaengine.ui.views.stimulimanager.StimuliManagerView.java

License:Open Source License

private SelectionListener createSelectionListener() {
    SelectionListener listener = new SelectionListener() {
        @Override//from  w w  w. j  ava 2  s  .  com
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection selection = (StructuredSelection) _viewer.getSelection();
            ArrayList<ModelSpecificEventWrapper> mses = new ArrayList<ModelSpecificEventWrapper>();
            for (Object o : selection.toList()) {
                mses.add((ModelSpecificEventWrapper) o);
            }

            ClockStatus state = ClockStatus.NOTFORCED_NOTSET;

            if (e.getSource() instanceof MenuItem) {
                state = (ClockStatus) ((MenuItem) e.getSource()).getData();
            }
            if (e.getSource() instanceof Button) {
                state = (ClockStatus) ((Button) e.getSource()).getData();
            }

            forceClocks(mses, state);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    return listener;
}

From source file:org.eclipse.gmf.refactoring.editorconnector.GMFEditorConnector.java

License:Open Source License

public List<EObject> handleSelection(ISelection selection) {
    StructuredSelection structuredSelection = (StructuredSelection) selection;
    List<EObject> selectedElements = new LinkedList<EObject>();
    @SuppressWarnings("unchecked")
    List<EditPart> editParts = (List<EditPart>) structuredSelection.toList();
    for (EditPart editPart : editParts) {
        Object model = editPart.getModel();
        if (model instanceof View) {
            selectedElements.add(((View) model).getElement());
        }/*from   ww w.j  av a  2s.  c o m*/
    }
    return selectedElements;
}

From source file:org.eclipse.gmf.runtime.common.ui.services.elementselection.ElementSelectionComposite.java

License:Open Source License

/**
 * Handles a selection change and validates the new selection.
 *//*from w w  w.j  a  v a 2s . c om*/
private void handleSelectionChange() {
    StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
    if (selection.size() == 0) {
        // nothing selected
        selectedElements.clear();
        handleSelection(false);
        return;
    }

    List selectionList = selection.toList();

    // get the current selected elements
    List currentSelectedElements = new ArrayList();
    for (Iterator iter = selectionList.iterator(); iter.hasNext();) {
        AbstractMatchingObject matchingObject = (AbstractMatchingObject) iter.next();
        currentSelectedElements.add(matchingObject);
    }

    // validate selection
    boolean isValidSelection = isValidSelection(currentSelectedElements);

    // store the selection
    selectedElements.clear();
    if (isValidSelection) {
        selectedElements.addAll(currentSelectedElements);
    }

    // update UI based on selection
    handleSelection(isValidSelection);

}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.DiagramPrintRangeBlock.java

License:Open Source License

/**
 * Create the contents of the diagram selection block. It contains 2 radio
 * buttons for current or multi-selection and a list box of diagram options.
 *//*from w ww.j av a2s  .c  om*/
@Override
public Control createContents(Composite parent) {

    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintRange);
    layout(result, 3);

    Button currentDiagramRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintCurrent);
    layoutSpanHorizontal(currentDiagramRadio, 4);

    Button selectedDiagramsRadio = radio(result,
            DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintSelected);
    layoutSpanHorizontal(selectedDiagramsRadio, 4);

    diagramList = list(result);

    layoutFillHorizontal(layoutHeight(diagramList.getControl(), 48));
    GridData data = getLayoutData(diagramList.getControl());
    data.widthHint = 300;

    diagramList.getControl().setEnabled(options.isDiagramSelection());

    currentDiagramRadio.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            //do nothing
        }

        public void widgetSelected(SelectionEvent event) {
            diagramList.getControl().setEnabled(options.isDiagramSelection());
        }
    });

    selectedDiagramsRadio.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            //do nothing
        }

        public void widgetSelected(SelectionEvent event) {
            diagramList.getControl().setEnabled(!options.isDiagramCurrent());
        }
    });

    diagramList.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            if (event != null) {

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

                options.setDiagramsToPrint(selection.toList());

            }

        }
    });

    diagramList.setContentProvider(new DiagramContentProvider());
    diagramList.setLabelProvider(new DiagramLabelProvider());

    diagramList.setInput(availableDiagrams);

    bindings.bindValue(SWTObservables.observeSelection(currentDiagramRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_DIAGRAM_CURRENT), null, null);

    bindings.bindValue(SWTObservables.observeSelection(selectedDiagramsRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_DIAGRAM_SELECTION), null, null);

    return result;
}

From source file:org.eclipse.gmf.tooling.runtime.sheet.DefaultPropertySection.java

License:Open Source License

@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;//from   w w  w. j a v a  2 s . com
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList<Object> transformedSelection = new ArrayList<Object>(structuredSelection.size());
    for (Object next : structuredSelection.toList()) {
        Object r = transformSelection(next);
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Returns the current selection./* w ww  .  j  a v  a 2  s  .com*/
 * 
 * @return the current selection
 */
@SuppressWarnings("unchecked")
protected StructuredSelection getSelectedItems() {

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

    final List<Object> selectedItems = selection.toList();
    Object itemToRemove = null;

    for (final Iterator it = selection.iterator(); it.hasNext();) {
        final Object item = it.next();
        if (item instanceof ItemsListSeparator) {
            itemToRemove = item;
            break;
        }
    }

    if (itemToRemove == null)
        return new StructuredSelection(selectedItems);
    // Create a new selection without the collision
    final List<Object> newItems = new ArrayList<Object>(selectedItems);
    newItems.remove(itemToRemove);
    return new StructuredSelection(newItems);

}

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.FilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Handle selection in the items list by updating labels of selected and
 * unselected items and refresh the details field using the selection.
 * //from w w  w.  j  a v a  2 s  .  c  om
 * @param selection
 *            the new selection
 */
@SuppressWarnings("unchecked")
protected void handleSelected(final StructuredSelection selection) {
    IStatus status = new Status(IStatus.OK, AdminUiActivator.SYMBOLIC_NAME, IStatus.OK, EMPTY_STRING, null);

    final Object[] lastSelection = currentSelection;

    currentSelection = selection.toArray();

    if (selection.size() == 0) {
        status = new Status(IStatus.ERROR, AdminUiActivator.SYMBOLIC_NAME, IStatus.ERROR, EMPTY_STRING, null);

        if ((lastSelection != null) && (getListSelectionLabelDecorator() != null)) {
            list.update(lastSelection, null);
        }

        currentSelection = null;

    } else {
        status = new Status(IStatus.ERROR, AdminUiActivator.SYMBOLIC_NAME, IStatus.ERROR, EMPTY_STRING, null);

        final List<Object> items = selection.toList();

        Object item = null;
        IStatus tempStatus = null;

        for (final Object o : items) {
            if (o instanceof ItemsListSeparator) {
                continue;
            }

            item = o;
            tempStatus = validateItem(item);

            if (tempStatus.isOK()) {
                status = new Status(IStatus.OK, AdminUiActivator.SYMBOLIC_NAME, IStatus.OK, EMPTY_STRING, null);
            } else {
                status = tempStatus;
                // if any selected element is not valid status is set to
                // ERROR
                break;
            }
        }

        if ((lastSelection != null) && (getListSelectionLabelDecorator() != null)) {
            list.update(lastSelection, null);
        }

        if (getListSelectionLabelDecorator() != null) {
            list.update(currentSelection, null);
        }
    }

    refreshDetails();
    updateStatus(status);
}

From source file:org.eclipse.ice.client.widgets.TreeNodeFilteredItemsSelectionDialog.java

License:Open Source License

@Override
protected void handleSelected(StructuredSelection selection) {
    String nameTextStr = "";
    for (Object o : selection.toList()) {
        int counter = 1;
        String name = o.toString().toLowerCase();
        while (currentChildren.contains(name)) {
            name += "_" + counter;
        }/*ww  w.j  a  v  a 2  s .  c o m*/

        nameTextStr += name + " ; ";
    }
    nameTextStr = nameTextStr.substring(0, nameTextStr.length() - 2);
    nameText.setText(nameTextStr);
    currentNameText = nameTextStr;

    super.handleSelected(selection);
    return;
}

From source file:org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionEnablementTest.java

License:Open Source License

private IJavaProject createProject() throws CoreException {
    fProject = JavaProjectHelper.createJavaProject("Dummy project", "bin");
    IPath srcPath = new Path("src");
    IPath normalFolderPath = new Path("NormalFolder");
    IPath packagePath = srcPath.append("pack1");
    IPath filePath = packagePath.append("NormalFile");

    // src folder
    IFolder folder = fProject.getProject().getFolder(srcPath);
    CoreUtility.createFolder(folder, true, true, null);

    // one normal folder
    IFolder folder2 = fProject.getProject().getFolder(normalFolderPath);
    CoreUtility.createFolder(folder, true, true, null);

    final IPath projectPath = fProject.getProject().getFullPath();

    // configure the classpath entries, including the default jre library.
    List cpEntries = new ArrayList();
    cpEntries.add(JavaCore.newSourceEntry(projectPath.append(srcPath)));
    cpEntries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));
    IClasspathEntry[] entries = (IClasspathEntry[]) cpEntries.toArray(new IClasspathEntry[cpEntries.size()]);
    fProject.setRawClasspath(entries, null);

    // one package in src folder
    IPackageFragmentRoot root = fProject.findPackageFragmentRoot(fProject.getPath().append(srcPath));
    IPackageFragment pack1 = root.createPackageFragment("pack1", true, null);
    IPackageFragment defaultPack = root.getPackageFragment("");

    IPath libraryPath = root.getPath().append("archive.jar");
    IPackageFragmentRoot jarRoot = JavaProjectHelper.addLibrary(fProject, libraryPath);
    assertFalse(ClasspathModifier.getClasspathEntryFor(jarRoot.getPath(), fProject,
            IClasspathEntry.CPE_LIBRARY) == null);

    libraryPath = root.getPath().append("archive.zip");
    IFile zipFile = fProject.getProject().getWorkspace().getRoot().getFile(libraryPath);
    zipFile.create(new ByteArrayInputStream(new byte[] {}), true, null);
    final IPackageFragmentRoot zipRoot = JavaProjectHelper.addLibrary(fProject, libraryPath);
    assertFalse(ClasspathModifier.getClasspathEntryFor(zipRoot.getPath(), fProject,
            IClasspathEntry.CPE_LIBRARY) == null);

    // two compilation units A and B in 'package'
    ICompilationUnit cuA = createICompilationUnit("A", pack1);
    final IResource excludedElements[] = { null, null };
    final IPackageFragment pack2 = root.createPackageFragment("pack1.pack2", true, null);
    final ICompilationUnit cuB = createICompilationUnit("B", pack1);
    ExcludeFromBuildpathAction exclude = new ExcludeFromBuildpathAction(
            PlatformUI.getWorkbench().getProgressService(), new ISetSelectionTarget() {

                public void selectReveal(ISelection selection) {
                    StructuredSelection ss = (StructuredSelection) selection;
                    List list = ss.toList();
                    excludedElements[0] = (IResource) list.get(0);
                    excludedElements[1] = (IResource) list.get(1);
                }//  w  ww  .ja  va2s. c o m

            });
    exclude.selectionChanged(new SelectionChangedEvent(new ISelectionProvider() {
        public void addSelectionChangedListener(ISelectionChangedListener listener) {
        }

        public ISelection getSelection() {
            return new StructuredSelection(new Object[] { cuB, pack2 });
        }

        public void removeSelectionChangedListener(ISelectionChangedListener listener) {
        }

        public void setSelection(ISelection selection) {
        }
    }, new StructuredSelection(new Object[] { cuB, pack2 })));
    exclude.run();

    IFile file = fProject.getProject().getFile(filePath);
    file.create(null, false, null);

    final IFile[] removedZipFile = { null };
    RemoveFromBuildpathAction remove = new RemoveFromBuildpathAction(
            PlatformUI.getWorkbench().getProgressService(), new ISetSelectionTarget() {

                public void selectReveal(ISelection selection) {
                    removedZipFile[0] = (IFile) ((StructuredSelection) selection).getFirstElement();
                }

            });
    remove.selectionChanged(new SelectionChangedEvent(new ISelectionProvider() {
        public void addSelectionChangedListener(ISelectionChangedListener listener) {
        }

        public ISelection getSelection() {
            return new StructuredSelection(zipRoot);
        }

        public void removeSelectionChangedListener(ISelectionChangedListener listener) {
        }

        public void setSelection(ISelection selection) {
        }
    }, new StructuredSelection(zipRoot)));
    remove.run();

    fSourceFolder = root;
    fFolder = folder2;
    fPackage = pack1;
    fCompilationUnit = cuA;
    fExcludedFile = excludedElements[0];
    fFile = file;
    fExcludedPackage = excludedElements[1];
    fDefaultPackage = defaultPack;
    fLibrary = jarRoot;
    fExcludedLibrary = removedZipFile[0];

    return fProject;
}

From source file:org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaSeeAlsoAttributeEditor.java

License:Open Source License

private void createSeeAlsoTable(FormToolkit toolkit, final Composite seeAlsoComposite) {

    seeAlsoTable = toolkit.createTable(seeAlsoComposite, SWT.MULTI | SWT.FULL_SELECTION);
    seeAlsoTable.setLinesVisible(true);/*from w  w w  .j a  v a2s  .  c  o m*/
    seeAlsoTable.setHeaderVisible(true);
    seeAlsoTable.setLayout(new GridLayout());
    seeAlsoTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    for (int i = 0; i < seeAlsoColumns.length; i++) {
        TableColumn column = new TableColumn(seeAlsoTable, SWT.LEFT, i);
        column.setText(seeAlsoColumns[i]);
        column.setWidth(seeAlsoColumnWidths[i]);
        column.setMoveable(true);
    }

    seeAlsoViewer = new TableViewer(seeAlsoTable);
    seeAlsoViewer.setUseHashlookup(true);
    seeAlsoViewer.setColumnProperties(seeAlsoColumns);
    ColumnViewerToolTipSupport.enableFor(seeAlsoViewer, ToolTip.NO_RECREATE);

    seeAlsoViewer.setContentProvider(new ArrayContentProvider());
    seeAlsoViewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            openseeAlso(event);
        }

        private void openseeAlso(OpenEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            for (String item : (List<String>) selection.toList()) {
                BrowserUtil.openUrl(item);
            }

        }
    });
    seeAlsoViewer.setLabelProvider(new ColumnLabelProvider() {

        public Image getColumnImage(Object element, int columnIndex) {
            String value = (String) element;
            if (columnIndex == 0) {
                if (value.contains("/r/#/c/") || value.contains("git.eclipse.org/r/")) { //$NON-NLS-1$ //$NON-NLS-2$
                    return CommonImages.getImage(BugzillaImages.GERRIT);
                } else if (value.contains("/commit/?id=")) { //$NON-NLS-1$
                    return CommonImages.getImage(BugzillaImages.GIT);
                } else {
                    return CommonImages.getImage(BugzillaImages.BUG);
                }
            }
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {
            String value = (String) element;
            switch (columnIndex) {
            case 0:
                return null;
            case 1:
                return attrRemoveSeeAlso.getValues().contains(value)
                        ? Messages.BugzillaSeeAlsoAttributeEditor_Yes
                        : Messages.BugzillaSeeAlsoAttributeEditor_No;
            default:
                return value;
            }
        }

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            cell.setText(getColumnText(element, cell.getColumnIndex()));
            Image image = getColumnImage(element, cell.getColumnIndex());
            cell.setImage(image);
            cell.setBackground(getBackground(element));
            cell.setForeground(getForeground(element));
            cell.setFont(getFont(element));
        }

    });
    seeAlsoViewer.setInput(getTaskAttribute().getValues().toArray());
    GC gc = new GC(seeAlsoComposite);
    int maxSize = 0;
    for (String string : getTaskAttribute().getValues()) {
        Point size = gc.textExtent(string);
        if (size.x > maxSize) {
            maxSize = size.x;
        }
    }
    if (maxSize == 0) {
        maxSize = 100;
    }
    seeAlsoTable.getColumn(2).setWidth(maxSize);
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            manager.add(openAction);
            manager.add(copyURLToClipAction);
            manager.add(toggelRemoveStateAction);
        }
    });
    Menu menu = menuManager.createContextMenu(seeAlsoTable);
    seeAlsoTable.setMenu(menu);
}