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

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

Introduction

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

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:com.bluexml.side.view.presentation.ViewActionBarContributor.java

License:Open Source License

/**
 * Add actions specific to cols//from w ww.  ja v a  2  s . co m
 * @param menuManager
 * @param o
 */
private void addActionsForCols(IMenuManager menuManager) {
    // Merge cols :
    TreeSelection selection = ((TreeSelection) this.selectionProvider.getSelection());
    // Check if there is more than one col selected
    if (selection.size() > 0) {
        // Check if all selected objects are cols
        boolean allCol = true;
        for (Object s : selection.toList()) {
            if (!(s instanceof Col)) {
                allCol = false;
            }
        }
        if (allCol) {
            mergeCol.setImageDescriptor(
                    ImageDescriptor.createFromFile(this.getClass(), "/icons/menu/merge.gif"));
            menuManager.insertAfter("ui-actions", mergeCol);
        }
    }
    // Paste configuration
    pasteColConfAction.setImageDescriptor(
            ImageDescriptor.createFromFile(this.getClass(), "/icons/menu/pasteColConf.gif"));
    menuManager.insertAfter("ui-actions", pasteColConfAction);

    // Copy configuration
    copyColConfAction
            .setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "/icons/menu/copyColConf.png"));
    menuManager.insertAfter("ui-actions", copyColConfAction);
}

From source file:com.clustercontrol.repository.composite.action.FacilityTreeSelectionChangedListener.java

License:Open Source License

/**
 * ??????<BR>/*from  www .  j ava2 s .  c  o  m*/
 * ?[]??????<BR>
 * ??????[]?????
 * <P>
 * <ol>
 * <li>??????</li>
 * <li>?[]?????</li>
 * </ol>
 *
 * @param event ?
 *
 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
 */
@Override
public void selectionChanged(SelectionChangedEvent event) {
    FacilityTreeItem selectItem = null;

    if (((StructuredSelection) event.getSelection()).getFirstElement() != null) {
        //??
        selectItem = (FacilityTreeItem) ((StructuredSelection) event.getSelection()).getFirstElement();
    }

    // ?[]??
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart viewPart = page.findView(ScopeListView.ID);

    if (viewPart != null && selectItem != null) {
        ScopeListView view = (ScopeListView) viewPart.getAdapter(ScopeListView.class);

        if (view == null) {
            m_log.info("selection changed: view is null");
            return;
        }

        // Set last focus
        FacilityTreeComposite composite = view.getScopeTreeComposite();
        if (composite != null && composite.getTree().isFocusControl()) {
            view.setLastFocusComposite(composite);
        }

        TreeSelection selection = (TreeSelection) event.getSelection();
        boolean builtin = false;
        if (selectItem.getData().getFacilityType() != FacilityConstant.TYPE_MANAGER) {
            builtin = isBuiltin((List<?>) selection.toList());
        }

        // ??/
        view.setEnabledAction(builtin, selectItem.getData().getFacilityType(), event.getSelection(),
                selectItem.getData().isNotReferFlg());
    }

}

From source file:de.instanttouch.ui.scaffolding.swt.viewer.SnakeTreeViewer.java

License:Open Source License

@Override
public List<SnakeType> getAllSelected() {
    List<SnakeType> all = new ArrayList<SnakeType>();

    if (getSelection() instanceof TreeSelection) {
        TreeSelection treeSelection = (TreeSelection) getSelection();

        for (Object selected : treeSelection.toList()) {
            if (selected instanceof SnakeType) {
                SnakeType type = (SnakeType) selected;
                all.add(type);/*from w  w w .  j av a2 s . c  om*/
            }
        }

    }
    return all;
}

From source file:es.cv.gvcase.emf.ui.common.dialogs.ChooseDialog.java

License:Open Source License

