Search in sources :

Example 1 with ConversionCompleteAction

use of net.heartsome.cat.convert.ui.action.ConversionCompleteAction in project translationstudio8 by heartsome.

the class ConverterViewModel method convert.

/**
	 * 根据用户的选择和配置信息,执行文件的转换功能
	 * @return ;
	 */
public Map<String, String> convert() {
    // System.out.print(getConfigBean().toString());
    // 以用户最后在配置对话框所选择的源文件为准
    JobRunnable runnalbe = new JobRunnable() {

        private Map<String, String> conversionResult;

        public IStatus run(IProgressMonitor monitor) {
            IStatus result = Status.OK_STATUS;
            try {
                conversionResult = convertWithoutJob(monitor);
            } catch (OperationCanceledException e) {
                LOGGER.info(Messages.getString("model.ConverterViewModel.logger2"), e);
                result = Status.CANCEL_STATUS;
            } catch (ConverterException e) {
                String msg = Messages.getString("model.ConverterViewModel.logger3");
                Object[] args = { getConfigBean().getSource() };
                LOGGER.error(new MessageFormat(msg).format(args), e);
                result = e.getStatus();
            } finally {
                ConverterViewModel.this.close();
            }
            return result;
        }

        public void showResults(IStatus status) {
            IAction action = getRunnableCompletedAction(status);
            if (action != null) {
                action.run();
            }
        }

        public IAction getRunnableCompletedAction(IStatus status) {
            return new ConversionCompleteAction(Messages.getString("model.ConverterViewModel.msg1"), status, conversionResult);
        }
    };
    Job conversionJob = JobFactoryFacade.createJob(Display.getDefault(), "conversion job", runnalbe);
    conversionJob.setUser(true);
    conversionJob.setRule(conversionItem.getProject());
    conversionJob.schedule();
    return null;
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) MessageFormat(java.text.MessageFormat) IAction(org.eclipse.jface.action.IAction) ConversionCompleteAction(net.heartsome.cat.convert.ui.action.ConversionCompleteAction) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobRunnable(net.heartsome.cat.convert.ui.job.JobRunnable) Job(org.eclipse.core.runtime.jobs.Job) Map(java.util.Map)

Aggregations

MessageFormat (java.text.MessageFormat)1 Map (java.util.Map)1 ConversionCompleteAction (net.heartsome.cat.convert.ui.action.ConversionCompleteAction)1 JobRunnable (net.heartsome.cat.convert.ui.job.JobRunnable)1 ConverterException (net.heartsome.cat.converter.ConverterException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Job (org.eclipse.core.runtime.jobs.Job)1 IAction (org.eclipse.jface.action.IAction)1