use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class ERXmlContainer method parseAttributes.
private void parseAttributes() {
NodeList attributes = doc.getElementsByTagName("Attribute");
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
ERWinDBAttribute erwinAttribute = new ERWinDBAttribute();
String attrId = attribute.getAttributes().getNamedItem("id").getNodeValue().trim();
//logical name
String attrName = attribute.getAttributes().getNamedItem("Name").getNodeValue().trim();
erwinAttribute.setLogicalName(attrName);
attributeMap.put(attrId, erwinAttribute);
String physicalName = "";
String fkAttrName = "";
int attributeType = -1;
boolean duplicate = false;
Node pNode = findPNode(attribute, "Entity");
if (pNode == null) {
continue;
}
String pId = pNode.getAttributes().getNamedItem("id").getNodeValue().trim();
String tableName = physicalNameMap.get(pId);
if (tableName == null) {
tableName = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
ERWinSchemaInfo schemaInfo = schemaInfos.get(tableName);
for (int ii = 0; ii < attribute.getChildNodes().getLength(); ii++) {
Node tempNode = attribute.getChildNodes().item(ii);
if (tempNode.getNodeName().equals("AttributeProps")) {
physicalName = handler.getChildValueByProperty(tempNode, "Physical_Name");
if (physicalName == null) {
physicalName = attrName;
}
DBAttribute duplicateAttr = schemaInfo.getDBAttributeByName(physicalName, false);
if (duplicateAttr != null) {
duplicate = true;
break;
}
erwinAttribute.setName(physicalName);
columnIdMap.put(attrId, physicalName);
Node attributePropsChild = tempNode.getFirstChild();
while (attributePropsChild != null) {
String attributeName = attributePropsChild.getNodeName();
if (attributeName.equals("Datatype")) {
String dataType = attributePropsChild.getFirstChild().getNodeValue().trim();
if (dataType.startsWith(DataType.getUpperEnumType())) {
//convert to show type
dataType = dataType.replaceFirst(DataType.getUpperEnumType(), DataType.getLowerEnumType());
}
String enumeration = DataType.getEnumeration(dataType);
if (!StringUtil.isEmpty(enumeration)) {
dataType = DataType.getUpperEnumType();
erwinAttribute.setEnumeration(enumeration);
}
erwinAttribute.setType(dataType);
erwinAttribute.setDefault(updateData(dataType, erwinAttribute.getDefault()));
} else if (attributeName.equals("Type")) {
attributeType = Integer.parseInt(attributePropsChild.getFirstChild().getNodeValue().trim());
} else if (attributeName.equals("Null_Option")) {
int value = Integer.parseInt(attributePropsChild.getFirstChild().getNodeValue().trim());
switch(value) {
case 1:
case 8:
erwinAttribute.setNotNull(true);
break;
default:
break;
}
} else if (attributeName.equals("Default")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Node defaultValueNode = getNodeById(id, "Default_Value");
if (defaultValueNode == null) {
attributePropsChild = attributePropsChild.getNextSibling();
continue;
}
String value = handler.getChildValueByProperty(defaultValueNode, "Default_ValueProps.Server_Value");
if (erwinAttribute.getType() != null) {
value = updateData(erwinAttribute.getType(), value);
}
erwinAttribute.setDefault(value);
} else if (attributeName.equals("Identity_Seed")) {
SerialInfo serialInfo = new SerialInfo();
serialInfo.setIncrementValue(attributePropsChild.getFirstChild().getNodeValue().trim());
erwinAttribute.setAutoIncrement(serialInfo);
} else if (attributeName.equals("Parent_Domain")) {
String id = attributePropsChild.getFirstChild().getNodeValue();
String value = handler.getNodeChildValueById("Domain", id, "DomainProps.Datatype");
if (value == null) {
// if it has reference-id (DomainProps.Parent_Domain)
String refId = handler.getNodeChildValueById("Domain", id, "DomainProps.Parent_Domain");
value = handler.getNodeChildValueById("Domain", refId, "DomainProps.Datatype");
}
if (StringUtil.isEmpty(erwinAttribute.getType())) {
erwinAttribute.setType(DataType.getRealType(StringUtil.toUpper(value)));
}
} else if (attributeName.equals("Parent_Relationship")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Constraint relType = foreignKeyMap.get(id);
if (relType != null) {
boolean isPk = relType.getType().equals(Constraint.ConstraintType.PRIMARYKEY.getText());
boolean isFk = relType.getType().equals(Constraint.ConstraintType.FOREIGNKEY.getText());
if (isPk || isFk) {
erwinAttribute.setNotNull(true);
erwinAttribute.setUnique(true);
}
}
} else if (attributeName.equals("Physical_Name")) {
physicalName = attributePropsChild.getFirstChild().getNodeValue().trim();
} else if (attributeName.equals("Logical_Datatype")) {
String logicalDataType = attributePropsChild.getFirstChild().getNodeValue().trim();
erwinAttribute.setLogicalDataType(logicalDataType);
} else if (attributeName.equals("Parent_Attribute")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Node fkAttrNode = getNodeById(id, "Attribute");
if (fkAttrNode == null) {
attributePropsChild = attributePropsChild.getNextSibling();
continue;
}
fkAttrName = handler.getChildValueByProperty(fkAttrNode, "AttributeProps.Physical_Name");
if (fkAttrName == null) {
fkAttrName = fkAttrNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
Node fkTableNode = findPNode(fkAttrNode, "Entity");
String fkTableId = fkTableNode.getAttributes().getNamedItem("id").getNodeValue().trim();
String fkTableName = physicalNameMap.get(fkTableId);
erwinAttribute.setInherit(fkTableName);
// SchemaInfo schemaInfo = schemaInfos.get(tName);
// schemaInfo.addSuperClass(tableName);
} else if (attributeName.equals("View_Expression")) {
fkAttrName = attributePropsChild.getFirstChild().getNodeValue().trim();
}
attributePropsChild = attributePropsChild.getNextSibling();
}
}
}
if (duplicate) {
continue;
}
if (attributeType != ERXmlModelConstant.ATTRIBUTE_TYPE_VIEW) {
if (attributeType == ERXmlModelConstant.ATTRIBUTE_TYPE_PK) {
erwinAttribute.setUnique(true);
erwinAttribute.setNotNull(true);
}
erwinAttribute.setInherit(tableName);
schemaInfo.addAttribute(erwinAttribute);
} else {
String viewName = tableName;
if (viewName == null) {
viewName = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
ViewModel model = viewModelMap.get(viewName);
String pTable = erwinAttribute.getInherit();
if (pTable == null) {
pTable = "DEFAULT";
}
model.addTableColumnAlias(pTable, fkAttrName, erwinAttribute.getName());
}
}
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class SetPKDialog method buttonPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
* @param buttonId the id of the button that was pressed (see
* <code>IDialogConstants.*_ID</code> constants)
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
// FIXME move this logic to core module
setErrorMessage(null);
List<String> selected = new ArrayList<String>();
for (int i = 0, n = constraintTable.getItemCount(); i < n; i++) {
if (constraintTable.getItem(i).getChecked()) {
String columnName = constraintTable.getItem(i).getText(1);
selected.add(columnName);
}
}
String pkName = null;
if (changeNameButton.getSelection()) {
pkName = pkNameText.getText().trim();
if (pkName.length() == 0) {
setErrorMessage(Messages.errPKNameEmpty);
return;
}
} else {
StringBuffer pkNameSB = new StringBuffer();
pkNameSB.append("pk_");
pkNameSB.append(schema.getClassname() == null ? "" : schema.getClassname());
for (int i = 0, n = constraintTable.getItemCount(); i < n; i++) {
if (constraintTable.getItem(i).getChecked()) {
String columnName = constraintTable.getItem(i).getText(1);
pkNameSB.append("_" + columnName);
}
}
pkName = pkNameSB.toString();
}
newPK = new Constraint(true);
newPK.setName(pkName);
//$NON-NLS-1$
newPK.setType(ConstraintType.PRIMARYKEY.getText());
for (String s : selected) {
newPK.addAttribute(s);
}
boolean isNew = false;
if (oldPK == null && !selected.isEmpty()) {
isNew = true;
//$NON-NLS-1$
operation = "ADD";
} else if (oldPK != null && selected.isEmpty()) {
//$NON-NLS-1$
operation = "DEL";
isNew = false;
} else if (oldPK != null && !selected.isEmpty()) {
isNew = oldPK.getAttributes().equals(selected) && StringUtil.isEqualNotIgnoreNull(oldPK.getName(), newPK.getName()) ? false : true;
if (isNew) {
//$NON-NLS-1$
operation = "MODIFY";
} else {
//$NON-NLS-1$
operation = "NO Change";
}
}
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType2 method generateTableDetailSheets.
/**
* generate table name sheet
* @param wwb
* @param conn
* @param exportSchemaInfoList
* @param monitor
* @throws Exception
*/
public void generateTableDetailSheets(WritableWorkbook wwb, Connection conn, List<SchemaInfo> exportSchemaInfoList, IProgressMonitor monitor) throws Exception {
int sheetIndex = 1;
for (SchemaInfo schemaInfo : exportSchemaInfoList) {
String tableName = schemaInfo.getClassname();
monitor.subTask(Messages.bind(Messages.exportTableDefinitionProgressTaskWriteTable, tableName));
List<SchemaInfo> supers = SuperClassUtil.getSuperClasses(getProgressObject().getDatabase().getDatabaseInfo(), schemaInfo);
WritableSheet ws = wwb.createSheet(tableName, sheetIndex++);
int rowIndex = 0;
// Title
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell10, boldCellStyle));
ws.mergeCells(0, 0, 7, 0);
rowIndex++;
// System name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell11, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
ws.mergeCells(3, 1, 4, 1);
ws.mergeCells(5, 1, 6, 1);
rowIndex++;
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
// Table Name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell6, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.mergeCells(1, 2, 7, 2);
rowIndex++;
// Table ID
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell7, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableName, normalLeftAlignCellStyle));
ws.mergeCells(1, 3, 7, 3);
rowIndex++;
// Column name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell12, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Data type
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell14, boldCellStyle));
// Size
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell15, boldCellStyle));
// Null
ws.addCell(new jxl.write.Label(4, rowIndex, Messages.exportTableDefinitionCell16, boldCellStyle));
// PK
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell17, boldCellStyle));
// FK
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell18, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(7, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
rowIndex++;
// column info
for (DBAttribute columnAtt : schemaInfo.getAttributes()) {
String attrName = columnAtt.getName();
String columnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment columnComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, attrName);
if (columnComment != null) {
columnText = columnComment.getDescription() == null ? "" : columnComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, columnText, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, attrName, normalLeftAlignCellStyle));
String showType = DataType.getShownType((columnAtt.getType()));
if (showType.indexOf("(") > -1 && showType.endsWith("")) {
showType = showType.substring(0, showType.indexOf("("));
}
ws.addCell(new jxl.write.Label(2, rowIndex, showType, normalLeftAlignCellStyle));
int size = DataType.getSize(columnAtt.getType());
int scale = DataType.getScale(columnAtt.getType());
if (size < 0 && scale < 0) {
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalRightAlignCellStyle));
} else if (scale < 0) {
ws.addCell(new jxl.write.Number(3, rowIndex, size, normalRightAlignCellStyle));
} else {
ws.addCell(new jxl.write.Label(3, rowIndex, Integer.toString(size) + "," + Integer.toString(scale), normalRightAlignCellStyle));
}
//get nullable
boolean isNULL = true;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isNULL = false;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isNULL = false;
}
}
}
}
if (columnAtt.isNotNull()) {
isNULL = false;
}
ws.addCell(new jxl.write.Label(4, rowIndex, isNULL ? "Y" : "", normalCellStyle));
//get pk
boolean isPk = false;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isPk = true;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isPk = true;
}
}
}
}
ws.addCell(new jxl.write.Label(5, rowIndex, isPk ? "Y" : "", normalCellStyle));
//get fk
boolean isFk = false;
for (Constraint fk : schemaInfo.getFKConstraints()) {
for (String columns : fk.getAttributes()) {
if (columns.equals(attrName)) {
isFk = true;
break;
}
}
}
ws.addCell(new jxl.write.Label(6, rowIndex, isFk ? "Y" : "", normalCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
rowIndex++;
}
// blank
for (int i = 0; i < 8; i++) {
ws.addCell(new jxl.write.Label(i, rowIndex, "", normalCellStyle));
}
rowIndex++;
// index
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell20, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
// NO
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell21, boldCellStyle));
// Index name
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell22, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Order
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell23, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
List<Constraint> constraints = getProgressObject().getIndexList(schemaInfo);
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = constraints.get(i);
int columnSize = constraint.getAttributes().size();
// mark current row index
int currentRowIndex = rowIndex;
for (int j = 0; j < columnSize; j++) {
String columnName = constraint.getAttributes().get(j);
ws.addCell(new jxl.write.Number(0, rowIndex, i + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, constraint.getName(), normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, columnName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Number(5, rowIndex, j + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
if (columnSize == 1) {
ws.mergeCells(1, rowIndex, 2, rowIndex);
}
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
}
//if multiple colulmn merge NO/Index Name CELL by vertical logic
if (columnSize > 1) {
ws.mergeCells(0, currentRowIndex, 0, currentRowIndex + columnSize - 1);
ws.mergeCells(1, currentRowIndex, 2, currentRowIndex + columnSize - 1);
}
}
// blank
ws.addCell(new jxl.write.Label(0, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
// DDL
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell24, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
String ddl = getProgressObject().getDDL(schemaInfo);
ws.addCell(new jxl.write.Label(0, rowIndex, ddl, normalLeftAlignCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
ws.setRowView(0, 500);
int lineNumbner = ddl.split(StringUtil.NEWLINE).length;
ws.setRowView(rowIndex, lineNumbner * 350);
// column width
ws.setColumnView(0, 18);
ws.setColumnView(1, 20);
ws.setColumnView(2, 13);
ws.setColumnView(3, 13);
ws.setColumnView(4, 11);
ws.setColumnView(5, 11);
ws.setColumnView(6, 11);
ws.setColumnView(7, 20);
monitor.worked(1);
}
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method createFkIndexTabItem.
/**
* Create foreign key/Index tab item.
*
* @param tabFolder the object of TabFolder
*/
private void createFkIndexTabItem(final TabFolder tabFolder) {
final TabItem foreignKeyTabItem = new TabItem(tabFolder, SWT.NONE);
foreignKeyTabItem.setText(Messages.infoIndexesTab);
final Composite composite = new Composite(tabFolder, SWT.NONE);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
foreignKeyTabItem.setControl(composite);
// create the fk table viewer
final Label fkLabel = new Label(composite, SWT.NONE);
fkLabel.setText(Messages.lblFK);
fkTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
fkTable = fkTableView.getTable();
final GridData gdFkTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
fkTable.setLayoutData(gdFkTable);
fkTable.setLinesVisible(true);
fkTable.setHeaderVisible(true);
TableColumn tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnFK);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(119);
tblCol.setText(Messages.tblColumnColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(93);
tblCol.setText(Messages.tblColumnForeignTable);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(143);
tblCol.setText(Messages.tblColumnForeignColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(84);
tblCol.setText(Messages.tblColumnUpdateRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(86);
tblCol.setText(Messages.tblColumnDeleteRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnCacheColumn);
FKTableViewerContentProvider fkContentProvider = new FKTableViewerContentProvider();
FKTableViewerLabelProvider fkLabelProvider = new FKTableViewerLabelProvider(database.getDatabaseInfo(), erSchema);
fkTableView.setContentProvider(fkContentProvider);
fkTableView.setLabelProvider(fkLabelProvider);
fkTableView.setInput(getNewSchemaInfo());
final Composite fkBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
fkBtnComposite.setLayoutData(gdBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
fkBtnComposite.setLayout(gridLayout);
final GridData gdFKBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addFKBTN = new Button(fkBtnComposite, SWT.NONE);
addFKBTN.setLayoutData(gdFKBTN);
addFKBTN.setText(Messages.btnAddFk);
addFKBTN.addSelectionListener(new AddFkBtnListenerOnFkIndexTab());
final Button editFKBTN = new Button(fkBtnComposite, SWT.NONE);
editFKBTN.setLayoutData(gdFKBTN);
editFKBTN.setEnabled(false);
editFKBTN.setText(Messages.btnEditFk);
editFKBTN.addSelectionListener(new EditFkBtnListenerOnFkIndexTab());
final Button deleteFKBTN = new Button(fkBtnComposite, SWT.NONE);
deleteFKBTN.setLayoutData(gdFKBTN);
deleteFKBTN.setEnabled(false);
deleteFKBTN.setText(Messages.btnDelFk);
deleteFKBTN.addSelectionListener(new DelFkBtnListenerOnFkIndexTab());
fkTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (database == null || database.getDatabaseInfo() == null || newSchemaInfo == null) {
return;
}
TableItem[] items = fkTable.getSelection();
if (items == null || items.length == 0) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
} else {
deleteFKBTN.setEnabled(true);
editFKBTN.setEnabled(items.length == 1);
for (TableItem item : items) {
String fkName = item.getText(0);
List<SchemaInfo> superList = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo.getSuperClasses());
if (newSchemaInfo.isInSuperClasses(superList, fkName)) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
}
}
}
}
});
// create index table view
final Label indexLabel = new Label(composite, SWT.NONE);
indexLabel.setText(Messages.lblIndexes);
indexTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
indexTable = indexTableView.getTable();
indexTable.setLinesVisible(true);
indexTable.setHeaderVisible(true);
final GridData gdIndexTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
indexTable.setLayoutData(gdIndexTable);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(150);
tblCol.setText(Messages.tblColumnIndexName);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(78);
tblCol.setText(Messages.tblColumnIndexType);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(218);
tblCol.setText(Messages.tblColumnOnColumns);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(282);
tblCol.setText(Messages.tblColumnIndexRule);
IndexTableViewerContentProvider indexContentProvider = new IndexTableViewerContentProvider();
IndexTableViewerLabelProvider indexLabelProvider = new IndexTableViewerLabelProvider();
indexTableView.setContentProvider(indexContentProvider);
indexTableView.setLabelProvider(indexLabelProvider);
indexTableView.setInput(getNewSchemaInfo());
indexTableView.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
StructuredSelection selected = (StructuredSelection) event.getSelection();
if (selected == null) {
return;
}
Constraint constraint = (Constraint) selected.getFirstElement();
openEditIndexDialog(constraint);
}
});
final Composite indexBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdIndexBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
indexBtnComposite.setLayoutData(gdIndexBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
indexBtnComposite.setLayout(gridLayout);
final GridData gdIndexBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addIndexBTN = new Button(indexBtnComposite, SWT.NONE);
addIndexBTN.setLayoutData(gdIndexBTN);
addIndexBTN.setText(Messages.btnAddIndex);
addIndexBTN.addSelectionListener(new AddIndexBtnListenerOnFkIndexTab());
final Button editIndexBTN = new Button(indexBtnComposite, SWT.NONE);
editIndexBTN.setLayoutData(gdIndexBTN);
editIndexBTN.setEnabled(false);
editIndexBTN.setText(Messages.btnEditIndex);
editIndexBTN.addSelectionListener(new EditIndexBtnListenerOnFkIndexTab());
final Button deleteIndexBTN = new Button(indexBtnComposite, SWT.NONE);
deleteIndexBTN.setLayoutData(gdIndexBTN);
deleteIndexBTN.setEnabled(false);
deleteIndexBTN.setText(Messages.btnDelIndex);
deleteIndexBTN.addSelectionListener(new DelIndexBtnListenerOnFkIndexTab());
indexTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
TableItem[] items = indexTable.getSelection();
if (items == null || items.length == 0) {
deleteIndexBTN.setEnabled(false);
editIndexBTN.setEnabled(false);
} else {
deleteIndexBTN.setEnabled(true);
editIndexBTN.setEnabled(items.length == 1);
}
}
});
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method makeChangeLogForIndex.
public boolean makeChangeLogForIndex(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
// FIXME move this logic to core module
List<Constraint> constrainList = newERTable.getSchemaInfo().getConstraints();
if (constrainList.size() == 0 || StringUtil.isEmpty(attrName)) {
return false;
}
List<Constraint> removedConstrainList = new ArrayList<Constraint>();
List<Constraint> addedConstrainList = new ArrayList<Constraint>();
for (Constraint cons : constrainList) {
if (cons == null) {
continue;
}
if (ConstraintType.INDEX.getText().equals(cons.getType()) || ConstraintType.REVERSEINDEX.getText().equals(cons.getType()) || ConstraintType.UNIQUE.getText().equals(cons.getType()) || ConstraintType.REVERSEUNIQUE.getText().equals(cons.getType())) {
List<String> attrs = cons.getAttributes();
if (!(attrs != null && attrs.contains(attrName))) {
continue;
}
removedConstrainList.add(cons);
Constraint newCons = new Constraint(true);
newCons.setType(cons.getType());
newCons.setName(cons.getName());
cons.replaceAttribute(attrName, editAttr.getName());
newCons.setAttributes(cons.getAttributes());
for (String origRule : cons.getRules()) {
if (cons.getRules().size() == 1) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
break;
}
int spaceIndex = origRule.indexOf(" ");
String attrNameFromRule = origRule.substring(0, spaceIndex);
if (attrName.equals(attrNameFromRule)) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
} else {
newCons.addRule(origRule);
}
}
addedConstrainList.add(newCons);
String key = cons.getDefaultName(newERTable.getSchemaInfo().getClassname()) + "$" + cons.getName();
SchemaChangeLog changeLog = new SchemaChangeLog(key, key, SchemeInnerType.TYPE_INDEX);
schemaChangeMgr.addSchemeChangeLog(changeLog);
}
}
if (removedConstrainList.size() == 0) {
return false;
}
constrainList.removeAll(removedConstrainList);
constrainList.addAll(addedConstrainList);
indexTableView.setInput(newERTable.getSchemaInfo());
return true;
}
Aggregations