use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method getCurPageMap.
private LinkedHashMap<MetaData, List<Integer>> getCurPageMap() {
int startIndex = (curPageNum - 1) * rowNumPerPage;
int endIndex = curPageNum * rowNumPerPage;
if (curPageNum == amountPage) {
endIndex = size;
}
Iterator<Entry<MetaData, ArrayList<Integer>>> it = mapGroupId.entrySet().iterator();
int index = 0;
LinkedHashMap<MetaData, List<Integer>> mapSub = new LinkedHashMap<MetaData, List<Integer>>();
while (it.hasNext()) {
Entry<MetaData, ArrayList<Integer>> entry = (Entry<MetaData, ArrayList<Integer>>) it.next();
ArrayList<Integer> lstGroupId = entry.getValue();
if (index <= startIndex && index + lstGroupId.size() >= startIndex) {
List<Integer> subList = null;
if (index + lstGroupId.size() - 1 >= endIndex) {
subList = lstGroupId.subList(startIndex - index, endIndex - index);
mapSub.put(entry.getKey(), subList);
break;
} else {
subList = lstGroupId.subList(startIndex - index, lstGroupId.size());
index += lstGroupId.size();
startIndex += lstGroupId.size();
mapSub.put(entry.getKey(), subList);
}
} else {
index += lstGroupId.size();
}
}
return mapSub;
}
use of net.heartsome.cat.common.bean.MetaData 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.common.bean.MetaData 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.common.bean.MetaData in project translationstudio8 by heartsome.
the class OperateSystemDBImpl method addSysDb.
/**
* 插入系统库
* @param dbName
* 数据库名称
* @param quality
* 是否优化
*/
public void addSysDb(String dbName, String quality, int type) {
MetaData data = null;
try {
data = (MetaData) metaData.clone();
data.setDatabaseName(Constants.HSSYSDB);
} catch (CloneNotSupportedException e) {
logger.warn("", e);
return;
}
String driver = dbConfig.getDriver();
String url = Utils.replaceParams(dbConfig.getDbURL(), data);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = getConnection(driver, url, prop);
String insertDb = Utils.replaceParams(dbConfig.getInsertSysDb(), data);
stmt = conn.prepareStatement(insertDb);
stmt.setString(1, dbName);
stmt.setString(2, quality);
stmt.setInt(3, type);
stmt.execute();
} catch (ClassNotFoundException e) {
logger.warn("", e);
} catch (SQLException e) {
logger.warn("", e);
} finally {
Statement _stmt = null;
try {
_stmt = conn.createStatement();
_stmt.executeUpdate("SHUTDOWN;");
} catch (SQLException e) {
logger.error("", e);
} finally {
if (_stmt != null) {
try {
_stmt.close();
} catch (SQLException e) {
logger.error("", e);
}
}
}
freeConnection(stmt, conn);
}
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class OperateSystemDBImpl method checkDbExistOnServer.
/**
* (non-Javadoc)
* @see net.heartsome.cat.database.SystemDBOperator#checkDbExistOnServer()
*/
@Override
public boolean checkDbExistOnServer() {
Connection conn = null;
MetaData data = null;
try {
data = (MetaData) metaData.clone();
} catch (CloneNotSupportedException e) {
logger.warn("", e);
return false;
}
try {
String url = Utils.replaceParams(dbConfig.getDbURL(), data);
String driver = dbConfig.getDriver();
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
prop.setProperty("ifexists", "true");
conn = getConnection(driver, url, prop);
} catch (ClassNotFoundException e) {
logger.error(Messages.getString("hsql.OperateSystemDBImpl.logger3"), e);
return false;
} catch (SQLException e) {
// Just check ,so don't need record the exception
return false;
} finally {
if (conn != null) {
try {
Statement stmt = conn.createStatement();
stmt.executeUpdate("SHUTDOWN;");
freeConnection(stmt, conn);
} catch (SQLException e) {
logger.error("", e);
}
}
}
return true;
}
Aggregations