Search in sources :

Example 1 with MutableCell

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

the class AlignmentServiceImpl method setCellProperty.

/**
 * @see eu.esdihumboldt.hale.ui.service.align.AlignmentService#setCellProperty(java.lang.String,
 *      java.lang.String, java.lang.Object)
 */
@Override
public void setCellProperty(String cellId, String propertyName, Object property) {
    if (propertyName == null || property == null) {
        throw new IllegalArgumentException("Mandatory parameter is null");
    }
    Cell cell = getAlignment().getCell(cellId);
    if (cell instanceof ModifiableCell && (Cell.PROPERTY_DISABLE_FOR.equals(propertyName) || Cell.PROPERTY_ENABLE_FOR.equals(propertyName))) {
        boolean disable = Cell.PROPERTY_DISABLE_FOR.equals(propertyName);
        if (property instanceof Cell) {
            Cell other = (Cell) property;
            if (!AlignmentUtil.isTypeCell(other))
                throw new IllegalArgumentException();
            // This call may fail, if the cell was disabled in a base
            // alignment and someone tries to enable it again.
            ((ModifiableCell) cell).setDisabledFor(other, disable);
        } else
            throw new IllegalArgumentException();
        notifyCellsPropertyChanged(Arrays.asList(cell), propertyName);
    } else if (Cell.PROPERTY_TRANSFORMATION_MODE.equals(propertyName)) {
        // set the transformation mode
        if (cell instanceof ModifiableCell && property instanceof TransformationMode) {
            ModifiableCell modCell = (ModifiableCell) cell;
            modCell.setTransformationMode((TransformationMode) property);
            notifyCellsPropertyChanged(Arrays.asList(cell), propertyName);
        }
    } else if (cell instanceof MutableCell) {
        MutableCell mutableCell = (MutableCell) cell;
        if (Cell.PROPERTY_PRIORITY.equals(propertyName)) {
            if (property instanceof Priority) {
                Priority priority = (Priority) property;
                mutableCell.setPriority(priority);
            }
            if (property instanceof String) {
                String priorityStr = (String) property;
                Priority priority = Priority.valueOf(priorityStr);
                if (priority != null) {
                    mutableCell.setPriority(priority);
                } else {
                    throw new IllegalArgumentException();
                }
            }
            notifyCellsPropertyChanged(Arrays.asList(cell), propertyName);
        }
    } else {
        throw new IllegalArgumentException("No mutable cell by the given id found: " + cellId);
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) Priority(eu.esdihumboldt.hale.common.align.model.Priority) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell)

Example 2 with MutableCell

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

the class AlignmentServiceImpl method addOrUpdateAlignment.

/**
 * @see AlignmentService#addOrUpdateAlignment(MutableAlignment)
 */
