use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class TerminologyViewPart method selectionChanged.
/**
* 监听来自IHSEditor的选中改变事件。
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// UNDO 每次启动程序后,术语匹配面板无法识别出术语。 2012-06-21
if (part == null || selection == null) {
return;
}
if (part instanceof IXliffEditor) {
if (!part.equals(tempEditor)) {
IXliffEditor editor = (IXliffEditor) part;
tempEditor = editor;
tempEditor = (IXliffEditor) part;
FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
IProject currProject = input.getFile().getProject();
matcher.setCurrentProject(currProject);
}
} else {
firstAction.setEnabled(false);
return;
}
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
firstAction.setEnabled(false);
return;
}
IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
Object object = structuredSelecion.getFirstElement();
if (object instanceof Integer) {
rowIndex = (Integer) object;
IXliffEditor editor = (IXliffEditor) part;
// handler.getTransUnit(rowId);
TransUnitBean bean = editor.getRowTransUnitBean(rowIndex);
String pureText = bean.getSrcText();
srcLang = bean.getSrcLang();
tgtLang = bean.getTgtLang();
tgtLang = tgtLang == null || tgtLang.equals("") ? editor.getTgtColumnName() : tgtLang;
srcLang = srcLang == null || "".equals(srcLang) ? editor.getSrcColumnName() : srcLang;
if (srcLang == null || "".equals(srcLang) || tgtLang == null || "".equals(tgtLang)) {
return;
}
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
gridTable.setOrientation(SWT.RIGHT_TO_LEFT);
} else {
gridTable.setOrientation(SWT.LEFT_TO_RIGHT);
}
srcTableColumn.setText(srcLang);
tgtTableColumn.setText(tgtLang);
loadData(pureText, srcLang, tgtLang, true);
}
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class AddTermToTBHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
// ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
// List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(true);
TbImporter.getInstance().setProject(file.getProject());
if (!TbImporter.getInstance().checkImporter()) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
return null;
}
StringBuffer srcTerm = new StringBuffer();
StringBuffer tgtTerm = new StringBuffer();
String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);
AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(), tgtTerm.toString().trim(), AddTermToTBDialog.ADD_TYPE);
dialog.setProject(file.getProject());
dialog.setSrcLang(xliffEditor.getSrcColumnName());
dialog.setTgtLang(xliffEditor.getTgtColumnName());
dialog.setSrcAllText(srcAllText);
dialog.open();
}
return null;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class TermViewerBodyMenu method addTerm.
void addTerm() {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
TbImporter.getInstance().setProject(file.getProject());
if (!TbImporter.getInstance().checkImporter()) {
MessageDialog.openInformation(editor.getSite().getShell(), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
return;
}
StringBuffer srcTerm = new StringBuffer();
StringBuffer tgtTerm = new StringBuffer();
String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);
AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(), tgtTerm.toString().trim(), AddTermToTBDialog.ADD_TYPE);
dialog.setProject(file.getProject());
dialog.setSrcLang(xliffEditor.getSrcColumnName());
dialog.setTgtLang(xliffEditor.getTgtColumnName());
dialog.setSrcAllText(srcAllText);
dialog.open();
}
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ColorConfigLoader method loadColor.
private void loadColor() {
Device device = Activator.getDefault().getWorkbench().getDisplay();
if (pfStore == null) {
pfStore = Activator.getDefault().getPreferenceStore();
pfStore.addPropertyChangeListener(this);
}
colorConfigBean.release();
colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
String strColor = colorConfigBean.toString();
IXliffEditor xliffEditor = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart editor = page.getActiveEditor();
if (editor != null && editor instanceof IXliffEditor) {
xliffEditor = (IXliffEditor) editor;
}
}
}
if (strCurColor != null && !strCurColor.equals(strColor)) {
// 更改颜色设置后刷新界面
if (xliffEditor != null) {
xliffEditor.autoResize();
xliffEditor.refresh();
}
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart viewPart = page.findView("net.heartsome.cat.ts.ui.translation.view.matchview");
if (viewPart != null) {
IMatchViewPart part = (IMatchViewPart) viewPart;
part.refreshTable();
}
}
}
strCurColor = strColor;
}
Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
highlightedTermColor = new Color(device, newRgb);
} else if (!highlightedTermColor.getRGB().equals(newRgb)) {
highlightedTermColor.dispose();
highlightedTermColor = new Color(device, newRgb);
// had changed
if (xliffEditor != null) {
// 刷新
xliffEditor.highlightedTerms(0, null);
}
}
colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ExecuteBingTransHandler method execute.
/**
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof IXliffEditor)) {
return null;
}
// check the google translation state: check the key availability
PrefrenceParameters ps = PrefrenceParameters.getInstance();
if (!ps.getState()) {
MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
return null;
}
String tshelp = System.getProperties().getProperty("TSHelp");
String tsstate = System.getProperties().getProperty("TSState");
if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
LoggerFactory.getLogger(ExecuteBingTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
System.exit(0);
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
// int currentRowIndex = selectedRowIndexs[0];
// TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
// if (transUnitBean == null) {
// return null;
// }
// String srcPureText = transUnitBean.getSrcText();
// String tgtLanguage = xliffEditor.getTgtColumnName();
// String srcLanguage = xliffEditor.getSrcColumnName();
// TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
// tuInfo2Trans.setSrcPureText(srcPureText);
// tuInfo2Trans.setSrcLanguage(srcLanguage);
// tuInfo2Trans.setTgtLangugage(tgtLanguage);
ISimpleMatcher matcher = new SimpleMatcherBingImpl();
// String tgtText = matcher.executeMatch(tuInfo2Trans);
// if (tgtText.equals("")) {
// return null;
// }
// AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
// matcher.getMathcerOrigin(), matcher.getMathcerToolId());
// bean.getMatchProps().put("match-quality", "100");
// bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
// bean.setSrcContent(srcPureText);
// bean.setTgtContent(tgtText);
// List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
// newAltTrans.add(bean);
// check if need save the AltTrans to file
// if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
// List<String> oldToolIds = new ArrayList<String>();
// oldToolIds.add(matcher.getMathcerToolId());
// xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
// }
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
//matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
// matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
// matchView.replaceMatchs(newAltTrans);
// newAltTrans.clear();
matchView.manualExecSimpleTranslation(matcher);
}
return null;
}
Aggregations