Search in sources :

Example 1 with ProjectInfoBean

use of net.heartsome.cat.common.bean.ProjectInfoBean in project translationstudio8 by heartsome.

the class ProjectSettingHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    runWizardPageExtension();
    ISelection curSelection = HandlerUtil.getCurrentSelection(event);
    if (curSelection != null && !curSelection.isEmpty() && curSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) curSelection;
        Object obj = selection.getFirstElement();
        if (obj instanceof IProject) {
            IProject project = (IProject) obj;
            ProjectConfiger cfg = ProjectConfigerFactory.getProjectConfiger(project);
            final ProjectInfoBean cfgBean = cfg.getCurrentProjectConfig();
            cfgBean.setProjectName(project.getName());
            ProjectSettingBaseInfoPage infoPage = new ProjectSettingBaseInfoPage(cfgBean);
            ProjectSettingLanguagePage langPag = new ProjectSettingLanguagePage(cfgBean);
            final PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode infoNode = new PreferenceNode("infoPage", infoPage);
            IPreferenceNode langNode = new PreferenceNode("langPag", langPag);
            mgr.addToRoot(infoNode);
            mgr.addTo("infoPage", langNode);
            AbstractProjectSettingPage pageTm = getPageByType("TM");
            if (pageTm != null) {
                pageTm.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tmInfo", pageTm);
                mgr.addTo("infoPage", extensionNode);
            }
            AbstractProjectSettingPage pageTb = getPageByType("TB");
            if (pageTb != null) {
                pageTb.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", pageTb);
                mgr.addTo("infoPage", extensionNode);
            }
            for (AbstractProjectSettingPage page : extensionPages) {
                page.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", page);
                mgr.addTo("infoPage", extensionNode);
            }
            ProjectSettingDialog dialog = new ProjectSettingDialog(window.getShell(), mgr);
            dialog.create();
            dialog.setMessage(infoPage.getTitle());
            if (dialog.open() == 0) {
                cfg.updateProjectConfig(cfgBean);
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    logger.error("", e);
                }
            }
        } else {
            MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
            return null;
        }
    } else {
        MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
        return null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProjectSettingBaseInfoPage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage) ProjectSettingDialog(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingDialog) ProjectSettingLanguagePage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingLanguagePage) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractProjectSettingPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IProject(org.eclipse.core.resources.IProject) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ISelection(org.eclipse.jface.viewers.ISelection)

Example 2 with ProjectInfoBean

use of net.heartsome.cat.common.bean.ProjectInfoBean in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method resetConfigContent.

public void resetConfigContent(IProject project) {
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    if (null == projectConfig) {
        return;
    }
    // FIX Bug#3709 导入项目时更新库--打开XLIFF文件时无法更新同名的记忆库/术语库
    // 重新加载一次数据,如果ProjectConfigerFactory缓存中含有导入项目的名称时,有bug
    projectConfig.reloadConfig();
    ProjectInfoBean currentProjectConfig = projectConfig.getCurrentProjectConfig();
    List<DatabaseModelBean> tmDb = currentProjectConfig.getTmDb();
    int index = 0;
    for (DatabaseModelBean bean : tmDb) {
        // update tm config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTMNameAndPath(project, bean, index);
            index++;
        }
    }
    List<DatabaseModelBean> tbDb = currentProjectConfig.getTbDb();
    index = 0;
    for (DatabaseModelBean bean : tbDb) {
        // update tb config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTBNameAndPath(project, bean, index);
            index++;
        }
    }
    projectConfig.updateProjectConfig(currentProjectConfig);
    try {
        project.refreshLocal(IResource.DEPTH_ZERO, null);
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 3 with ProjectInfoBean

use of net.heartsome.cat.common.bean.ProjectInfoBean 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)

Example 4 with ProjectInfoBean

use of net.heartsome.cat.common.bean.ProjectInfoBean in project translationstudio8 by heartsome.

the class ProjectConfiger method getCurrentProjectConfig.

/**
	 * 获取项目配置信息
	 * @return 指定项目配置文件中的所有信息;
	 */
public ProjectInfoBean getCurrentProjectConfig() {
    ProjectInfoBean bean = new ProjectInfoBean();
    vu.getVTDNav().push();
    AutoPilot hsAp = new AutoPilot(vu.getVTDNav());
    try {
        hsAp.selectXPath("/projectDescription/hs");
        if (hsAp.evalXPath() != -1) {
            bean.setProjectName(getProjectName());
            bean.setMapField(getFieldMap());
            bean.setMapAttr(getAttrMap());
            bean.setSourceLang(getSourceLanguage());
            bean.setTargetLang(getTargetlanguages());
            bean.setTmDb(getAllTmDbs());
            bean.setTbDb(getTermBaseDbs(false));
        }
    } catch (XPathParseException e) {
        logger.error("", e);
    } catch (XPathEvalException e) {
        logger.error("", e);
    } catch (NavException e) {
        logger.error("", e);
    }
    vu.getVTDNav().pop();
    return bean;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Example 5 with ProjectInfoBean

use of net.heartsome.cat.common.bean.ProjectInfoBean in project translationstudio8 by heartsome.

the class ProjectConfigerUtil method restoreMementos.

public void restoreMementos() {
    if (null == config) {
        return;
    }
    ProjectInfoBean currentProjectBean = config.getCurrentProjectConfig();
    if (null == currentProjectBean) {
        return;
    }
    if (null != mementoTmDbs) {
        currentProjectBean.setTmDb(mementoTmDbs);
    }
    if (null != mementoTbDbs) {
        currentProjectBean.setTbDb(mementoTbDbs);
    }
    config.updateProjectConfig(currentProjectBean);
    try {
        projcet.refreshLocal(IResource.DEPTH_ZERO, null);
    } catch (CoreException e) {
        logger.error("", e);
    }
}
Also used : ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)9 CoreException (org.eclipse.core.runtime.CoreException)5 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)4 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)3 ArrayList (java.util.ArrayList)2 AutoPilot (com.ximpleware.AutoPilot)1 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 File (java.io.File)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Language (net.heartsome.cat.common.locale.Language)1 AbstractNewProjectWizardPage (net.heartsome.cat.ts.ui.extensionpoint.AbstractNewProjectWizardPage)1 AbstractProjectSettingPage (net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage)1 ProjectSettingBaseInfoPage (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage)1 ProjectSettingDialog (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingDialog)1 ProjectSettingLanguagePage (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingLanguagePage)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1