Search in sources :

Example 1 with ERTable

use of com.cubrid.common.ui.er.model.ERTable 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 2 with ERTable

use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.

the class ReconnectForeignKeyCommand method canExecute.

/**
	 * Makes sure that primary key doesn't reconnect to itself or try to create
	 * a relationship which already exists
	 */
@Override
public boolean canExecute() {
    boolean returnVal = true;
    ERTable primaryKeyTable = relationship.getPrimaryKeyTable();
    // cannot connect to itself
    if (primaryKeyTable.equals(sourceForeignTable)) {
        returnVal = false;
    } else {
        List relationships = sourceForeignTable.getForeignKeyRelationships();
        for (int i = 0; i < relationships.size(); i++) {
            Relationship relationship = ((Relationship) (relationships.get(i)));
            if (relationship.getPrimaryKeyTable().equals(targetPrimaryTable) && relationship.getForeignKeyTable().equals(sourceForeignTable)) {
                returnVal = false;
                break;
            }
        }
    }
    return returnVal;
}
Also used : Relationship(com.cubrid.common.ui.er.model.Relationship) ERTable(com.cubrid.common.ui.er.model.ERTable) List(java.util.List)

Example 3 with ERTable

use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.

the class AddColumnAction method run.

public void run() {
    ERTable table = this.getERTable();
    List<String> names = new ArrayList<String>();
    List<ERTableColumn> columns = table.getColumns();
    for (ERTableColumn column : columns) {
        names.add(column.getName());
    }
    AddColumnDialog dlg = new AddColumnDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), table.getName(), true, names, getERSchema());
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        boolean isPhysical = table.getERSchema().isPhysicModel();
        String newName = dlg.getNewColumnName();
        String type = dlg.getDataType();
        String realType = null;
        String enumeration = null;
        if (isPhysical) {
            realType = DataType.getRealType(type);
        } else {
            String upPhysicalShowType = type;
            realType = DataType.getRealType(upPhysicalShowType);
        }
        if (DataType.DATATYPE_ENUM.equals(type)) {
            realType = DataType.getUpperEnumType().toLowerCase();
            enumeration = "('" + DataType.ENUM_DAFAULT_VALUE + "')";
        }
        DBAttribute addAttribute = new DBAttribute(newName, realType, table.getName(), false, false, false, false, null, Collation.DEFAULT_COLLATION);
        addAttribute.setEnumeration(enumeration);
        ERTableColumn col = new ERTableColumn(table, addAttribute, false);
        if (DataType.DATATYPE_STRING.equals(type)) {
            col.setLogicalType(DataType.DATATYPE_STRING);
        }
        table.addColumnAndFire(col);
    }
}
Also used : AddColumnDialog(com.cubrid.common.ui.er.dialog.AddColumnDialog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ArrayList(java.util.ArrayList) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 4 with ERTable

use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.

the class ExportImportGsonDataController method buildERDSchema.

private void buildERDSchema(ERSchema originSchema, ERSchema deserializedERSchema, Map<String, SchemaInfo> schemaInfos, boolean isImportMap) {
    String message = "";
    CubridTableParser tableParser = new CubridTableParser(originSchema);
    tableParser.buildERTables(schemaInfos.values(), -1, -1, false);
    if (isImportMap) {
        originSchema.setPhysicalLogicRelation(deserializedERSchema.getPhysicalLogicRelation());
    }
    List<ERTable> successTables = tableParser.getSuccessTables();
    for (ERTable table : successTables) {
        ERTable savedTable = deserializedERSchema.getTable(table.getName());
        table.setLogicalName(savedTable.getLogicalName());
        List<ERTableColumn> columns = table.getColumns();
        for (ERTableColumn column : columns) {
            String colName = column.getName();
            ERTableColumn savedColumn = savedTable.getColumn(colName, true);
            column.setLogicalName(savedColumn.getLogicalName());
            column.setLogicalType(savedColumn.getLogicalType());
        }
        if (originSchema.isLayoutManualDesired()) {
            table.setBounds(savedTable.getBounds());
        }
    }
    originSchema.FireAddedTable(successTables);
    Map<String, Exception> failedTables = tableParser.getFailedTables();
    Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
    if (failedTables.size() > 0) {
        message = Messages.bind(com.cubrid.common.ui.er.Messages.errorAddTables, failedTables.keySet());
    }
    if (removedFKs.size() > 0) {
        if (!message.equals("")) {
            message += "\n";
        }
        message += Messages.bind(com.cubrid.common.ui.er.Messages.cannotBeBuiltFK, tableParser.getOneRemovedFK().getName());
        if (tableParser.getRemovedFKCount() > 1) {
            message += ", ...";
        }
    }
    if (!message.equals("")) {
        CommonUITool.openErrorBox(message);
    }
}
Also used : ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) ERTable(com.cubrid.common.ui.er.model.ERTable) List(java.util.List)

