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