Search in sources :

Example 1 with EntityConnectionData

use of org.eclipse.zest.core.viewers.EntityConnectionData 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

Joiner (com.google.common.base.Joiner)1 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)1 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)1 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)1 Group (eu.esdihumboldt.hale.common.instance.model.Group)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 IdentityWrapper (eu.esdihumboldt.util.IdentityWrapper)1 EntityConnectionData (org.eclipse.zest.core.viewers.EntityConnectionData)1