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

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

Introduction

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

Prototype

@Override
    public Iterator iterator() 

Source Link

Usage

From source file:ar.com.tadp.xml.rinzo.core.actions.EditorAndTreeAction.java

License:Open Source License

public void run(IAction action) {
    if (action == null || action instanceof EditorPluginAction) {
        this.runEditor(this.editor.getEditorInputIFile());
    }//www .  j  av a  2s.co  m
    if (action instanceof PluginAction) {
        PluginAction objectAction = (PluginAction) action;
        if (objectAction.getSelection() instanceof TreeSelection) {
            TreeSelection selection = (TreeSelection) objectAction.getSelection();
            List<IFile> files = new ArrayList<IFile>();
            for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
                IFile file = (IFile) iterator.next();
                files.add(file);
            }
            this.runTree(files);
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.properties.PropertySheetPage.java

License:Open Source License

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (selection instanceof TreeSelection && mPropertyTable != null && !mPropertyTable.isDisposed()) {
        TreeSelection treeSelection = (TreeSelection) selection;

        // We get a lot of repeated selection requests for the same selection
        // as before, so try to eliminate these
        if (mSelection != null) {
            if (mSelection.isEmpty()) {
                if (treeSelection.isEmpty()) {
                    return;
                }//  www. j  av  a2 s.  co  m
            } else {
                int selectionCount = treeSelection.size();
                if (selectionCount == mSelection.size()) {
                    boolean same = true;
                    Iterator<?> iterator = treeSelection.iterator();
                    for (int i = 0, n = selectionCount; i < n && iterator.hasNext(); i++) {
                        Object next = iterator.next();
                        if (next instanceof CanvasViewInfo) {
                            CanvasViewInfo info = (CanvasViewInfo) next;
                            if (info != mSelection.get(i)) {
                                same = false;
                                break;
                            }
                        } else {
                            same = false;
                            break;
                        }
                    }
                    if (same) {
                        return;
                    }
                }
            }
        }

        stopTrackingSelection();

        if (treeSelection.isEmpty()) {
            mSelection = Collections.emptyList();
        } else {
            int selectionCount = treeSelection.size();
            List<CanvasViewInfo> newSelection = new ArrayList<CanvasViewInfo>(selectionCount);
            Iterator<?> iterator = treeSelection.iterator();
            while (iterator.hasNext()) {
                Object next = iterator.next();
                if (next instanceof CanvasViewInfo) {
                    CanvasViewInfo info = (CanvasViewInfo) next;
                    newSelection.add(info);
                }
            }
            mSelection = newSelection;
        }

        startTrackingSelection();

        refreshProperties();
    }
}

From source file:com.bluexml.side.form.presentation.FormActionBarContributor.java

License:Open Source License

/**
 * Take a TreeSelection and return true if all have the same FormContainer as parent
 * @param selection/*from w  ww  .  j a va2  s  . co  m*/
 * @return
 */
private boolean haveSameFormContainer(TreeSelection selection) {
    Object o = selection.getFirstElement();
    boolean result = true;
    FormContainer parent = null;
    if (o instanceof FormElement) {
        parent = FormDiagramUtils.getParentForm((FormElement) o);
    }
    if (parent != null) {
        for (Iterator<Object> iterator = selection.iterator(); iterator.hasNext();) {
            Object s = (Object) iterator.next();
            if (s instanceof FormElement) {
                FormContainer sParent = FormDiagramUtils.getParentForm((FormElement) s);
                if (!parent.equals(sParent)) {
                    result = false;
                }
            }

        }
    }
    return result;
}

From source file:com.buildml.eclipse.utils.EclipsePartUtils.java

License:Open Source License

/**
 * Given an Eclipse command handler's selection, such as when a user selects a bunch of UIInteger
 * nodes from a TreeViewer, convert the selection into a FileSet. Selected items that are not of type
 * UIFile or UIDirectory are ignored.// w  ww . j a  v a 2 s.co m
 * @param buildStore The BuildStore that stores the selected objects.
 * @param selection The Eclipse command handler's selection.
 * @return The equivalent FileSet.
 */
public static FileSet getFileSetFromSelection(IBuildStore buildStore, TreeSelection selection) {

    IFileMgr fileMgr = buildStore.getFileMgr();
    FileSet fs = new FileSet(fileMgr);
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        Object item = iter.next();
        if ((item instanceof UIFile) || (item instanceof UIDirectory)) {
            UIInteger uiInt = (UIInteger) item;
            fs.add(uiInt.getId());
        }
    }
    return fs;
}

