Search in sources :

Example 11 with SchemaInfo

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

the class EditVirtualTableDialog method createTableInformationGroup.

private void createTableInformationGroup(Composite compositeGenaral) {
    final Group group = new Group(compositeGenaral, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    group.setLayout(gridLayout);
    group.setText(Messages.lblTableInfo);
    final Label tableNameLabel = new Label(group, SWT.NONE);
    tableNameLabel.setData(Messages.dataNewKey, null);
    tableNameLabel.setText(Messages.lblTableName);
    final SchemaInfo newSchemaInfo = getNewSchemaInfo();
    tableNameComp = new Composite(group, SWT.NONE);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 2;
        gl.marginWidth = 0;
        tableNameComp.setLayout(gl);
        tableNameComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        tableNameText = new Text(tableNameComp, SWT.BORDER);
        {
            GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
            tableNameText.setLayoutData(gd);
        }
        tableNameText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent event) {
                if (tableNameText.getText().length() == 0) {
                    CommonUITool.hideErrorBaloon(errorBaloon);
                } else if (verifyTableName()) {
                    String tableName = tableNameText.getText();
                    newSchemaInfo.setClassname(tableName);
                }
            }
        });
        tableNameText.addFocusListener(new FocusAdapter() {

            public void focusLost(FocusEvent e) {
                CommonUITool.hideErrorBaloon(errorBaloon);
            }
        });
    }
    //char set
    if (supportCharset) {
        Composite collationComposite = new Composite(tableNameComp, SWT.NONE);
        collationComposite.setLayout(new GridLayout(2, false));
        final Label collationLabel = new Label(collationComposite, SWT.NONE);
        collationLabel.setText(Messages.lblCollation);
        collationCombo = new Combo(collationComposite, SWT.READ_ONLY);
        collationCombo.setLayout(new FillLayout());
        collationCombo.setVisibleItemCount(10);
        fillCollationCombo();
        String collation = collationCombo.getText();
        newSchemaInfo.setCollation(collation);
        collationCombo.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                String collation = collationCombo.getText();
                newSchemaInfo.setCollation(collation);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        if (!isNewTableFlag && newSchemaInfo.getCollation() != null) {
            collationCombo.setText(newSchemaInfo.getCollation());
        }
    } else {
        new Label(tableNameComp, SWT.NONE);
    }
    if (erSchema.isPhysicModel()) {
        //desc info
        final Label tableDescLabel = new Label(group, SWT.NONE);
        tableDescLabel.setText(Messages.lblTableDesc);
        tableDescText = new Text(group, SWT.BORDER);
        tableDescText.setTextLimit(612);
        tableDescText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        //		tableDescText.setLayoutData(new FillLayout());
        if (newSchemaInfo != null && newSchemaInfo.getDescription() != null) {
            tableDescText.setText(newSchemaInfo.getDescription());
        }
        tableDescText.addFocusListener(new FocusAdapter() {

            public void focusGained(FocusEvent e) {
            }

            public void focusLost(FocusEvent e) {
                CommonUITool.hideErrorBaloon(errorBaloon);
            }
        });
        tableDescText.setEditable(true);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with SchemaInfo

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

the class EditVirtualTableDialog method postEdittedTable.

/**
	 * Parse the table and add new table to the er schema
	 * 
	 * @param erSchema ERSchema
	 */
public void postEdittedTable(ERSchema erSchema) {
    ERTable tmpTable = (ERTable) oldERTable.clone();
    SchemaInfo newSchemaInfo = getNewSchemaInfo();
    //update table name
    if (!oldERTable.getName(isPhysical).equals(newERTable.getName(isPhysical))) {
        oldERTable.modifyNameAndFire(newERTable.getName(isPhysical), isPhysical);
    }
    //update table collation
    oldERTable.getSchemaInfo().setCollation(newSchemaInfo.getCollation());
    //deleted columns
    for (String oldColName : deletedColumns) {
        oldERTable.removeColumnAndFire(oldERTable.getColumn(oldColName, isPhysical));
    }
    //modified columns
    Set<String> oldNames = modifiedColumns.keySet();
    for (String oldColName : oldNames) {
        String newName = modifiedColumns.get(oldColName);
        ERTableColumn oldColumn = oldERTable.getColumn(oldColName, isPhysical);
        ERTableColumn newCol = newERTable.getColumn(newName, isPhysical);
        if (oldColumn == null) {
            continue;
        }
        ERTableColumn firedOldColumn = oldColumn.clone();
        if (newCol == null) {
            continue;
        }
        //will modify the old column to new
        oldERTable.modifyColumn(oldColName, isPhysical, newCol);
        oldColumn.firePropertyChange(ERTableColumn.TEXT_CHANGE, firedOldColumn, newCol);
    }
    //added columns
    for (String addedColumn : addedColumns) {
        ERTableColumn newColumn = newERTable.getColumn(addedColumn, isPhysical);
        if (newColumn == null) {
            continue;
        }
        //from new to old now
        newColumn.setIsNew(false);
        if (oldERTable.getColumn(addedColumn, isPhysical) != null) {
            continue;
        }
        oldERTable.addColumnAndFire(newColumn);
    }
    //update pk
    Constraint newPK = newSchemaInfo.getPK();
    Constraint oldPK = oldERTable.getSchemaInfo().getPK();
    if (oldPK != null) {
        oldERTable.getSchemaInfo().removeConstraintByName(oldPK.getName(), ConstraintType.PRIMARYKEY.getText());
    }
    if (newPK != null) {
        oldERTable.getSchemaInfo().addConstraint(newPK);
    }
    //update fk
    List<Constraint> oldFKs = oldERTable.getSchemaInfo().getFKConstraints();
    oldERTable.deleteAllFKShipsAndFire();
    for (Constraint fk : oldFKs) {
        oldERTable.getSchemaInfo().addConstraint(fk);
    }
    CubridTableParser tableParser = new CubridTableParser(erSchema);
    try {
        tableParser.buildReferenceShip(oldERTable, newSchemaInfo);
    } catch (Exception e) {
        CommonUITool.openErrorBox(e.getMessage());
        oldERTable = tmpTable;
        return;
    }
    syncLogicalNameAndPhysicalComment();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ERTable(com.cubrid.common.ui.er.model.ERTable) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 13 with SchemaInfo

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

the class EditVirtualTableDialog method addNewColumn.

public void addNewColumn() {
    SchemaInfo newSchemaInfo = getNewSchemaInfo();
    if (newSchemaInfo == null) {
        return;
    }
    // boolean hasNotFinishedColumn = false;
    boolean hasDuplicatedColumn = false;
    List<ERTableColumn> items = newERTable.getColumns();
    if (items != null && items.size() > 0) {
        Set<String> matches = new HashSet<String>();
        // check whether there is no name column
        for (ERTableColumn col : items) {
            if (col == null) {
                continue;
            }
            if (StringUtil.isEmpty(col.getName(erSchema.isPhysicModel()))) {
                continue;
            }
            if (matches.contains(col.getName(erSchema.isPhysicModel()))) {
                hasDuplicatedColumn = true;
                break;
            }
            matches.add(col.getName(erSchema.isPhysicModel()));
        }
    }
    if (hasDuplicatedColumn) {
        CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
        return;
    }
    String collation = null;
    if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
        collation = newSchemaInfo.getCollation();
    } else {
        collation = Collation.DEFAULT_COLLATION;
    }
    DBAttribute addAttribute = new DBAttribute("", DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
    ERTableColumn column = new ERTableColumn(newERTable, addAttribute, false);
    column.setIsNew(true);
    tempERColumnList.add(column);
    loadColumnData();
    columnTableView.setSelection(new StructuredSelection(addAttribute), true);
    columnsTable.setFocus();
    handleSelectionChangeInColumnTable();
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) HashSet(java.util.HashSet)

Example 14 with SchemaInfo

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

the class CreateRelationshipCommand method execute.

@Override
public void execute() {
    if (!check()) {
        return;
    }
    ERSchema erSchema = foreignTable.getERSchema();
    SchemaInfo fkSchemaInfo = erSchema.getSchemaInfo(foreignTable.getName());
    AddFKDialog dlg = new AddFKDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), erSchema.getCubridDatabase(), fkSchemaInfo, null, false, erSchema.getAllSchemaInfo());
    dlg.setDefaultTableName(primaryTable.getName());
    int returnCode = dlg.open();
    if (returnCode == AddFKDialog.OK) {
        Constraint fk = dlg.getRetFK();
        if (fk == null) {
            return;
        }
        CubridTableParser parser = new CubridTableParser(erSchema);
        try {
            parser.addFKShip(foreignTable, fkSchemaInfo, fk);
            fkSchemaInfo.addConstraint(fk);
        } catch (Exception e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ERSchema(com.cubrid.common.ui.er.model.ERSchema) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) AddFKDialog(com.cubrid.common.ui.cubrid.table.dialog.AddFKDialog)

Example 15 with SchemaInfo

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

the class ERDNDController method getSelectedSchemaInfos.

/**
	 * Replace the SQL, and get clone SchemaInfo list
	 *
	 * @return boolean
	 */
private List<SchemaInfo> getSelectedSchemaInfos() {
    // FIXME move this logic to core module
    List<ISchemaNode> schemaNodeList = new ArrayList<ISchemaNode>();
    List<SchemaInfo> validSchemaInfoList = new ArrayList<SchemaInfo>();
    boolean isValid = fillInSelectedNode(schemaNodeList);
    if (!isValid || (schemaNodeList.isEmpty())) {
        return null;
    }
    boolean isSame = checkSourceDB(schemaNodeList);
    if (!isSame) {
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.errDragTableSource);
        return null;
    }
    Connection conn = null;
    String err = null;
    try {
        conn = JDBCConnectionManager.getConnection(schemaNodeList.get(0).getDatabase().getDatabaseInfo(), false);
        // Get all tables SchemaInfo
        for (ISchemaNode node : schemaNodeList) {
            SchemaInfo tableInfo = getSchemaInfo(node, conn);
            if (tableInfo == null) {
                String error = node.getDatabase().getDatabaseInfo().getErrorMessage();
                if (StringUtil.isEmpty(error)) {
                    error = com.cubrid.common.ui.er.Messages.errNotExistDraggedTable;
                }
                CommonUITool.openErrorBox(error);
                return null;
            }
            validSchemaInfoList.add(tableInfo);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        err = e.getMessage();
    } finally {
        QueryUtil.freeQuery(conn);
    }
    if (err != null) {
        CommonUITool.openErrorBox(editor.getGraphicalControl().getShell(), err);
    }
    return validSchemaInfoList;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) SQLException(java.sql.SQLException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5