Search in sources :

Example 1 with AttributeEditPart

use of org.tmdmaker.ui.editor.gef3.editparts.node.AttributeEditPart in project tmdmaker by tmdmaker.

the class EntityLayoutEditPolicy method createAddCommand.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy#createAddCommand(org.eclipse.gef.EditPart,
 *      org.eclipse.gef.EditPart)
 */
@Override
protected Command createAddCommand(EditPart child, EditPart after) {
    logger.debug("{}#createAddCommand()", getClass());
    if (!(child instanceof AttributeEditPart)) {
        logger.debug("child is not AttributeEditPart.{}", child);
        return null;
    }
    Attribute toMove = (Attribute) child.getModel();
    AbstractModelEditPart<?> originalEntityEditPart = (AbstractModelEditPart<?>) child.getParent();
    AbstractEntityModel originalEntity = (AbstractEntityModel) originalEntityEditPart.getModel();
    int oldIndex = originalEntityEditPart.getChildren().indexOf(child);
    AbstractModelEditPart<?> newEntityEditPart = null;
    int newIndex = 0;
    // アトリビュートが0件か最終行を指定した場合はnull
    if (after == null) {
        newEntityEditPart = (AbstractModelEditPart<?>) getHost();
        newIndex = newEntityEditPart.getChildren().size();
    } else if (after instanceof AttributeEditPart) {
        newEntityEditPart = (AbstractModelEditPart<?>) getHost();
        newIndex = newEntityEditPart.getChildren().indexOf(after);
    } else {
        logger.debug("after is null or not AttributeEditPart.{}", after);
        return null;
    }
    AbstractEntityModel newEntity = (AbstractEntityModel) newEntityEditPart.getModel();
    return new AttributeTransferCommand(toMove, originalEntity, oldIndex, newEntity, newIndex);
}
Also used : AbstractModelEditPart(org.tmdmaker.ui.editor.gef3.editparts.node.AbstractModelEditPart) AttributeEditPart(org.tmdmaker.ui.editor.gef3.editparts.node.AttributeEditPart) Attribute(org.tmdmaker.core.model.Attribute) AttributeTransferCommand(org.tmdmaker.ui.editor.gef3.commands.AttributeTransferCommand) AbstractEntityModel(org.tmdmaker.core.model.AbstractEntityModel)

Aggregations

AbstractEntityModel (org.tmdmaker.core.model.AbstractEntityModel)1 Attribute (org.tmdmaker.core.model.Attribute)1 AttributeTransferCommand (org.tmdmaker.ui.editor.gef3.commands.AttributeTransferCommand)1 AbstractModelEditPart (org.tmdmaker.ui.editor.gef3.editparts.node.AbstractModelEditPart)1 AttributeEditPart (org.tmdmaker.ui.editor.gef3.editparts.node.AttributeEditPart)1