use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method initGroupIdAndSearch.
public void initGroupIdAndSearch() {
updateHistory(cmbSearch, lstSearchHistory);
updateHistory(cmbFilter, lstFilterHistory);
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;
}
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);
clearTable();
mapGroupId.clear();
curPageNum = 1;
String[] arrFilter = null;
String strFilter = cmbFilter.getText();
if (cmpExpandableFilter.isExpanded() && strFilter != null && !strFilter.equals("")) {
String srcOrTgt = (String) cmbSrcOrTgt.getData(cmbSrcOrTgt.getText());
String contain = (String) cmbContain.getData(cmbContain.getText());
arrFilter = new String[] { srcOrTgt, contain, strFilter };
}
ArrayList<String> lstSelLangs = new ArrayList<String>();
for (MenuItem item : menu.getItems()) {
if (item.getSelection()) {
lstSelLangs.add(item.getText());
}
}
List<MetaData> lstMetaData = new ArrayList<MetaData>();
if (cmbDatabase.getSelectionIndex() == 0) {
for (DatabaseModelBean model : lstDatabase) {
lstMetaData.add(model.toDbMetaData());
}
} else {
DatabaseModelBean model = lstDatabase.get(cmbDatabase.getSelectionIndex() - 1);
MetaData metaData = model.toDbMetaData();
lstMetaData.add(metaData);
}
size = 0;
for (MetaData metaData : lstMetaData) {
DBOperator dbOp = DatabaseService.getDBOperator(metaData);
if (null == dbOp) {
continue;
}
try {
dbOp.start();
ArrayList<Integer> lstGroupId = dbOp.getConcordanceGroupId(searchText, btnIsCaseSensitive.getSelection(), btnApplyRegularExpression.getSelection(), btnIsIgnoreMark.getSelection(), strSrcLang, arrFilter, lstSelLangs);
if (lstGroupId.size() != 0) {
mapGroupId.put(metaData, lstGroupId);
}
size += lstGroupId.size();
} 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 (size == 0) {
clearTable();
txtPage.setText("");
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ConcordanceSearchDialog.msgTitle"), Messages.getString("dialog.ConcordanceSearchDialog.msg1"));
return;
}
amountPage = size / rowNumPerPage;
if (size % rowNumPerPage != 0) {
amountPage += 1;
}
if (search()) {
refreshPageNumText();
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method search.
/**
* 搜索术语库 ;
*/
@SuppressWarnings("unchecked")
public void search() {
updateHistory(cmbSearch, lstSearchHistory);
String searchText = cmbSearch.getText();
searchText = cleanString(searchText);
if (searchText == null || searchText.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg1"));
return;
}
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg2"));
return;
}
ArrayList<String> lstSelLangs = new ArrayList<String>();
lstSelLangs.add(strSrcLang);
for (MenuItem item : menu.getItems()) {
if (item.getSelection()) {
lstSelLangs.add(item.getText());
}
}
LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>> mapResult = new LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>>();
ArrayList<DatabaseModelBean> lstDB = new ArrayList<DatabaseModelBean>();
if (cmbDatabase.getSelectionIndex() == 0) {
lstDB.addAll(lstDatabase);
} else {
DatabaseModelBean model = lstDatabase.get(cmbDatabase.getSelectionIndex() - 1);
lstDB.add(model);
}
for (DatabaseModelBean model : lstDB) {
MetaData metaData = model.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
try {
dbop.start();
HashMap<String, IdentityHashMap<String, String>> mapTermBase = dbop.getTermBaseResult(searchText, !(btnIsCaseSensitive.getSelection()), btnApplyRegularExpression.getSelection(), btnIsIgnoreMark.getSelection(), strSrcLang, lstSelLangs, spiMatchQuality.getSelection());
if (mapTermBase != null && mapTermBase.size() > 0) {
mapResult.put(metaData, mapTermBase);
}
} catch (SQLException e1) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger2"), e1);
} catch (ClassNotFoundException e1) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger3"), e1);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
Rectangle rect = grid.getBounds();
grid.removeAll();
grid.pack();
grid.setHeaderVisible(true);
grid.setBounds(rect);
if (mapResult.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg3"));
return;
}
srcCellRenderer.setStrText(searchText);
srcCellRenderer.setBlnIsCaseSensitive(btnIsCaseSensitive.getSelection());
srcCellRenderer.setBlnIsApplyRegular(btnApplyRegularExpression.getSelection());
if (mapResult.size() > 0) {
if (btnApplyRegularExpression.getSelection()) {
Iterator<Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>>> iterator = mapResult.entrySet().iterator();
while (iterator.hasNext()) {
Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>> entry = iterator.next();
MetaData metaData1 = entry.getKey();
HashMap<String, IdentityHashMap<String, String>> map = entry.getValue();
Iterator<Entry<String, IdentityHashMap<String, String>>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, IdentityHashMap<String, String>> e = it.next();
createGridItem(metaData1, e.getValue());
}
}
} else {
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();
createGridItem((MetaData) arrObj[0], (IdentityHashMap<String, String>) arrObj[1]);
}
}
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method initLanguageMenu.
/**
* 初始化语言菜单 ;
*/
private void initLanguageMenu() {
Set<String> set = new HashSet<String>();
for (DatabaseModelBean model : lstDatabase) {
MetaData metaData = model.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
if (null == dbop) {
continue;
}
try {
dbop.start();
set.addAll(dbop.getLanguages());
} catch (SQLException e) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
set.remove(strSrcLang);
set.remove(strTgtLang);
lstLangs = new ArrayList<String>(set);
Collections.sort(lstLangs);
// cmbLang.setItems((String[]) langs.toArray(new String[langs.size()]));
menu = new Menu(getShell(), SWT.POP_UP);
// }
if (strTgtLang != null) {
MenuItem itemTgt = new MenuItem(menu, SWT.CHECK);
itemTgt.setText(strTgtLang);
itemTgt.setSelection(true);
itemTgt.setEnabled(false);
}
for (final String lang : lstLangs) {
final MenuItem itemLang = new MenuItem(menu, SWT.CHECK);
itemLang.setText(lang);
itemLang.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
ArrayList<GridColumn> lstShowColumn = new ArrayList<GridColumn>();
// 每增加一列,除标记列外的其他列的和加100,然后平均分配给各个语言列,删除一列则做相反的操作
if (itemLang.getSelection()) {
int totalWidth = 0;
boolean blnIsResetWidth = false;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getText().equals(lang) && column.getWidth() == 0) {
lstShowColumn.add(column);
blnIsResetWidth = true;
} else if (column.getWidth() > 0) {
totalWidth += column.getWidth();
lstShowColumn.add(column);
}
}
if (blnIsResetWidth) {
int width = (totalWidth + 100) / lstShowColumn.size();
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
}
// if (grid.getItemCount() > 0) {
// search();
// }
} else {
GridColumn deleteColumn = null;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getWidth() > 0) {
lstShowColumn.add(column);
}
if (column.getText().equals(lang)) {
deleteColumn = column;
// 将删除列中的数据清空,以保证行高正常调整
for (GridItem item : grid.getItems()) {
item.setText(index, "");
}
}
}
int width = (deleteColumn.getWidth() * lstShowColumn.size() - 100) / (lstShowColumn.size() - 1);
deleteColumn.setWidth(0);
lstShowColumn.remove(deleteColumn);
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
// search();
}
}
});
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class ProjectSettingTMPage method checkDbHashMatch.
/**
* 需要调用Database模块 检查当前项目在库中是否有语言对的匹配
* @param dbModel
* 数据库信息;
*/
public void checkDbHashMatch(DatabaseModelBean dbModel) {
Language srcLang = super.projectInfoBean.getSourceLang();
DBOperator dbOp = DatabaseService.getDBOperator(dbModel.toDbMetaData());
if (null == dbOp) {
return;
}
try {
if (dbOp != null) {
dbOp.start();
dbModel.setHasMatch(dbOp.checkHasMatchs(srcLang.getCode(), "M"));
}
} catch (Exception e) {
LOGGER.error("", e);
dbModel.setHasMatch(false);
} finally {
if (dbOp != null) {
try {
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TmDbManagerDialog method searchCurrServerDatabase.
private List<DatabaseManagerDbListBean> searchCurrServerDatabase(SystemDBOperator sysDbOp, DatabaseModelBean currServer) {
List<DatabaseManagerDbListBean> temp = new ArrayList<DatabaseManagerDbListBean>();
// 检查是否创建了系统库
if (!sysDbOp.checkSysDb()) {
// MessageDialog.openInformation(getShell(), "提示信息",
// "当前服务器上没有创建任何库");
setLastSelectedServer(null);
return null;
}
// 检查是否创建了库
List<String> dbNames = sysDbOp.getSysDbNames(Constants.DB_TYPE_TM);
if (dbNames.size() == 0) {
// MessageDialog.openInformation(getShell(), "提示信息",
// "当前服务器上没有创建任何库");
setLastSelectedServer(null);
return null;
}
// 获取数据库相关资料,封装了库名称和语言
MetaData metaData = currServer.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
for (int i = 0; i < dbNames.size(); i++) {
DatabaseManagerDbListBean bean = new DatabaseManagerDbListBean();
String dbName = dbNames.get(i);
bean.setIndex(i + 1 + "");
bean.setDbName(dbName);
metaData.setDatabaseName(dbName);
dbop.setMetaData(metaData);
String lang = "";
try {
dbop.start();
List<String> langs = dbop.getLanguages();
for (int j = 0; j < langs.size(); j++) {
lang += langs.get(j);
if (j != langs.size() - 1) {
lang += ", ";
}
}
} catch (Exception e1) {
logger.error("", e1);
continue;
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
logger.error("", e);
}
}
if (lang.equals("")) {
bean.setLangs(Messages.getString("dialog.TmDbManagerDialog.msg10"));
} else {
bean.setLangs(lang);
}
temp.add(bean);
}
return temp;
}
Aggregations