Search in sources :

Example 31 with ERTableColumn

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();
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 32 with ERTableColumn

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);
            }
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)32 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)11 ERTable (com.cubrid.common.ui.er.model.ERTable)11 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)10 Constraint (com.cubrid.common.core.common.model.Constraint)9 List (java.util.List)6 EditableLabel (com.cubrid.common.ui.er.figures.EditableLabel)5 CubridTableParser (com.cubrid.common.ui.er.model.CubridTableParser)4 ArrayList (java.util.ArrayList)4 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)3 ERSchema (com.cubrid.common.ui.er.model.ERSchema)3 Relationship (com.cubrid.common.ui.er.model.Relationship)3 EditPart (org.eclipse.gef.EditPart)3 TableItem (org.eclipse.swt.widgets.TableItem)3 TablePart (com.cubrid.common.ui.er.part.TablePart)2 HashSet (java.util.HashSet)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ITask (com.cubrid.common.core.task.ITask)1 ERWinDBAttribute (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute)1 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)1