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);
}
Aggregations