use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class XmlConverterConfigurationDialog method editConfigXml.
/**
* 编辑转换配置XML文件 ;
*/
public void editConfigXml() {
ISelection selection = tableViewer.getSelection();
if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<String[]> iter = structuredSelection.iterator();
String convertXml = iter.next()[1];
AddOrEditXmlConvertConfigDialog dialog = new AddOrEditXmlConvertConfigDialog(getShell(), false);
dialog.create();
String convertXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append(convertXml).toOSString();
if (dialog.setInitEditData(convertXmlLoaction)) {
int result = dialog.open();
// 如果点击的是确定按钮,那么更新列表
if (result == IDialogConstants.OK_ID) {
String curentConvertXMl = dialog.getCurentConverXML();
refreshTable();
setTableSelection(curentConvertXMl);
}
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"), Messages.getString("dialogs.XmlConverterConfigurationDialog.msg2"));
}
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class ExportDocxHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
IFile file = null;
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();
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("ExportDocxHandler.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);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.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();
}
ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
dialog.open();
return null;
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class PluginConfigManage method executePlugin.
/**
* 运行自定义的插件
* @param bean
* ;
*/
@SuppressWarnings("unchecked")
public void executePlugin(PluginConfigBean bean) {
String commandLine = bean.getCommandLine();
if (commandLine == null || "".equals(commandLine)) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg1"));
return;
}
try {
// 当输出(进程)为当前文档时
if (bean.getOutput().equals(PluginConstants.SEGMENT)) {
// 先检查是否有已经打开的文件,若没有,退出插件执行
XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
if (nattable == null) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg2"));
return;
}
XLFHandler handler = nattable.getXLFHandler();
List<String> selectRowIds = nattable.getSelectedRowIds();
if (selectRowIds.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg3"));
return;
}
if (selectRowIds.size() > 1) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg4"));
}
String rowId = selectRowIds.get(0);
sendSegment(bean, handler, rowId);
// 执行后返回的文件
String returnContent = runPlugin(bean);
// 如果返回为交换文件,则更新当前文本段
if (bean.getInput().equals(PluginConstants.EXCHANGEFILE)) {
handler.updateAndSave(rowId, "", returnContent);
// 更新完后,要刷新界面。此处未做,滞留。
}
}
// 当输出(进程)为当前文档时
if (bean.getOutput().equals(PluginConstants.DOCUMENT)) {
XLFHandler handler;
IFile selectIFile = null;
// 先检查是否有已经打开的文件,若没有,退出插件执行
XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
if (nattable == null) {
// 如果当前没有打开的文件,那么获取左边导航框中选中的文件
ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
if (selection == null || selection.isEmpty() || !(selection instanceof StructuredSelection)) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
return;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Iterator<Object> selectIt = structuredSelection.iterator();
if (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
selectIFile = (IFile) object;
String fileExtension = selectIFile.getFileExtension();
if (!CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
return;
}
}
}
handler = new XLFHandler();
// 打开该xliff文件
Map<String, Object> resultMap = handler.openFile(selectIFile.getLocation().toOSString());
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
MessageDialog.openInformation(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg5"));
return;
}
} else {
handler = nattable.getXLFHandler();
selectIFile = ResourceUtil.getFile(nattable.getEditorInput());
// IEditorInput fileInput = nattable.getEditorInput();
}
sendDocument(bean, selectIFile);
if (bean.getInput().equals(PluginConstants.DOCUMENT)) {
// 重新解析该文件
Map<String, Object> resultMap = handler.openFile(selectIFile.getLocation().toOSString());
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
MessageDialog.openError(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg6"));
return;
}
}
}
// 当输出(进程)为空时
if (bean.getOutput().equals(PluginConstants.NONE)) {
runPlugin(bean);
}
} catch (Exception e) {
LOGGER.error("", e);
MessageDialog.openError(shell, Messages.getString("plugin.PluginConfigManage.msgTitle"), Messages.getString("plugin.PluginConfigManage.msg7"));
}
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class BatchQAHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
isMultiFile = false;
preferenceStore = Activator.getDefault().getPreferenceStore();
// UNDO 如果焦点在其他视图上时,获取的文件错误。
IFile multiTempIFile = null;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
// ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
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;
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;
}
continue;
}
selectIFiles.add(selectFile);
} else if (object instanceof IProject) {
IProject selectProject = (IProject) object;
try {
ResourceUtils.getXliffs(selectProject, selectIFiles);
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (Exception e) {
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
e.printStackTrace();
}
}
}
}
} else {
//如果左边未选择品质检查的类型,那么,获取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);
}
}
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() == 0) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.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;
}
model = new QAModel();
model.setQaXlfList(selectIFiles);
quality = new QualityAssurance(model);
BatchQADialog dialog = new BatchQADialog(shell, model, isMultiFile);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果显示了的。删除数据
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));
// 将当前所处理的文件传至 qaResult
List<String> fileList = new ArrayList<String>();
for (IFile iFIle : model.getQaXlfList()) {
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
qaResult.setMultiOper(model.getMultiOper());
quality.beginMultiFileQA(qaResult);
} else {
model.setMuliFiles(false);
qaResult.setMultiOper(model.getMultiOper());
quality.beginQA(qaResult);
}
}
return null;
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class MatchViewPart method selectionChanged.
/**
* 监听XLFEditor的选择事件
*/
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (part == null || selection == null) {
return;
}
if (!(part instanceof IEditorPart)) {
updateActionState();
return;
}
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
updateActionState();
return;
}
IXliffEditor editor = (IXliffEditor) part;
IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
final Object object = structuredSelecion.getFirstElement();
if (object instanceof Integer) {
int rowIndex = -1;
int selRowIndex = (Integer) object;
if (rowIndex == selRowIndex) {
if (gridTable.getItemCount() != 0) {
updateActionState();
}
return;
} else {
rowIndex = selRowIndex;
}
XLFHandler handler = editor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
// handler.getTransUnit(rowId);
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
if (transUnit == null) {
updateActionState();
return;
}
TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
IProject currentProject = input.getFile().getProject();
copyEnable.resetSelection();
gridTable.removeAll();
altTransCacheList.clear();
menuMgr.setEditor(editor);
menuMgr.setRowIndex(rowIndex);
executeMatch(editor, rowId, transUnit, tuInfoBean, currentProject);
}
}
Aggregations