Search in sources :

Example 11 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class UndoManager2 method fireRedoStackChanged.

private void fireRedoStackChanged() {
    if (fListeners == null)
        return;
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final IUndoManagerListener listener = (IUndoManagerListener) listeners[i];
        SafeRunner.run(new ISafeRunnable() {

            public void run() throws Exception {
                listener.redoStackChanged(UndoManager2.this);
            }

            public void handleException(Throwable exception) {
                RefactoringCorePlugin.log(exception);
            }
        });
    }
}
Also used : IUndoManagerListener(org.eclipse.ltk.core.refactoring.IUndoManagerListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 12 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.

the class UndoManager2 method fireUndoStackChanged.

private void fireUndoStackChanged() {
    if (fListeners == null)
        return;
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final IUndoManagerListener listener = (IUndoManagerListener) listeners[i];
        SafeRunner.run(new ISafeRunnable() {

            public void run() throws Exception {
                listener.undoStackChanged(UndoManager2.this);
            }

            public void handleException(Throwable exception) {
                RefactoringCorePlugin.log(exception);
            }
        });
    }
}
Also used : IUndoManagerListener(org.eclipse.ltk.core.refactoring.IUndoManagerListener) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 13 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project translationstudio8 by heartsome.

the class OpenConversionDialogHandler method execute.

