use of net.heartsome.cat.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.
the class TermBaseSearchHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
IProject project = ((FileEditorInput) editor.getEditorInput()).getFile().getProject();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(false);
if (lstDatabase == null || lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.TermBaseSearchHandler.msgTitle"), Messages.getString("handler.TermBaseSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
selectText = resetCeanString(selectText);
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
TermBaseSearchDialog dialog = new TermBaseSearchDialog(editor.getSite().getShell(), project, srcLang, tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.search();
}
}
return null;
}
use of net.heartsome.cat.ts.core.file.ProjectConfiger 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.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.
the class AddTermToTBDialog method initProperty.
/**
* 初始化各个控件的值 ;
*/
public void initProperty() {
if (srcText != null && !srcText.equals("")) {
txtSrc.setText(srcText);
txtSrc.setSelection(0, srcText.length());
txtSrc.setFocus();
}
if (tgtText != null && !tgtText.equals("")) {
txtTgt.setText(tgtText);
txtTgt.setSelection(0, tgtText.length());
txtTgt.setFocus();
}
if (getPropertyValue() != null) {
txtProperty.setText(getPropertyValue());
}
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
List<Language> rsLstSrcLangs = new ArrayList<Language>();
List<Language> rsLstTgtLangs = null;
try {
rsLstSrcLangs.add(projectConfig.getSourceLanguage());
rsLstTgtLangs = projectConfig.getTargetlanguages();
} catch (XPathParseException e) {
LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
} catch (NavException e) {
LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
} catch (XPathEvalException e) {
LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
}
ArrayList<String> lstTgtLangs = new ArrayList<String>();
if (rsLstTgtLangs != null) {
for (Language lang : rsLstTgtLangs) {
lstTgtLangs.add(lang.getCode());
}
}
cmbSrcLang.setLabelProvider(new LanguageLabelProvider());
cmbSrcLang.setInput(rsLstSrcLangs);
cmbSrcLang.getTableCombo().select(0);
cmbTgtLang.setLabelProvider(new LanguageLabelProvider());
cmbTgtLang.setInput(rsLstTgtLangs);
if (tgtLang != null) {
cmbTgtLang.getTableCombo().select(lstTgtLangs.indexOf(tgtLang));
}
}
use of net.heartsome.cat.ts.core.file.ProjectConfiger 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.ts.core.file.ProjectConfiger in project translationstudio8 by heartsome.
the class ConcordanceSearchHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {
}
}
}
}
return null;
}
Aggregations