Search in sources :

Example 61 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class PropertyDefinitionDialog method getObjectFromSelection.

@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            return (EntityDefinition) element;
        }
    }
    if (!selection.isEmpty() && selection instanceof ITreeSelection) {
        // create property definition w/ default contexts
        TreePath path = ((ITreeSelection) selection).getPaths()[0];
        // get parent type
        TypeDefinition type = ((ChildDefinition<?>) path.getFirstSegment()).getParentType();
        // determine definition path
        List<ChildContext> defPath = new ArrayList<ChildContext>();
        for (int i = 0; i < path.getSegmentCount(); i++) {
            defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
        }
        // TODO check if property entity definition is applicable?
        return new PropertyEntityDefinition(type, defPath, ssid, null);
    }
    return null;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 62 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class SchemaPatternFilter method isElementVisible.

/**
 * @see eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter#isElementVisible(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object)
 */
@Override
public boolean isElementVisible(Viewer viewer, Object element) {
    TreePath elementPath = (TreePath) element;
    Object segment = elementPath.getLastSegment();
    if (segment instanceof EntityDefinition) {
        segment = ((EntityDefinition) segment).getDefinition();
    }
    if (memoryAccepted.contains(segment))
        return true;
    if (memoryRejected.contains(segment))
        return false;
    boolean match = isLeafMatch(viewer, element);
    if (!match) {
        match = isParentMatch(viewer, element);
        if (!match) {
            memoryRejected.add(segment);
        }
    }
    if (match) {
        memoryAccepted.add(segment);
    }
    return match;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath)

Example 63 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class SchemaPatternFilter method isLeafMatch.

/**
 * @see eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter#isLeafMatch(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object)
 */
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
    boolean leaf = matches(viewer, element);
    if (leaf) {
        return true;
    }
    // return true, if this element' definition was classified as visible
    TreePath elementPath = (TreePath) element;
    Object segment = elementPath.getLastSegment();
    if (segment instanceof EntityDefinition) {
        segment = ((EntityDefinition) segment).getDefinition();
    }
    return memoryAccepted.contains(segment);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath)

Example 64 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class TreePathFilteredTree method getPathsForElements.

/**
 * Get the tree paths for the given objects with the given parent path.
 *
 * @param parentPath the parent path for each object
 * @param elements the objects
 * @return the list of tree paths
 */
public static List<TreePath> getPathsForElements(TreePath parentPath, Object[] elements) {
    List<TreePath> paths = new ArrayList<TreePath>();
    // create tree paths from elements
    List<Object> parentSegments = new ArrayList<Object>();
    if (parentPath != null) {
        for (int i = 0; i < parentPath.getSegmentCount(); i++) {
            parentSegments.add(parentPath.getSegment(i));
        }
    }
    for (Object element : elements) {
        TreePath path;
        if (parentPath == null) {
            path = new TreePath(new Object[] { element });
        } else {
            parentSegments.add(element);
            path = new TreePath(parentSegments.toArray());
            parentSegments.remove(parentSegments.size() - 1);
        }
        paths.add(path);
    }
    return paths;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList)

Example 65 with TreePath

use of org.eclipse.jface.viewers.TreePath in project hale by halestudio.

the class ClassificationFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof TreePath) {
        element = ((TreePath) element).getLastSegment();
    }
    if (element instanceof EntityDefinition) {
        element = ((EntityDefinition) element).getDefinition();
    }
    if (hidden.isEmpty() || !(element instanceof Definition<?>)) {
        // fast exit
        return true;
    }
    Definition<?> def = (Definition<?>) element;
    Classification clazz = Classification.getClassification(def);
    return !hidden.contains(clazz);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TreePath(org.eclipse.jface.viewers.TreePath) Classification(eu.esdihumboldt.hale.common.schema.Classification) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition)

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