Search in sources :

Example 6 with ERTableColumn

use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.

the class ERAttributeCellModifier method canModify.

public boolean canModify(Object element, String property) {
    // FIXME move this logic to core module
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute attr = erColumn.getAttr();
    if (!editor.isNewTableFlag() && !editor.isSupportChange() && editor.getOldSchemaInfo().getDBAttributeByName(attr.getName(), false) != null) {
        return false;
    }
    if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            return false;
        } else if (!DataType.isIntegerType(attr.getType())) {
            return false;
        } else if (attr != null && StringUtil.isNotEmpty(attr.getDefault())) {
            CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL) || StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
        Constraint pk = editor.getNewSchemaInfo().getPK();
        if (pk != null && pk.getAttributes().contains(attr.getName())) {
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        if (attr.isNew() && DataType.canUseCollation(attr.getType())) {
            return true;
        } else {
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return editor.isSupportTableComment();
    }
    return true;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn)

Example 7 with ERTableColumn

use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.

the class ERAttributeLabelProvider method getBackground.

public Color getBackground(Object element, int columnIndex) {
    if (schema == null || element == null || !editableMode) {
        return null;
    }
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute attr = erColumn.getAttr();
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = schema.getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            return DISABLED_COLOR;
        } else if (!DataType.isIntegerType(attr.getType())) {
            return DISABLED_COLOR;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return editorAdaptor.isSupportTableComment() ? null : DISABLED_COLOR;
    }
    return null;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn)

Example 8 with ERTableColumn

use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.

the class ERAttributeLabelProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element == null) {
        return null;
    }
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute dbAttribute = erColumn.getAttr();
    if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
        return null;
    }
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_FLAG)) {
        if (StringUtil.isEmpty(dbAttribute.getName())) {
            return "*";
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
        return erColumn.getName(isPhysical);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
        if (isPhysical) {
            if (DataType.DATATYPE_ENUM.equalsIgnoreCase(dbAttribute.getType())) {
                String type = StringUtil.toUpper(dbAttribute.getType()) + dbAttribute.getEnumeration();
                return DataType.getShownType(type);
            } else {
                return DataType.getShownType(dbAttribute.getType());
            }
        } else {
            return erColumn.getShowType(false).toUpperCase();
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
        String defaultValue = dbAttribute.getDefault();
        if (defaultValue == null) {
            return DataType.NULL_EXPORT_FORMAT;
        }
        if (defaultValue.length() == 0 && DataType.isStringType(dbAttribute.getType())) {
            return "";
        }
        return defaultValue;
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        SerialInfo serial = dbAttribute.getAutoIncrement();
        if (serial == null) {
            return "";
        }
        return serial.getMinValue() + "," + serial.getIncrementValue();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return dbAttribute.getDescription();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        return dbAttribute.getCollation();
    }
    return null;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 9 with ERTableColumn

use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.

the class AddColumnAction method run.

public void run() {
    ERTable table = this.getERTable();
    List<String> names = new ArrayList<String>();
    List<ERTableColumn> columns = table.getColumns();
    for (ERTableColumn column : columns) {
        names.add(column.getName());
    }
    AddColumnDialog dlg = new AddColumnDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), table.getName(), true, names, getERSchema());
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        boolean isPhysical = table.getERSchema().isPhysicModel();
        String newName = dlg.getNewColumnName();
        String type = dlg.getDataType();
        String realType = null;
        String enumeration = null;
        if (isPhysical) {
            realType = DataType.getRealType(type);
        } else {
            String upPhysicalShowType = type;
            realType = DataType.getRealType(upPhysicalShowType);
        }
        if (DataType.DATATYPE_ENUM.equals(type)) {
            realType = DataType.getUpperEnumType().toLowerCase();
            enumeration = "('" + DataType.ENUM_DAFAULT_VALUE + "')";
        }
        DBAttribute addAttribute = new DBAttribute(newName, realType, table.getName(), false, false, false, false, null, Collation.DEFAULT_COLLATION);
        addAttribute.setEnumeration(enumeration);
        ERTableColumn col = new ERTableColumn(table, addAttribute, false);
        if (DataType.DATATYPE_STRING.equals(type)) {
            col.setLogicalType(DataType.DATATYPE_STRING);
        }
        table.addColumnAndFire(col);
    }
}
Also used : AddColumnDialog(com.cubrid.common.ui.er.dialog.AddColumnDialog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ArrayList(java.util.ArrayList) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 10 with ERTableColumn

use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.

the class ExportImportGsonDataController method buildERDSchema.

private void buildERDSchema(ERSchema originSchema, ERSchema deserializedERSchema, Map<String, SchemaInfo> schemaInfos, boolean isImportMap) {
    String message = "";
    CubridTableParser tableParser = new CubridTableParser(originSchema);
    tableParser.buildERTables(schemaInfos.values(), -1, -1, false);
    if (isImportMap) {
        originSchema.setPhysicalLogicRelation(deserializedERSchema.getPhysicalLogicRelation());
    }
    List<ERTable> successTables = tableParser.getSuccessTables();
    for (ERTable table : successTables) {
        ERTable savedTable = deserializedERSchema.getTable(table.getName());
        table.setLogicalName(savedTable.getLogicalName());
        List<ERTableColumn> columns = table.getColumns();
        for (ERTableColumn column : columns) {
            String colName = column.getName();
            ERTableColumn savedColumn = savedTable.getColumn(colName, true);
            column.setLogicalName(savedColumn.getLogicalName());
            column.setLogicalType(savedColumn.getLogicalType());
        }
        if (originSchema.isLayoutManualDesired()) {
            table.setBounds(savedTable.getBounds());
        }
    }
    originSchema.FireAddedTable(successTables);
    Map<String, Exception> failedTables = tableParser.getFailedTables();
    Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
    if (failedTables.size() > 0) {
        message = Messages.bind(com.cubrid.common.ui.er.Messages.errorAddTables, failedTables.keySet());
    }
    if (removedFKs.size() > 0) {
        if (!message.equals("")) {
            message += "\n";
        }
        message += Messages.bind(com.cubrid.common.ui.er.Messages.cannotBeBuiltFK, tableParser.getOneRemovedFK().getName());
        if (tableParser.getRemovedFKCount() > 1) {
            message += ", ...";
        }
    }
    if (!message.equals("")) {
        CommonUITool.openErrorBox(message);
    }
}
Also used : ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) ERTable(com.cubrid.common.ui.er.model.ERTable) List(java.util.List)

Aggregations

ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)32 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)11 ERTable (com.cubrid.common.ui.er.model.ERTable)11 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)10 Constraint (com.cubrid.common.core.common.model.Constraint)9 List (java.util.List)6 EditableLabel (com.cubrid.common.ui.er.figures.EditableLabel)5 CubridTableParser (com.cubrid.common.ui.er.model.CubridTableParser)4 ArrayList (java.util.ArrayList)4 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)3 ERSchema (com.cubrid.common.ui.er.model.ERSchema)3 Relationship (com.cubrid.common.ui.er.model.Relationship)3 EditPart (org.eclipse.gef.EditPart)3 TableItem (org.eclipse.swt.widgets.TableItem)3 TablePart (com.cubrid.common.ui.er.part.TablePart)2 HashSet (java.util.HashSet)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ITask (com.cubrid.common.core.task.ITask)1 ERWinDBAttribute (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute)1 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)1