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();
}
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);
}
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);
}
Aggregations