use of net.heartsome.cat.ts.ui.editors.IXliffEditor 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.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method addViewPartVisibleListener.
private void addViewPartVisibleListener(final IWorkbenchWindow window) {
final ICommandService commandService = (ICommandService) window.getService(ICommandService.class);
window.getActivePage().addPartListener(new PartAdapter2() {
private void setStates(String partId) {
if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.common.ui.navigator.command.OpenNavigatorView", null);
} else if ("net.heartsome.cat.ts.ui.views.DocumentPropertiesViewPart".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.ts.ui.handlers.OpenDocumentPropertiesViewCommand", null);
} else if ("net.heartsome.cat.ts.ui.translation.view.matchview".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.ts.ui.translation.menu.command.openMatchView", null);
} else if ("net.heartsome.cat.ts.ui.term.view.termView".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.ts.ui.term.command.openTermView", null);
} else if ("net.heartsome.cat.ts.ui.qa.views.QAResultViewPart".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
} else if ("net.heartsome.cat.ts.websearch.ui.view.BrowserViewPart".equals(partId)) {
commandService.refreshElements("net.heartsome.cat.ts.websearch.showOrHideView", null);
}
}
/**
* 视图打开时
* @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partOpened(final IWorkbenchPartReference partRef) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setStates(partRef.getId());
}
});
}
/**
* 视图关闭时
* @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partClosed(IWorkbenchPartReference partRef) {
if (!partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
setStates(partRef.getId());
}
// 关闭时,根据是否是合并打开的文件,如果是,标识其是否被存储--robert
if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
if (partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
IXliffEditor xlfEditor = (IXliffEditor) partRef.getPart(true);
xlfEditor.setStore(true);
}
}
}
});
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor 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;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class UpdateTMWizard method performFinish.
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final boolean isDraft = page.isDraft();
final boolean isApproved = page.isApproved();
final boolean isSignedOff = page.isSignedOff();
final boolean isTranslated = page.isTranslated();
final boolean isLocked = page.isLocked();
if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
return false;
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
IRunnableWithProgress progress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
for (final IFile xliffFile : lstXLIFF) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
FileEditorInput editorInput = new FileEditorInput(xliffFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
} else {
// xliff 文件未打开
handler = new XLFHandler();
}
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
// 修改获取系统用户方式/*System.getProperty("user.name");*/
String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
monitor.worked(1);
if (arrTempTMX != null) {
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
// }
try {
DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
}
});
canFinish = false;
return;
}
}
}
monitor.done();
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
canFinish = true;
}
};
try {
getContainer().run(true, true, progress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return canFinish;
}
use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.
the class WebSearchHandler method execute.
/** (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
String selectPureText = "";
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
selectPureText = xliffEditor.getSelectPureText();
}
try {
IViewPart showView = getActivePage().showView(BrowserViewPart.ID);
if (showView instanceof BrowserViewPart) {
BrowserViewPart browserViewPart = (BrowserViewPart) showView;
browserViewPart.setKeyWord(selectPureText, true);
}
} catch (PartInitException e) {
e.printStackTrace();
logger.error("", e);
}
return null;
}
Aggregations