@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
    CommonFunction.removeRepeateSelect(list);
    if (list == null || list.size() == 0) {
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.OpenConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenConversionDialogHandler.msg1"));
        return null;
    }
    ArrayList<ConverterViewModel> converterViewModels = new ArrayList<ConverterViewModel>();
    for (int i = 0; i < list.size(); i++) {
        Object adapter = Platform.getAdapterManager().getAdapter(list.get(i), IConversionItem.class);
        IConversionItem sourceItem = null;
        if (adapter instanceof IConversionItem) {
            sourceItem = (IConversionItem) adapter;
        }
        ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
        // 记住所选择的文件
        converterViewModel.setConversionItem(sourceItem);
        converterViewModels.add(converterViewModel);
    }
    IProject project = list.get(0).getProject();
    ConversionWizard wizard = new ConversionWizard(converterViewModels, project);
    TSWizardDialog dialog = new TSWizardDialog(shell, wizard) {

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            super.createButtonsForButtonBar(parent);
            getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handler.OpenConversionDialogHandler.finishLbl"));
        }
    };
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        final List<ConverterViewModel> models = wizard.getConverterViewModels();
        final List<IFile> targetFiles = new ArrayList<IFile>();
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task1"));
                monitor.beginTask(Messages.getString("handler.OpenConversionDialogHandler.task2"), models.size());
                for (ConverterViewModel converterViewModel : models) {
                    try {
                        IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
                        subMonitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
                        converterViewModel.convertWithoutJob(subMonitor);
                        List<File> tgtFileList = converterViewModel.getGenerateTgtFileList();
                        for (File f : tgtFileList) {
                            IFile tgtIfile = ConverterUtil.localPath2IFile(f.getAbsolutePath());
                            if (tgtIfile != null) {
                                targetFiles.add(tgtIfile);
                            }
                        }
                        // 若新转换的 xliff 文件重复,那么关闭已经打开的重复文件,防止文件同步冲突	robert	2013-04-01
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CommonFunction.closePointEditor(targetFiles);
                            }
                        });
                    } catch (ConverterException e) {
                        final String message = e.getMessage();
                        LOGGER.error("", e);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), message);
                            }
                        });
                    } catch (Exception e) {
                        final String message = e.getMessage();
                        LOGGER.error("", e);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), message);
                            }
                        });
                    }
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (InvocationTargetException e) {
            MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error("", e);
        } catch (InterruptedException e) {
            MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error(e.getMessage());
        }
        if (wizard.isOpenPreTranslation()) {
            // 加载转换器扩展
            final IExecutePretranslation[] impls = new IExecutePretranslation[1];
            IConfigurationElement[] config2 = Platform.getExtensionRegistry().getConfigurationElementsFor("net.heartsome.converter.extension.pretranslation");
            try {
                for (IConfigurationElement e : config2) {
                    final Object o = e.createExecutableExtension("class");
                    if (o instanceof IExecutePretranslation) {
                        ISafeRunnable runnable1 = new ISafeRunnable() {

                            public void handleException(Throwable exception) {
                                LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), exception);
                            }

                            public void run() throws Exception {
                                impls[0] = (IExecutePretranslation) o;
                            }
                        };
                        SafeRunner.run(runnable1);
                    }
                }
            } catch (CoreException ex) {
                LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), ex);
            }
            if (impls[0] != null) {
                if (targetFiles.size() < 1) {
                    return null;
                }
                impls[0].executePreTranslation(targetFiles);
            }
        }
    }
    return null;
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IFile(org.eclipse.core.resources.IFile) ConversionWizard(net.heartsome.cat.convert.ui.wizard.ConversionWizard) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IExecutePretranslation(net.heartsome.cat.convert.extenstion.IExecutePretranslation) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) Composite(org.eclipse.swt.widgets.Composite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ConverterException(net.heartsome.cat.converter.ConverterException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 14 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class SearchDialog method createPageControl.

private Control createPageControl(Composite parent, final SearchPageDescriptor descriptor) {
    // Page wrapper
    final Composite pageWrapper = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    pageWrapper.setLayout(layout);
    applyDialogFont(pageWrapper);
    BusyIndicator.showWhile(getShell().getDisplay(), () -> SafeRunner.run(new ISafeRunnable() {

        @Override
        public void run() throws Exception {
            // create page and control
            ISearchPage page = descriptor.createObject(SearchDialog.this);
            if (page != null) {
                page.createControl(pageWrapper);
            }
        }

        @Override
        public void handleException(Throwable ex) {
            if (ex instanceof CoreException) {
                ExceptionHandler.handle((CoreException) ex, getShell(), SearchMessages.Search_Error_createSearchPage_title, Messages.format(SearchMessages.Search_Error_createSearchPage_message, descriptor.getLabel()));
            } else {
                ExceptionHandler.displayMessageDialog(ex, getShell(), SearchMessages.Search_Error_createSearchPage_title, Messages.format(SearchMessages.Search_Error_createSearchPage_message, descriptor.getLabel()));
            }
        }
    }));
    ISearchPage page = descriptor.getPage();
    if (page == null || page.getControl() == null) {
        Composite container = new Composite(parent, SWT.NONE);
        Label label = new Label(container, SWT.WRAP);
        label.setText(Messages.format(SearchMessages.SearchDialog_error_pageCreationFailed, descriptor.getLabel()));
        container.setLayout(new GridLayout());
        label.setLayoutData(new GridData());
        return container;
    }
    page.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // Search scope
    boolean showScope = descriptor.showScopeSection();
    if (showScope) {
        Composite c = new Composite(pageWrapper, SWT.NONE);
        c.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        c.setLayout(new GridLayout());
        int index = fDescriptors.indexOf(descriptor);
        fScopeParts[index] = new ScopePart(this, descriptor.canSearchInProjects());
        Control part = fScopeParts[index].createPart(c);
        applyDialogFont(part);
        part.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        fScopeParts[index].setVisible(true);
    }
    return pageWrapper;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) CoreException(org.eclipse.core.runtime.CoreException) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ISearchPage(org.eclipse.search.ui.ISearchPage) Point(org.eclipse.swt.graphics.Point)

Example 15 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class SearchPageRegistry method getSearchResultPage.

private ISearchResultPage getSearchResultPage(final IConfigurationElement configElement, boolean create) {
    ISearchResultPage instance = fExtensionToInstance.get(configElement);
    if (instance == null && create) {
        final Object[] result = new Object[1];
        ISafeRunnable safeRunnable = new SafeRunnable(SearchMessages.SearchPageRegistry_error_creating_extensionpoint) {

            @Override
            public void run() throws Exception {
                // $NON-NLS-1$
                result[0] = configElement.createExecutableExtension("class");
            }

            @Override
            public void handleException(Throwable e) {
                // invalid contribution
                SearchPlugin.log(e);
            }
        };
        SafeRunner.run(safeRunnable);
        if (result[0] instanceof ISearchResultPage) {
            instance = (ISearchResultPage) result[0];
            instance.setID(configElement.getAttribute(ATTRIB_ID));
            fExtensionToInstance.put(configElement, instance);
        }
    }
    return instance;
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISearchResultPage(org.eclipse.search.ui.ISearchResultPage) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable)

Aggregations

ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)44 CoreException (org.eclipse.core.runtime.CoreException)28 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)6 ISpellingPreferenceBlock (org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)5 ExecutionException (org.eclipse.core.commands.ExecutionException)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 SpellingEngineDescriptor (org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)4 ArrayList (java.util.ArrayList)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ASTParser (org.eclipse.jdt.core.dom.ASTParser)3 IDocument (org.eclipse.jface.text.IDocument)3 IUndoManagerListener (org.eclipse.ltk.core.refactoring.IUndoManagerListener)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 IDocumentSetupParticipant (org.eclipse.core.filebuffers.IDocumentSetupParticipant)2 IDocumentSetupParticipantExtension (org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension)2 IFile (org.eclipse.core.resources.IFile)2