Search in sources :

Example 31 with MutableCell

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

the class AbstractGenericFunctionWizard method getUnfinishedCell.

/**
 * Returns the cell that would be created if the wizard would be finished
 * now.
 *
 * @return the cell
 */
public Cell getUnfinishedCell() {
    MutableCell current = new DefaultCell();
    current.setTransformationIdentifier(getFunctionId());
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    current.setTransformationParameters(parameters);
    for (IWizardPage page : getPages()) {
        // stop at first uncompleted page
        if (!page.isPageComplete())
            break;
        if (page instanceof FunctionWizardPage)
            ((FunctionWizardPage) page).configureCell(current);
        else if (page instanceof ParameterPage)
            parameters.putAll(((ParameterPage) page).getConfiguration());
    }
    return current;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ParameterPage(eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage) GenericParameterPage(eu.esdihumboldt.hale.ui.function.generic.pages.GenericParameterPage) IWizardPage(org.eclipse.jface.wizard.IWizardPage) FunctionWizardPage(eu.esdihumboldt.hale.ui.function.generic.pages.FunctionWizardPage)

Example 32 with MutableCell

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

the class NewRelationWizard method performFinish.

/**
 * @see MultiWizard#performFinish()
 */
@Override
public boolean performFinish() {
    // performFinish of the function wizard was called first
    FunctionWizard functionWizard = getSelectionPage().getFunctionWizard();
    if (functionWizard == null) {
        return false;
    }
    MutableCell cell = functionWizard.getResult();
    if (cell != null) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        as.addCell(cell);
    }
    createdCell = cell;
    // save page configuration
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    getSelectionPage().store(ps.getConfigurationService());
    return true;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard)

Example 33 with MutableCell

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

the class AlignmentServiceUndoSupport method removeCells.

/**
 * @see AlignmentServiceDecorator#removeCells(Cell[])
 */
@Override
public synchronized void removeCells(Cell... cells) {
    if (cells == null || cells.length == 0) {
        return;
    }
    List<MutableCell> contained = new ArrayList<MutableCell>();
    for (Cell cell : cells) {
        if (cell instanceof MutableCell && getAlignment().getCells().contains(cell)) {
            contained.add((MutableCell) cell);
        }
    }
    if (!contained.isEmpty()) {
        /*
			 * Cells must be contained in the current alignment, else the redo
			 * would do something unexpected (readding a cell that was not
			 * previously there).
			 * 
			 * Also, as long as there is no copy constructor in DefaultCell,
			 * undo only for removing MutableCells supported.
			 */
        IUndoableOperation operation = new RemoveCellOperation(contained);
        executeOperation(operation);
    } else {
        super.removeCells(cells);
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Example 34 with MutableCell

use of eu.esdihumboldt.hale.common.align.model.MutableCell 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;
}
Also used : AlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrator) DefaultAlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) UserMigration(eu.esdihumboldt.hale.ui.service.align.migrate.UserMigration) SimpleReporter(eu.esdihumboldt.hale.common.core.report.impl.SimpleReporter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DefaultAlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) MigrationOptionsImpl(eu.esdihumboldt.hale.common.align.migrate.impl.MigrationOptionsImpl) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MigrationOptions(eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)

Example 35 with MutableCell

use of eu.esdihumboldt.hale.common.align.model.MutableCell 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

MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)35 Cell (eu.esdihumboldt.hale.common.align.model.Cell)17 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 ArrayList (java.util.ArrayList)11 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)6 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)5 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)5 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)5 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)5 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)4 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)4 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)4 HashSet (java.util.HashSet)4