protected void modifySelectionPath(TreeSelection ts) {
    paths.clear();//from  w  w w  .  j  av a2  s. com

    for (Object o : ts.toList()) {
        DataPath dp = new DataPath(o, ts.getPathsFor(o)[0], getAllowedTypesInThePath());
        paths.add(dp);
    }
}

From source file:es.cv.gvcase.fefem.common.composites.EMFContainedHierarchicalCollectionEditionComposite.java

License:Open Source License

/**
 * Creates the a SelectionListener which will invoke the code to remove/delete
 * a selected element from the tree viewer.
 *     /*from w ww  .j  a  v  a 2 s .c  o  m*/
 * @return SelectionListener the {@link SelectionListener} which will
 * remove/delete a selected element from the viewer.  
 */
protected SelectionListener getRemoveButtonSelectionListener() {
    SelectionAdapter adapter = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            TreeViewer viewer = getViewer();
            if (viewer.getSelection() instanceof TreeSelection) {
                TreeSelection selection = (TreeSelection) viewer.getSelection();
                List<?> elementsToDelete = selection.toList();
                if (elementsToDelete.size() > 0) {
                    // We prepare the next selection, based on the element to delete
                    EObject eObject = (EObject) elementsToDelete.get(0);
                    TreePath path = selection.getPathsFor(eObject)[0];
                    TreeSelection nextSelection = TreeSelection.EMPTY;
                    ;
                    if (path.getSegmentCount() == 1) { // If it is a first level element, we will select a sibling element
                        if (modelObservable.size() > 1) { // If we have more than one element 
                            int pos = modelObservable.indexOf(eObject);
                            nextSelection = (pos == modelObservable.size() - 1) // If it's the last first level element, we will select the previous sibling
                                    ? new TreeSelection(
                                            new TreePath(new Object[] { modelObservable.get(pos - 1) }))
                                    : new TreeSelection(
                                            new TreePath(new Object[] { modelObservable.get(pos + 1) })); // otherwise, we will select the next one
                        }
                    } else { // If it is not a first level element, we will select its parent element
                        nextSelection = new TreeSelection(path.getParentPath());
                    }

                    EditingDomain domain = getEditingDomain();
                    domain.getCommandStack().execute(DeleteCommand.create(domain, elementsToDelete));
                    getPage().setDirty(true);
                    viewer.setSelection(nextSelection);
                }
            }
        }
    };
    return adapter;
}

From source file:gov.nasa.ensemble.core.plan.advisor.view.ViolationClickListener.java

License:Open Source License

private void select(ISelection selection) {
    if (selection instanceof TreeSelection) {
        TreeSelection treeSelection = (TreeSelection) selection;
        List<EPlanElement> elements = new ArrayList<EPlanElement>();
        Violation violation = null;/* w  ww .  ja v a2  s . c o  m*/
        EPlan plan = planAdvisorMember.getPlan();
        // can only double click on one violation at a time...
        for (Object object : treeSelection.toList()) {
            if (object instanceof ViolationTracker) {
                violation = ((ViolationTracker) object).getViolation();
                for (EPlanElement element : violation.getElements()) {
                    if (EPlanUtils.getPlan(element) == plan) {
                        elements.add(element);
                    }
                }
            }
        }
        if (!elements.isEmpty()) {
            ISelectionProvider selectionProvider = editor.getSite().getSelectionProvider();
            selectionProvider.setSelection(new StructuredSelection(elements));
        }
        IEditorPart editor = this.editor;
        IResource resource = getResource(editor);
        if (editor instanceof MultiPagePlanEditor) {
            editor = ((MultiPagePlanEditor) editor).getCurrentEditor();
        }
        if (editor instanceof IGotoMarker && violation != null && resource != null) {
            IGotoMarker gotoMarkerEditor = (IGotoMarker) editor;
            try {
                IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
                for (IMarker marker : markers) {
                    Violation markerViolation = planAdvisorMember.getMarkerViolation(marker);
                    if (violation.equals(markerViolation)) {
                        gotoMarkerEditor.gotoMarker(marker);
                        break;
                    }
                }
            } catch (CoreException e) {
                LogUtil.error(e);
            }
        }
    }
}

