use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class SetSplitPointByWordNumHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
IFile selectFile = null;
XLIFFEditorImplWithNatTable xliffEditor = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
// 如果是导航视图,那么就获取导航视图中选中的文件
if (activePart instanceof IViewPart) {
if (navegatorID.equals(activePart.getSite().getId())) {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Object object = structuredSelection.getFirstElement();
if (object instanceof IFile) {
selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就退出操作
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
FileEditorInput fileInput = new FileEditorInput(selectFile);
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
} else {
try {
xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
} catch (PartInitException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointToNotXlf"));
return null;
}
}
}
} else if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointByWOrdNumHandler.cantSetForMulty"));
return null;
}
selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
}
}
if (selectFile == null) {
return null;
}
XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
final XLFHandler xlfHander = nattable.getXLFHandler();
Map<String, Integer> rowWordNumMap = xlfHander.getSplitFileInfoForPointSetting(selectFile.getLocation().toOSString());
if (rowWordNumMap.size() <= 1) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("SetSplitPointHandler.cantSetPointForTuNum"));
return null;
}
List<String> splitPointList = nattable.getSplitXliffPoints();
// 排序之前先过滤重复
HashSet<String> set = new HashSet<String>(splitPointList);
splitPointList.clear();
splitPointList.addAll(set);
// 先对 splitPointList 进行排序
Collections.sort(splitPointList, new Comparator<String>() {
public int compare(String rowId1, String rowId2) {
int rowIndex1 = xlfHander.getRowIndex(rowId1);
int rowIndex2 = xlfHander.getRowIndex(rowId2);
return rowIndex1 > rowIndex2 ? 1 : -1;
}
});
List<SegPointBean> segPointList = new ArrayList<SegPointBean>();
if (splitPointList.size() > 0) {
int segWordNum = 0;
int i = 0;
String pointRowId = splitPointList.get(i);
for (Entry<String, Integer> entry : rowWordNumMap.entrySet()) {
segWordNum += entry.getValue();
if (pointRowId.equals(entry.getKey())) {
segPointList.add(new SegPointBean(segWordNum));
segWordNum = 0;
i++;
if (i < splitPointList.size()) {
pointRowId = splitPointList.get(i);
}
}
}
if (splitPointList.size() + 1 > segPointList.size()) {
segPointList.add(new SegPointBean(segWordNum));
}
}
SetSplitPointByWordNumDialog dialog = new SetSplitPointByWordNumDialog(shell, xlfHander, selectFile.getLocation().toOSString(), rowWordNumMap, segPointList);
int openResult = dialog.open();
if (openResult == IDialogConstants.OK_ID) {
// 如果选择确定,那么在界面上生成分割点
nattable.getSplitXliffPoints().clear();
for (SegPointBean bean : segPointList) {
if (bean.getRowId() != null && !bean.getRowId().isEmpty()) {
nattable.getSplitXliffPoints().add(bean.getRowId());
}
}
nattable.refresh();
}
return null;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class FileAnalysisHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
model = new FAModel();
faItemId = event.getParameter("faItemId");
allTUSize = 0;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
IFile multiTempIFile = null;
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
@SuppressWarnings("unchecked") Iterator<Object> selectIt = structuredSelection.iterator();
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就进行提示
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
if (!isSure) {
return null;
}
}
selectIFiles.add(selectFile);
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.handlers.FileAnalysisHandler.log1"), e);
}
}
}
}
} else if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
// 如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
return null;
}
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
isMultiFile = nattable.isMultiFile();
multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
if (isMultiFile) {
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String multiFileStr : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
}
} else {
selectIFiles.add(multiTempIFile);
}
} else {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip3"));
return null;
}
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() <= 0) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip1"));
return null;
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : selectIFiles) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
selectIFiles.removeAll(lstFiles);
if (selectIFiles.size() == 0) {
return null;
}
// 判断要分析的文件是否是属于同一个项目中的.
IProject project = selectIFiles.get(0).getProject();
if (selectIFiles.size() >= 2) {
for (int i = 1; i < selectIFiles.size(); i++) {
if (selectIFiles.get(i).getProject() != project) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip2"));
return null;
}
}
}
model.setAnalysisIFileList(selectIFiles);
model.setShell(shell);
model.setMultiFile(isMultiFile);
if (isMultiFile) {
model.setMultiTempIFile(multiTempIFile);
}
// 文件分析框的框名
title = model.getAnalysisItemMap().get(faItemId).get(QAConstant.FA_ITEM_NAME);
FileAnalysisDialog dialog = new FileAnalysisDialog(shell, model, title, faItemId);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
analysisFile(title);
}
return null;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class NumberOrTagConsisQAHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean isMultiFile = false;
IFile multiTempIFile = null;
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
// 改为布局
if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
String qaItem = event.getParameter("qaItemId");
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
// 首先判断是否是合并打开的文件
if (nattable.isMultiFile()) {
isMultiFile = true;
}
if (isMultiFile) {
multiTempIFile = input.getFile();
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String filePath : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(filePath));
}
} else {
selectIFiles.add(input.getFile());
}
QAModel model = new QAModel();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
if (view != null) {
// 运行时,将结果视图中列表的数据清除
((QAResultViewPart) view).clearTableData();
}
QAResult qaResult = new QAResult();
// 存储品质检查的检查项
// model.setBatchQAItemIdList(getBatchQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(getNotIncludePara());
// 给品质检查结果视图发出通告,本次检查对象为合并打开文件
qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
} else {
model.setMuliFiles(false);
}
boolean isNumberQA = false;
if (QAConstant.QA_NUMBER.equals(qaItem)) {
isNumberQA = true;
} else if (QAConstant.QA_TAG.equals(qaItem)) {
isNumberQA = false;
}
List<String> fileList = new ArrayList<String>();
for (IFile iFIle : selectIFiles) {
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
beginQA(selectIFiles, model, isNumberQA, qaResult);
}
return null;
}
use of org.eclipse.ui.IViewPart in project translationstudio8 by heartsome.
the class UpdateTMHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
// boolean isShowCurrentLangBtn = true;
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();
// ISelection selection = HandlerUtil.getCurrentSelection(event);
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())) {
lstXliff.add(file);
}
} else if (obj instanceof IFolder) {
try {
ResourceUtils.getXliffs((IFolder) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
}
} else if (obj instanceof IProject) {
try {
ResourceUtils.getXliffs((IProject) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
}
}
}
CommonFunction.removeRepeateSelect(lstXliff);
if (lstXliff.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
Iterator<IFile> iterator = lstXliff.iterator();
while (iterator.hasNext()) {
IFile file = iterator.next();
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.findEditor(editorInput);
if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
// isShowCurrentLangBtn = false;
break;
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
} 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);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
if (lstFile.size() > 0) {
for (String filePath : lstFile) {
lstXliff.add(ResourceUtils.fileToIFile(filePath));
}
}
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
lstXliff.add(iFile);
}
}
if (lstXliff.size() > 0) {
if (lstXliff.size() > 1) {
String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
for (int i = 1; i < lstXliff.size(); i++) {
String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
if (!projectPath.equals(projectPath2)) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
return null;
}
}
}
ArrayList<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : lstXliff) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
lstXliff.removeAll(lstFiles);
if (lstXliff.size() == 0) {
return null;
}
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
if (projectConfig.getDefaultTMDb() == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
return null;
}
UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
// UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
dialog.open();
}
return null;
}
use of org.eclipse.ui.IViewPart 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.isBingState()) {
MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
return null;
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
ISimpleMatcher matcher = new SimpleMatcherBingImpl();
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
}
return null;
}
Aggregations