use of net.heartsome.cat.ts.ui.jaret.renderer.StyleTextCellRenderer in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method search.
/**
* 搜索记忆库 ;
*/
private boolean search() {
String searchText = cmbSearch.getText();
if (searchText == null || searchText.trim().equals("")) {
txtPage.setText("");
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ConcordanceSearchDialog.msgTitle"), Messages.getString("dialog.ConcordanceSearchDialog.msg2"));
return false;
}
StringBuffer searchTextBf = new StringBuffer(searchText);
TreeMap<String, InnerTagBean> tags = InnerTagUtil.parseXmlToDisplayValue(searchTextBf, TagStyle.getDefault(false));
searchText = InnerTagUtil.resolveTag(searchTextBf.toString());
searchText = InnerTagUtil.escapeTag(searchText);
searchText = InnerTagUtil.parseDisplayToXmlValue(tags, searchText);
// 此处的判断已加在 ConcordanceSearchHandler 中
// if (lstDatabase.size() == 0) {
// txtPage.setText("");
// MessageDialog.openInformation(getShell(), "提示", "请为项目指定翻译记忆库");
// return false;
// }
ArrayList<String> lstSelLangs = new ArrayList<String>();
lstSelLangs.add(strSrcLang);
for (MenuItem item : menu.getItems()) {
if (item.getSelection()) {
lstSelLangs.add(item.getText());
}
}
LinkedHashMap<MetaData, List<Integer>> mapSub = getCurPageMap();
LinkedHashMap<MetaData, List<ConcordanceBean>> mapResult = new LinkedHashMap<MetaData, List<ConcordanceBean>>();
Iterator<Entry<MetaData, List<Integer>>> iterator = mapSub.entrySet().iterator();
while (iterator.hasNext()) {
Entry<MetaData, List<Integer>> entry = (Entry<MetaData, List<Integer>>) iterator.next();
MetaData metaData = entry.getKey();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
try {
dbop.start();
List<ConcordanceBean> lstConcordance = dbop.getConcordanceSearchResult(cmbSearch.getText(), btnIsCaseSensitive.getSelection(), btnApplyRegularExpression.getSelection(), btnIsIgnoreMark.getSelection(), strSrcLang, lstSelLangs, entry.getValue());
if (lstConcordance != null && lstConcordance.size() > 0) {
mapResult.put(metaData, lstConcordance);
}
} catch (SQLException e1) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger2"), e1);
} catch (ClassNotFoundException e1) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger3"), e1);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
if (mapResult.size() == 0) {
clearTable();
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ConcordanceSearchDialog.msgTitle"), Messages.getString("dialog.ConcordanceSearchDialog.msg1"));
txtPage.setText("");
return false;
}
// 当有多个数据库的数据时要对所有数据按 changedate 重新排序,然后取前 spiResultCount.getSelection() 数量的记录
int rowNum = 0;
HashMap<IRow, ArrayList<int[]>> mapStyle = new HashMap<IRow, ArrayList<int[]>>();
if (mapResult.size() > 1) {
LinkedHashMap<String, Object[]> map = sortMap(mapResult);
Iterator<Entry<String, Object[]>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object[]> entry = it.next();
Object[] arrObj = entry.getValue();
createItem((MetaData) arrObj[0], (ConcordanceBean) arrObj[1], rowNum++, mapStyle);
}
} else {
Iterator<Entry<MetaData, List<ConcordanceBean>>> it = mapResult.entrySet().iterator();
while (it.hasNext()) {
Entry<MetaData, List<ConcordanceBean>> entry = it.next();
MetaData metaData2 = entry.getKey();
List<ConcordanceBean> lstBean = entry.getValue();
for (ConcordanceBean bean : lstBean) {
createItem(metaData2, bean, rowNum++, mapStyle);
}
if (lstBean.size() < rowNumPerPage) {
for (int row = lstBean.size(); row < rowNumPerPage; row++) {
if (rowNum < tableModel.getRowCount() && tableModel.getRow(rowNum) != null) {
tableModel.remRow(tableModel.getRow(rowNum));
}
}
}
}
}
jTable.registerCellRenderer(tableModel.getColumn(1), new StyleTextCellRenderer(searchText, btnIsCaseSensitive.getSelection(), btnApplyRegularExpression.getSelection(), createResultsStyle()));
jTable.registerCellRenderer(tableModel.getColumn(tableModel.getColumnCount() - 1), new AttributeTextCellRenderer(mapStyle, style));
jTable.setTableModel(tableModel);
return true;
}
Aggregations