From source file:ilg.gnuarmeclipse.packs.ui.views.PacksView.java

License:Open Source License

private boolean checkCopyDestinationFolders(TreeSelection selection, String[] param) {

    IPath m_destFolderPath = new Path(param[0]);

    boolean isNonEmpty = false;
    for (Object sel : selection.toList()) {

        PackNode exampleNode = (PackNode) sel;

        Leaf outlineExampleNode = exampleNode.getOutline().findChild(Type.EXAMPLE);

        String exampleRelativeFolder = outlineExampleNode.getProperty(Node.FOLDER_PROPERTY);

        File destFolder = m_destFolderPath.append(exampleRelativeFolder).toFile();

        if (destFolder.isDirectory() && (destFolder.listFiles().length > 0)) {
            isNonEmpty = true;/* w w w .  j  a  v  a  2 s . com*/
            break;
        }

    }

    if (isNonEmpty) {

        String msg = "One of the destination folders is not empty.";
        msg += "\nDo you agree to delete the previous content?";

        String[] buttons = new String[] { "OK", "Cancel" };
        MessageDialog dlg = new MessageDialog(fComposite.getShell(), null, null, msg, MessageDialog.ERROR,
                buttons, 0);
        if (dlg.open() == 0) {
            return true; // OK
        }

        return false;
    }
    return true;
}

From source file:org.eclipse.acceleo.internal.ide.ui.commands.CreateAntCommandHandler.java

License:Open Source License

/**
 * {@inheritDoc}/*ww  w  . j av  a  2s. c  o m*/
 * 
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object applicationContext = event.getApplicationContext();
    if (applicationContext instanceof IEvaluationContext) {
        IEvaluationContext context = (IEvaluationContext) applicationContext;
        Object defaultVariable = context.getDefaultVariable();
        List<IProject> projects = new ArrayList<IProject>();
        if (defaultVariable instanceof List) {
            List<Object> variables = (List<Object>) defaultVariable;
            for (Object object : variables) {
                if (object instanceof IProject) {
                    IProject project = (IProject) object;
                    projects.add(project);
                } else if (object instanceof IJavaProject) {
                    IJavaProject javaProject = (IJavaProject) object;
                    projects.add(javaProject.getProject());
                } else if (Platform.getAdapterManager().getAdapter(object,
                        IProject.class) instanceof IProject) {
                    projects.add((IProject) Platform.getAdapterManager().getAdapter(object, IProject.class));
                }
            }
        } else if (defaultVariable instanceof TreeSelection && ((TreeSelection) defaultVariable).size() > 0) {
            TreeSelection selection = (TreeSelection) defaultVariable;
            List<?> list = selection.toList();
            for (Object object : list) {
                if (object instanceof IProject) {
                    IProject project = (IProject) object;
                    projects.add(project);
                } else if (object instanceof IJavaProject) {
                    IJavaProject javaProject = (IJavaProject) object;
                    projects.add(javaProject.getProject());
                } else if (Platform.getAdapterManager().getAdapter(object,
                        IProject.class) instanceof IProject) {
                    projects.add((IProject) Platform.getAdapterManager().getAdapter(object, IProject.class));
                }
            }
        }

        for (IProject iProject : projects) {
            try {
                if (iProject.isAccessible() && iProject.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID)) {
                    generateAnt(iProject);
                }
            } catch (CoreException e) {
                AcceleoUIActivator.log(e, true);
            }
        }
    }
    return applicationContext;
}

From source file:org.eclipse.acceleo.internal.ide.ui.commands.CreateAntCommandHandler.java

License:Open Source License

/**
 * {@inheritDoc}//from   w  w w .  java  2  s.c o m
 * 
 * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
 */
