use of org.eclipse.ui.IWorkbenchPart 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.IWorkbenchPart 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;
}
use of org.eclipse.ui.IWorkbenchPart 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.IWorkbenchPart 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.IWorkbenchPart in project translationstudio8 by heartsome.
the class StyledTextCellEditor method close.
public void close() {
if (close) {
return;
}
for (Listener listener : closingListeners) {
Event event = new Event();
event.data = this;
listener.handleEvent(event);
}
// 状态改为已经关闭
close = true;
xliffEditor.getTable().removeDisposeListener(this);
StyledText text = viewer.getTextWidget();
if (text != null && !text.isDisposed()) {
actionHandler.removeTextViewer();
// dispose前应去掉右键menu,因为右键menu是和nattable共享的
text.setMenu(null);
viewer.reset();
text.dispose();
text = null;
}
// 如果 XLIFF 编辑器仍处于激活状态,则把焦点交给编辑器
try {
IWorkbenchPart activepart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
if (xliffEditor.equals(activepart)) {
xliffEditor.setFocus();
}
} catch (NullPointerException e) {
}
// NatTable table = xliffEditor.getTable();
// int[] rowPositions = new int[] { hsCellEditor.getRowPosition() };
// table.doCommand(new AutoResizeCurrentRowsCommand(table, rowPositions, table.getConfigRegistry()));
}
Aggregations