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

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

Introduction

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

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenFileGroup.java

License:Open Source License

private boolean allResourcesAreOfType(IStructuredSelection selection, int resourceMask) {
    Iterator resources = selection.iterator();
    while (resources.hasNext()) {
        Object next = resources.next();
        IResource resource = null;/* w w w. ja v a  2  s  .  c  om*/
        if (next instanceof IResource) {
            resource = (IResource) next;
        } else if (next instanceof IAdaptable) {
            resource = (IResource) ((IAdaptable) next).getAdapter(IResource.class);
        }
        if (resource != null) {
            if (!resourceIsType(resource, resourceMask)) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenProjectGroup.java

License:Open Source License

/**
 * Adds the open project, close project and refresh resource actions to the
 * context menu./*from w  w w  .  ja  v  a2  s  .  co  m*/
 * <p>
 * refresh-no closed project selected
 * </p>
 * <p>
 * Both the open project and close project action may be on the menu at the
 * same time.
 * </p>
 * <p>
 * No disabled action should be on the context menu.
 * </p>
 * 
 * @param menu
 *            context menu to add actions to
 */
public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    boolean isProjectSelection = true;
    boolean hasOpenProjects = false;
    boolean hasClosedProjects = false;
    boolean hasBuilder = true; // false if any project is closed or does not have builder 
    Iterator resources = selection.iterator();

    while (resources.hasNext()
            && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
        Object next = resources.next();
        IProject project = null;

        if (next instanceof IProject) {
            project = (IProject) next;
        } else if (next instanceof IAdaptable) {
            project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
        }

        if (project == null) {
            isProjectSelection = false;
            continue;
        }
        if (project.isOpen()) {
            hasOpenProjects = true;
            if (hasBuilder && !hasBuilder(project)) {
                hasBuilder = false;
            }
        } else {
            hasClosedProjects = true;
            hasBuilder = false;
        }
    }

    if (!selection.isEmpty() && isProjectSelection && !ResourcesPlugin.getWorkspace().isAutoBuilding()
            && hasBuilder) {
        // Allow manual incremental build only if auto build is off.
        buildAction.selectionChanged(selection);
        menu.add(buildAction);
        cleanAction.selectionChanged(selection);
        menu.add(cleanAction);
    }

    if (!hasClosedProjects) {
        refreshAction.selectionChanged(selection);
        menu.add(refreshAction);
    }
    if (isProjectSelection) {
        if (hasClosedProjects) {
            openProjectAction.selectionChanged(selection);
            menu.add(openProjectAction);
        }
        if (hasOpenProjects) {
            closeProjectAction.selectionChanged(selection);
            menu.add(closeProjectAction);
            closeUnrelatedProjectsAction.selectionChanged(selection);
            menu.add(closeUnrelatedProjectsAction);
        }
    }
    menu.add(new Separator());
    menu.add(new GroupMarker(BUILD_GROUP_MARKER));
    menu.add(new GroupMarker(BUILD_GROUP_MARKER_END));
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.SPNDragSourceListener.java

License:Open Source License

public void dragStart(DragSourceEvent event) {
    fSelectedNodes.clear();/*ww  w  . j ava 2s. c om*/
    if (event.doit) {
        IStructuredSelection sel = (IStructuredSelection) fTreeViewer.getSelection();
        for (Iterator iter = sel.iterator(); iter.hasNext();) {
            Object element = iter.next();
            if (element instanceof IAdaptable) {
                IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
                if (resource != null) {
                    fSelectedNodes.add(resource);
                }
            }
        }
        event.doit = !fSelectedNodes.isEmpty();
    }
}

From source file:com.nokia.carbide.search.system.internal.ui.text.ReplaceAction2.java

License:Open Source License

public ReplaceAction2(FileSearchPage page, IStructuredSelection selection) {
    fSite = page.getSite();//from  w  w  w. j a v a  2 s  . co  m
    fPage = page;
    setText(SearchMessages.ReplaceAction_label_selected);
    fElements = collectFiles(selection.iterator());
    setEnabled(!(fElements.length == 0));
}

From source file:com.nokia.carbide.search.system2.internal.ui.SearchHistorySelectionDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    if (buttonId == REMOVE_ID) {
        IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
        Iterator searchResults = selection.iterator();
        while (searchResults.hasNext()) {
            Object curr = searchResults.next();
            fRemovedEntries.add(curr);//ww w.j a v a2s.com
            fInput.remove(curr);
            fViewer.remove(curr);
        }
        if (fViewer.getSelection().isEmpty() && !fInput.isEmpty()) {
            fViewer.setSelection(new StructuredSelection(fInput.get(0)));
        }
        return;
    }
    if (buttonId == IDialogConstants.OPEN_ID) {
        fIsOpenInNewView = true;
        buttonId = IDialogConstants.OK_ID;
    }
    super.buttonPressed(buttonId);
}

From source file:com.nokia.cdt.internal.debug.launch.ui.ExecutablesBlock.java

License:Open Source License

/**
 * Creates this block's control in the given control.
 * //w  ww  . j a v  a 2s  . co  m
 * @param ancestor
 *            containing control
 */
public void createControl(Composite comp) {
    fControl = comp;

    GridData data;

    Table table = new Table(comp, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    data = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    data.horizontalIndent = 10;
    table.setLayoutData(data);

    table.setHeaderVisible(false);
    table.setLinesVisible(false);
    table.setToolTipText(Messages.getString("ExecutablesTab.TableToolTip")); //$NON-NLS-1$

    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);

    fExeFileList = new CheckboxTableViewer(table);
    fExeFileList.setLabelProvider(new ExeFilesLabelProvider());
    fExeFileList.setContentProvider(new ArrayContentProvider());

    // listen to checks
    fExeFileList.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent e) {
            ExeFileToDebug file = (ExeFileToDebug) e.getElement();
            if (file == fMainExecutable) {
                fExeFileList.setChecked(file, true);
            } else {
                file.setEnabled(e.getChecked());
            }
            if (fExeFileList.getCheckedElements().length == 0)
                fExeFileList.setChecked(fExeFiles.get(0), true);
            fLaunchTab.dataChanged();
        }
    });
    // listen to double clicks
    fExeFileList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent e) {
            IStructuredSelection selection = (IStructuredSelection) e.getSelection();
            for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
                ExeFileToDebug file = (ExeFileToDebug) iterator.next();
                if (file != fMainExecutable) {
                    fExeFileList.setChecked(file, !fExeFileList.getChecked(file));
                }
            }
            if (fExeFileList.getCheckedElements().length == 0)
                fExeFileList.setChecked(fExeFiles.get(0), true);
            fLaunchTab.dataChanged();
        }
    });

    fExeFileList.setComparator(new ViewerComparator());
}

