Search in sources :

Example 1 with AddIndexDialog

use of com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog in project cubrid-manager by CUBRID.

the class TableEditorPart method openEditIndexDialog.

/**
	 * Open the index edit dialog with the constraint object
	 *
	 * @param editedIndex Constraint
	 */
private void openEditIndexDialog(Constraint editedIndex) {
    boolean isNewConstraint = true;
    for (int i = 0, len = originalConstraints.size(); i < len; i++) {
        if (originalConstraints.get(i) == editedIndex) {
            isNewConstraint = false;
        }
    }
    AddIndexDialog dlg = new AddIndexDialog(getSite().getShell(), newSchemaInfo, database, editedIndex, isNewConstraint);
    int returnCode = dlg.open();
    if (returnCode == AddIndexDialog.OK) {
        Constraint newIndex = dlg.getIndexConstraint();
        if (newIndex == null) {
            return;
        }
        newSchemaInfo.removeConstraintByName(editedIndex.getName(), editedIndex.getType());
        newSchemaInfo.addConstraint(newIndex);
        // For bug TOOLS-2394 Unique index can't be added again
        if (Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) && newIndex.getAttributes().size() == 1) {
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(newIndex.getAttributes().get(0), false);
            attr.setUnique(true);
            loadColumnData();
        }
        boolean modifiedUK = Constraint.ConstraintType.UNIQUE.getText().equals(editedIndex.getType()) && editedIndex.getAttributes().size() == 1;
        boolean noNewUK = !Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) || newIndex.getAttributes().size() != 1;
        if (modifiedUK && noNewUK) {
            String attrName = editedIndex.getAttributes().get(0);
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(attrName, false);
            if (attr != null) {
                attr.setUnique(false);
                loadColumnData();
            }
        }
        String key1 = editedIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + editedIndex.getName();
        String key2 = newIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + newIndex.getName();
        SchemaChangeLog changeLog = new SchemaChangeLog(key1, key2, SchemeInnerType.TYPE_INDEX);
        schemaChangeMgr.addSchemeChangeLog(changeLog);
        indexTableView.setInput(newSchemaInfo);
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) AddIndexDialog(com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 2 with AddIndexDialog

use of com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog in project cubrid-manager by CUBRID.

the class EditVirtualTableDialog method openEditIndexDialog.

/**
	 * Open the index edit dialog with the constraint object
	 *
	 * @param editedIndex Constraint
	 */
private void openEditIndexDialog(Constraint editedIndex) {
    boolean isNewConstraint = true;
    for (int i = 0, len = originalConstraints.size(); i < len; i++) {
        if (originalConstraints.get(i) == editedIndex) {
            isNewConstraint = false;
        }
    }
    SchemaInfo newSchemaInfo = getNewSchemaInfo();
    AddIndexDialog dlg = new AddIndexDialog(getShell(), newSchemaInfo, database, editedIndex, isNewConstraint);
    int returnCode = dlg.open();
    if (returnCode == AddIndexDialog.OK) {
        Constraint newIndex = dlg.getIndexConstraint();
        if (newIndex == null) {
            return;
        }
        newSchemaInfo.removeConstraintByName(editedIndex.getName(), editedIndex.getType());
        newSchemaInfo.addConstraint(newIndex);
        // For bug TOOLS-2394 Unique index can't be added again
        if (Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) && newIndex.getAttributes().size() == 1) {
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(newIndex.getAttributes().get(0), false);
            attr.setUnique(true);
            loadColumnData();
        }
        boolean modifiedUK = Constraint.ConstraintType.UNIQUE.getText().equals(editedIndex.getType()) && editedIndex.getAttributes().size() == 1;
        boolean noNewUK = !Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) || newIndex.getAttributes().size() != 1;
        if (modifiedUK && noNewUK) {
            String attrName = editedIndex.getAttributes().get(0);
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(attrName, false);
            if (attr != null) {
                attr.setUnique(false);
                loadColumnData();
            }
        }
        String key1 = editedIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + editedIndex.getName();
        String key2 = newIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + newIndex.getName();
        SchemaChangeLog changeLog = new SchemaChangeLog(key1, key2, SchemeInnerType.TYPE_INDEX);
        schemaChangeMgr.addSchemeChangeLog(changeLog);
        indexTableView.setInput(newSchemaInfo);
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) AddIndexDialog(com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Aggregations

Constraint (com.cubrid.common.core.common.model.Constraint)2 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 AddIndexDialog (com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog)2 SchemaChangeLog (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1