Search in sources :

Example 1 with TransformationMode

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

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

the class SetTransformationModeContribution method fill.

/**
 * @see AbstractFunctionWizardContribution#fill(Menu, int)
 */
@Override
public void fill(Menu menu, int index) {
    if (getOriginalCell() == null)
        return;
    Cell cell = getOriginalCell();
    TransformationMode currentmode = cell.getTransformationMode();
    for (TransformationMode mode : TransformationMode.values()) {
        if (mode != currentmode) {
            IAction action = new SetModeAction(mode, cell.getId());
            IContributionItem item = new ActionContributionItem(action);
            item.fill(menu, index++);
        }
    }
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IAction(org.eclipse.jface.action.IAction) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) IContributionItem(org.eclipse.jface.action.IContributionItem) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 3 with TransformationMode

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

the class AbstractBaseAlignmentLoader method applyModifiers.

/**
 * Apply modifiers on the alignment.
 *
 * @param alignment the alignment to work on
 * @param modifiers the modifiers to apply
 * @param prefixMapping the mapping of prefixes (see
 *            {@link #getCell(Alignment, String, String, Map, IOReporter)})
 * @param defaultPrefix the default prefix (may be <code>null</code>) (see
 *            {@link #getCell(Alignment, String, String, Map, IOReporter)})
 * @param base whether the added modifiers are from a base alignment or the
 *            main alignment
 * @param reporter the I/O reporter to report any errors to, may be
 *            <code>null</code>
 */
private void applyModifiers(Alignment alignment, Collection<M> modifiers, Map<String, String> prefixMapping, String defaultPrefix, boolean base, IOReporter reporter) {
    for (M modifier : modifiers) {
        Cell cell = getCell(alignment, getModifiedCell(modifier), defaultPrefix, prefixMapping, reporter);
        if (cell == null)
            continue;
        // disabledFor
        for (String disabledForId : getDisabledForList(modifier)) {
            Cell other = getCell(alignment, disabledForId, defaultPrefix, prefixMapping, reporter);
            if (other == null)
                continue;
            else if (!AlignmentUtil.isTypeCell(other)) {
                reporter.warn(new IOMessageImpl("A cell referenced in disable-for is not a type cell.", null));
                continue;
            } else if (!alignment.getPropertyCells(other, true, false).contains(cell)) {
                reporter.warn(new IOMessageImpl("A cell referenced in disable-for does not contain the cell that gets modified.", null));
                continue;
            }
            // so it has to be a BaseAlignmentCell
            if (base)
                ((BaseAlignmentCell) cell).setBaseDisabledFor(other, true);
            else
                ((ModifiableCell) cell).setDisabledFor(other, true);
        }
        // transformation mode
        TransformationMode mode = getTransformationMode(modifier);
        if (mode != null) {
            if (base)
                ((BaseAlignmentCell) cell).setBaseTransformationMode(mode);
            else
                ((ModifiableCell) cell).setTransformationMode(mode);
        }
    // XXX handle additional properties
    }
}
Also used : TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) 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) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)3 TransformationMode (eu.esdihumboldt.hale.common.align.model.TransformationMode)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2 UnmigratedCell (eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell)1 Priority (eu.esdihumboldt.hale.common.align.model.Priority)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IAction (org.eclipse.jface.action.IAction)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1