Search in sources :

Example 81 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class DataModelMainPage method getStructureByActiveItem.

public XSDAnnotationsStructure getStructureByActiveItem() {
    XSDComponent xSDCom = null;
    XSDAnnotationsStructure struc = null;
    IStructuredSelection selection = (TreeSelection) getTreeViewer().getSelection();
    if (selection.getFirstElement() instanceof Element) {
        TreePath tPath = ((TreeSelection) selection).getPaths()[0];
        for (int i = 0; i < tPath.getSegmentCount(); i++) {
            if (tPath.getSegment(i) instanceof XSDAnnotation) {
                xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        }
    } else {
        xSDCom = (XSDComponent) selection.getFirstElement();
    }
    if (xSDCom != null) {
        struc = new XSDAnnotationsStructure(xSDCom);
    }
    return struc;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 82 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class DataModelMainPage method activeMarkerItem.

private void activeMarkerItem(TreeViewer v, Element dom) {
    ITreeContentProvider provider = (ITreeContentProvider) v.getContentProvider();
    for (Object data : provider.getElements(xsdSchema)) {
        Object[] foundData = findMarkerData(provider, data, dom, new Object[0]);
        if (foundData != null) {
            TreePath treePath = new TreePath(foundData);
            v.setSelection(new TreeSelection(treePath));
            return;
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) TreeObject(com.amalto.workbench.models.TreeObject)

Example 83 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class TreeExpandHelper method removeInvalidTreePaths.

private TreePath[] removeInvalidTreePaths(TreePath[] expandedElementPaths) {
    Map<Integer, Set<TreePath>> pathMaps = new HashMap<Integer, Set<TreePath>>();
    int maxSegmentCount = -1;
    for (TreePath path : expandedElementPaths) {
        int segmentCount = path.getSegmentCount();
        Set<TreePath> pathSet = pathMaps.get(segmentCount);
        if (pathSet == null) {
            pathSet = new HashSet<TreePath>();
            pathMaps.put(segmentCount, pathSet);
        }
        pathSet.add(path);
        // 
        if (maxSegmentCount < segmentCount) {
            maxSegmentCount = segmentCount;
        }
    }
    Set<TreePath> roots = pathMaps.get(1);
    if (roots == null || roots.size() == 0) {
        return new TreePath[0];
    }
    // record TreePath by tree level
    List<TreePath> paths = new ArrayList<TreePath>();
    paths.addAll(roots);
    for (int i = 2; i < maxSegmentCount + 1; i++) {
        Set<TreePath> set = pathMaps.get(i);
        if (set == null || set.size() == 0) {
            break;
        }
        Set<TreePath> parents = pathMaps.get(i - 1);
        Iterator<TreePath> iterator = set.iterator();
        while (iterator.hasNext()) {
            TreePath path = iterator.next();
            if (parents.contains(path.getParentPath())) {
                paths.add(path);
            } else {
                iterator.remove();
            }
        }
    }
    return paths.toArray(new TreePath[0]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TreePath(org.eclipse.jface.viewers.TreePath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 84 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class TreeExpandHelper method getExpandedNodes.

private List<ExpandInfoNode> getExpandedNodes(TreePath[] expandedElementPaths) {
    TreePath[] expandedPaths = removeInvalidTreePaths(expandedElementPaths);
    List<ExpandInfoNode> expanded = new ArrayList<ExpandInfoNode>();
    ExpandInfoNode rootNode = null;
    for (TreePath path : expandedPaths) {
        int segmentCount = path.getSegmentCount();
        Object firstSegment = path.getFirstSegment();
        rootNode = ExpandInfoNode.create(getName(firstSegment), firstSegment.getClass().getName());
        if (expanded.contains(rootNode)) {
            rootNode = expanded.get(expanded.indexOf(rootNode));
        } else {
            expanded.add(rootNode);
        }
        for (int i = 1; i < segmentCount; i++) {
            Object segment = path.getSegment(i);
            ExpandInfoNode newNode = ExpandInfoNode.create(getName(segment), segment.getClass().getName());
            if (rootNode.childs == null) {
                rootNode.addChild(newNode);
            } else {
                if (rootNode.childs.contains(newNode)) {
                    newNode = rootNode.childs.get(rootNode.childs.indexOf(newNode));
                } else {
                    rootNode.addChild(newNode);
                }
            }
            rootNode = newNode;
        }
    }
    return expanded;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList)

Example 85 with TreePath

use of org.eclipse.jface.viewers.TreePath in project abstools by abstools.

the class LinkHelper method buildTreeSelection.

/**
 * Build up a {@link TreeSelection} suitable for the ABSNavigator from the
 * given component
 *
 * @param project
 *            IProject The according project of the ModuleDecl.
 * @param md
 *            ModuleDecl The target ModuleDecl to highlight.
 * @return A TreeSelection including a {@link TreePath} from project to md
 *         or null if md or project is null, or if no ABSnature can be
 *         retrieved from project
 */
private static TreeSelection buildTreeSelection(AbsNature nature, IProject project, InternalASTNode<ModuleDecl> md) {
    assert nature != null;
    // TODO: if this holds (as it should), remove argument
    assert nature == md.getNature();
    if (project != null && md != null) {
        // Split the module's name and return the module hierarchy
        ArrayList<ModulePath> paths = md.getParentHierarchyForModuleDecl();
        ArrayList<Object> arli = new ArrayList<Object>();
        arli.add(project);
        if (paths.size() > 0) {
            ModulePath lastElement = paths.get(paths.size() - 1);
            arli.addAll(paths);
            if (!(lastElement.hasModule() && lastElement.getModulePath().equals(md.getASTNode().getName()))) {
                arli.add(md);
            }
        } else {
            if (NavigatorUtils.hasSubModules(md)) {
                arli.add(new ModulePath(nature, md.getASTNode().getName()));
            } else {
                arli.add(md);
            }
        }
        TreePath path = new TreePath(arli.toArray());
        TreeSelection ts = new TreeSelection(new TreePath[] { path });
        return ts;
    }
    return null;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ArrayList(java.util.ArrayList)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5