Search in sources :

Example 1 with Alignment

use of eu.esdihumboldt.hale.common.align.model.Alignment 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 2 with Alignment

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

the class AlignmentViewContentProvider method getEdges.

/**
 * Get all edges for the given type cell and its property cells.
 *
 * @param typeCell the type cell to show
 * @return the array of edges
 */
private Object[] getEdges(Cell typeCell) {
    List<Edge> edges = new ArrayList<Edge>();
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    boolean dummyCell;
    if (typeCell.getId() != null) {
        // XXX really filter type cell out?
        if (select(typeCell)) {
            addEdges(typeCell, edges);
        }
        dummyCell = false;
    } else {
        // dummy cell, look for matching type cells
        for (Cell cell : alignment.getTypeCells(typeCell)) if (select(cell))
            addEdges(cell, edges);
        dummyCell = true;
    }
    for (Cell cell : sortCells(as.getAlignment().getPropertyCells(typeCell, true, dummyCell))) {
        if (!select(cell))
            continue;
        Cell reparentCell = AlignmentUtil.reparentCell(cell, typeCell, false);
        // to the original cell
        if (reparentCell == cell)
            addEdges(cell, edges);
        else {
            // add edges leading to the cell for each source entity
            if (reparentCell.getSource() != null) {
                for (Entry<String, ? extends Entity> entry : reparentCell.getSource().entries()) {
                    edges.add(new Edge(entry.getValue(), cell, entry.getKey()));
                }
            }
            // add edges leading to the target entities from the cell
            for (Entry<String, ? extends Entity> entry : reparentCell.getTarget().entries()) {
                edges.add(new Edge(cell, entry.getValue(), entry.getKey()));
            }
        }
    }
    return edges.toArray();
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) Edge(eu.esdihumboldt.hale.ui.common.graph.content.Edge) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 3 with Alignment

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

the class MappingView method update.

/**
 * Update the view
 *
 * @param selection the selection
 */
protected void update(SchemaSelection selection) {
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    List<Cell> cells = new ArrayList<Cell>();
    Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
    // find cells associated with the selection
    for (Cell cell : alignment.getCells()) {
        if ((cell.getSource() != null && associatedWith(items.getFirst(), cell)) || associatedWith(items.getSecond(), cell)) {
            cells.add(cell);
        }
    }
    getViewer().setInput(cells);
    updateLayout(true);
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) HashSet(java.util.HashSet) Set(java.util.Set) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 4 with Alignment

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

the class OrientInstanceService method performTransformation.

/**
 * Perform the transformation
 *
 * @return if the transformation was successful
 */
protected boolean performTransformation() {
    final TransformationService ts = getTransformationService();
    if (ts == null) {
        log.userError("No transformation service available");
        return false;
    }
    final AtomicBoolean transformationFinished = new AtomicBoolean(false);
    final AtomicBoolean transformationCanceled = new AtomicBoolean(false);
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                Alignment alignment = getAlignmentService().getAlignment();
                if (alignment.getActiveTypeCells().isEmpty()) {
                    // early exit if there are no type relations
                    return;
                }
                // determine if there are any active type cells w/o source
                boolean transformEmpty = false;
                for (Cell cell : alignment.getActiveTypeCells()) {
                    if (cell.getSource() == null || cell.getSource().isEmpty()) {
                        transformEmpty = true;
                        break;
                    }
                }
                InstanceCollection sources = getInstances(DataSet.SOURCE);
                if (!transformEmpty && sources.isEmpty()) {
                    return;
                }
                HaleOrientInstanceSink sink = new HaleOrientInstanceSink(transformed, true);
                TransformationReport report;
                ATransaction trans = log.begin("Instance transformation");
                try {
                    report = ts.transform(alignment, sources, sink, HaleUI.getServiceProvider(), new ProgressMonitorIndicator(monitor));
                    // publish report
                    ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
                    rs.addReport(report);
                } finally {
                    try {
                        sink.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    trans.end();
                }
            } finally {
                // remember if canceled
                if (monitor.isCanceled()) {
                    transformationCanceled.set(true);
                }
                // transformation finished
                transformationFinished.set(true);
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, ts.isCancelable());
    } catch (Throwable e) {
        log.error("Error starting transformation process", e);
    }
    // wait for transformation to complete
    HaleUI.waitFor(transformationFinished);
    return !transformationCanceled.get();
}
Also used : TransformationReport(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) BrowseOrientInstanceCollection(eu.esdihumboldt.hale.common.instance.orient.storage.BrowseOrientInstanceCollection) FilteredInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ATransaction(de.fhg.igd.slf4jplus.ATransaction) TransformationService(eu.esdihumboldt.hale.common.align.transformation.service.TransformationService) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 5 with Alignment

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

the class TypeEntityDialog method addToolBarActions.

/**
 * @see eu.esdihumboldt.hale.ui.function.common.EntityDialog#addToolBarActions(org.eclipse.jface.action.ToolBarManager)
 */
@Override
protected void addToolBarActions(ToolBarManager manager) {
    // filter to only show mapped types
    manager.add(new FilterAction("Hide unmapped types", "Show unmapped types", HALEUIPlugin.getImageDescriptor("icons/empty.gif"), getViewer(), new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            if (element instanceof TreePath)
                element = ((TreePath) element).getLastSegment();
            return isMapped((ITreeContentProvider) ((TreeViewer) viewer).getContentProvider(), element, alignment);
        }

        private boolean isMapped(ITreeContentProvider cp, Object element, Alignment align) {
            if (element instanceof EntityDefinition) {
                boolean mapped = AlignmentUtil.entityOrChildMapped((EntityDefinition) element, align);
                if (mapped)
                    return true;
            }
            // recursively check children
            Object[] children = cp.getChildren(element);
            if (children != null)
                for (Object child : children) if (isMapped(cp, child, align))
                    return true;
            return false;
        }
    }, true, true));
    // do not add choice if only mapping relevant types should be selected
    if (onlyMappingRelevant)
        return;
    manager.add(new Separator());
    // MappingRelevant types only, flat
    manager.add(new ContentProviderAction("Mapping relevant types as list", HALEUIPlugin.getImageDescriptor("icons/flat_relevant.png"), getViewer(), flatRelevantProvider, false));
    // MappingRelevant types only, hierarchical
    manager.add(new ContentProviderAction("Mapping relevant types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_relevant.png"), getViewer(), hierarchicalRelevantProvider, false));
    // Mappable types, flat
    manager.add(new ContentProviderAction("All types as list", HALEUIPlugin.getImageDescriptor("icons/flat_all.png"), getViewer(), flatAllProvider, true));
    // Mappable types, hierarchical
    manager.add(new ContentProviderAction("All types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_all.png"), getViewer(), hierarchicalAllProvider, false));
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentProviderAction(eu.esdihumboldt.hale.ui.service.entity.util.ContentProviderAction) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TreePath(org.eclipse.jface.viewers.TreePath) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) FilterAction(eu.esdihumboldt.hale.ui.util.viewer.FilterAction) Separator(org.eclipse.jface.action.Separator)

Aggregations

Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)23 Cell (eu.esdihumboldt.hale.common.align.model.Cell)12 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)10 ArrayList (java.util.ArrayList)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)6 CustomPropertyFunction (eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)5 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)5 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)4 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)3 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)3 URI (java.net.URI)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ATransaction (de.fhg.igd.slf4jplus.ATransaction)2 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)2 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2