use of eu.esdihumboldt.hale.ui.service.align.AlignmentService 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.ui.service.align.AlignmentService in project hale by halestudio.
the class FunctionsView method dispose.
@Override
public void dispose() {
if (compListener != null) {
CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
cs.removeListener(compListener);
}
if (alignListener != null) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.removeListener(alignListener);
}
super.dispose();
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService 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));
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class EditRelationHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof Cell) {
final Cell originalCell = (Cell) selected;
FunctionWizard wizard = null;
List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {
@Override
public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
return true;
}
});
if (!factories.isEmpty()) {
// create registered wizard
FunctionWizardDescriptor<?> fwd = factories.get(0);
wizard = fwd.createEditWizard(originalCell);
}
if (wizard == null) {
FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
if (function == null) {
log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
return null;
}
// create generic wizard
if (function instanceof TypeFunction) {
wizard = new GenericTypeFunctionWizard(originalCell);
} else {
wizard = new GenericPropertyFunctionWizard(originalCell);
}
}
// initialize wizard
wizard.init();
HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
if (dialog.open() == WizardDialog.OK) {
MutableCell cell = wizard.getResult();
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
// remove the original cell
// and add the new cell
alignmentService.replaceCell(originalCell, cell);
}
}
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AlignmentImportAdvisor method handleResults.
/**
* @see AbstractIOAdvisor#handleResults(IOProvider)
*/
@Override
public void handleResults(AlignmentReader provider) {
super.handleResults(provider);
AlignmentService as = getService(AlignmentService.class);
// XXX clear old mapping?
// FIXME merging alignments not supported yet
as.addOrUpdateAlignment(provider.getAlignment());
}
Aggregations