Search in sources :

Example 16 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class EditVirtualTableDialog 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.setImage(CommonUIPlugin.getImageDescriptor("icons/action/table_record_delete.png").createImage());
    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 = getNewSchemaInfo().getAttributes();
                if (!items.contains(attr)) {
                    deleteItem.setEnabled(false);
                } else {
                    deleteItem.setEnabled(true);
                }
            }
        }

        public void menuHidden(MenuEvent e) {
        }
    });
}
Also used : MenuListener(org.eclipse.swt.events.MenuListener) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 17 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class ERDNDController method getDescInformation.

private void getDescInformation(SchemaInfo newSchemaInfo, CubridDatabase database, Connection conn) {
    // FIXME move this logic to core module
    try {
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
        if (isSupportTableComment && newSchemaInfo != null) {
            Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
            for (DBAttribute attr : newSchemaInfo.getAttributes()) {
                SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
                if (schemaComment != null) {
                    attr.setDescription(schemaComment.getDescription());
                }
            }
            SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
            if (schemaComment != null) {
                newSchemaInfo.setDescription(schemaComment.getDescription());
            }
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) SQLException(java.sql.SQLException) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) SQLException(java.sql.SQLException)

Example 18 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class ERAttributeCellModifier method canModify.

public boolean canModify(Object element, String property) {
    // FIXME move this logic to core module
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute attr = erColumn.getAttr();
    if (!editor.isNewTableFlag() && !editor.isSupportChange() && editor.getOldSchemaInfo().getDBAttributeByName(attr.getName(), false) != null) {
        return false;
    }
    if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            return false;
        } else if (!DataType.isIntegerType(attr.getType())) {
            return false;
        } else if (attr != null && StringUtil.isNotEmpty(attr.getDefault())) {
            CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL) || StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
        Constraint pk = editor.getNewSchemaInfo().getPK();
        if (pk != null && pk.getAttributes().contains(attr.getName())) {
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        if (attr.isNew() && DataType.canUseCollation(attr.getType())) {
            return true;
        } else {
            return false;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return editor.isSupportTableComment();
    }
    return true;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn)

Example 19 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class ERAttributeLabelProvider method getBackground.

public Color getBackground(Object element, int columnIndex) {
    if (schema == null || element == null || !editableMode) {
        return null;
    }
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute attr = erColumn.getAttr();
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = schema.getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            return DISABLED_COLOR;
        } else if (!DataType.isIntegerType(attr.getType())) {
            return DISABLED_COLOR;
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return editorAdaptor.isSupportTableComment() ? null : DISABLED_COLOR;
    }
    return null;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn)

Example 20 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class ERAttributeLabelProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element == null) {
        return null;
    }
    ERTableColumn erColumn = (ERTableColumn) element;
    DBAttribute dbAttribute = erColumn.getAttr();
    if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
        return null;
    }
    String property = editorAdaptor.getColumnProperty(columnIndex);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_FLAG)) {
        if (StringUtil.isEmpty(dbAttribute.getName())) {
            return "*";
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
        return erColumn.getName(isPhysical);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
        if (isPhysical) {
            if (DataType.DATATYPE_ENUM.equalsIgnoreCase(dbAttribute.getType())) {
                String type = StringUtil.toUpper(dbAttribute.getType()) + dbAttribute.getEnumeration();
                return DataType.getShownType(type);
            } else {
                return DataType.getShownType(dbAttribute.getType());
            }
        } else {
            return erColumn.getShowType(false).toUpperCase();
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
        String defaultValue = dbAttribute.getDefault();
        if (defaultValue == null) {
            return DataType.NULL_EXPORT_FORMAT;
        }
        if (defaultValue.length() == 0 && DataType.isStringType(dbAttribute.getType())) {
            return "";
        }
        return defaultValue;
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        SerialInfo serial = dbAttribute.getAutoIncrement();
        if (serial == null) {
            return "";
        }
        return serial.getMinValue() + "," + serial.getIncrementValue();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        return dbAttribute.getDescription();
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        return dbAttribute.getCollation();
    }
    return null;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Aggregations

DBAttribute (com.cubrid.common.core.common.model.DBAttribute)130 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)57 Constraint (com.cubrid.common.core.common.model.Constraint)53 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)16 List (java.util.List)15 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)14 TableItem (org.eclipse.swt.widgets.TableItem)13 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)10 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 Map (java.util.Map)8 Point (org.eclipse.swt.graphics.Point)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)7 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)6 DBResolution (com.cubrid.common.core.common.model.DBResolution)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)5