Search in sources :

Example 91 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.

the class AutomaticUpdate method checkForUpdates.

public void checkForUpdates() throws OperationCanceledException {
    // 检查 propfile
    String profileId = getProvisioningUI().getProfileId();
    IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
    IProfile profile = null;
    if (agent != null) {
        IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
        if (registry != null) {
            profile = registry.getProfile(profileId);
        }
    }
    if (profile == null) {
        // Inform the user nicely
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    // 开始检查前先确定是否有repository
    RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
    if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    final IStatus[] checkStatus = new IStatus[1];
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {

        public IStatus runModal(IProgressMonitor monitor) {
            SubMonitor sub = SubMonitor.convert(monitor, P2UpdateUtil.CHECK_UPDATE_TASK_NAME, 1000);
            // load repository
            IStatus status = super.runModal(sub.newChild(500));
            if (status.getSeverity() == IStatus.CANCEL) {
                return status;
            }
            if (status.getSeverity() != Status.OK) {
                // load repository error
                checkStatus[0] = status;
            }
            operation = getProvisioningUI().getUpdateOperation(null, null);
            // check for updates
            IStatus resolveStatus = operation.resolveModal(sub.newChild(500));
            if (resolveStatus.getSeverity() == IStatus.CANCEL) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    loadJob.setName(P2UpdateUtil.ATUO_CHECK_UPDATE_JOB_NAME);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        public void done(IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning())
                if (event.getResult().isOK()) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            if (checkStatus[0] != null) {
                                // 提示连接异常
                                P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
                                return;
                            }
                            doUpdate();
                        }
                    });
                }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 92 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.

the class TMX2TXTConverterDialog method convert.

/**
	 * 开始转换
	 */
