Search in sources :

Example 46 with DefaultCell

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

the class AbstractGenericFunctionWizard method init.

/**
 * @see AbstractFunctionWizard#init(SchemaSelection)
 */
@Override
protected void init(SchemaSelection selection) {
    // create a new cell
    resultCell = new DefaultCell();
    resultCell.setTransformationIdentifier(getFunctionId());
}
Also used : DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 47 with DefaultCell

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell 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;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) Predicate(com.google.common.base.Predicate) MessageBox(org.eclipse.swt.widgets.MessageBox) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Aggregations

DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)47 Test (org.junit.Test)24 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)22 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)21 Cell (eu.esdihumboldt.hale.common.align.model.Cell)17 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)17 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)16 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)15 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)13 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 ArrayList (java.util.ArrayList)10 Property (eu.esdihumboldt.hale.common.align.model.Property)9 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)9 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Entity (eu.esdihumboldt.hale.common.align.model.Entity)8 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)8 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6