From source file:com.nokia.cdt.internal.debug.launch.ui.FilesBlock.java

License:Open Source License

private void removeFiles() {
    IStructuredSelection selection = (IStructuredSelection) fFileList.getSelection();
    FileToTransfer[] files = new FileToTransfer[selection.size()];
    Iterator<?> iter = selection.iterator();
    int i = 0;/* w  ww . java  2 s  .com*/
    while (iter.hasNext()) {
        files[i] = (FileToTransfer) iter.next();
        i++;
    }
    removeFiles(files);
}

From source file:com.nokia.cdt.internal.debug.launch.wizard.LaunchWizardSelectionPage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    selectedWizard = null;/* www  .j ava  2s.  c  om*/
    setErrorMessage(null);
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    Object selectedObject = null;
    Iterator<?> iter = selection.iterator();
    if (iter.hasNext()) {
        selectedObject = iter.next();
        if (selectedObject instanceof AbstractLaunchWizard)
            selectedWizard = (AbstractLaunchWizard) selectedObject;
    }
    mainWizard.setSelectedWizard(selectedWizard);

    if (selectedWizard == null) {
        setDescriptionText(""); //$NON-NLS-1$
        setSelectedNode(null);
        return;
    }
    setSelectedNode(new WizardNode(this, (Wizard) selectedWizard));
    setDescriptionText(selectedWizard.getDescription());
}

From source file:com.nokia.s60ct.cenrep.gui.view.BitmaskKeyView.java

License:Open Source License

private Object processSelection(ISelection selection) {
    Object selectedObject = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        for (Iterator<Object> iterator = structedSelection.iterator(); iterator.hasNext();) {
            selectedObject = iterator.next();
        }// w w w  .  j a  v a 2 s.  com
    }
    return selectedObject;
}

From source file:com.nokia.s60ct.gui.actions.GenerateAll.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    findConfigurationBrowser();/*ww  w.j  ava2s  . co m*/
    if (editors.size() > 0)
        action.setEnabled(true);
    else {
        action.setEnabled(false);
        if (generateToolButton != null)
            generateToolButton.setToolTipText("Generate All...");
    }

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        for (Iterator iterator = structedSelection.iterator(); iterator.hasNext();) {
            Object object = iterator.next();
            if (object instanceof RootConf) {
                RootConf rc = (RootConf) object;
                boolean rootConfFound = false;
                do //find the root configuration  
                {
                    if (rc.getRoot() == null) {
                        this.rootConf = rc;
                        rootConfFound = true;
                    } else {
                        rc = rc.getRoot();
                    }
                } while (!rootConfFound);
            }
        }
    }
}