Search in sources :

Example 1 with IdentityWrapper

use of eu.esdihumboldt.util.IdentityWrapper in project hale by halestudio.

the class TransformationTreeContentProvider method getChilddren.

/**
 * Get the children of a node
 *
 * @param node the node
 * @return the node's children
 */
private Collection<? extends Object> getChilddren(Object node) {
    if (node instanceof IdentityWrapper<?>) {
        node = ((IdentityWrapper<?>) node).getValue();
    }
    if (node instanceof TransformationTree) {
        return wrapNodes(((TransformationTree) node).getChildren(true));
    }
    if (node instanceof TargetNode) {
        List<Object> children = new ArrayList<Object>();
        children.addAll(((TargetNode) node).getChildren(true));
        children.addAll(((TargetNode) node).getAssignments());
        return wrapNodes(children);
    }
    if (node instanceof CellNode) {
        return wrapNodes(((CellNode) node).getSources());
    }
    if (node instanceof SourceNode) {
        SourceNode parent = ((SourceNode) node).getParent();
        if (parent != null) {
            return Collections.singleton(new IdentityWrapper<Object>(parent));
        }
    }
    return Collections.emptyList();
}
Also used : CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) ArrayList(java.util.ArrayList) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)

Example 2 with IdentityWrapper

use of eu.esdihumboldt.util.IdentityWrapper in project hale by halestudio.

the class TransformationTreeLabelProvider method getFigure.

/**
 * @see GraphLabelProvider#getFigure(Object)
 */
@Override
public IFigure getFigure(Object element) {
    if (element instanceof IdentityWrapper<?>) {
        element = ((IdentityWrapper<?>) element).getValue();
    }
    ShapePainter shape = null;
    String contextText = null;
    String cardText = null;
    if (element instanceof TransformationTree) {
        shape = new TransformationNodeShape(10, SWT.NONE);
    } else if (element instanceof TargetNode) {
        TargetNode node = (TargetNode) element;
        contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
        if (!hasTransformationAnnotations(element)) {
            cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
        }
        if (node.getAssignments().isEmpty()) {
            shape = new TransformationNodeShape(10, SWT.NONE);
        } else {
            // shape = new TransformationNodeShape(10, SWT.LEFT);
            shape = new FingerPost(10, SWT.LEFT);
        }
    } else if (element instanceof SourceNode) {
        SourceNode node = (SourceNode) element;
        contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
        if (!hasTransformationAnnotations(element)) {
            cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
        }
        if (node.getParent() == null) {
            shape = new TransformationNodeShape(10, SWT.NONE);
        } else {
            shape = new FingerPost(10, SWT.RIGHT);
        }
    }
    if (shape != null) {
        CustomShapeFigure figure;
        if (contextText != null || cardText != null) {
            figure = new EntityFigure(shape, contextText, cardText, getCustomFigureFont());
        } else {
            figure = new CustomShapeLabel(shape, getCustomFigureFont());
        }
        figure.setMaximumWidth(MAX_FIGURE_WIDTH);
        return figure;
    }
    element = TransformationTreeUtil.extractObject(element);
    return super.getFigure(element);
}
Also used : SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) EntityFigure(eu.esdihumboldt.hale.ui.common.graph.figures.EntityFigure) CustomShapeFigure(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure) FingerPost(eu.esdihumboldt.hale.ui.util.graph.shapes.FingerPost) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) ShapePainter(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure.ShapePainter) CustomShapeLabel(eu.esdihumboldt.hale.ui.util.graph.CustomShapeLabel) TransformationNodeShape(eu.esdihumboldt.hale.ui.common.graph.figures.TransformationNodeShape)

Example 3 with IdentityWrapper

use of eu.esdihumboldt.util.IdentityWrapper in project hale by halestudio.

the class TransformationTreeLabelProvider method getText.

/**
 * @see GraphLabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof IdentityWrapper<?>) {
        element = ((IdentityWrapper<?>) element).getValue();
    }
    if (element instanceof EntityConnectionData) {
        // text for connections
        EntityConnectionData connection = (EntityConnectionData) element;
        Set<String> names = null;
        Object source = connection.source;
        if (source instanceof IdentityWrapper<?>) {
            source = ((IdentityWrapper<?>) source).getValue();
        }
        Object dest = connection.dest;
        if (dest instanceof IdentityWrapper<?>) {
            dest = ((IdentityWrapper<?>) dest).getValue();
        }
        if (source instanceof TargetNode && dest instanceof CellNode) {
            names = ((TargetNode) source).getAssignmentNames((CellNode) dest);
        }
        if (source instanceof CellNode && dest instanceof SourceNode) {
            names = ((CellNode) source).getSourceNames((SourceNode) dest);
        }
        if (names != null && !names.isEmpty()) {
            if (names.contains(null)) {
                names = new HashSet<String>(names);
                names.remove(null);
                if (!names.isEmpty()) {
                    names.add("(unnamed)");
                }
            }
            // build name string
            Joiner joiner = Joiner.on(',');
            return joiner.join(names);
        }
        return "";
    }
    if (hasTransformationAnnotations(element)) {
        if (element instanceof SourceNode) {
            SourceNode node = (SourceNode) element;
            if (node.isDefined()) {
                Object value = node.getValue();
                if (value == null) {
                    // no value
                    return "(not set)";
                } else if (value instanceof Instance) {
                    // use the instance value if present
                    value = ((Instance) value).getValue();
                }
                if (value != null && !(value instanceof Group)) {
                    // TODO shorten if needed?
                    return value.toString();
                }
            // otherwise, just display the definition name
            }
        }
    }
    element = TransformationTreeUtil.extractObject(element);
    return super.getText(element);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) Joiner(com.google.common.base.Joiner) EntityConnectionData(org.eclipse.zest.core.viewers.EntityConnectionData) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper)

Aggregations

SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)3 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)3 IdentityWrapper (eu.esdihumboldt.util.IdentityWrapper)3 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)2 TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)2 Joiner (com.google.common.base.Joiner)1 Group (eu.esdihumboldt.hale.common.instance.model.Group)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 EntityFigure (eu.esdihumboldt.hale.ui.common.graph.figures.EntityFigure)1 TransformationNodeShape (eu.esdihumboldt.hale.ui.common.graph.figures.TransformationNodeShape)1 CustomShapeFigure (eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure)1 ShapePainter (eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure.ShapePainter)1 CustomShapeLabel (eu.esdihumboldt.hale.ui.util.graph.CustomShapeLabel)1 FingerPost (eu.esdihumboldt.hale.ui.util.graph.shapes.FingerPost)1 ArrayList (java.util.ArrayList)1 EntityConnectionData (org.eclipse.zest.core.viewers.EntityConnectionData)1