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.gyrex.admin.ui.internal.widgets.FilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Returns the current selection./*from  ww w.  j  ava 2s  .co  m*/
 * 
 * @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.imp.pdb.browser.FactBrowserView.java

License:Open Source License

public void removeCurrentSelection() {
    ISelection s = tableViewer.getSelection();
    if (s instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) s;
        Iterator<?> iter = selection.iterator();

        while (iter.hasNext()) {
            IFactKey key = (IFactKey) iter.next();
            factBase.removeFact(key);//from  ww  w .ja v a 2s.  co  m
        }
    }
}

From source file:org.eclipse.imp.pdb.browser.FactBrowserView.java

License:Open Source License

public List<IFactKey> getCurrentSelection() {
    ISelection s = tableViewer.getSelection();
    List<IFactKey> result = new ArrayList<IFactKey>();
    if (s instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) s;
        Iterator<?> iter = selection.iterator();

        while (iter.hasNext()) {
            IFactKey key = (IFactKey) iter.next();
            result.add(key);//from ww  w  .j av  a  2  s  .  com
        }
    }
    return result;
}

From source file:org.eclipse.jst.jsf.ui.internal.classpath.JSFLibraryEditControl.java

License:Open Source License

private void createButtons(Composite c) {
    btnBar = new Composite(c, SWT.NONE);
    GridLayout gl = new GridLayout(1, false);
    gl.marginHeight = 0;/* w  w  w  . j a  v  a 2s .  c  o m*/
    gl.marginTop = 0;
    gl.marginWidth = 0;
    btnBar.setLayout(gl);
    btnBar.setLayoutData(new GridData(GridData.END));

    btnAdd = new Button(btnBar, SWT.NONE);
    btnAdd.setText(Messages.JSFLibraryWizard_Add);
    btnAdd.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
    btnAdd.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String cur = null;
            String[] chosenJars = openExtJarFileDialog(cur);
            if (chosenJars != null) {
                for (int i = 0; i < chosenJars.length; i++) {
                    String jar = chosenJars[i];
                    if (!workingCopyLibrary.containsArchiveFile(jar)) {
                        ArchiveFile archive = JSFLibraryRegistryFactory.eINSTANCE.createArchiveFile();
                        archive.setSourceLocation(jar);
                        archive.setRelativeDestLocation("WEB-INF/lib"); //$NON-NLS-1$
                        workingCopyLibrary.getArchiveFiles().add(archive);
                    }
                }
                jars.refresh();
                validate();
            }
        }
    });

    btnRemove = new Button(btnBar, SWT.NONE);
    btnRemove.setEnabled(false);
    btnRemove.setText(Messages.JSFLibraryWizard_Remove);
    btnRemove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
    btnRemove.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (jars.getSelection() instanceof StructuredSelection) {
                StructuredSelection objs = (StructuredSelection) jars.getSelection();
                if (objs != null) {
                    Iterator it = objs.iterator();
                    while (it.hasNext()) {
                        Object obj = it.next();
                        ArchiveFile jar = (ArchiveFile) obj;
                        workingCopyLibrary.getArchiveFiles().remove(jar);
                    }
                }
                jars.refresh();
                validate();
            }
        }
    });
}

From source file:org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControl.java

License:Open Source License

private void resetComponentLibSelection(StructuredSelection item, TreeViewer srcViewer,
        CheckboxTableViewer destViewer, boolean state) {
    if (item != null && !item.isEmpty()) {
        List selected = new ArrayList(item.size());
        for (Iterator sel = item.iterator(); sel.hasNext();) {
            JSFLibraryInternalReference jsfLibDctr = (JSFLibraryInternalReference) sel.next();
            selected.add(jsfLibDctr);/*from ww  w .  java2s  .com*/
            List list = workingCopyModel.getJSFComponentLibraries();
            Iterator it = list.iterator();
            JSFLibraryInternalReference crtjsfLibDctr = null;
            while (it.hasNext()) {
                crtjsfLibDctr = (JSFLibraryInternalReference) it.next();
                if (crtjsfLibDctr.getID().equals(jsfLibDctr.getID())) {
                    crtjsfLibDctr.setToBeDeployed(state);
                    crtjsfLibDctr.setSelected(state);
                }
            }
        }

        loadJSFCompList();

        srcViewer.refresh();
        destViewer.refresh();
        for (Iterator it = selected.iterator(); it.hasNext();) {
            destViewer.setChecked(it.next(), state);
        }

        setCompListModelProperty();
    }
}

