Search in sources :

Example 1 with IAttribute

use of org.tmdmaker.core.model.IAttribute in project tmdmaker by tmdmaker.

the class AttributeComponentEditPolicy method createEditCommand.

@Override
protected Command createEditCommand() {
    EditAttribute edited = ((AttributeDialog) dialog).getEditedValue();
    if (!edited.isEdited()) {
        return null;
    }
    Attribute editedValueAttribute = new Attribute();
    edited.copyTo(editedValueAttribute);
    IAttribute original = edited.getOriginalAttribute();
    EditPart part = getHost();
    if (!(part instanceof IAttributeEditPart)) {
        return null;
    }
    AbstractEntityModel entity = ((IAttributeEditPart) part).getParentModel();
    return new AttributeEditCommand(original, editedValueAttribute, entity);
}
Also used : EditAttribute(org.tmdmaker.ui.dialogs.model.EditAttribute) IAttributeEditPart(org.tmdmaker.ui.editor.gef3.editparts.IAttributeEditPart) Attribute(org.tmdmaker.core.model.Attribute) EditAttribute(org.tmdmaker.ui.dialogs.model.EditAttribute) IAttribute(org.tmdmaker.core.model.IAttribute) IAttribute(org.tmdmaker.core.model.IAttribute) EditPart(org.eclipse.gef.EditPart) IAttributeEditPart(org.tmdmaker.ui.editor.gef3.editparts.IAttributeEditPart) AttributeDialog(org.tmdmaker.ui.dialogs.AttributeDialog) AttributeEditCommand(org.tmdmaker.ui.editor.gef3.commands.AttributeEditCommand) AbstractEntityModel(org.tmdmaker.core.model.AbstractEntityModel)

Example 2 with IAttribute

use of org.tmdmaker.core.model.IAttribute in project tmdmaker by tmdmaker.

the class EntityFileImporter method convertEntityIfPossible.

private AbstractEntityModel convertEntityIfPossible(AbstractEntityModel model) {
    String entityName = model.getName();
    List<IAttribute> identifierCandidates = new ArrayList<IAttribute>();
    for (IAttribute a : model.getAttributes()) {
        String generateName = new Identifier(a.getName()).createEntityName().getValue();
        if (entityName.equals(generateName)) {
            identifierCandidates.add(a);
        }
    }
    if (!identifierCandidates.isEmpty()) {
        IAttribute attribute = identifierCandidates.get(0);
        Entity entity = null;
        Identifier identifier = new Identifier(attribute.getName());
        ModelName name = new ModelName(model.getName());
        if (isEvent(model)) {
            entity = Entity.ofEvent(name, identifier);
        } else {
            entity = Entity.ofResource(name, identifier);
        }
        EntityType type = entity.getEntityType();
        model.copyTo(entity);
        entity.setEntityType(type);
        entity.removeAttribute((Attribute) attribute);
        entity.setNotImplement(false);
        return entity;
    }
    return model;
}
Also used : EntityType(org.tmdmaker.core.model.EntityType) Entity(org.tmdmaker.core.model.Entity) Identifier(org.tmdmaker.core.model.Identifier) ModelName(org.tmdmaker.core.model.parts.ModelName) IAttribute(org.tmdmaker.core.model.IAttribute) ArrayList(java.util.ArrayList)

Example 3 with IAttribute

use of org.tmdmaker.core.model.IAttribute in project tmdmaker by tmdmaker.

the class ImplementRule method findAllImplementAttributes.

/**
 * モデルの実装対象アトリビュートを取得する
 *
 * @param model
 *            対象モデル
 * @return アトリビュートのリスト
 */
public static List<IAttribute> findAllImplementAttributes(AbstractEntityModel model) {
    List<IAttribute> attributes = new ArrayList<IAttribute>();
    SurrogateKey surrogateKey = model.getKeyModels().getSurrogateKey();
    if (surrogateKey.isEnabled()) {
        attributes.add(surrogateKey);
    }
    // 個体指定子を追加
    addIdentifier(model, attributes);
    // re-usedを追加
    Map<AbstractEntityModel, ReusedIdentifier> reused = model.getReusedIdentifiers();
    for (Entry<AbstractEntityModel, ReusedIdentifier> entry : reused.entrySet()) {
        ReusedIdentifier ri = entry.getValue();
        if (ri == null) {
            continue;
        }
        if (ri.isSurrogateKeyEnabled()) {
            for (SurrogateKeyRef s : ri.getSurrogateKeys()) {
                attributes.add(s);
            }
        } else {
            for (IdentifierRef ref : ri.getUniqueIdentifiers()) {
                attributes.add(ref);
            }
        }
    }
    // モデルのアトリビュートを追加
    attributes.addAll(model.getAttributes());
    // 派生元に戻して実装するモデルのアトリビュートを追加
    for (AbstractEntityModel m : model.getImplementDerivationModels()) {
        attributes.addAll(m.getAttributes());
    }
    return attributes;
}
Also used : ReusedIdentifier(org.tmdmaker.core.model.ReusedIdentifier) SurrogateKeyRef(org.tmdmaker.core.model.SurrogateKeyRef) IAttribute(org.tmdmaker.core.model.IAttribute) ArrayList(java.util.ArrayList) AbstractEntityModel(org.tmdmaker.core.model.AbstractEntityModel) SurrogateKey(org.tmdmaker.core.model.SurrogateKey) IdentifierRef(org.tmdmaker.core.model.IdentifierRef)

