use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class PreviewTranslationHandler method getConverterViewModel.
/**
* 得到 ConverterViewModel 对象
* @param file
* 需要预览翻译的文件
* @return
* @throws ExecutionException
* ;
*/
private ConverterViewModel getConverterViewModel(IFile file) throws ExecutionException {
Object adapter = Platform.getAdapterManager().getAdapter(file, IConversionItem.class);
if (adapter instanceof IConversionItem) {
IConversionItem item = (IConversionItem) adapter;
ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), // 逆向转换
Converter.DIRECTION_REVERSE);
converterViewModel.setConversionItem(item);
try {
ConversionResource resource = new ConversionResource(Converter.DIRECTION_REVERSE, item);
String xliffpath = resource.getXliffPath();
String targetPath = resource.getPreviewPath();
ConversionConfigBean configBean = converterViewModel.getConfigBean();
configBean.setSource(xliffpath);
configBean.setTarget(targetPath);
configBean.setTargetEncoding("UTF-8");
// 设为预览翻译模式
configBean.setPreviewMode(true);
final IStatus status = converterViewModel.validateXliffFile(ConverterUtil.toLocalPath(xliffpath), new XLFHandler(), // 注:验证的过程中,会为文件类型和骨架文件的路径赋值。
null);
if (status != null && status.isOK()) {
return converterViewModel;
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), status.getMessage());
}
});
throw new ExecutionException(status.getMessage(), status.getException());
}
} catch (CoreException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class PreviewTranslationHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor == null) {
return false;
}
IEditorInput input = editor.getEditorInput();
IFile file = ResourceUtil.getFile(input);
shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
if (file == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg1"));
} else {
String fileExtension = file.getFileExtension();
if (fileExtension != null && CommonFunction.validXlfExtension(fileExtension)) {
ConverterViewModel model = getConverterViewModel(file);
if (model != null) {
// model.convert();
try {
previewFiles(new ArrayList<IFile>(Arrays.asList(new IFile[] { file })));
} catch (Exception e) {
// 修改 当异常没有消息,提示信息为空
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg7"));
LOGGER.error("", e);
}
}
} else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) {
// UNDO 合并打开的预览翻译有问题,是针对合并打开的文件,而不是针对项目所有的文件 robert 2012-07-12
if (file.exists()) {
// IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF);
// Fixed Bug #2616 预览翻译--合并打开的文件不能进行预览翻译 by Jason
XLFHandler hander = new XLFHandler();
List<String> files = hander.getMultiFiles(file);
List<IFile> ifileList = new ArrayList<IFile>();
for (String tf : files) {
ifileList.add(ResourceUtils.fileToIFile(tf));
}
// if (xliffFolder.exists()) {
// ArrayList<IFile> files = new ArrayList<IFile>();
// try {
// ResourceUtils.getXliffs(xliffFolder, files);
// } catch (CoreException e) {
// throw new ExecutionException(e.getMessage(), e);
// }
previewFiles(ifileList);
// } else {
// MessageDialog
// .openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"),
// Messages.getString("handler.PreviewTranslationHandler.msg2"));
// }
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), Messages.getString("handler.PreviewTranslationHandler.msg3"));
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project gfm_viewer by satyagraha.
the class ViewManager method activateView.
/**
* Activate a view by id.
*
* @param event
* @param viewId
* @throws ExecutionException
*/
public static void activateView(ExecutionEvent event, String viewId) throws ExecutionException {
try {
IViewPart view = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().activate(view);
} catch (PartInitException e) {
throw new ExecutionException("failed to show view", e);
}
}
use of org.eclipse.core.commands.ExecutionException in project gfm_viewer by satyagraha.
the class ShowMarkdownFile method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
LOGGER.fine("");
IStructuredSelection structuredSelection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
ViewManager.activateView(event, MarkdownView.ID);
IFile iFile = (IFile) firstElement;
try {
DIManager.getDefault().getInjector(Scope.PAGE).getInstance(ViewerActions.class).showMarkdownFile(iFile);
} catch (IOException e) {
throw new ExecutionException("could not show file", e);
}
} else {
LOGGER.fine("unexpected selection: " + firstElement);
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project bndtools by bndtools.
the class OpenMainConfigHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
IFile buildFile = Central.getWorkspaceBuildFile();
if (buildFile == null)
return null;
FileEditorInput input = new FileEditorInput(buildFile);
IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
page.openEditor(input, "bndtools.bndWorkspaceConfigEditor", true);
} catch (PartInitException e) {
ErrorDialog.openError(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), "Error", "Unable to open editor", e.getStatus());
} catch (Exception e) {
logger.logError("Error retrieving bnd configuration file", e);
}
return null;
}
Aggregations