use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.
the class SetPhysicalLogicaMapDialog method checkNewMapValid.
private void checkNewMapValid() throws ERException {
ERSchema copySchema = erSchema.clone();
PhysicalLogicRelation relation = copySchema.getPhysicalLogicRelation();
relation.setDataTypeMap(newColumnTypeMap);
//refresh all columns physical/logical data type by map
copySchema.setPhysicalLogicRelation(relation);
List<ERTable> tables = copySchema.getTables();
for (ERTable table : tables) {
table.checkValidate();
}
}
use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.
the class ERDNDController method addTables.
private void addTables(List<SchemaInfo> schemaInfoList, int x, int y) {
if (schemaInfoList == null) {
return;
}
List<String> existTables = new ArrayList<String>();
String message = "";
ERSchema erSchema = editor.getERSchema();
Iterator<SchemaInfo> it = schemaInfoList.iterator();
while (it.hasNext()) {
SchemaInfo table = (SchemaInfo) it.next();
ERTable existTable = erSchema.getTable(table.getClassname());
if (existTable != null) {
existTables.add(table.getClassname());
it.remove();
continue;
}
}
CubridTableParser tableParser = new CubridTableParser(erSchema);
if (schemaInfoList.size() == 1) {
tableParser.buildERTables(schemaInfoList, x, y, false);
} else {
tableParser.buildERTables(schemaInfoList, x, y, true);
}
erSchema.FireAddedTable(tableParser.getSuccessTables());
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 (existTables.size() > 0) {
if (!message.equals("")) {
message += "\n";
}
message += Messages.bind(com.cubrid.common.ui.er.Messages.errExistTables, existTables);
}
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);
}
}
use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.
the class ERAttributeCellModifier method modify.
public void modify(Object element, String property, Object value) {
// FIXME move this logic to core module
final TableItem item = (TableItem) element;
if (item == null) {
return;
}
ERTableColumn erColumn = (ERTableColumn) item.getData();
ERTable table = editor.getDialog().getNewERTable();
if (!StringUtil.isEmpty(erColumn.getName())) {
erColumn = table.getColumn(erColumn.getName());
}
DBAttribute attr = erColumn.getAttr();
String oldAttrName = attr.getName();
DBAttribute oldAttribute = null;
if (editor.getOldSchemaInfo() != null) {
oldAttribute = editor.getOldSchemaInfo().getDBAttributeByName(oldAttrName, false);
}
ERTableColumn oldColumn = editor.getDialog().getOldERTable().getColumn(oldAttrName);
if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
SchemaInfo schemaInfo = editor.getNewSchemaInfo();
if (schemaInfo == null) {
return;
}
boolean on = ((Boolean) value).booleanValue();
erColumn.setIsPrimaryKey(on);
if (on) {
Constraint constraint = schemaInfo.getPK();
if (constraint == null) {
constraint = new Constraint("pk", Constraint.ConstraintType.PRIMARYKEY.getText());
schemaInfo.addConstraint(constraint);
}
constraint.addAttribute(attr.getName());
} else {
Constraint constraint = schemaInfo.getPK();
if (constraint == null) {
return;
}
List<String> columns = constraint.getAttributes();
if (columns == null || columns.size() == 0) {
return;
}
boolean isContain = columns.remove(attr.getName());
/*For bug TOOLS-3972 The collumn's setting in Edit Table Inconsistent with the setting in Set Primary Key*/
if (isContain && columns.size() == 0) {
schemaInfo.removeConstraintByName(constraint.getName(), constraint.getType());
}
/*For bug TOOLS-3046 : deal with edit column*/
if (oldAttribute != null && isContain) {
attr.setNotNull(false);
}
}
editor.makeChangeLogForIndex(oldAttrName, attr, oldAttribute);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
String newName = (String) value;
SchemaInfo schemaInfo = editor.getNewSchemaInfo();
if (schemaInfo == null) {
// TODO Improve error message
CommonUITool.openErrorBox(Messages.errEmptyNameOnEditTableColumn);
return;
}
if (!StringUtil.isEmpty(newName) && isPhysical && !ValidateUtil.isValidIdentifier(newName)) {
CommonUITool.openErrorBox(Messages.errColumnName);
return;
}
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn col : columns) {
if (StringUtil.isEqualIgnoreCase(col.getName(isPhysical), newName) && erColumn != col) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableColumn);
return;
}
}
if (!StringUtil.isEqualIgnoreCase(erColumn.getName(isPhysical), newName)) {
if (isPhysical) {
replaceNewConstraintAttributeName(schemaInfo, attr.getName(), newName);
}
String oldName = erColumn.getName(isPhysical);
erColumn.setName(newName, isPhysical);
if (erColumn.isNew()) {
erColumn.setName(newName, !isPhysical);
for (ERTableColumn col : columns) {
if (StringUtil.isEqualIgnoreCase(col.getName(!isPhysical), newName) && erColumn != col) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableColumn);
erColumn.setName(oldName, isPhysical);
erColumn.setName(oldName, !isPhysical);
return;
}
}
}
if (!hasAddedToSchemaInfo(attr)) {
if (!StringUtil.isEmpty(newName)) {
if (!columns.contains(erColumn)) {
erColumn.getAttr().setInherit(editor.getNewSchemaInfo().getClassname());
table.addColumn(erColumn);
editor.removeElementByName(newName);
}
if (!StringUtil.isEmpty(oldAttrName)) {
editor.makeChangeLogForIndex(oldAttrName, erColumn.getAttr(), oldAttribute);
}
}
} else {
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
}
}
ERTableColumn col = null;
if (columns.size() > 0) {
Table columnsTable = editor.getColumnsTable();
col = (ERTableColumn) columnsTable.getItem(columnsTable.getItemCount() - 1).getData();
}
if (!StringUtil.isEmpty(newName) && (col == null || !StringUtil.isEmpty(col.getName(isPhysical)))) {
editor.addNewColumn();
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
String dataTypeRaw = (String) value;
ERSchema schema = erColumn.getERSchema();
if (isPhysical) {
if (dataTypeRaw.equalsIgnoreCase(DataType.getUpperEnumType())) {
dataTypeRaw += "('" + DataType.ENUM_DAFAULT_VALUE + "')";
}
erColumn.setPhysicalDataType(DataType.reviseDataType(dataTypeRaw));
if (!DataType.isIntegerType(attr.getType())) {
attr.setAutoIncrement(null);
}
if (!DataType.canUseCollation(attr.getType())) {
attr.setCollation("");
}
String physicalRealType = erColumn.getRealType();
if (erColumn.getERSchema().hasPhysicalTypeInMap(physicalRealType) || erColumn.isNew()) {
String logicalType = schema.convert2LogicalShowType(physicalRealType);
erColumn.setShowType(logicalType, false);
}
} else {
if (!DataType.DATATYPE_STRING.equalsIgnoreCase(dataTypeRaw)) {
dataTypeRaw = DataType.reviseDataType(dataTypeRaw);
}
erColumn.setShowType(dataTypeRaw, false);
if (erColumn.getERSchema().hasLogicalTypeInMap(dataTypeRaw) || erColumn.isNew()) {
String physicalType = schema.convert2UpPhysicalShowType(dataTypeRaw);
if (DataType.DATATYPE_STRING.equalsIgnoreCase(dataTypeRaw)) {
physicalType = DataType.reviseDataType(physicalType);
}
erColumn.setPhysicalDataType(physicalType);
}
}
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
String defaultVal = (String) value;
boolean isStringType = DataType.isStringType(attr.getType());
boolean isEmpty = StringUtil.isEmpty(defaultVal);
boolean isNull = false;
if (defaultVal == null || DataType.NULL_EXPORT_FORMAT.equals(defaultVal) || DataType.VALUE_NULL.equals(defaultVal) || (isEmpty && !isStringType)) {
isNull = true;
}
if (isNull) {
attr.setDefault(null);
} else {
if (attr.getAutoIncrement() != null) {
attr.setDefault(null);
CommonUITool.openErrorBox(Messages.errCanNotSetDefaultOnAI);
return;
}
boolean isConfirmReset = "".equals(defaultVal) && oldAttribute != null && !"".equals(oldAttribute.getDefault());
if (isConfirmReset) {
String confirmResetDef = Messages.confirmResetDef;
if (CommonUITool.openConfirmBox(confirmResetDef)) {
attr.setDefault(null);
} else {
attr.setDefault(defaultVal);
}
} else {
attr.setDefault(defaultVal);
}
}
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
if (aiAttr != null && aiAttr != attr) {
attr.setAutoIncrement(null);
return;
}
String param = (String) value;
if (StringUtil.isNotEmpty(param)) {
if (!param.matches("\\s*[0-9]+\\s*,\\s*[0-9]+\\s*")) {
CommonUITool.openErrorBox(Messages.errInvalidAutoIncrForm);
return;
}
String defaultValue = attr.getDefault();
if (StringUtil.isNotEmpty(defaultValue)) {
CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
return;
}
String[] params = param.split(",");
String startVal = params[0].trim();
String incrVal = params[1].trim();
SchemaInfo schemaInfo = editor.getNewSchemaInfo();
SerialInfo serial = new SerialInfo();
serial.setOwner(schemaInfo.getOwner());
serial.setClassName(schemaInfo.getClassname());
serial.setAttName(oldAttrName);
serial.setCacheCount("1");
serial.setCurrentValue(startVal);
serial.setCyclic(false);
serial.setIncrementValue(incrVal);
serial.setMaxValue(String.valueOf(Integer.MAX_VALUE));
serial.setMinValue(startVal);
serial.setStartedValue(startVal);
if (attr.getAutoIncrement() != null && schemaInfo != null && schemaInfo.getAutoIncrementColumn() != null && schemaInfo.getAutoIncrementColumn().getAutoIncrement() != null) {
String oldAI = attr.getAutoIncrement().getTableAutoIncrementString();
String newAI = serial.getTableAutoIncrementString();
if (StringUtil.isEqual(oldAI, newAI)) {
return;
}
}
attr.setAutoIncrement(serial);
} else {
attr.setAutoIncrement(null);
}
editor.changeForEditElement(oldAttrName, attr, oldAttribute);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
boolean on = ((Boolean) value).booleanValue();
attr.setNotNull(on);
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
boolean on = ((Boolean) value).booleanValue();
if (on && attr.isShared()) {
CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
return;
}
attr.setUnique(on);
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
boolean on = ((Boolean) value).booleanValue();
String defaultValue = attr.getDefault();
if (on && StringUtil.isEmpty(defaultValue)) {
CommonUITool.openErrorBox(Messages.msgInputSharedValue);
return;
}
if (on && attr.isUnique()) {
CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
return;
}
attr.setShared(on);
editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
String orignCollation = attr.getCollation();
Integer selection = StringUtil.intValue(value.toString(), 0);
if (selection > -1) {
String newCollation = editor.getCollationArray()[selection];
if (!StringUtil.isEqualNotIgnoreNull(orignCollation, newCollation)) {
attr.setCollation(newCollation);
}
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
attr.setDescription((String) value);
}
editor.loadColumnData();
editor.afterModifyColumn(oldColumn == null ? null : oldColumn.getName(isPhysical), erColumn.getName(isPhysical));
}
use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.
the class ReconnectPrimaryKeyCommand method canExecute.
@Override
public boolean canExecute() {
boolean returnVal = true;
ERTable foreignKeyTable = relationship.getForeignKeyTable();
if (foreignKeyTable.equals(targetTable)) {
returnVal = false;
} else {
List relationships = targetTable.getTargetedRelationships();
for (int i = 0; i < relationships.size(); i++) {
Relationship relationship = ((Relationship) (relationships.get(i)));
if (relationship.getForeignKeyTable().equals(sourceTable) && relationship.getPrimaryKeyTable().equals(targetTable)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.
the class ModifyTableNameAction method run.
@Override
public void run() {
PropertyChangeProvider node = getSelectedNode();
boolean isPhysicModel = getERSchema().isPhysicModel();
String oldName = ((ERTable) node).getShownName();
Set<String> names = getERSchema().getAllShownTableNames();
names.remove(oldName);
RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), oldName, true, new ArrayList<String>(names), isPhysicModel);
int ret = dlg.open();
if (ret == IDialogConstants.OK_ID) {
String newName = dlg.getNewName();
if (StringUtil.isEqual(oldName, newName)) {
return;
}
getERSchema().modifyTableNameAndFire(oldName, newName, isPhysicModel);
}
}
Aggregations