use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class SelectProjectOrXLIFFPropertyTester method test.
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
if (page.getActivePartReference() == null) {
return false;
}
String partId = page.getActivePartReference().getId();
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile file = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (file.getFileExtension() == null || !CommonFunction.validXlfExtension(file.getFileExtension())) {
return false;
} else {
String xlfFolderPath = file.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
if (!file.getFullPath().toOSString().startsWith(xlfFolderPath)) {
return false;
}
}
} else if (obj instanceof IFolder) {
IFolder folder = (IFolder) obj;
String xlfFolderPath = folder.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
if (!folder.getFullPath().toOSString().startsWith(xlfFolderPath)) {
return false;
}
}
}
} else {
return false;
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = page.getActivePart();
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
if (iFile == null) {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
return true;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class NewFolderHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
if (lstObj == null || lstObj.size() != 1) {
MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg1"));
return null;
}
IContainer container = null;
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile file = (IFile) obj;
container = file.getParent();
} else if (obj instanceof IFolder) {
container = (IFolder) obj;
} else if (obj instanceof IProject) {
container = (IProject) obj;
}
}
ResourcesPlugin.getPlugin().getPluginPreferences().setValue(ResourcesPlugin.PREF_DISABLE_LINKING, true);
NewFolderDialogOfHs dialog = new NewFolderDialogOfHs(shell, container);
dialog.open();
} else {
MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg2"));
return null;
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handlers.NewFolderHandler.msgTitle"), Messages.getString("handlers.NewFolderHandler.msg2"));
return null;
}
return null;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class NattableUtil method approveTransUnits.
/**
* 批准或取消批准文本段
* @param selectedRowIds1
* 选中行的rowId集合
* @param approve
* true:批准;false:取消批准;
*/
public void approveTransUnits(boolean isJumpNext) {
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() == 0) {
return;
}
final Map<String, List<String>> tmpGroup = RowIdUtil.groupRowIdByFileName(selectedRowIds);
boolean hasEmpty = false;
XLFHandler handler = xliffEditor.getXLFHandler();
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
// 目标文本为空不能执行批准,将要跳过
List<String> rowIds = entry.getValue();
int size = rowIds.size();
handler.removeNullTgtContentRowId(rowIds);
if (rowIds.size() != size) {
hasEmpty = true;
}
handler.removeLockedRowIds(rowIds);
}
// 入库前进行品质检查 --robert
int i = 0;
final AutomaticQATrigger auto = new AutomaticQATrigger(xliffEditor.getXLFHandler());
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
for (Iterator<String> it = rowIdList.iterator(); it.hasNext(); ) {
String rowId = it.next();
String result = auto.beginAutoQa(false, rowId, i == 0 ? true : false);
if (result == null) {
return;
}
if (result.length() > 1) {
boolean respons = MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("translation.ApproveSegmentHandler.msgTitle"), result);
// 若选择ok,则继续操作
if (!respons) {
auto.bringQAResultViewerToTop();
it.remove();
selectedRowIds.remove(rowId);
}
}
i++;
}
}
auto.informQAEndFlag();
String message = null;
if (hasEmpty) {
message = Messages.getString("utils.NattableUtil.msg1");
}
if (message != null) {
if (!MessageDialog.openConfirm(xliffEditor.getTable().getShell(), Messages.getString("utils.NattableUtil.msgTitle"), message)) {
return;
}
}
if (selectedRowIds.size() == 0) {
return;
}
HsMultiActiveCellEditor.commit(true);
// 将选中的文本段添加记忆库,在生成TMX的过程中会过滤掉标记不添加到记忆库的文本段
final IProject project = ((FileEditorInput) (xliffEditor.getEditorInput())).getFile().getProject();
this.importer.setProject(project);
final int contextSize = importer.getContextSize();
BusyIndicator.showWhile(xliffEditor.getSite().getShell().getDisplay(), new Runnable() {
public void run() {
// monitor.beginTask(Messages.getString("utils.NattableUtil.task1"), 8);
if (!CommonFunction.checkEdition("L")) {
if (!importer.checkImporter() && ProjectConfigerFactory.getProjectConfiger(project).getDefaultTMDb() != null) {
final boolean[] state = new boolean[] { true };
Display.getDefault().syncExec(new Runnable() {
public void run() {
state[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle2"), Messages.getString("utils.NattableUtil.msg.cantConnDefaultDb"));
}
});
if (!state[0]) {
return;
}
}
}
final List<String> addToTmResultRowIds = new ArrayList<String>();
for (Entry<String, List<String>> entry : tmpGroup.entrySet()) {
List<String> rowIdList = tmpGroup.get(entry.getKey());
if (importer.checkImporter()) {
String systemUser = Activator.getDefault().getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
StringBuffer fileContent = xliffEditor.getXLFHandler().generateTMXFileContent(systemUser, rowIdList, xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), /* new SubProgressMonitor(monitor, 3) */
null, contextSize, project);
// }
if (fileContent != null) {
int state = -1;
try {
state = importer.executeImport(fileContent.toString(), xliffEditor.getSrcColumnName(), /* monitor */
null);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), msg);
}
});
return;
}
if (state == ITmImporter.IMPORT_STATE_FAILED) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg2"));
}
});
return;
} else if (state == ITmImporter.IMPORT_STATE_NODB) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("utils.NattableUtil.msgTitle"), Messages.getString("utils.NattableUtil.msg3"));
}
});
}
}
}
addToTmResultRowIds.addAll(rowIdList);
}
// monitor.setTaskName(Messages.getString("utils.NattableUtil.task2"));
Display.getDefault().syncExec(new Runnable() {
public void run() {
// 修改文本段状态,目前没有取消批准的功能,所以直接传入true,即所有的操作都是批准
List<String> rowIds = xliffEditor.getXLFHandler().approveTransUnits(addToTmResultRowIds, true);
if (rowIds.size() > 0) {
String message;
if (addToTmResultRowIds != null && addToTmResultRowIds.size() == 1) {
message = Messages.getString("utils.NattableUtil.msg4");
} else {
message = MessageFormat.format(Messages.getString("utils.NattableUtil.msg5"), rowIds.size());
}
boolean res = MessageDialog.openQuestion(xliffEditor.getTable().getShell(), null, message);
if (res) {
xliffEditor.getXLFHandler().approveTransUnits(rowIds, true, false);
}
}
xliffEditor.updateStatusLine();
xliffEditor.getTable().redraw();
}
});
// monitor.worked(2);
// if (monitor.isCanceled()) {
// return;
// }
//
// // 批准时需要进行繁殖翻译
// // propagateTranslations(addToTmResultRowIds, new
// // SubProgressMonitor(monitor, 2));
// monitor.done();
}
});
// runnable);
if (isJumpNext) {
int[] selectedRows = xliffEditor.getSelectedRows();
Arrays.sort(selectedRows);
xliffEditor.jumpToRow(selectedRows[selectedRows.length - 1] + 1);
} else {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.ts.ui.translation.view.matchview");
int[] selected = xliffEditor.getSelectedRows();
if (viewPart != null && viewPart instanceof IMatchViewPart && selected.length != 0) {
((IMatchViewPart) viewPart).reLoadMatches(xliffEditor, selected[selected.length - 1]);
}
HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
}
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class ImportDocxHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
XLIFFEditorImplWithNatTable xliffEditor = null;
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
xliffEditor = (XLIFFEditorImplWithNatTable) editor;
}
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile tempFile = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
lstXliff.add(tempFile);
}
}
}
if (lstXliff.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg1"));
return null;
}
if (lstXliff.size() == 1) {
file = lstXliff.get(0);
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg2"));
return null;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
file = iFile;
}
}
if (file != null) {
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(file)) {
return null;
}
XLFValidator.resetFlag();
}
ImportDocxDialog dialog = new ImportDocxDialog(shell, xliffEditor, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
dialog.open();
return null;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class ImportExternal method execute.
@SuppressWarnings("deprecation")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
XLIFFEditorImplWithNatTable xliffEditor = null;
final Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
xliffEditor = (XLIFFEditorImplWithNatTable) editor;
}
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile tempFile = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
lstXliff.add(tempFile);
}
}
}
if (lstXliff.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg1"));
return null;
}
if (lstXliff.size() == 1) {
file = lstXliff.get(0);
}
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ImportDocxHandler.msg2"));
return null;
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
file = iFile;
}
}
if (file != null) {
XLFValidator.resetFlag();
if (!XLFValidator.validateXliffFile(file)) {
return null;
}
XLFValidator.resetFlag();
}
final ImportConfig config = new ImportConfig();
config.setShell(shell);
config.set_xliff(file == null ? "" : file.getFullPath().toOSString());
config.setXliffEditor(xliffEditor);
config.setXliffFile(file == null ? "" : ResourceUtils.iFileToOSPath(file));
HsMultiActiveCellEditor.commit(true);
ImportExternalDialog dialog = new ImportExternalDialog(shell, xliffEditor, config);
if (Dialog.OK == dialog.open()) {
config.doImport();
if (xliffEditor != null) {
// reopen if need
if (xliffEditor.getXLFHandler().getVnMap().get(config.getXliffFile()) != null) {
Map<String, Object> resultMap = xliffEditor.getXLFHandler().openFile(config.getXliffFile());
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
// 打开文件失败。
MessageDialog.openWarning(shell, Messages.getString("all.dialog.warning"), MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"), config.get_xliff()));
LOGGER.error(MessageFormat.format(Messages.getString("ImportDocxDialog.ok.parseError"), config.get_xliff()));
return null;
}
xliffEditor.reloadData();
HsMultiCellEditorControl.activeSourceAndTargetCell(xliffEditor);
}
}
}
return null;
}
Aggregations