use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method changeForEditElement.
/**
* Make a change log for editing attribute
*
* @param attrName
* @param editingCol ERD column to be changed by the user
* @param oldCol ERD column
* @return
*/
public boolean changeForEditElement(String attrName, ERTableColumn editingCol, ERTableColumn oldCol) {
// FIXME move this logic to core module
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (database == null || editingCol == null) {
return false;
}
editingCol.getAttr().setInherit(newSchemaInfo.getClassname());
String newAttrName = editingCol.getAttr().getName();
if (oldCol == null) {
oldCol = new ERTableColumn(newERTable, editingCol.getAttr(), false);
oldCol.setIsNew(true);
}
DBAttribute oldAttr = oldCol.getAttr();
DBAttribute editingAttr = editingCol.getAttr();
if (!oldAttr.isUnique() && newSchemaInfo.getUniqueByAttrName(editingAttr.getName()) == null && editingAttr.isUnique()) {
Constraint unique = new Constraint(true);
unique.setType(Constraint.ConstraintType.UNIQUE.getText());
unique.addAttribute(newAttrName);
unique.addRule(newAttrName + " ASC");
unique.setName(ConstraintNamingUtil.getUniqueName(newSchemaInfo.getClassname(), unique.getRules()));
newSchemaInfo.addConstraint(unique);
} else if (oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
} else if (!oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
}
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
if (database != null && database.getDatabaseInfo() != null && newSchemaInfo != null) {
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(editingCol), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
return true;
}
use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method postEdittedTable.
/**
* Parse the table and add new table to the er schema
*
* @param erSchema ERSchema
*/
public void postEdittedTable(ERSchema erSchema) {
ERTable tmpTable = (ERTable) oldERTable.clone();
SchemaInfo newSchemaInfo = getNewSchemaInfo();
//update table name
if (!oldERTable.getName(isPhysical).equals(newERTable.getName(isPhysical))) {
oldERTable.modifyNameAndFire(newERTable.getName(isPhysical), isPhysical);
}
//update table collation
oldERTable.getSchemaInfo().setCollation(newSchemaInfo.getCollation());
//deleted columns
for (String oldColName : deletedColumns) {
oldERTable.removeColumnAndFire(oldERTable.getColumn(oldColName, isPhysical));
}
//modified columns
Set<String> oldNames = modifiedColumns.keySet();
for (String oldColName : oldNames) {
String newName = modifiedColumns.get(oldColName);
ERTableColumn oldColumn = oldERTable.getColumn(oldColName, isPhysical);
ERTableColumn newCol = newERTable.getColumn(newName, isPhysical);
if (oldColumn == null) {
continue;
}
ERTableColumn firedOldColumn = oldColumn.clone();
if (newCol == null) {
continue;
}
//will modify the old column to new
oldERTable.modifyColumn(oldColName, isPhysical, newCol);
oldColumn.firePropertyChange(ERTableColumn.TEXT_CHANGE, firedOldColumn, newCol);
}
//added columns
for (String addedColumn : addedColumns) {
ERTableColumn newColumn = newERTable.getColumn(addedColumn, isPhysical);
if (newColumn == null) {
continue;
}
//from new to old now
newColumn.setIsNew(false);
if (oldERTable.getColumn(addedColumn, isPhysical) != null) {
continue;
}
oldERTable.addColumnAndFire(newColumn);
}
//update pk
Constraint newPK = newSchemaInfo.getPK();
Constraint oldPK = oldERTable.getSchemaInfo().getPK();
if (oldPK != null) {
oldERTable.getSchemaInfo().removeConstraintByName(oldPK.getName(), ConstraintType.PRIMARYKEY.getText());
}
if (newPK != null) {
oldERTable.getSchemaInfo().addConstraint(newPK);
}
//update fk
List<Constraint> oldFKs = oldERTable.getSchemaInfo().getFKConstraints();
oldERTable.deleteAllFKShipsAndFire();
for (Constraint fk : oldFKs) {
oldERTable.getSchemaInfo().addConstraint(fk);
}
CubridTableParser tableParser = new CubridTableParser(erSchema);
try {
tableParser.buildReferenceShip(oldERTable, newSchemaInfo);
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
oldERTable = tmpTable;
return;
}
syncLogicalNameAndPhysicalComment();
}
use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method addNewColumn.
public void addNewColumn() {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (newSchemaInfo == null) {
return;
}
// boolean hasNotFinishedColumn = false;
boolean hasDuplicatedColumn = false;
List<ERTableColumn> items = newERTable.getColumns();
if (items != null && items.size() > 0) {
Set<String> matches = new HashSet<String>();
// check whether there is no name column
for (ERTableColumn col : items) {
if (col == null) {
continue;
}
if (StringUtil.isEmpty(col.getName(erSchema.isPhysicModel()))) {
continue;
}
if (matches.contains(col.getName(erSchema.isPhysicModel()))) {
hasDuplicatedColumn = true;
break;
}
matches.add(col.getName(erSchema.isPhysicModel()));
}
}
if (hasDuplicatedColumn) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
return;
}
String collation = null;
if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
collation = newSchemaInfo.getCollation();
} else {
collation = Collation.DEFAULT_COLLATION;
}
DBAttribute addAttribute = new DBAttribute("", DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
ERTableColumn column = new ERTableColumn(newERTable, addAttribute, false);
column.setIsNew(true);
tempERColumnList.add(column);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(addAttribute), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
}
use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method removeTmpElementByName.
/**
* Remove temporary ER column by name
*
* @param name physical or logical name
*/
public void removeTmpElementByName(String name) {
// FIXME move this logic to core module
List<ERTableColumn> removeList = new ArrayList<ERTableColumn>();
for (ERTableColumn col : tempERColumnList) {
if (!StringUtil.isEmpty(name) && StringUtil.isEqual(name, col.getName(erSchema.isPhysicModel()))) {
removeList.add(col);
}
}
tempERColumnList.removeAll(removeList);
}
use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class ModifyColumnLabelCommand method changeNameType.
/**
* Sets the new Column name
*
* @param labelString the new name
*/
public void changeNameType(String labelString) {
if (labelString != null) {
ERTableColumn newColumn = source.clone();
String name = ERTableColumn.getName(labelString);
String type = ERTableColumn.getType(labelString);
newColumn.setName(name, isPhysical);
newColumn.setShowType(type, isPhysical);
if (isPhysical) {
String upperShowType = DataType.getUpperShowType(type);
String realType = DataType.getRealType(upperShowType);
if (realType.startsWith(DataType.getUpperEnumType())) {
realType = realType.replaceFirst(DataType.getUpperEnumType(), DataType.getLowerEnumType());
}
if (source.getERSchema().hasPhysicalTypeInMap(realType)) {
changedLogicalShowType = source.getERSchema().convert2LogicalShowType(realType);
newColumn.setShowType(changedLogicalShowType, !isPhysical);
}
} else if (source.getERSchema().hasLogicalTypeInMap(type)) {
changedPhysicalShowType = source.getERSchema().convert2UpPhysicalShowType(type);
newColumn.setPhysicalDataType(changedPhysicalShowType);
}
String err = source.getTable().checkColumnChange(source, newColumn);
if (!StringUtil.isEmpty(err)) {
CommonUITool.openErrorBox(err);
} else {
//physical name
newName = name;
//physical data type
newType = type;
colHandler.setLatestData(labelString);
}
}
if (this.newType == null || newName == null) {
this.newName = oldName;
this.newType = oldType;
changedLogicalShowType = null;
changedPhysicalShowType = null;
}
if (StringUtil.isNotEmpty(changedLogicalShowType)) {
source.setShowType(changedLogicalShowType, false);
} else if (StringUtil.isNotEmpty(changedPhysicalShowType)) {
source.setPhysicalDataType(changedPhysicalShowType);
}
execute();
}
Aggregations