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