@Override
public void addOrUpdateAlignment(MutableAlignment alignment) {
    Collection<Cell> added = new ArrayList<Cell>();
    /*
		 * XXX Updates for disables not supported
		 * 
		 * One problem is, that base alignments shouldn't be added twice, so if
		 * the given alignment contains a base alignment that is also contained
		 * in the current alignment it won't be added.
		 * 
		 * Now what about cells in the given alignment, that reference those
		 * base alignments (-> disabled for)? They need to be changed to the
		 * base alignment cells of the current alignment.
		 * 
		 * Those cells can be obtained by replacing the prefix part of the cell
		 * and using getCell(String).
		 * 
		 * XXX Addition of base alignments not supported
		 * 
		 * Here the problem is, that it is not enough to gather the base
		 * alignment cells and change their prefix to a new one, since the base
		 * cell could be another base alignment cell, which would need to
		 * change, too. They would have to be added in order. An option would be
		 * to load them with the base alignment loading mechanism, which would
		 * result in a loss of additional disables.
		 * 
		 * XXX Changes of conflicting base alignment cells not handled
		 */
    // if (!alignment.getBaseAlignments().isEmpty()) {
    // _log.warn("Adding alignments currently does not support merging of base alignments. Import base alignments independently.");
    // }
    boolean addedBaseCells = false;
    // add cells
    synchronized (this) {
        for (Cell cell : alignment.getCells()) {
            if (cell instanceof MutableCell) {
                this.alignment.addCell((MutableCell) cell);
                added.add(cell);
            } else if (!(cell instanceof BaseAlignmentCell)) {
                throw new IllegalStateException("The given alignment contained a cell which is neither mutable nor from a base alignment.");
            } else {
                addedBaseCells = true;
            }
        }
    }
    synchronized (this) {
        // XXX this needs merging, see above
        boolean first = true;
        for (Entry<String, URI> baseAlignment : alignment.getBaseAlignments().entrySet()) {
            Collection<CustomPropertyFunction> baseFunctions;
            if (first) {
                // XXX hack - insert all base functions with the first base
                // alignment
                baseFunctions = alignment.getBasePropertyFunctions().values();
            } else {
                // base functions should only be added once
                baseFunctions = Collections.<CustomPropertyFunction>emptyList();
            }
            this.alignment.addBaseAlignment(baseAlignment.getKey(), baseAlignment.getValue(), // 
            alignment.getBaseAlignmentCells(baseAlignment.getValue()), baseFunctions);
        }
    }
    // add custom functions
    boolean addedFunctions = false;
    synchronized (this) {
        for (CustomPropertyFunction cf : alignment.getCustomPropertyFunctions().values()) {
            this.alignment.addCustomPropertyFunction(cf);
            addedFunctions = true;
        }
    }
    if (addedBaseCells || (!added.isEmpty() && addedFunctions)) {
        // only emit one combined event (not to trigger multiple
        // transformations)
        notifyAlignmentChanged();
    } else {
        if (!added.isEmpty()) {
            notifyCellsAdded(added);
        }
        if (addedFunctions) {
            notifyCustomFunctionsChanged();
        }
    }
}
Also used : BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) URI(java.net.URI) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)

Example 3 with MutableCell

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

the class AlignmentServiceUndoSupport method replaceCell.

/**
 * @see AlignmentServiceDecorator#replaceCell(Cell, MutableCell)
 */
@Override
public synchronized void replaceCell(Cell oldCell, MutableCell newCell) {
    if (oldCell != null && newCell != null) {
        if (oldCell != newCell) {
            boolean contains = getAlignment().getCells().contains(oldCell);
            if (!contains) {
                /*
					 * Cell must be contained in the current alignment, else the
					 * redo would do something unexpected (reading a cell that
					 * was not previously there).
					 */
                addCell(newCell);
            } else {
                if (oldCell instanceof MutableCell) {
                    /*
						 * As long as there is no copy constructor in
						 * DefaultCell, undo only supported for MutableCells to
						 * be replaced.
						 */
                    IUndoableOperation operation = new ReplaceOperation((MutableCell) oldCell, newCell);
                    executeOperation(operation);
                } else {
                    super.replaceCell(oldCell, newCell);
                }
            }
        }
    } else if (newCell != null) {
        addCell(newCell);
    } else if (oldCell != null) {
        removeCells(oldCell);
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 4 with MutableCell

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

the class AlignmentServiceUndoSupport method replaceCells.

/**
 * @see eu.esdihumboldt.hale.ui.service.align.AlignmentService#replaceCells(java.util.Map)
 */
@Override
public void replaceCells(Map<? extends Cell, MutableCell> cells) {
    BiMap<MutableCell, MutableCell> map = HashBiMap.create(cells.size());
    for (Entry<? extends Cell, MutableCell> e : cells.entrySet()) {
        if (e.getKey() instanceof MutableCell && e.getValue() != null && getAlignment().getCells().contains(e.getKey()))
            map.put((MutableCell) e.getKey(), e.getValue());
        else {
            log.warn("Replaced cells contains at least one cell which " + "is either not mutable or not in the alignment. " + "No undo/redo possible.");
            super.replaceCells(cells);
            return;
        }
    }
    IUndoableOperation operation = new ReplaceOperation(map);
    executeOperation(operation);
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Example 5 with MutableCell

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

the class AbstractWizardAction method run.

/**
 * @see Action#run()
 */
@Override
public void run() {
    FunctionWizard wizard = createWizard();
    if (wizard != null) {
        // initialize the wizard
        wizard.init();
        HaleWizardDialog dialog = new HaleWizardDialog(Display.getCurrent().getActiveShell(), wizard);
        if (dialog.open() == WizardDialog.OK) {
            MutableCell cell = wizard.getResult();
            handleResult(cell);
        }
    }
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

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