Search in sources :

Example 1 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class CellGraphContentProvider method getEdges.

/**
 * Get all edges for the given cells.
 *
 * @param cells an iterable of {@link Cell}s, other objects will be ignored
 * @return the array of edges
 */
protected Object[] getEdges(Iterable<?> cells) {
    List<Edge> edges = new ArrayList<Edge>();
    for (Object object : cells) {
        if (object instanceof Cell) {
            Cell cell = (Cell) object;
            addEdges(cell, edges);
        }
    }
    return edges.toArray();
}
Also used : ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 2 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class TransformationTreeContentProvider method getElements.

/**
 * @see ArrayContentProvider#getElements(Object)
 */
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof TransformationTree)
        return collectNodes((TransformationTree) inputElement).toArray();
    Collection<Instance> instances = null;
    if (inputElement instanceof Pair<?, ?>) {
        Pair<?, ?> pair = (Pair<?, ?>) inputElement;
        inputElement = pair.getFirst();
        if (pair.getSecond() instanceof Collection<?>) {
            instances = (Collection<Instance>) pair.getSecond();
        }
    }
    if (inputElement instanceof Alignment) {
        Alignment alignment = (Alignment) inputElement;
        // input contained specific instances
        if (instances != null && !instances.isEmpty()) {
            Collection<Object> result = new ArrayList<Object>();
            // create transformation trees for each instance
            for (Instance instance : instances) {
                // find type cells matching the instance
                Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
                Collection<Cell> associatedTypeCells = new LinkedList<Cell>();
                for (Cell typeCell : typeCells) for (Entity entity : typeCell.getSource().values()) {
                    TypeEntityDefinition type = (TypeEntityDefinition) entity.getDefinition();
                    if (type.getDefinition().equals(instance.getDefinition()) && (type.getFilter() == null || type.getFilter().match(instance))) {
                        associatedTypeCells.add(typeCell);
                        break;
                    }
                }
                // for each type cell one tree
                for (Cell cell : associatedTypeCells) {
                    TransformationTree tree = createInstanceTree(instance, cell, alignment);
                    if (tree != null)
                        result.addAll(collectNodes(tree));
                }
            }
            return result.toArray();
        }
        // input was alignment only, show trees for all type cells
        Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
        Collection<Object> result = new ArrayList<Object>(typeCells.size());
        for (Cell typeCell : typeCells) {
            // create tree and add nodes for each cell
            result.addAll(collectNodes(new TransformationTreeImpl(alignment, typeCell)));
        }
        return result.toArray();
    }
    return super.getElements(inputElement);
}
Also used : TransformationTreeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TransformationTreeImpl) Entity(eu.esdihumboldt.hale.common.align.model.Entity) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) LinkedList(java.util.LinkedList) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Collection(java.util.Collection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Pair(eu.esdihumboldt.util.Pair)

Example 3 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class GraphLabelProvider method getText.

/**
 * @see LabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition) {
        // use definition text
        return definitionLabels.getText(element);
    }
    if (element instanceof Definition<?>) {
        // use definition text
        return definitionLabels.getText(element);
    }
    if (element instanceof Cell) {
        // use function name if possible
        Cell cell = (Cell) element;
        String functionId = cell.getTransformationIdentifier();
        FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
        if (function != null) {
            return functionLabels.getText(function);
        }
        return functionId;
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getText(element);
    }
    return super.getText(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 4 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class GraphLabelProvider method getImage.

/**
 * @see LabelProvider#getImage(Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition || element instanceof Definition<?>) {
        // use definition image
        return definitionLabels.getImage(element);
    }
    if (element instanceof Cell) {
        // use function image if possible
        Cell cell = (Cell) element;
        String functionId = cell.getTransformationIdentifier();
        FunctionDefinition<?> function = FunctionUtil.getFunction(functionId, serviceProvider);
        if (function != null) {
            Image image = functionLabels.getImage(function);
            if (image == null) {
                // use a default image if none is available
                image = CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_FUNCTION);
            }
            if (cell.isBaseCell()) {
                Image baseAlignmentImage = baseAlignmentFunctionImages.get(functionId);
                if (baseAlignmentImage == null) {
                    baseAlignmentImage = new Image(image.getDevice(), image.getBounds());
                    GC gc = new GC(baseAlignmentImage);
                    try {
                        gc.drawImage(image, 0, 0);
                        gc.drawImage(baseAlignmentFunctionOverlay, 0, 0);
                    } finally {
                        gc.dispose();
                    }
                    baseAlignmentFunctionImages.put(functionId, baseAlignmentImage);
                }
                image = baseAlignmentImage;
            }
            return image;
        }
        return null;
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getImage(element);
    }
    return super.getImage(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 5 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class ClassificationMappingParameterPage method onShowPage.

@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    Cell unfinishedCell = getWizard().getUnfinishedCell();
    sourceEntity = (PropertyEntityDefinition) unfinishedCell.getSource().values().iterator().next().getDefinition();
    sourceProperty = sourceEntity.getDefinition();
    targetEntity = (PropertyEntityDefinition) unfinishedCell.getTarget().values().iterator().next().getDefinition();
    targetProperty = targetEntity.getDefinition();
    if (fixedValueText == null || fixedValueText.getText() != null)
        setPageComplete(true);
}
Also used : ViewerCell(org.eclipse.jface.viewers.ViewerCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)123 ArrayList (java.util.ArrayList)33 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)28 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)28 Test (org.junit.Test)27 Entity (eu.esdihumboldt.hale.common.align.model.Entity)24 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)18 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)13 HashSet (java.util.HashSet)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 List (java.util.List)11 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)9 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)9 Property (eu.esdihumboldt.hale.common.align.model.Property)8