From source file:com.buildml.eclipse.utils.EclipsePartUtils.java

License:Open Source License

/**
 * Given an Eclipse command handler's selection, such as when a user selects a bunch of UIAction
 * nodes from a TreeViewer, convert the selection into an ActionSet. Selected items that are not of type
 * UIAction are ignored./*  w  ww. j a  v a  2  s.c  om*/
 * @param buildStore The BuildStore that stores the selected objects.
 * @param selection The Eclipse command handler's selection.
 * @return The equivalent ActionSet.
 */
public static ActionSet getActionSetFromSelection(IBuildStore buildStore, TreeSelection selection) {

    IActionMgr actionMgr = buildStore.getActionMgr();
    ActionSet acts = new ActionSet(actionMgr);
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        Object item = iter.next();
        if (item instanceof UIAction) {
            acts.add(((UIAction) item).getId());
        }
    }
    return acts;
}

From source file:de.cau.cs.se.software.evaluation.java.JavaProjectAnalysisHandler.java

License:Apache License

/**
 * Find java project./*w w w  . j a  v a 2 s  . c o  m*/
 *
 * @param selection
 *            the selected Java project
 * @param monitor
 *            the progress monitor
 */
private IProject findProject(final ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        if (selection instanceof ITreeSelection) {
            final TreeSelection treeSelection = (TreeSelection) selection;

            while (treeSelection.iterator().hasNext()) {
                final Object selectedElement = treeSelection.iterator().next();
                if (selectedElement instanceof IProject) {
                    return (IProject) selectedElement;
                } else if (selectedElement instanceof IJavaProject) {
                    return ((IJavaProject) selectedElement).getProject();
                }
            }
        }
    }
    return null;
}

From source file:eu.hydrologis.jgrass.ui.utils.WhatRastTool.java

License:Open Source License

public void onMouseReleased(final MapMouseEvent e) {

    try {//www.ja va  2  s  .  c o m
        final IViewportModel viewportModel = getContext().getViewportModel();
        clickedCoordinate = viewportModel.pixelToWorld(e.x, e.y);

        ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .findView(LayersView.ID).getSite().getSelectionProvider().getSelection();

        jgList = new ArrayList<JGrassMapGeoResource>();
        ncList = new ArrayList<NetcdfMapGeoResource>();
        gcList = new ArrayList<GridCoverage2D>();
        fsList = new ArrayList<SimpleFeatureSource>();
        if (selection instanceof TreeSelection) {
            TreeSelection treeSelection = (TreeSelection) selection;
            Iterator<?> iterator = treeSelection.iterator();
            while (iterator.hasNext()) {
                Object object = iterator.next();
                if (object instanceof LayerImpl) {
                    LayerImpl layer = (LayerImpl) object;
                    JGrassMapGeoResource resourceJGrass = layer.getResource(JGrassMapGeoResource.class,
                            new NullProgressMonitor());
                    if (resourceJGrass != null) {
                        jgList.add(resourceJGrass);
                        continue;
                    }
                    NetcdfMapGeoResource resourceNetcdf = layer.getResource(NetcdfMapGeoResource.class,
                            new NullProgressMonitor());
                    if (resourceNetcdf != null) {
                        ncList.add(resourceNetcdf);
                        continue;
                    }
                    SimpleFeatureSource resourceFeature = layer.getResource(SimpleFeatureSource.class,
                            new NullProgressMonitor());
                    if (resourceFeature != null) {
                        fsList.add(resourceFeature);
                        continue;
                    }
                    AbstractGridCoverage2DReader resourceGC = layer
                            .getResource(AbstractGridCoverage2DReader.class, new NullProgressMonitor());
                    if (resourceGC != null) {
                        gcList.add(resourceGC.read(null));
                        continue;
                    }
                    gcList.clear();
                    jgList.clear();
                    ncList.clear();
                    break;
                }
            }
        }

        if (fsList.size() > 0) {
            showFeatureInfo(e);
        }

        if (jgList.size() > 0) {
            showJGrassInfo(e);
        }

        if (gcList.size() > 0) {
            showGridCoverageInfo(e);
        }

        if (ncList.size() > 0) {
            IRunnableWithProgress operation = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
                    pm.beginTask("Querying netcdf layers...", IProgressMonitor.UNKNOWN);
                    try {
                        showNetcdfInfo(e);
                    } catch (IOException e) {
                        e.printStackTrace();
                        String message = "An error occurred while querying the netcdf data.";
                        ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, UiPlugin.PLUGIN_ID, e);
                    } finally {
                        pm.done();
                    }
                }

            };
            PlatformGIS.runInProgressDialog("Processing data query...", true, operation, true);
        }

        // if (jgList.size() < 1) {
        // Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
        // MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR);
        // msgBox.setMessage("No suitable layer has been selected.");
        // msgBox.open();
        // return;
        // }

    } catch (Exception ex) {
        ex.printStackTrace();
        String message = "An error occurred while querying the data.";
        ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, UiPlugin.PLUGIN_ID, ex);
    }
}

