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();
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations