use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AlignmentView method dispose.
/**
* @see WorkbenchPart#dispose()
*/
@Override
public void dispose() {
if (alignmentListener != null) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.removeListener(alignmentListener);
}
if (compListener != null) {
CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
cs.removeListener(compListener);
}
if (selectionListener != null) {
getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
}
if (tasksListener != null) {
TaskService ts = PlatformUI.getWorkbench().getService(TaskService.class);
ts.removeListener(tasksListener);
}
functionLabels.dispose();
super.dispose();
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class AlignmentView method updateRelation.
/**
* Update the selected type relation to a cell that is related to the given
* schema selection.
*
* @param selection the schema selection
*/
private void updateRelation(SchemaSelection selection) {
Cell typeCell = sourceTargetSelector.getSelectedCell();
if (typeCell != null && (associatedWithType(typeCell.getSource(), selection.getSourceItems()) && associatedWithType(typeCell.getTarget(), selection.getTargetItems()))) {
// type cell is associated with source and target, don't change
return;
}
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
// find type cell associated with both source and target
for (Cell cell : alignment.getTypeCells()) {
if ((associatedWithType(cell.getSource(), selection.getSourceItems())) && associatedWithType(cell.getTarget(), selection.getTargetItems())) {
// typeRelations.setSelection(new StructuredSelection(cell));
sourceTargetSelector.setSelection(new StructuredSelection(cell));
return;
}
}
if (typeCell != null && (associatedWithType(typeCell.getSource(), selection.getSourceItems()) || associatedWithType(typeCell.getTarget(), selection.getTargetItems()))) {
// type cell is associated with source or target, don't change
return;
}
// find type cell associated with source or target
for (Cell cell : alignment.getTypeCells()) {
if ((associatedWithType(cell.getSource(), selection.getSourceItems())) || associatedWithType(cell.getTarget(), selection.getTargetItems())) {
sourceTargetSelector.setSelection(new StructuredSelection(cell));
// typeRelations.setSelection(new StructuredSelection(cell));
return;
}
}
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class EntityDefinitionServiceImpl method editConditionContext.
/**
* @see eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService#editConditionContext(eu.esdihumboldt.hale.common.align.model.EntityDefinition,
* eu.esdihumboldt.hale.common.instance.model.Filter)
*/
@Override
public EntityDefinition editConditionContext(final EntityDefinition sibling, Filter filter) {
List<ChildContext> path = sibling.getPropertyPath();
if (sibling.getSchemaSpace() == SchemaSpaceID.TARGET && path.isEmpty()) {
// XXX throw exception instead?
return null;
}
// Check whether there actually is a change. If not, we are done.
Condition oldCondition = AlignmentUtil.getContextCondition(sibling);
if (Objects.equal(filter, oldCondition == null ? null : oldCondition.getFilter()))
return sibling;
// Create the new entity. Do not add context yet, since the user could
// still abort the process (see below).
EntityDefinition newDef = AlignmentUtil.getDefaultEntity(sibling);
if (filter != null)
newDef = createWithCondition(sibling, new Condition(filter));
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
Alignment alignment = as.getAlignment();
// Collect cells to replace.
// All cells of the EntityDefinition's type can be affected.
Collection<? extends Cell> potentiallyAffected = alignment.getCells(sibling.getType(), sibling.getSchemaSpace());
Predicate<Cell> associatedCellPredicate = new Predicate<Cell>() {
@Override
public boolean apply(Cell input) {
return input != null && AlignmentUtil.associatedWith(sibling, input, false, true);
}
};
Collection<? extends Cell> affected = new HashSet<Cell>(Collections2.filter(potentiallyAffected, associatedCellPredicate));
// Check whether base alignment cells are affected.
boolean baseCellsAffected = false;
Predicate<Cell> baseCellPredicate = new Predicate<Cell>() {
@Override
public boolean apply(Cell input) {
return input != null && input.isBaseCell();
}
};
if (Iterables.find(affected, baseCellPredicate, null) != null) {
// Check whether the user wants to continue.
final Display display = PlatformUI.getWorkbench().getDisplay();
final AtomicBoolean abort = new AtomicBoolean();
display.syncExec(new Runnable() {
@Override
public void run() {
MessageBox mb = new MessageBox(display.getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
mb.setMessage("Some base alignment cells reference the entity definition you wish to change.\n" + "The change will only affect cells which aren't from any base alignment.\n\n" + "Do you still wish to continue?");
mb.setText("Continue?");
abort.set(mb.open() != SWT.YES);
}
});
if (abort.get())
return null;
// Filter base alignment cells out.
baseCellsAffected = true;
affected = Collections2.filter(affected, Predicates.not(baseCellPredicate));
}
// Add condition context if necessary
if (filter != null)
addConditionContext(sibling, filter);
// Replace affected (filtered) cells.
Map<Cell, MutableCell> replaceMap = new HashMap<Cell, MutableCell>();
for (Cell cell : affected) {
DefaultCell newCell = new DefaultCell(cell);
if (newDef.getSchemaSpace() == SchemaSpaceID.SOURCE)
newCell.setSource(replace(newCell.getSource(), sibling, newDef));
else
newCell.setTarget(replace(newCell.getTarget(), sibling, newDef));
replaceMap.put(cell, newCell);
}
as.replaceCells(replaceMap);
// nor do any base alignment cells still use it.
if (oldCondition != null && !baseCellsAffected)
removeContext(sibling);
return newDef;
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class CleanAlignmentHandler method execute.
/**
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), "Delete cells", "Do you really want to delete all cells?")) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
as.clean();
}
return null;
}
use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.
the class ReplaceEntitiesHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// collect cells from selection
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List<?> list = ((IStructuredSelection) selection).toList();
// create dummy alignment
DefaultAlignment dummy = new DefaultAlignment();
for (Object object : list) {
if (object instanceof MutableCell) {
dummy.addCell((MutableCell) object);
// FIXME what about others?
}
}
/*
* Replace entities on cells
*/
SimpleReporter reporter = new SimpleReporter("Replace entities for cells", null, false);
try {
// create migrator
AlignmentMigrator migrator = new DefaultAlignmentMigrator(HaleUI.getServiceProvider());
AlignmentMigration migration = new UserMigration(schemaSpace);
MigrationOptions options = new MigrationOptionsImpl(schemaSpace.equals(SchemaSpaceID.SOURCE), schemaSpace.equals(SchemaSpaceID.TARGET), false);
Alignment updated = migrator.updateAligmment(dummy, migration, options, reporter);
AlignmentService as = HaleUI.getServiceProvider().getService(AlignmentService.class);
Map<Cell, MutableCell> replacements = new HashMap<>();
for (Cell newCell : updated.getCells()) {
Cell oldCell = dummy.getCell(newCell.getId());
if (oldCell == null) {
reporter.error("No original cell with ID {0} found", newCell.getId());
} else {
// TODO detect where there has been no change?
replacements.put(oldCell, (MutableCell) newCell);
}
}
as.replaceCells(replacements);
reporter.setSuccess(true);
} catch (Throwable e) {
reporter.error("Fatal error when trying to replace entities", e);
reporter.setSuccess(false);
} finally {
HaleUI.getServiceProvider().getService(ReportService.class).addReport(reporter);
}
}
return null;
}
Aggregations