From source file:org.eclipse.jst.servlet.ui.internal.wizard.NewFilterClassOptionsWizardPage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    StructuredSelection selection = (StructuredSelection) event.getSelection();

    // if the selection is empty, then the remove button is disabled
    if (selection.isEmpty()) {
        removeButton.setEnabled(false);//from   w ww  . j ava2  s  .c o  m
        return;
    }

    // if the selection is non-empty and the filter extends a class which
    // implements javax.servlet.Filter, then the remove button is enabled
    if (FilterSupertypesValidator.isFilterSuperclass(model)) {
        removeButton.setEnabled(true);
        return;
    }

    // if the selection is non-empty and the filter does not extend a class
    // which implements javax.servlet.Filter, then the remove button is
    // disabled only if the Filter interface is in the selection
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        if (QUALIFIED_FILTER.equals(iter.next()))
            removeButton.setEnabled(false);
        return;
    }

    // in all other cases the remove button is enabled
    removeButton.setEnabled(true);
}

From source file:org.eclipse.jubula.client.alm.mylyn.ui.bridge.monitor.UserInteractionMonitor.java

License:Open Source License

/** {@inheritDoc} */
protected void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.equals(m_oldSelection)) {
            return;
        }//from   w w  w .j  a va 2  s.  c o m
        m_oldSelection = structuredSelection;
        if (structuredSelection != null) {
            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof INodePO || selectedObject instanceof IReusedProjectPO) {
                    super.handleElementSelection(part, selectedObject, contributeToContext);
                }
            }
        }
    }
}

From source file:org.eclipse.jubula.client.ui.rcp.properties.ProjectALMPropertyPage.java

License:Open Source License

/** Handles the remove-button event of a given table by deleting the selected
 *  reporting rule from the given table.
 * @param tableViewer the table viewer//from  ww  w .  j  ava 2s.  c o  m
 */
void handleRemoveButtonEvent(TableViewer tableViewer) {
    StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();

    Iterator itr = selection.iterator();
    while (itr.hasNext()) {
        m_reportingRules.remove(itr.next());
    }
    tableViewer.refresh();
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.AddContextOnChannelHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//from   w ww  .  j a v a 2  s . c o m

    TraceChannelComponent channel = null;
    TraceSessionComponent session = null;
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceChannelComponent) {
                // Add only if corresponding TraceSessionComponents is inactive and not destroyed
                TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
                session = tmpChannel.getSession();
                if (session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
                    channel = tmpChannel;
                }
            }
        }
    }

    boolean isEnabled = (channel != null);
    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new ChannelCommandParameter(session, channel);
        }
    } finally {
        fLock.unlock();
    }
    return isEnabled;
}

From source file:org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.AddContextOnDomainHandler.java

License:Open Source License

@Override
public boolean isEnabled() {

    // Get workbench page for the Control View
    IWorkbenchPage page = getWorkbenchPage();
    if (page == null) {
        return false;
    }//ww  w.jav  a  2s  .  c o  m

    TraceDomainComponent domain = null;
    TraceSessionComponent session = null;

    // Check if one domain is selected
    ISelection selection = page.getSelection(ControlView.ID);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structered = ((StructuredSelection) selection);
        for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
            Object element = iterator.next();
            if (element instanceof TraceDomainComponent) {
                TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
                session = (TraceSessionComponent) tmpDomain.getParent();

                // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
                if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
                    domain = tmpDomain;
                }
            }
        }
    }

    boolean isEnabled = domain != null;

    fLock.lock();
    try {
        fParam = null;
        if (isEnabled) {
            fParam = new DomainCommandParameter(session, domain);
        }
    } finally {
        fLock.unlock();
    }

    return isEnabled;
}