From source file:fr.inria.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }//w w  w  . j  a v  a 2 s .  c o  m

    // Confirm the operation
    Shell shell = window.getShell();
    MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK);
    confirmOperation.setText(Messages.DeleteDialog_Title);
    confirmOperation.setMessage(Messages.DeleteExperimentHandler_Message);
    if (confirmOperation.open() != SWT.OK) {
        return null;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return Boolean.FALSE;
    }
    ISelection selection = part.getSite().getSelectionProvider().getSelection();

    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        Iterator<Object> iterator = sel.iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof TmfExperimentElement) {
                final TmfExperimentElement experiment = (TmfExperimentElement) element;
                IResource resource = experiment.getResource();

                try {
                    // Close the experiment if open
                    experiment.closeEditors();

                    IPath path = resource.getLocation();
                    if (path != null) {
                        // Delete supplementary files
                        experiment.deleteSupplementaryFolder();
                    }

                    // Finally, delete the experiment
                    resource.delete(true, null);

                } catch (final CoreException e) {
                    Display.getDefault().asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            final MessageBox mb = new MessageBox(
                                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
                            mb.setText(Messages.DeleteTraceHandler_Error + ' ' + experiment.getName());
                            mb.setMessage(e.getMessage());
                            mb.open();
                        }
                    });
                    Activator.getDefault().logError("Error deleting experiment: " + experiment.getName(), e); //$NON-NLS-1$
                }
            }
        }
    }

    return null;
}

From source file:name.nirav.evariablesview.ui.ExpandVariablesAction.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
public void run(IAction action) {
    ISelection selection = view.getViewer().getSelection();
    if (selection instanceof TreeSelection) {
        TreeSelection treeSel = (TreeSelection) selection;
        Iterator iterator = treeSel.iterator();
        while (iterator.hasNext()) {
            Object object = iterator.next();
            ((TreeViewer) view.getViewer()).expandToLevel(object, TreeViewer.ALL_LEVELS);
        }//from  w  w  w  .j a  v  a 2 s . co  m

    }
}

From source file:net.tourbook.ui.views.tourCatalog.TourCompareResultView.java

License:Open Source License

private TVICompareResultComparedTour getSelectedComparedTour() {

    final TreeSelection selection = (TreeSelection) _tourViewer.getSelection();
    for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {

        final Object treeItem = iterator.next();
        if (treeItem instanceof TVICompareResultComparedTour) {

            return (TVICompareResultComparedTour) treeItem;
        }/*w  ww  .  jav a2s  .c o m*/
    }

    return null;
}