use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method getUpdateDescriptionTaskList.
/**
* Get UpdateDescriptionTaskList
*
* @param dbInfo
* @return
*/
private List<UpdateDescriptionTask> getUpdateDescriptionTaskList(DatabaseInfo dbInfo) {
// FIXME move this logic to core module
List<UpdateDescriptionTask> updateDescriptionTaskList = new ArrayList<UpdateDescriptionTask>();
if (isSupportTableComment) {
for (DBAttribute newAttr : newSchemaInfo.getAttributes()) {
DBAttribute oldAttr = null;
if (oldSchemaInfo != null) {
oldAttr = oldSchemaInfo.getDBAttributeByName(newAttr.getName(), newAttr.isClassAttribute());
}
if (oldAttr != null && StringUtil.isEqual(oldAttr.getDescription(), newAttr.getDescription())) {
continue;
} else {
updateDescriptionTaskList.add(new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, newAttr.getName(), newAttr.getDescription()));
}
}
boolean notSameDescription = false;
if (oldSchemaInfo != null) {
notSameDescription = !StringUtil.isEqualNotIgnoreNull(oldSchemaInfo.getDescription(), newSchemaInfo.getDescription());
}
if (oldSchemaInfo == null || notSameDescription) {
UpdateDescriptionTask task = new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, null, newSchemaInfo.getDescription());
updateDescriptionTaskList.add(task);
}
}
return updateDescriptionTaskList;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method handleSelectionChangeInColumnTable.
/**
* Handle selection change event in column table
*/
private void handleSelectionChangeInColumnTable() {
int selectionCount = columnsTable.getSelectionCount();
if (selectionCount <= 0) {
deleteColumnBtn.setEnabled(false);
downColumnBtn.setEnabled(false);
upColumnBtn.setEnabled(false);
} else {
TableItem[] tblItems = columnsTable.getSelection();
DBAttribute attr = (DBAttribute) tblItems[0].getData();
boolean isInheritAttr = attr.getInherit() != null && !tableNameText.getText().trim().equalsIgnoreCase(attr.getInherit().trim());
deleteColumnBtn.setEnabled(!isInheritAttr);
if (selectionCount > 1) {
upColumnBtn.setEnabled(false);
downColumnBtn.setEnabled(false);
} else {
if (database == null || database.getDatabaseInfo() == null) {
return;
}
boolean isSupportReorderColumn = CompatibleUtil.isSupportReorderColumn(database.getDatabaseInfo());
if (isSupportReorderColumn && !isNewTableFlag) {
// class attribute do not support to reorder
if (attr.isClassAttribute() || isInheritAttr) {
isSupportReorderColumn = false;
}
// the attribute which was used by subClass, it not support reorder.
if (isSupportReorderColumn && isHasSubClass()) {
isSupportReorderColumn = false;
}
}
int count = 0;
if (newSchemaInfo.getClassAttributes() != null) {
count = newSchemaInfo.getClassAttributes().size();
}
int index = columnsTable.getSelectionIndex();
if (!attr.isClassAttribute()) {
List<DBAttribute> attrList = newSchemaInfo.getAttributes();
count = attrList.size();
int inheritAttrCount = 0;
for (DBAttribute dbAttr : attrList) {
boolean isInheritDbAttr = dbAttr.getInherit() != null && dbAttr.getInherit().trim().length() > 0 && !tableNameText.getText().trim().equalsIgnoreCase(dbAttr.getInherit().trim());
if (isInheritDbAttr) {
inheritAttrCount++;
}
}
index = index - inheritAttrCount;
count = count - inheritAttrCount;
}
if (index == 0) {
upColumnBtn.setEnabled(false);
} else {
upColumnBtn.setEnabled(isNewTableFlag ? !isInheritAttr : isSupportReorderColumn);
}
if (index == count - 1) {
downColumnBtn.setEnabled(false);
} else {
downColumnBtn.setEnabled(isNewTableFlag ? !isInheritAttr : isSupportReorderColumn);
}
List<DBAttribute> items = newSchemaInfo.getAttributes();
if (!items.contains(attr)) {
deleteColumnBtn.setEnabled(false);
} else {
deleteColumnBtn.setEnabled(true);
}
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method getNotNullChangedColumn.
/**
* Get all not null changed column
*
* @return
*/
private List<String[]> getNotNullChangedColumn() {
// FIXME move this logic to core module
List<String[]> notNullChangedColumn = new ArrayList<String[]>();
List<SchemaChangeLog> allAttrChanges = schemaChangeMgr.getAttrChangeLogs();
List<SchemaInfo> oldSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), oldSchemaInfo);
if (oldSupers == null) {
return notNullChangedColumn;
}
List<SchemaInfo> newSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
if (newSupers == null) {
return notNullChangedColumn;
}
for (SchemaChangeLog changeLog : allAttrChanges) {
if (changeLog.getOldValue() == null || changeLog.getNewValue() == null) {
continue;
}
boolean isClassAttr = changeLog.getType() == SchemeInnerType.TYPE_CLASSATTRIBUTE;
DBAttribute oldAttr = oldSchemaInfo.getDBAttributeByName(changeLog.getOldValue(), isClassAttr);
DBAttribute newAttr = newSchemaInfo.getDBAttributeByName(changeLog.getNewValue(), isClassAttr);
if (oldAttr == null || newAttr == null) {
continue;
}
boolean oldNotNull = oldAttr.isNotNull();
boolean newNotNull = newAttr.isNotNull();
Constraint newPK = newSchemaInfo.getPK(newSupers);
List<String> pkAttributes = newPK == null ? new ArrayList<String>() : newPK.getAttributes();
if (oldNotNull == newNotNull) {
continue;
}
boolean isChangedByPK = false;
if (newNotNull) {
// add a new PK
if (pkAttributes.contains(newAttr.getName())) {
isChangedByPK = true;
}
} else {
// drop an old PK
Constraint oldPK = oldSchemaInfo.getPK(oldSupers);
if (oldPK != null) {
List<String> oldPKAttrs = oldPK.getAttributes();
if (oldPKAttrs != null && oldPKAttrs.contains(newAttr.getName())) {
isChangedByPK = true;
}
}
}
if (!isChangedByPK) {
String[] newColumn = new String[] { newAttr.getName(), String.valueOf(newNotNull) };
notNullChangedColumn.add(newColumn);
}
}
return notNullChangedColumn;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method buildColumnTableMenu.
private void buildColumnTableMenu() {
Menu menu = new Menu(columnsTable.getShell(), SWT.POP_UP);
columnsTable.setMenu(menu);
final MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
deleteItem.setText(Messages.itemDeleteColumn);
deleteItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
deleteColumn();
}
});
menu.addMenuListener(new MenuListener() {
public void menuShown(MenuEvent e) {
TableItem[] tblItems = columnsTable.getSelection();
if (tblItems.length > 0) {
DBAttribute attr = (DBAttribute) tblItems[0].getData();
List<DBAttribute> items = newSchemaInfo.getAttributes();
if (!items.contains(attr)) {
deleteItem.setEnabled(false);
} else {
deleteItem.setEnabled(true);
}
}
}
public void menuHidden(MenuEvent e) {
}
});
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class ERTable method buildColumns.
/**
* Build the columns in the schemaInfo to {@code ERTable}, and add to the er
* table.
*
* @param schemaInfo
*/
public void buildColumns(SchemaInfo schemaInfo) {
List<DBAttribute> attributesList = schemaInfo.getAttributes();
Constraint pk = schemaInfo.getPK();
for (DBAttribute attribute : attributesList) {
if (attribute == null || attribute.getInherit() == null) {
continue;
}
boolean isPK = pk == null ? false : pk.contains(attribute.getName(), false);
ERTableColumn column = new ERTableColumn(this, attribute, isPK);
this.addColumn(column);
}
}
Aggregations