Search in sources :

Example 21 with DBOperator

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();
    }
}
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)

Example 22 with DBOperator

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]);
            }
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) IdentityHashMap(java.util.IdentityHashMap) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) MetaData(net.heartsome.cat.common.bean.MetaData) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 23 with DBOperator

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();
                }
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) SQLException(java.sql.SQLException) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem) GridItem(org.eclipse.nebula.widgets.grid.GridItem) MetaData(net.heartsome.cat.common.bean.MetaData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Menu(org.eclipse.swt.widgets.Menu) HashSet(java.util.HashSet)

Example 24 with DBOperator

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);
            }
        }
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 25 with DBOperator

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;
}
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)

Aggregations

DBOperator (net.heartsome.cat.database.DBOperator)29 SQLException (java.sql.SQLException)28 ArrayList (java.util.ArrayList)9 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 MetaData (net.heartsome.cat.common.bean.MetaData)8 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)6 HashMap (java.util.HashMap)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 Point (org.eclipse.swt.graphics.Point)4 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 GridItem (org.eclipse.nebula.widgets.grid.GridItem)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2