Example 5 with ERTable

use of com.cubrid.common.ui.er.model.ERTable in project cubrid-manager by CUBRID.

the class ERSchemaEditor method searchAndLocate.

/**
	 * Set matched tables to be selected, and next(or first) finding table to be
	 * focused
	 * 
	 * @param keyWord
	 * @param isChangedKey
	 * @return
	 */
public boolean searchAndLocate(String keyWord, boolean isChangedKey) {
    SchemaDiagramPart schemaRootPart = getERSchemaRootPart();
    List allParts = schemaRootPart.getChildren();
    // set next focus table(focus circularly )
    if (!isChangedKey && graphicalViewer.getFocusEditPart() instanceof TablePart) {
        TablePart focusedTablePart = (TablePart) graphicalViewer.getFocusEditPart();
        int preFocusIndex = allParts.indexOf(focusedTablePart);
        int start = preFocusIndex + 1;
        for (; start < allParts.size(); start++) {
            Object table = allParts.get(start);
            if (table instanceof TablePart) {
                TablePart nexFocusTable = (TablePart) table;
                if (nexFocusTable.getTable().getShownName().contains(keyWord)) {
                    getViewPort().setViewLocation(nexFocusTable.getFigure().getBounds().x, nexFocusTable.getFigure().getBounds().y);
                    graphicalViewer.setFocus(nexFocusTable);
                    return true;
                }
            }
            if (start == allParts.size()) {
                start = 0;
            }
        }
    }
    // set first focus table and gray tables
    Iterator it = allParts.iterator();
    List matchedList = new ArrayList();
    boolean isFocus = false;
    while (it.hasNext()) {
        Object obj = it.next();
        if (!(obj instanceof TablePart)) {
            continue;
        }
        TablePart tablePart = (TablePart) obj;
        ERTable erTable = tablePart.getTable();
        if (erTable.getShownName().contains(keyWord)) {
            matchedList.add(tablePart);
            if (!isFocus) {
                getViewPort().setViewLocation(tablePart.getFigure().getBounds().x, tablePart.getFigure().getBounds().y);
                graphicalViewer.setFocus(tablePart);
                isFocus = true;
            }
        } else {
            TableFigure figure = (TableFigure) tablePart.getFigure();
            figure.setDisabled(true);
        }
    }
    StructuredSelection matchedTables = new StructuredSelection(matchedList);
    graphicalViewer.setSelection(matchedTables);
    return true;
}
Also used : TableFigure(com.cubrid.common.ui.er.figures.TableFigure) SchemaDiagramPart(com.cubrid.common.ui.er.part.SchemaDiagramPart) TablePart(com.cubrid.common.ui.er.part.TablePart) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ERTable(com.cubrid.common.ui.er.model.ERTable) ArrayList(java.util.ArrayList) List(java.util.List) EventObject(java.util.EventObject) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

ERTable (com.cubrid.common.ui.er.model.ERTable)30 List (java.util.List)14 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 TableFigure (com.cubrid.common.ui.er.figures.TableFigure)6 Iterator (java.util.Iterator)6 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)5 ERSchema (com.cubrid.common.ui.er.model.ERSchema)5 TablePart (com.cubrid.common.ui.er.part.TablePart)5 LinkedList (java.util.LinkedList)5 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 CubridTableParser (com.cubrid.common.ui.er.model.CubridTableParser)4 Relationship (com.cubrid.common.ui.er.model.Relationship)4 ArrayList (java.util.ArrayList)4 EventObject (java.util.EventObject)4 SchemaDiagramPart (com.cubrid.common.ui.er.part.SchemaDiagramPart)3 Constraint (com.cubrid.common.core.common.model.Constraint)2 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 EditableLabel (com.cubrid.common.ui.er.figures.EditableLabel)2 PropertyChangeProvider (com.cubrid.common.ui.er.model.PropertyChangeProvider)2 Point (org.eclipse.draw2d.geometry.Point)2