Search in sources :

Example 21 with ExecutionException

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) ConversionResource(net.heartsome.cat.convert.ui.utils.ConversionResource) ExecutionException(org.eclipse.core.commands.ExecutionException) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 22 with ExecutionException

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput) CoreException(org.eclipse.core.runtime.CoreException) ConverterException(net.heartsome.cat.converter.ConverterException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 23 with ExecutionException

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);
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 24 with ExecutionException

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ViewerActions(code.satyagraha.gfm.viewer.model.api.ViewerActions) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 25 with ExecutionException

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)66 CoreException (org.eclipse.core.runtime.CoreException)20 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 IStatus (org.eclipse.core.runtime.IStatus)12 Shell (org.eclipse.swt.widgets.Shell)12 Status (org.eclipse.core.runtime.Status)11 IEditorPart (org.eclipse.ui.IEditorPart)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 File (java.io.File)7 List (java.util.List)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)7 IProject (org.eclipse.core.resources.IProject)7 FileEditorInput (org.eclipse.ui.part.FileEditorInput)7