Search in sources :

Example 1 with ExportTbxImpl

use of net.heartsome.cat.document.ExportTbxImpl in project translationstudio8 by heartsome.

the class ExportTbxDialog method okPressed.

@Override
protected void okPressed() {
    String encoding = "UTF-8";
    if (hasChangedCodingCbtn.getSelection()) {
        encoding = this.encodingComboViewer.getCombo().getText();
    }
    String exportPath = this.tbxFileText.getText();
    ExportFilterBean filterBean = null;
    if (hasFilterChangedBtn.getSelection()) {
        IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
        filterBean = (ExportFilterBean) sel.getFirstElement();
        if (filterBean.equals(filterList.get(0))) {
            filterBean = null;
        }
    }
    if (this.dbList.size() == 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg3"));
        return;
    }
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean dbBean = iterator.next();
        if (dbBean.getHasSelectedLangs().size() < 2) {
            String dbType = dbBean.getDbBean().getDbType();
            String name = dbBean.getDbBean().getDatabaseName();
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg4"), dbType, name));
            return;
        }
    }
    if (exportPath == null || exportPath.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg5"));
        return;
    }
    if (this.dbList.size() > 1) {
        File f = new File(exportPath);
        if (!f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg7"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        File f = new File(exportPath);
        if (f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg8"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        dbList.get(0).setExportFilePath(exportPath);
        File file = new File(exportPath);
        if (file.exists()) {
            if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), exportPath))) {
                return;
            }
        }
    } else {
        for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
            ExportDatabaseBean db = iterator.next();
            String databaseName = db.getDbBean().getDatabaseName();
            String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tbx";
            File file = new File(path);
            if (file.exists()) {
                if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), path))) {
                    return;
                }
            }
            db.setExportFilePath(path);
        }
    }
    final ExportAbstract exportor = new ExportTbxImpl(this.dbList, filterBean, encoding);
    Job job = new Job(Messages.getString("dialog.ExportTbxDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final String result = DatabaseService.executeExport(exportor, monitor);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), result);
                }
            });
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
    super.okPressed();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportTbxImpl(net.heartsome.cat.document.ExportTbxImpl) ExportAbstract(net.heartsome.cat.document.ExportAbstract) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Aggregations

File (java.io.File)1 ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)1 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)1 ExportAbstract (net.heartsome.cat.document.ExportAbstract)1 ExportTbxImpl (net.heartsome.cat.document.ExportTbxImpl)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1