private void convert() {
    final String tmxLocation = tmxTxt.getText();
    if (tmxLocation.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg1"));
        return;
    }
    final String txtLocation = txtTxt.getText();
    if (txtLocation.equals("")) {
        //$NON-NLS-1$
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg2"));
        return;
    }
    File txtFile = new File(txtLocation);
    if (txtFile.exists()) {
        boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle2"), MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg3"), txtLocation));
        if (!response) {
            return;
        }
    } else if (!txtFile.getParentFile().exists()) {
        txtFile.getParentFile().mkdirs();
    }
    Job job = new Job(Messages.getString("dialog.TMX2TXTConverterDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(Messages.getString("dialog.TMX2TXTConverterDialog.task"), 10);
            // 先解析文件,花费一格
            int openResult = openFile(tmxLocation, monitor);
            if (openResult == 0) {
                return Status.CANCEL_STATUS;
            } else if (openResult == -2) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg4"));
                    }
                });
                return Status.CANCEL_STATUS;
            } else if (openResult == -1) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg5"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            if (!validVersion(tmxLocation)) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg6"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            if ((tuNodesCount = getTUCount(tmxLocation)) <= 0) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg7"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            try {
                output = new FileOutputStream(txtLocation);
                byte[] bom = new byte[3];
                bom[0] = (byte) 0xEF;
                bom[1] = (byte) 0xBB;
                bom[2] = (byte) 0xBF;
                output.write(bom);
                writeHeader();
                monitor.worked(1);
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 8, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                return processTU(tmxLocation, txtLocation, subMonitor);
            } catch (Exception e) {
                e.printStackTrace();
                LOGGER.error("", e);
            }
            monitor.done();
            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();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) NavException(com.ximpleware.NavException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 93 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.

the class ExportTmxDialog method okPressed.

@Override
protected void okPressed() {
    String encoding = "UTF-8";
    if (hasChangedCodingCbtn.getSelection()) {
        encoding = this.encodingComboViewer.getCombo().getText();
    }
    String exportPath = this.tmxFileText.getText();
    boolean isTopLevelTmx = this.isTopLevelTmxCbtn.getSelection();
    boolean isTagLevelTmx = this.isTagCbtn.getSelection();
    ExportFilterBean filterBean = null;
    if (this.hasfilterCbtn.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.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg3"));
        return;
    }
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean dbBean = iterator.next();
        String dbType = dbBean.getDbBean().getDbType();
        String name = dbBean.getDbBean().getDatabaseName();
        if (dbBean.getHasSelectedLangs().size() < 2) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg4"), dbType, name));
            return;
        }
        if (dbBean.getSrcLang().equals("")) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg5"), dbType, name));
            return;
        }
    }
    if (exportPath == null || exportPath.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg6"));
        return;
    }
    if (this.dbList.size() > 1) {
        File f = new File(exportPath);
        if (!f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg8"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        File f = new File(exportPath);
        if (f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg9"));
            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.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), 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() + ".tmx";
            File file = new File(path);
            if (file.exists()) {
                if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), path))) {
                    return;
                }
            }
            db.setExportFilePath(path);
        }
    }
    final ExportAbstract tmxExport = new ExportTmxImpl(this.dbList, filterBean, encoding, isTopLevelTmx, isTagLevelTmx);
    Job job = new Job(Messages.getString("dialog.ExportTmxDialog.job")) {

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

                public void run() {
                    MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.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) ExportTmxImpl(net.heartsome.cat.document.ExportTmxImpl) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportAbstract(net.heartsome.cat.document.ExportAbstract) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 94 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.

the class ExportDocxDialog method okPressed.

@Override
protected void okPressed() {
    if (xliffPathTxt.getText() == null || xliffPathTxt.getText().trim().equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg0"));
        return;
    }
    String docxPath = docxPathTxt.getText().trim();
    if (docxPath == null || docxPath.length() <= 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg3"));
        return;
    }
    IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
    dialogSettings.put(STORE_DOCX_PATH, docxPath);
    XLFValidator.resetFlag();
    if (!XLFValidator.validateXliffFile(strXliffFullPath)) {
        return;
    }
    XLFValidator.resetFlag();
    // 补全 docx 路径
    docxPath = docxPath + File.separator + new File(strXliffFullPath).getName() + ".docx";
    if (new File(docxPath).exists()) {
        boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("all.dialog.confirm"), MessageFormat.format(Messages.getString("ExportDocxDialog.ok.msg5"), "DOCX", docxPath));
        if (confirm) {
            new File(docxPath).delete();
        } else {
            return;
        }
    }
    final boolean commentSelection = commentBtn.getSelection();
    final boolean statusSelection = statusBtn.getSelection();
    // 设置查询每个 tu 的条件,比如排除或者 仅导出
    String expandXpath = "";
    if (excludeBtn.getSelection()) {
        if (excludeLockedBtn.getSelection()) {
            expandXpath += " and not(@translate='no')";
        }
        if (exclude101Btn.getSelection()) {
            expandXpath += " and not(target[@hs:quality='101'])";
        }
        if (exclude100Btn.getSelection()) {
            expandXpath += " and not(target[@hs:quality='100'])";
        }
    } else if (onlyExportBtn.getSelection()) {
        if (onlyExportNoteBtn.getSelection()) {
            expandXpath += " and note/text()!=''";
        } else if (onlyExportReviewBtn.getSelection()) {
            expandXpath += " and @hs:needs-review='yes'";
        }
    }
    final String finalExpandXpath = expandXpath;
    // 这里开始调用导出的方法
    final String finalDocxPath = docxPath;
    Job job = new Job(Messages.getString("ExportDocxDialog.ok.monitor.title")) {

        protected IStatus run(final IProgressMonitor monitor) {
            try {
                // 解析文件花一格。读取 xliff 数据花 1 格,导出花 18 格。
                monitor.beginTask(Messages.getString("ExportDocxDialog.ok.monitor.msg0"), 20);
                beginExport(monitor, finalDocxPath, commentSelection, statusSelection, finalExpandXpath);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxDialog.ok.msg4"));
                    }
                });
                monitor.done();
            } catch (OperationCanceledException e) {
            // do nothing
            } catch (final Exception e) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(getShell(), Messages.getString("all.dialog.error"), Messages.getString("ExportDocxDialog.ok.exportError") + "\n" + e.getMessage());
                    }
                });
                LOGGER.error("Export xliff to MS WORD error\n" + e.getMessage(), e);
            }
            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();
    close();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 95 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project translationstudio8 by heartsome.

the class FileAnalysisHandler method analysisFile.

/**
	 * 准备分析文件
	 */
public void analysisFile(String title) {
    final QAXmlHandler handler = new QAXmlHandler();
    Job job = new Job(title) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 要分析的文件的个数
            int fileNum = model.getAnalysisIFileList().size();
            model.setSubFileNum(fileNum);
            // 定义的进度条总共四格,其中,解析文件一格,分析文件三格
            monitor.beginTask("", fileNum * 4);
            // 解析文件,如果解析不成功,退出程序, 解析要分析的文件,用掉fileNum*1个格子
            if (!openXliff(handler, monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getAnalysisIFileList().size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("qa.all.dialog.info"), Messages.getString("qa.handlers.FileAnalysisHandler.tip4"));
                return Status.CANCEL_STATUS;
            }
            // 填充要分析文件的所有trans-unit节点个数的总和
            model.setAllTuSize(allTUSize);
            FileAnalysis fileAnalysis = getClassInstance(faItemId);
            // 分析文件用去fileNum*3个格子
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 3, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            int analysisResult = fileAnalysis.beginAnalysis(model, subMonitor, handler);
            if (analysisResult == -1 || analysisResult == QAConstant.QA_ZERO) {
                return Status.CANCEL_STATUS;
            }
            subMonitor.done();
            monitor.done();
            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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) FileAnalysis(net.heartsome.cat.ts.core.qa.FileAnalysis) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)172 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)163 Job (org.eclipse.core.runtime.jobs.Job)46 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)45 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 IProject (org.eclipse.core.resources.IProject)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7