Search in sources :

Example 11 with ProjectConfiger

use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.

the class NewProjectWizard method initProjectConfig.

/**
	 * 构建项目配置信息
	 * @param project
	 *            ;
	 * @throws CoreException
	 */
private void initProjectConfig(final IProject project, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    final IProgressMonitor sMonitor = monitor;
    sMonitor.beginTask(Messages.getString("wizard.NewProjectWizard.task2"), 3);
    sMonitor.worked(1);
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            ProjectInfoBean bean = new ProjectInfoBean();
            bean.setProjectName(project.getName());
            bean.setMapField(firstPage.getFieldMap());
            bean.setMapAttr(firstPage.getAttributeMap());
            bean.setSourceLang(secondPage.getSrcLanguage());
            bean.setTargetLang(secondPage.getTargetlanguage());
            for (AbstractNewProjectWizardPage extensionPage : extensionPages) {
                if (extensionPage.getPageType().equals("TM")) {
                    bean.setTmDb(extensionPage.getSelectedDatabase());
                } else if (extensionPage.getPageType().equals("TB")) {
                    bean.setTbDb(extensionPage.getSelectedDatabase());
                }
            }
            sMonitor.worked(1);
            ProjectConfiger projCfg = ProjectConfigerFactory.getProjectConfiger(project);
            sMonitor.worked(1);
            projCfg.updateProjectConfig(bean);
            // 记住当前语言信息
            IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
            ps.setValue(IPreferenceConstants.NEW_PROJECT_SRC_LANG, bean.getSourceLang().getCode());
            List<Language> targetLangList = bean.getTargetLang();
            StringBuffer bf = new StringBuffer();
            for (Language lang : targetLangList) {
                bf.append(lang.getCode());
                bf.append(",");
            }
            ps.setValue(IPreferenceConstants.NEW_PROJECT_TGT_LANG, bf.substring(0, bf.lastIndexOf(",")));
            if (sMonitor.isCanceled()) {
                try {
                    project.delete(true, sMonitor);
                } catch (CoreException e) {
                    logger.error("", e);
                }
                throw new OperationCanceledException();
            }
        }
    });
    sMonitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AbstractNewProjectWizardPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractNewProjectWizardPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) Language(net.heartsome.cat.common.locale.Language) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)7 IFile (org.eclipse.core.resources.IFile)5 ArrayList (java.util.ArrayList)4 ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)4 Language (net.heartsome.cat.common.locale.Language)4 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)4 IProject (org.eclipse.core.resources.IProject)4 CoreException (org.eclipse.core.runtime.CoreException)4 IEditorPart (org.eclipse.ui.IEditorPart)4 FileEditorInput (org.eclipse.ui.part.FileEditorInput)3 File (java.io.File)2 List (java.util.List)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1