use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method deleteColumn.
private void deleteColumn() {
if (!CommonUITool.openConfirmBox(Messages.msgDeleteColumnConfirm)) {
return;
}
TableItem[] tblItems = columnsTable.getSelection();
if (tblItems.length > 0) {
ERTableColumn column = (ERTableColumn) tblItems[0].getData();
List<ERTableColumn> items = newERTable.getColumns();
if (!items.contains(column)) {
return;
}
}
TableItem[] selection = columnsTable.getSelection();
int selectionIndex = columnsTable.getSelectionIndex();
if (selection != null && selection.length >= 1) {
List<String> physicalNames = new ArrayList<String>();
List<String> columnNames = new ArrayList<String>();
for (int m = 0; m < selection.length; m++) {
columnNames.add(m, selection[m].getText(2));
physicalNames.add(m, ((ERTableColumn) selection[m].getData()).getName());
}
List<SchemaInfo> allSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newERTable.getSchemaInfo());
Constraint pk = newERTable.getSchemaInfo().getPK(allSupers);
List<String> pkAttributes = pk == null ? new ArrayList<String>() : pk.getAttributes();
boolean hasPk = false;
for (String pkAttribute : pkAttributes) {
if (physicalNames.contains(pkAttribute)) {
hasPk = true;
break;
}
}
if (hasPk && physicalNames.containsAll(pkAttributes)) {
newERTable.getSchemaInfo().removeConstraintByName(pk.getName(), Constraint.ConstraintType.PRIMARYKEY.getText());
}
SchemaInfo newSchemaInfo = getNewSchemaInfo();
for (TableItem selec : selection) {
ERTableColumn oldColumn = (ERTableColumn) selec.getData();
if (oldColumn == null) {
continue;
}
if (oldColumn.getAttr().isClassAttribute()) {
newSchemaInfo.getClassAttributes().remove(oldColumn.getAttr());
} else {
newSchemaInfo.getAttributes().remove(oldColumn.getAttr());
newSchemaInfo.removeAttrInConstraints(oldColumn.getAttr().getName());
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
}
afterDeleteColumn(oldColumn.getName(isPhysical));
newERTable.removeColumn(oldColumn.getName(isPhysical), isPhysical);
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
int itemCount = columnsTable.getItemCount();
columnsTable.select(selectionIndex < itemCount ? selectionIndex : selectionIndex - 1);
columnsTable.setFocus();
}
}
use of com.cubrid.common.ui.er.model.ERTableColumn in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog 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();
ERTableColumn erColumn = (ERTableColumn) tblItems[0].getData();
boolean isInheritAttr = erColumn.getAttr().getInherit() != null && !tableNameText.getText().trim().equalsIgnoreCase(erColumn.getAttr().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 (erColumn.getAttr().isClassAttribute() || isInheritAttr) {
isSupportReorderColumn = false;
}
}
int count = 0;
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (newSchemaInfo.getClassAttributes() != null) {
count = newSchemaInfo.getClassAttributes().size();
}
int index = columnsTable.getSelectionIndex();
if (!erColumn.getAttr().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<ERTableColumn> items = newERTable.getColumns();
if (!items.contains(erColumn)) {
deleteColumnBtn.setEnabled(false);
} else {
deleteColumnBtn.setEnabled(true);
}
}
}
}
Aggregations