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;
}
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();
}
}
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();
}
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;
}
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);
}
}
Aggregations