Search in sources :

Example 26 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TermDbManagerDialog method updateServer.

/**
	 * 更新当前操作的服务器配置信息到配置文件中
	 * @param currServer
	 *            需要处理的服务器配置信息
	 * @param currDbTypeServers
	 *            当前数据库类型下的所有服务器,用于显示在界面上;
	 */
private void updateServer(DatabaseModelBean currServer, List<DatabaseModelBean> currDbTypeServers) {
    MetaData metaDataWithCheck = dbMetaDataMap.get(currServer.getDbType());
    DatabaseModelBean hasChanged = configIsChanged(currDbTypeServers, currServer, metaDataWithCheck);
    if (hasChanged != null) {
        currServer.copyToOtherIntance(hasChanged);
        configer.updateServerConfigById(hasChanged.getId(), hasChanged);
    }
    setLastSelectedServer(currServer.getId());
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 27 with MetaData

use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.

the class TermDbManagerDialog 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_TB);
    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.TermDbManagerDialog.msg10"));
        } else {
            bean.setLangs(lang);
        }
        temp.add(bean);
    }
    return temp;
}
Also used : SQLException(java.sql.SQLException) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) MetaData(net.heartsome.cat.common.bean.MetaData) ArrayList(java.util.ArrayList) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException)

Example 28 with MetaData

use of net.heartsome.cat.common.bean.MetaData 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 29 with MetaData

use of net.heartsome.cat.common.bean.MetaData 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)

Example 30 with MetaData

use of net.heartsome.cat.common.bean.MetaData 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();
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem) MetaData(net.heartsome.cat.common.bean.MetaData)

Aggregations

MetaData (net.heartsome.cat.common.bean.MetaData)40 SQLException (java.sql.SQLException)21 ArrayList (java.util.ArrayList)14 Properties (java.util.Properties)13 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 DBOperator (net.heartsome.cat.database.DBOperator)8 Statement (java.sql.Statement)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Entry (java.util.Map.Entry)5 Point (org.eclipse.swt.graphics.Point)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 List (java.util.List)4 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)4 File (java.io.File)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2