Search in sources :

Example 16 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class NewTmDbWizard method performFinish.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
@Override
public boolean performFinish() {
    final String tmxFile = importPage.getTMXFile();
    final SystemDBOperator dbOp = createDbPage.getCurrDbOp();
    if (dbOp.getDBConfig().getDefaultType().equals(Constants.DBTYPE_SQLITE)) {
        String dbName = dbOp.getMetaData().getDatabaseName();
        dbName += ".hstm";
        dbOp.getMetaData().setDatabaseName(dbName);
    }
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            importPage.performFinish(tmxFile, dbOp, monitor);
        }
    };
    try {
        getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 17 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator 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

SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)17 IStatus (org.eclipse.core.runtime.IStatus)6 ISelection (org.eclipse.jface.viewers.ISelection)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 SQLException (java.sql.SQLException)4 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)4 MetaData (net.heartsome.cat.common.bean.MetaData)4 DatabaseManagerDbListBean (net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean)4 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 Point (org.eclipse.swt.graphics.Point)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Button (org.eclipse.swt.widgets.Button)4 Composite (org.eclipse.swt.widgets.Composite)4 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)4 Group (org.eclipse.swt.widgets.Group)4