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