Example 4 with IAttribute

use of org.tmdmaker.core.model.IAttribute in project tmdmaker by tmdmaker.

the class DdlUtilsConverter method convert.

/**
 * TMD-MakerのキーモデルをDDLUtilsのインデックスモデルへ変換する
 *
 * @param key
 *            TMD-Makerのアトリビュートモデル
 * @return DDLUtilsのインデックスモデル
 */
private Index convert(KeyModel key, Map<IAttribute, Column> attributeColumnMap) {
    Index index = null;
    if (key.isUnique()) {
        index = new UniqueIndex();
    } else {
        index = new NonUniqueIndex();
    }
    index.setName(key.getName());
    for (IAttribute attr : key.getAttributes()) {
        Column column = attributeColumnMap.get(attr);
        if (column != null) {
            IndexColumn indexColumn = new IndexColumn(column);
            index.addColumn(indexColumn);
        } else {
            logger.error("column not found.{}", attr.getName());
        }
    }
    return index;
}
Also used : NonUniqueIndex(org.apache.ddlutils.model.NonUniqueIndex) IndexColumn(org.apache.ddlutils.model.IndexColumn) Column(org.apache.ddlutils.model.Column) IAttribute(org.tmdmaker.core.model.IAttribute) NonUniqueIndex(org.apache.ddlutils.model.NonUniqueIndex) UniqueIndex(org.apache.ddlutils.model.UniqueIndex) Index(org.apache.ddlutils.model.Index) NonUniqueIndex(org.apache.ddlutils.model.NonUniqueIndex) UniqueIndex(org.apache.ddlutils.model.UniqueIndex) IndexColumn(org.apache.ddlutils.model.IndexColumn)

Example 5 with IAttribute

use of org.tmdmaker.core.model.IAttribute in project tmdmaker by tmdmaker.

the class DdlUtilsConverter method addColumns.

/**
 * カラムを追加する
 *
 * @param entity
 *            対象エンティティ
 * @param table
 *            対象テーブル
 * @param attributeColumnMap
 *            アトリビュートとカラムのマップ
 */
private void addColumns(AbstractEntityModel entity, Table table, Map<IAttribute, Column> attributeColumnMap) {
    List<IAttribute> attributes = ImplementRule.findAllImplementAttributes(entity);
    for (IAttribute a : attributes) {
        Column column = convert(a);
        table.addColumn(column);
        attributeColumnMap.put(a, column);
    }
}
Also used : IndexColumn(org.apache.ddlutils.model.IndexColumn) Column(org.apache.ddlutils.model.Column) IAttribute(org.tmdmaker.core.model.IAttribute)

Aggregations

IAttribute (org.tmdmaker.core.model.IAttribute)18 ArrayList (java.util.ArrayList)6 AbstractEntityModel (org.tmdmaker.core.model.AbstractEntityModel)6 File (java.io.File)3 Column (org.apache.ddlutils.model.Column)3 IndexColumn (org.apache.ddlutils.model.IndexColumn)3 Entity (org.tmdmaker.core.model.Entity)3 AttributeEditCommand (org.tmdmaker.ui.editor.gef3.commands.AttributeEditCommand)3 List (java.util.List)2 VelocityContext (org.apache.velocity.VelocityContext)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Attribute (org.tmdmaker.core.model.Attribute)2 Identifier (org.tmdmaker.core.model.Identifier)2 KeyModel (org.tmdmaker.core.model.KeyModel)2 SurrogateKey (org.tmdmaker.core.model.SurrogateKey)2 AttributeListModelBuilder (org.tmdmaker.core.model.generate.attributelist.AttributeListModelBuilder)2 EntityAttributePair (org.tmdmaker.core.model.generate.attributelist.EntityAttributePair)2