Search in sources :

Example 21 with Cell

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

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

the class AlignmentViewContentProvider method getElements.

/**
 * @see eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider#getElements(java.lang.Object)
 */
@Override
public Object[] getElements(Object input) {
    // check if the input is a (incomplete) type cell
    if (input instanceof Cell) {
        Cell cell = (Cell) input;
        Entity source = CellUtil.getFirstEntity(cell.getSource());
        Entity target = CellUtil.getFirstEntity(cell.getTarget());
        if ((source == null || source instanceof Type) && (target == null || target instanceof Type))
            return getEdges((Cell) input);
    }
    return super.getElements(input);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Type(eu.esdihumboldt.hale.common.align.model.Type) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 23 with Cell

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

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

the class MappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    super.createViewControl(parent);
    updateLayout(false);
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(selection instanceof SchemaSelection)) {
                // only react on schema selections
                return;
            }
            if (part != MappingView.this) {
                update((SchemaSelection) selection);
            }
        }
    });
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    // update();
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            List<Cell> changedCells = new ArrayList<Cell>(2);
            changedCells.addAll(cells.keySet());
            changedCells.addAll(cells.values());
            updateViewWithCurrentSelection(changedCells);
        }

        @Override
        public void customFunctionsChanged() {
            SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
            if (current != null) {
                update(current);
            }
        }

        @Override
        public void cellsAdded(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            updateViewWithCurrentSelection(cells);
        }
    });
    TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
    taskService.addListener(new TaskServiceListener() {

        @Override
        public void tasksRemoved(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void tasksAdded(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void taskUserDataChanged(ResolvedTask<?> task) {
            updateViewWithCurrentSelection(getAffectedCells(Collections.singleton(task)));
        }

        private List<Cell> getAffectedCells(Iterable<Task<?>> tasks) {
            List<Cell> affectedCells = new ArrayList<>();
            tasks.forEach(t -> {
                if (t.getMainContext() instanceof Cell) {
                    affectedCells.add((Cell) t.getMainContext());
                }
            });
            return affectedCells;
        }
    });
    SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
    if (current != null) {
        update(current);
    }
    // listen on size changes
    getViewer().getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            updateLayout(true);
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Dimension(org.eclipse.draw2d.geometry.Dimension) ListMultimap(com.google.common.collect.ListMultimap) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IToolBarManager(org.eclipse.jface.action.IToolBarManager) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) MappingViewPlugin(eu.esdihumboldt.hale.ui.views.mapping.internal.MappingViewPlugin) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Type(eu.esdihumboldt.hale.common.align.model.Type) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) Pair(eu.esdihumboldt.util.Pair) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) WorkbenchPart(org.eclipse.ui.part.WorkbenchPart) PlatformUI(org.eclipse.ui.PlatformUI) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) Collection(java.util.Collection) Set(java.util.Set) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) Action(org.eclipse.jface.action.Action) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) List(java.util.List) AlignmentServiceListener(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ISelection(org.eclipse.jface.viewers.ISelection) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Task(eu.esdihumboldt.hale.common.tasks.Task) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) SchemaSelectionHelper(eu.esdihumboldt.hale.ui.selection.SchemaSelectionHelper) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ArrayList(java.util.ArrayList) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 25 with Cell

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

the class MappingView method createLabelProvider.

@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
    return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {

        @Override
        protected boolean isInherited(Cell cell) {
            // cannot inherit type cells
            if (AlignmentUtil.isTypeCell(cell))
                return false;
            SchemaSelection selection = SchemaSelectionHelper.getSchemaSelection();
            if (selection != null && !selection.isEmpty()) {
                DefaultCell dummyTypeCell = new DefaultCell();
                ListMultimap<String, Type> sources = ArrayListMultimap.create();
                ListMultimap<String, Type> targets = ArrayListMultimap.create();
                Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
                for (EntityDefinition def : items.getFirst()) sources.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
                for (EntityDefinition def : items.getSecond()) targets.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
                dummyTypeCell.setSource(sources);
                dummyTypeCell.setTarget(targets);
                return AlignmentUtil.reparentCell(cell, dummyTypeCell, true) != cell;
            } else
                return false;
        }
    };
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) HashSet(java.util.HashSet) Set(java.util.Set) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

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