use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class FKTableViewerLabelProvider method getColumnText.
/**
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
* int)
* @param element the object representing the entire row, or
* <code>null</code> indicating that no input object is set in the
* viewer
* @param columnIndex the zero-based index of the column in which the label
* appears
* @return String or or <code>null</code> if there is no text for the given
* object at columnIndex
*/
public String getColumnText(Object element, int columnIndex) {
Constraint fk = (Constraint) element;
String refTable = null;
String delRule = null;
String updateRule = null;
String cacheRule = null;
List<String> rules = fk.getRules();
for (String rule : rules) {
String refStr = "REFERENCES ";
String delStr = "ON DELETE ";
String updStr = "ON UPDATE ";
String cacheStr = "ON CACHE OBJECT ";
if (rule.startsWith(refStr)) {
refTable = rule.replace(refStr, "");
} else if (rule.startsWith(delStr)) {
delRule = rule.replace(delStr, "");
} else if (rule.startsWith(updStr)) {
updateRule = rule.replace(updStr, "");
} else if (rule.startsWith(cacheStr)) {
cacheRule = rule.replace(cacheStr, "");
}
}
switch(columnIndex) {
case 0:
return fk.getName() == null ? "" : fk.getName();
case 1:
List<String> columns = fk.getAttributes();
StringBuffer bf = new StringBuffer();
int count = 0;
for (String column : columns) {
if (count != 0) {
bf.append(",");
}
bf.append(column);
count++;
}
return bf.toString();
case 2:
return refTable;
case 3:
//get reference table's PK
if (null == refTable) {
return null;
}
SchemaInfo refSchema = getRefedTable(refTable);
List<SchemaInfo> refSupers = getRefedSupper(refSchema);
Constraint refPK = refSchema.getPK(refSupers);
if (refPK == null) {
return null;
} else {
List<String> refPKAttrs = refPK.getAttributes();
StringBuffer bf2 = new StringBuffer();
int count2 = 0;
for (String column : refPKAttrs) {
if (count2 != 0) {
bf2.append(",");
}
bf2.append(column);
count2++;
}
return bf2.toString();
}
case 4:
return updateRule;
case 5:
return delRule;
case 6:
return cacheRule;
default:
break;
}
return null;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class AddFKDialog method getPKTableData.
/**
* Get PK Table Data
*
*/
private void getPKTableData() {
pkForeignTable.removeAll();
if (oldCombo != null) {
oldCombo.dispose();
}
String refTable = foreignTableCombo.getText();
refSchema = getSchemaInfo(refTable);
if (refSchema == null) {
return;
}
List<SchemaInfo> supers = getRefedSupper(refSchema);
Constraint pk = refSchema.getPK(supers);
if (pk != null) {
List<String> pkAttrs = pk.getAttributes();
for (String attr : pkAttrs) {
DBAttribute da = (DBAttribute) refSchema.getDBAttributeByName(attr, false);
if (da == null) {
continue;
}
TableItem item = new TableItem(pkForeignTable, SWT.NONE);
item.setText(0, da.getName());
item.setText(1, DataType.getShownType(da.getType()));
}
}
if (fkTable.getItemCount() > 0) {
TableItem[] items = fkTable.getItems();
for (int i = 0, n = items.length; i < n; i++) {
//$NON-NLS-1$
items[i].setText(fkTableColCount - 1, "");
}
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method openTableDetail.
private void openTableDetail(TableDetailInfo info) {
//if had opend, set it selection
for (CTabItem tabItem : tabFolder.getItems()) {
if (tabItem.getText().equals(info.getTableName())) {
tabFolder.setSelection(tabItem);
return;
}
}
//if a new table info, create a new tab
TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
tableComp.initialize();
SchemaProvider schemaProvider = new SchemaProvider(database.getDatabaseInfo(), info.getTableName());
SchemaInfo schemaInfo = schemaProvider.getSchema();
if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
String msg = Messages.bind(Messages.errGetSchemaInfo, info.getTableName());
CommonUITool.openErrorBox(msg);
return;
}
// load table descriptions
// FIXME move this logic to core module
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
IDatabaseSpec dbSpec = database.getDatabaseInfo();
boolean isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (schemaInfo != null && isSchemaCommentInstalled) {
Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, conn, schemaInfo.getClassname());
SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method setInputs.
public void setInputs() {
tableListView.setInput(tableList);
tableListView.refresh();
Connection connection = null;
try {
connection = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(database.getDatabaseInfo(), connection);
TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
tableComp.initialize();
if (database.getDatabaseInfo().getUserTableInfoList().size() > 0) {
ClassInfo classInfo = database.getDatabaseInfo().getUserTableInfoList().get(0);
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, classInfo.getClassName());
IDatabaseSpec dbSpec = database.getDatabaseInfo();
if (schemaInfo != null && SchemaCommentHandler.isInstalledMetaTable(dbSpec, connection)) {
Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, connection, classInfo.getClassName());
if (comments != null) {
SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
}
}
tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(connection);
}
if (isSchemaCommentInstalled) {
new TableEditButtonSupport(tableListView, this, 1);
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method fireTableDetailChanged.
/**
* Fire the table info changed to tabFolder
*
* @param name
*/
private void fireTableDetailChanged(String name) {
if (tabFolder != null && !tabFolder.isDisposed()) {
CTabItem[] items = tabFolder.getItems();
for (CTabItem item : items) {
TablesDetailInfoCTabItem tabItem = (TablesDetailInfoCTabItem) item;
SchemaInfo schema = tabItem.getTableInfoComposite().getData();
if (schema != null && StringUtil.isEqualNotIgnoreNull(schema.getClassname(), name)) {
item.dispose();
}
}
}
}
Aggregations