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