Search in sources :

Example 1 with ConcordanceBean

use of net.heartsome.cat.database.tmx.ConcordanceBean in project translationstudio8 by heartsome.

the class DBOperator method getConcordanceSearchResult.

// TODO ======================匹配相关(结束) ======================//
/**
	 * 执行相关搜索
	 * @param strSearch
	 *            搜索文本
	 * @param isCaseSensitive
	 *            是否区分大小写
	 * @param isApplyRegular
	 *            是否使用正则表达式
	 * @param isIgnoreMark
	 *            是否忽略标记
	 * @param strLang
	 *            源语言
	 * @param lstLangs
	 *            语言集合(包括源语言)
	 * @param startIndex
	 *            开始行号
	 * @param intMax
	 *            最大查找结果数
	 * @return ;
	 */
public List<ConcordanceBean> getConcordanceSearchResult(String strSearch, boolean isCaseSensitive, boolean isApplyRegular, boolean isIgnoreMark, String strLang, List<String> lstLangs, List<Integer> subList) {
    String sql = getTMSearchSql(dbConfig.getOperateDbSQL("search-Corcondance"), isIgnoreMark, lstLangs, subList);
    if (sql == null) {
        return null;
    }
    List<ConcordanceBean> lstConcordance = new ArrayList<ConcordanceBean>();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = conn.prepareStatement(sql);
        rs = stmt.executeQuery();
        ArrayList<Integer> lstTuId = new ArrayList<Integer>();
        while (rs.next()) {
            Integer tuId = rs.getInt("TUID");
            if (lstTuId.contains(tuId)) {
                ConcordanceBean bean = lstConcordance.get(lstTuId.indexOf(tuId));
                LanguageTMX lang = new LanguageTMX();
                lang.setLanguageCode(rs.getString("LANG"));
                lang.setText(rs.getString("TMTEXT"));
                bean.getLanguageList().add(lang);
            } else {
                lstTuId.add(tuId);
                ConcordanceBean bean = new ConcordanceBean();
                bean.setId(tuId);
                bean.setCreationId(rs.getString("CREATIONID"));
                String creationDate = "";
                Timestamp tempCreationDate = rs.getTimestamp("CREATIONDATE");
                if (tempCreationDate != null) {
                    creationDate = DateUtils.formatLongTime(tempCreationDate.getTime(), "yyyy-MM-dd HH:mm:ss");
                }
                bean.setCreationDate(creationDate);
                bean.setChangeId(rs.getString("CHANGEID"));
                String changeDate = "";
                Timestamp tempChangeDate = rs.getTimestamp("CHANGEDATE");
                if (tempChangeDate != null) {
                    changeDate = DateUtils.formatLongTime(tempChangeDate.getTime(), "yyyy-MM-dd HH:mm:ss");
                }
                bean.setChangeDate(changeDate);
                bean.setBlnIsFlag(rs.getString("MPPKID") != null);
                List<LanguageTMX> lstLang = new ArrayList<LanguageTMX>();
                LanguageTMX lang = new LanguageTMX();
                lang.setLanguageCode(rs.getString("LANG"));
                lang.setText(rs.getString("TMTEXT"));
                lstLang.add(lang);
                bean.setLanguageList(lstLang);
                bean.setAttributeList(getTuMprops(tuId, "TU"));
                lstConcordance.add(bean);
            }
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
    return lstConcordance;
}
Also used : ConcordanceBean(net.heartsome.cat.database.tmx.ConcordanceBean) LanguageTMX(net.heartsome.cat.database.tmx.LanguageTMX) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 2 with ConcordanceBean

use of net.heartsome.cat.database.tmx.ConcordanceBean in project translationstudio8 by heartsome.

the class ConcordanceSearchDialog method sortMap.

/**
	 * 对搜索结果按修改日期进行排序
	 * @param mapItem
	 * @return ;
	 */
private LinkedHashMap<String, Object[]> sortMap(LinkedHashMap<MetaData, List<ConcordanceBean>> mapItem) {
    Iterator<Entry<MetaData, List<ConcordanceBean>>> it = mapItem.entrySet().iterator();
    LinkedHashMap<String, Object[]> map = new LinkedHashMap<String, Object[]>();
    while (it.hasNext()) {
        Entry<MetaData, List<ConcordanceBean>> entry = it.next();
        MetaData metaData = entry.getKey();
        List<ConcordanceBean> lstBean = entry.getValue();
        for (ConcordanceBean bean : lstBean) {
            String key = metaData.getDatabaseName() + "_" + bean.getId() + "_" + bean.getChangeDate();
            Object[] arrObj = new Object[] { metaData, bean };
            map.put(key, arrObj);
        }
    }
    // }
    return map;
}
Also used : ConcordanceBean(net.heartsome.cat.database.tmx.ConcordanceBean) Entry(java.util.Map.Entry) MetaData(net.heartsome.cat.common.bean.MetaData) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ConcordanceBean

use of net.heartsome.cat.database.tmx.ConcordanceBean 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;
}
Also used : SQLException(java.sql.SQLException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) LinkedHashMap(java.util.LinkedHashMap) ConcordanceBean(net.heartsome.cat.database.tmx.ConcordanceBean) Entry(java.util.Map.Entry) MetaData(net.heartsome.cat.common.bean.MetaData) List(java.util.List) ArrayList(java.util.ArrayList) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IRow(de.jaret.util.ui.table.model.IRow) StyleTextCellRenderer(net.heartsome.cat.ts.ui.jaret.renderer.StyleTextCellRenderer)

Aggregations

ArrayList (java.util.ArrayList)3 ConcordanceBean (net.heartsome.cat.database.tmx.ConcordanceBean)3 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 MetaData (net.heartsome.cat.common.bean.MetaData)2 IRow (de.jaret.util.ui.table.model.IRow)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 DBOperator (net.heartsome.cat.database.DBOperator)1 LanguageTMX (net.heartsome.cat.database.tmx.LanguageTMX)1 StyleTextCellRenderer (net.heartsome.cat.ts.ui.jaret.renderer.StyleTextCellRenderer)1 Point (org.eclipse.swt.graphics.Point)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1