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

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

Introduction

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

Prototype

@Override
    public Iterator iterator() 

Source Link

Usage

From source file:org.eclipse.sirius.ui.debug.properties.GMFDebugPropertySection.java

License:Open Source License

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    if (selection.isEmpty() || !(selection instanceof StructuredSelection)) {
        super.setInput(part, selection);
        return;//  w  ww . ja  v  a2 s. co m
    }
    final StructuredSelection structuredSelection = (StructuredSelection) selection;
    final ArrayList<Object> transformedSelection = new ArrayList<Object>(structuredSelection.size());
    final Iterator<?> it = structuredSelection.iterator();
    while (it.hasNext()) {
        final Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:org.eclipse.team.internal.ccvs.ui.TableViewerAction.java

License:Open Source License

public void run() {
    if (viewer.getSelection() instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) viewer.getSelection();
        if (!selection.isEmpty()) {
            Iterator selectionIter = selection.iterator();

            StringBuffer buf = new StringBuffer();
            ITag firstTag = (ITag) selectionIter.next();
            buf.append(firstTag.getName());
            while (selectionIter.hasNext()) {
                String tagName = ((ITag) selectionIter.next()).getName();
                buf.append(System.getProperty("line.separator", "\n")).append(tagName); //$NON-NLS-1$ //$NON-NLS-2$
            }//from  w  w  w.ja  va 2s.c o  m

            Clipboard clipboard = new Clipboard(Display.getDefault());
            Object[] data = new Object[] { buf.toString() };
            Transfer[] dataTypes = new Transfer[] { TextTransfer.getInstance() };
            try {
                clipboard.setContents(data, dataTypes);
            } catch (SWTError e) {
                if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
                    throw e;
                }
            } finally {
                clipboard.dispose();
            }
        }
    }
}

From source file:org.eclipse.team.internal.ui.mapping.ModelElementSelectionPage.java

License:Open Source License

private Collection computeSelectedResources(StructuredSelection selection) {
    List result = new ArrayList();
    for (Iterator iter = selection.iterator(); iter.hasNext();) {
        Object element = iter.next();
        ResourceMapping mapping = Utils.getResourceMapping(element);
        if (mapping != null && scopeContainsMapping(mapping)) {
            result.add(element);/*  www . jav  a  2s .c om*/
        }
    }
    return result;
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.compgroupmc.ComponentsSubPage.java

License:Open Source License

public void removeSelectedComponents() {
    if (componentsTableViewer == null || componentsSectionHandler == null) {
        return;//from   w ww.  j  a  va 2  s  . c o m
    }

    StructuredSelection selection = (StructuredSelection) componentsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Component component = (Component) iterator.next();
        if (component != null) {
            ConfigTreeNodeUtilities.removeChild(componentsSectionHandler.getLastSectionRoot(),
                    component.getRoot());
            componentsSectionHandler.getComponents().remove(component);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.compgroupmc.GroupsSubPage.java

License:Open Source License

private void removeSelectedGroups() {
    if (groupsTableViewer == null || groupSectionHandler == null) {
        return;/*from w  w w . jav a2 s.  c o m*/
    }

    StructuredSelection selection = (StructuredSelection) groupsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Group group = (Group) iterator.next();
        if (group != null) {
            ConfigTreeNodeUtilities.removeChild(groupSectionHandler.getLastSectionRoot(), group.getRoot());
            groupSectionHandler.getGroups().remove(group);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.compgroupmc.GroupsSubPage.java

License:Open Source License

private void removeSelectedItems() {
    if (itemsTableViewer == null || groupSectionHandler == null) {
        return;/*w  w  w .j av a 2s.c o  m*/
    }

    StructuredSelection selection = (StructuredSelection) itemsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        GroupItem item = (GroupItem) iterator.next();
        if (item != null) {
            final List<GroupItem> groupItems = selectedGroup.getGroupItems();
            final int size = groupItems.size();
            if (size == 1) {
                // if it is the only one
                // DO NOTHING
                // Each group must have at least one item.
                return;
            }

            final ParseTree selected = item.getItem();
            final ParseTree parent = selectedGroup.getRoot();
            // items are separated by ","
            // first 2 items of the rule are: group name, ":=", they are not items
            ConfigTreeNodeUtilities.removeChildWithSeparator(parent, selected, ",", 2);
            selectedGroup.getGroupItems().remove(item);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.execute.ExecuteSubPage.java

License:Open Source License

public void removeSelectedExecuteItems() {
    if (executeSectionHandler == null || executeElementsTableViewer == null) {
        return;//from w w  w.j a  v  a  2  s. c  om
    }

    StructuredSelection selection = (StructuredSelection) executeElementsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        ExecuteItem item = (ExecuteItem) iterator.next();
        if (item != null) {
            ConfigTreeNodeUtilities.removeChild(executeSectionHandler.getLastSectionRoot(), item.getRoot());
            executeSectionHandler.getExecuteitems().remove(item);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.DefineSubPage.java

License:Open Source License

public void removeSelectedDefineItems() {
    if (defineSectionHandler == null || defineElementsTableViewer == null) {
        return;// w w w.jav a  2 s  .  c o  m
    }

    StructuredSelection selection = (StructuredSelection) defineElementsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Definition item = (Definition) iterator.next();
        if (item != null) {
            ConfigTreeNodeUtilities.removeChild(defineSectionHandler.getLastSectionRoot(), item.getRoot());
            defineSectionHandler.getDefinitions().remove(item);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.IncludeSubPage.java

License:Open Source License

public void removeSelectedIncludeItems() {
    if (includeElementsTableViewer == null || includeSectionHandler == null) {
        return;//from   www.  j a v  a 2s .c o  m
    }

    StructuredSelection selection = (StructuredSelection) includeElementsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        ParseTree item = (ParseTree) iterator.next();
        if (item != null) {
            ConfigTreeNodeUtilities.removeChild(includeSectionHandler.getLastSectionRoot(), item);
            includeSectionHandler.getFiles().remove(item);
        }
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.modulepar.ModuleParameterSectionPage.java

License:Open Source License

private void createDetailsPart(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    section.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
    section.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR));

    Composite client = toolkit.createComposite(section, SWT.WRAP);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;//from  w ww.j  ava  2 s .  c o  m
    client.setLayout(layout);

    parameterValueText = toolkit.createText(client, "", SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    parameterValueText.setLayoutData(new GridData(GridData.FILL_BOTH));
    parameterValueText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            StructuredSelection selection = (StructuredSelection) moduleParametersTableViewer.getSelection();
            Iterator<?> iterator = selection.iterator();
            if (!iterator.hasNext()) {
                return;
            }

            ModuleParameter moduleParameter = (ModuleParameter) iterator.next();
            ConfigTreeNodeUtilities.setText(moduleParameter.getValue(), parameterValueText.getText());

            if (valueChanged) {
                valueChanged = false;
                return;
            }

            editor.setDirty();
        }
    });
    parameterValueText.setEnabled(moduleParametersHandler != null);

    section.setText("Module parameter value");
    section.setDescription("Specify the concrete value for the actually selected module parameter.");
    section.setClient(client);
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessVerticalSpace = true;
    section.setLayoutData(gd);
}