@Override
public void setEnabled(Object evaluationContext) {
    if (evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext context = (IEvaluationContext) evaluationContext;
        Object defaultVariable = context.getDefaultVariable();
        if (defaultVariable instanceof List && ((List) defaultVariable).size() > 0) {
            List<Object> variables = (List<Object>) defaultVariable;
            for (Object object : variables) {
                try {
                    if (object instanceof IProject) {
                        IProject project = (IProject) object;
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    } else if (object instanceof IJavaProject) {
                        IProject project = ((IJavaProject) object).getProject();
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    } else if (Platform.getAdapterManager().getAdapter(object,
                            IProject.class) instanceof IProject) {
                        IProject project = (IProject) Platform.getAdapterManager().getAdapter(object,
                                IProject.class);
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    }
                } catch (CoreException e) {
                    AcceleoUIActivator.log(e, true);
                }
            }
        } else if (defaultVariable instanceof TreeSelection && ((TreeSelection) defaultVariable).size() > 0) {
            TreeSelection selection = (TreeSelection) defaultVariable;
            List<?> list = selection.toList();
            for (Object object : list) {
                try {
                    if (object instanceof IProject) {
                        IProject project = (IProject) object;
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    } else if (object instanceof IJavaProject) {
                        IProject project = ((IJavaProject) object).getProject();
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    } else if (Platform.getAdapterManager().getAdapter(object,
                            IProject.class) instanceof IProject) {
                        IProject project = (IProject) Platform.getAdapterManager().getAdapter(object,
                                IProject.class);
                        enabled = project.isAccessible()
                                && project.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID);
                    }
                } catch (CoreException e) {
                    AcceleoUIActivator.log(e, true);
                }
            }
        }
    } else {
        // Eclipse 4, let's consider that it's true.
        enabled = true;
    }
}

From source file:org.eclipse.acceleo.internal.ide.ui.commands.CreatePomCommandHandler.java

License:Open Source License

/**
 * {@inheritDoc}//from  ww  w  .ja v a2  s .  c om
 * 
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object applicationContext = event.getApplicationContext();
    if (applicationContext instanceof IEvaluationContext) {
        IEvaluationContext context = (IEvaluationContext) applicationContext;
        Object defaultVariable = context.getDefaultVariable();
        List<IProject> projects = new ArrayList<IProject>();
        if (defaultVariable instanceof List) {
            List<Object> variables = (List<Object>) defaultVariable;
            for (Object object : variables) {
                if (object instanceof IProject) {
                    IProject project = (IProject) object;
                    projects.add(project);
                } else if (object instanceof IJavaProject) {
                    IJavaProject javaProject = (IJavaProject) object;
                    projects.add(javaProject.getProject());
                } else if (Platform.getAdapterManager().getAdapter(object,
                        IProject.class) instanceof IProject) {
                    projects.add((IProject) Platform.getAdapterManager().getAdapter(object, IProject.class));
                }
            }
        } else if (defaultVariable instanceof TreeSelection && ((TreeSelection) defaultVariable).size() > 0) {
            TreeSelection selection = (TreeSelection) defaultVariable;
            List<?> list = selection.toList();
            for (Object object : list) {
                if (object instanceof IProject) {
                    IProject project = (IProject) object;
                    projects.add(project);
                } else if (object instanceof IJavaProject) {
                    IJavaProject javaProject = (IJavaProject) object;
                    projects.add(javaProject.getProject());
                } else if (Platform.getAdapterManager().getAdapter(object,
                        IProject.class) instanceof IProject) {
                    projects.add((IProject) Platform.getAdapterManager().getAdapter(object, IProject.class));
                }
            }
        }

        for (IProject iProject : projects) {
            try {
                if (iProject.isAccessible() && iProject.hasNature(IAcceleoConstants.ACCELEO_NATURE_ID)) {
                    generatePom(iProject);
                }
            } catch (CoreException e) {
                AcceleoUIActivator.log(e, true);
            }
        }
    }
    return applicationContext;
}