use of com.cubrid.common.ui.spi.table.celleditor.CellViewer in project cubrid-manager by CUBRID.
the class QueryExecuter method handleButtonEvent.
/**
* Open detail dialog
*
* @param event MouseEvent
*/
@SuppressWarnings("unchecked")
public void handleButtonEvent(int rowIndex, int columnIndex) {
// Get columnInfo
ColumnInfo columnInfo = (ColumnInfo) tblResult.getColumn(columnIndex).getData();
// Get data
final TableItem item = selectableSupport.getTableCursor().getRow();
Map<String, CellValue> dataMap = (Map<String, CellValue>) item.getData();
Map<String, CellValue> newValueMap = (Map<String, CellValue>) item.getData(LASTEST_DATA_FLAG);
if (newValueMap == null) {
newValueMap = new HashMap<String, CellValue>();
newValueMap.putAll(dataMap);
item.setData(LASTEST_DATA_FLAG, newValueMap);
}
String dataIndex = String.valueOf(columnIndex);
CellValue cellValue = newValueMap.get(dataIndex);
if (cellValue == null) {
cellValue = new CellValue();
newValueMap.put(dataIndex, cellValue);
}
String charset = getDatabaseInfo() != null ? getDatabaseInfo().getCharSet() : null;
String dataType = DataType.makeType(columnInfo.getType(), columnInfo.getChildElementType(), columnInfo.getPrecision(), columnInfo.getScale());
cellValue.setFileCharset(charset);
CellViewer cellViewer = new CellViewer(columnInfo, editMode, charset);
if (IDialogConstants.OK_ID == cellViewer.openCellViewer(tblResult.getShell(), cellValue)) {
CellValue newValue = cellViewer.getValue();
if (!CellViewer.isCellValueEqual(cellValue, newValue)) {
String showValue = null;
if (newValue.getValue() == null) {
showValue = DataType.NULL_EXPORT_FORMAT;
item.setText(columnIndex, showValue);
newValueMap.put(dataIndex, newValue);
updateValue(item, dataMap, newValueMap);
} else if (newValue.getValue() instanceof String) {
String strValue = newValue.getValue().toString();
FormatDataResult result = DBAttrTypeFormatter.format(dataType, strValue, null, false, charset, false);
if (result.isSuccess()) {
// Update the data
showValue = newValue.getShowValue();
item.setText(columnIndex, showValue);
newValueMap.put(dataIndex, newValue);
updateValue(item, dataMap, newValueMap);
} else {
CommonUITool.openErrorBox(Messages.bind(Messages.errTextTypeNotMatch, dataType));
return;
}
} else if (newValue.getValue() instanceof byte[]) {
if (DataType.DATATYPE_BIT.equalsIgnoreCase(columnInfo.getType()) || DataType.DATATYPE_BIT_VARYING.equalsIgnoreCase(columnInfo.getType())) {
byte[] bValues = (byte[]) newValue.getValue();
if (bValues.length * 8 > columnInfo.getPrecision() + 7) {
String msg = Messages.bind(Messages.errTextTypeNotMatch, dataType);
CommonUITool.openErrorBox(msg);
return;
}
}
showValue = newValue.getShowValue();
item.setText(columnIndex, showValue);
newValueMap.put(dataIndex, newValue);
updateValue(item, dataMap, newValueMap);
} else {
showValue = newValue.getShowValue();
item.setText(columnIndex, showValue);
newValueMap.put(dataIndex, newValue);
updateValue(item, dataMap, newValueMap);
}
selectableSupport.getTableCursor().redraw();
}
}
}
Aggregations