use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class FilterResultContrItem method loadMenuItems.
/**
* Load the menu items
*/
private void loadMenuItems() {
if (filterMenu != null) {
return;
}
filterMenu = new Menu(qe.getTblResult().getShell(), SWT.POP_UP);
allMenuItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
allMenuItem.setText(Messages.menuAll);
allMenuItem.setSelection(true);
allMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (colMenuItemList == null || !allMenuItem.getSelection()) {
return;
}
for (MenuItem item : colMenuItemList) {
if (item == null) {
continue;
}
item.setSelection(false);
}
}
});
List<ColumnInfo> colInfoList = qe.getAllColumnList();
for (ColumnInfo colInfo : colInfoList) {
final MenuItem colMenuItem = new MenuItem(filterMenu, SWT.CHECK);
colMenuItem.setText(colInfo.getName());
colMenuItem.setData(colInfo);
colMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean selected = colMenuItem.getSelection();
if (selected) {
allMenuItem.setSelection(false);
}
}
});
colMenuItemList.add(colMenuItem);
}
moreMenuItem = new MenuItem(filterMenu, SWT.LEFT);
moreMenuItem.setText(Messages.menuMore);
moreMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<ColumnInfo> selectedColInfoList = new ArrayList<ColumnInfo>();
for (MenuItem colItem : colMenuItemList) {
if ((allMenuItem.getSelection() || colItem.getSelection()) && colItem.getData() != null) {
selectedColInfoList.add((ColumnInfo) colItem.getData());
}
}
FilterChooserDialog dialog = new FilterChooserDialog(qe.getTblResult().getShell(), qe.getAllColumnList(), selectedColInfoList);
if (IDialogConstants.OK_ID == dialog.open()) {
List<ColumnInfo> colInfoList = dialog.getSelectedColInfoList();
if (colInfoList.size() == qe.getAllColumnList().size()) {
allMenuItem.setSelection(true);
} else {
allMenuItem.setSelection(false);
}
for (MenuItem colItem : colMenuItemList) {
boolean isSelected = false;
for (ColumnInfo colInfo : colInfoList) {
if (colItem.getData() != null && colInfo.equals(colItem.getData())) {
isSelected = true;
break;
}
}
colItem.setSelection(isSelected);
}
doFilter();
}
}
});
new MenuItem(filterMenu, SWT.SEPARATOR);
caseSensitiveItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
caseSensitiveItem.setText(Messages.menuCaseSensitive);
caseInSensitiveItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
caseInSensitiveItem.setText(Messages.menuInCaseSensitive);
caseInSensitiveItem.setSelection(true);
new MenuItem(filterMenu, SWT.SEPARATOR);
useWildcardItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
useWildcardItem.setText(Messages.menuUsingWildCards);
useRegexItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
useRegexItem.setText(Messages.menuUsingRegex);
new MenuItem(filterMenu, SWT.SEPARATOR);
matchFromStartItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
matchFromStartItem.setText(Messages.menuMatchFromStart);
matchExactItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
matchExactItem.setText(Messages.menuMatchExactly);
matchAnyWhereItem = new MenuItem(filterMenu, SWT.CHECK | SWT.LEFT);
matchAnyWhereItem.setText(Messages.menuMatchAnywhere);
matchAnyWhereItem.setSelection(true);
addSelectionListener();
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class FilterResultContrItem method doFilter.
/**
*
* Do filter
*
*/
private void doFilter() {
// if (qe.getQueryModifier() != null && qe.getQueryModifier().isChanged()) {
// return;
// }
QueryResultFilterSetting filterSetting = new QueryResultFilterSetting();
filterSetting.setContent(text.getText());
if (caseSensitiveItem.getSelection()) {
filterSetting.setCaseSensitive(true);
filterSetting.setInCaseSensitive(false);
} else {
filterSetting.setCaseSensitive(false);
filterSetting.setInCaseSensitive(true);
}
if (useRegexItem.getSelection()) {
filterSetting.setUsingRegex(true);
} else {
filterSetting.setUsingRegex(false);
}
if (useWildcardItem.getSelection()) {
filterSetting.setUsingWildCard(true);
} else {
filterSetting.setUsingWildCard(false);
}
if (matchFromStartItem.getSelection()) {
filterSetting.setMatchType(MatchType.MATCH_FROM_START);
} else if (matchExactItem.getSelection()) {
filterSetting.setMatchType(MatchType.MATCH_EXACTLY);
} else if (matchAnyWhereItem.getSelection()) {
filterSetting.setMatchType(MatchType.MATCH_ANYWHERE);
}
filterSetting.setSearchAllColumn(allMenuItem.getSelection());
List<ColumnInfo> colInfoList = new ArrayList<ColumnInfo>();
for (MenuItem colItem : colMenuItemList) {
if ((allMenuItem.getSelection() || colItem.getSelection()) && colItem.getData() != null) {
colInfoList.add((ColumnInfo) colItem.getData());
}
}
filterSetting.setFilterColumnInfoList(colInfoList);
qe.setFilterSetting(filterSetting);
qe.makeItem();
qe.updateActions();
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class ExportToXlsxHandler method exportFromCache.
public void exportFromCache(String tableName) throws IOException {
if (StringUtil.isEmpty(tableName)) {
return;
}
// 1048576: limit xlsx row number.
int rowLimit = ImportFileConstants.XLSX_ROW_LIMIT;
// 16384: limit xlsx column number.
int columnLimit = ImportFileConstants.XLSX_COLUMN_LIMIT;
int cellCharacterLimit = ImportFileConstants.XLSX_CELL_CHAR_LIMIT;
XlsxWriterHelper xlsxWriterhelper = new XlsxWriterHelper();
//create memory workbook
XSSFWorkbook workbook = new XSSFWorkbook();
Calendar cal = Calendar.getInstance();
int datetimeStyleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("datetime")).getIndex();
int timestampStyleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("timestamp")).getIndex();
int dateStyleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("date")).getIndex();
int timeStyleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("time")).getIndex();
int sheetNum = 0;
int xssfRowNum = 0;
File file = new File(exportConfig.getDataFilePath(tableName));
Map<String, File> fileMap = new HashMap<String, File>();
XlsxWriterHelper.SpreadsheetWriter sheetWriter = null;
boolean isInitedColumnTitle = false;
List<String> columnTitles = new ArrayList<String>();
try {
int exportedCount = 0;
ResultSetDataCache resultSetDataCache = exportConfig.getResultSetDataCache();
List<ColumnInfo> columnInfos = resultSetDataCache.getColumnInfos();
List<ArrayList<Object>> datas = resultSetDataCache.getDatas();
int colCount = columnInfos.size();
if (colCount >= columnLimit && !isConfirmColumnLimit) {
isConfirmColumnLimit = true;
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (!CommonUITool.openConfirmBox(Messages.exportColumnCountOverWarnInfo)) {
isExit = true;
}
}
});
if (isExit) {
return;
}
colCount = columnLimit;
}
if (!isInitedColumnTitle) {
for (ColumnInfo column : columnInfos) {
columnTitles.add(column.getName());
}
isInitedColumnTitle = true;
if (isExit) {
return;
}
sheetWriter = createSheetWriter(workbook, xlsxWriterhelper, sheetNum++, fileMap, columnTitles, xssfRowNum);
if (exportConfig.isFirstRowAsColumnName()) {
xssfRowNum++;
}
}
try {
for (ArrayList<Object> rowData : datas) {
sheetWriter.insertRow(xssfRowNum);
for (int k = 1; k <= colCount; k++) {
String colType = columnInfos.get(k - 1).getType();
int precision = columnInfos.get(k - 1).getPrecision();
setIsHasBigValue(colType, precision);
Object cellValue = rowData.get(k - 1);
// We need judge the CLOB/BLOD data by column type
if (DataType.DATATYPE_BLOB.equals(colType) || DataType.DATATYPE_CLOB.equals(colType)) {
if (DataType.DATATYPE_BLOB.equals(colType)) {
String fileName = exportBlobData(tableName, (Blob) cellValue);
String dataCellValue = DataType.NULL_EXPORT_FORMAT;
if (StringUtil.isNotEmpty(fileName)) {
dataCellValue = DBAttrTypeFormatter.FILE_URL_PREFIX + tableName + BLOB_FOLDER_POSTFIX + File.separator + fileName;
}
sheetWriter.createCell(k - 1, dataCellValue);
} else {
String fileName = exportClobData(tableName, (Clob) cellValue);
String dataCellValue = DataType.NULL_EXPORT_FORMAT;
if (StringUtil.isNotEmpty(fileName)) {
dataCellValue = DBAttrTypeFormatter.FILE_URL_PREFIX + tableName + CLOB_FOLDER_POSTFIX + File.separator + fileName;
}
sheetWriter.createCell(k - 1, dataCellValue);
}
} else if (cellValue instanceof Long) {
sheetWriter.createCell(k - 1, ((Long) cellValue).longValue());
} else if (cellValue instanceof Double) {
sheetWriter.createCell(k - 1, ((Double) cellValue).doubleValue());
} else if (cellValue instanceof Date) {
cal.setTime((Date) cellValue);
if (DataType.DATATYPE_DATETIME.equals(colType)) {
sheetWriter.createCell(k - 1, cal, datetimeStyleIndex);
} else if (DataType.DATATYPE_DATE.equals(colType)) {
sheetWriter.createCell(k - 1, cal, dateStyleIndex);
} else if (DataType.DATATYPE_TIME.equals(colType)) {
sheetWriter.createCell(k - 1, cal, timeStyleIndex);
} else {
sheetWriter.createCell(k - 1, cal, timestampStyleIndex);
}
} else {
String cellStr = cellValue.toString().length() > cellCharacterLimit ? cellValue.toString().substring(0, cellCharacterLimit) : cellValue.toString();
sheetWriter.createCell(k - 1, Export.covertXMLString(cellStr));
}
}
sheetWriter.endRow();
xssfRowNum++;
exportedCount++;
if ((xssfRowNum + 1) % rowLimit == 0) {
xssfRowNum = 0;
if (sheetWriter != null) {
try {
XlsxWriterHelper.writeSheetWriter(sheetWriter);
} catch (IOException e) {
sheetWriter = null;
throw e;
}
}
sheetWriter = createSheetWriter(workbook, xlsxWriterhelper, sheetNum, fileMap, columnTitles, xssfRowNum);
sheetNum++;
if (exportConfig.isFirstRowAsColumnName()) {
xssfRowNum++;
}
}
if (exportedCount >= COMMIT_LINES) {
exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
exportedCount = 0;
}
if (stop) {
break;
}
}
exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
exportedCount = 0;
} catch (Exception e) {
LOGGER.error("", e);
exportDataEventHandler.handleEvent(new ExportDataFailedOneTableEvent(tableName));
}
System.gc();
} finally {
try {
if (sheetWriter != null) {
XlsxWriterHelper.writeSheetWriter(sheetWriter);
}
} catch (IOException e) {
sheetWriter = null;
throw e;
} finally {
XlsxWriterHelper.writeWorkbook(workbook, xlsxWriterhelper, fileMap, file);
}
}
}
Aggregations