Search in sources :

Example 16 with ISafeRunnable

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

the class SpellingConfigurationBlock method createProviderViewer.

private ComboViewer createProviderViewer() {
    /* list viewer */
    final ComboViewer viewer = new ComboViewer(fProviderCombo);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer v, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fProviderDescriptors.values().toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            return ((SpellingEngineDescriptor) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty())
                return;
            if (fCurrentBlock != null && fStatusMonitor.getStatus() != null && fStatusMonitor.getStatus().matches(IStatus.ERROR))
                if (isPerformRevert()) {
                    ISafeRunnable runnable = new ISafeRunnable() {

                        @Override
                        public void run() throws Exception {
                            fCurrentBlock.performRevert();
                        }

                        @Override
                        public void handleException(Throwable x) {
                        }
                    };
                    SafeRunner.run(runnable);
                } else {
                    revertSelection();
                    return;
                }
            fStore.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, ((SpellingEngineDescriptor) sel.getFirstElement()).getId());
            updateListDependencies();
        }

        private boolean isPerformRevert() {
            Shell shell = viewer.getControl().getShell();
            MessageDialog dialog = new MessageDialog(shell, TextEditorMessages.SpellingConfigurationBlock_error_title, null, TextEditorMessages.SpellingConfigurationBlock_error_message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
            return dialog.open() == 0;
        }

        private void revertSelection() {
            try {
                viewer.removeSelectionChangedListener(this);
                SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
                if (desc != null)
                    viewer.setSelection(new StructuredSelection(desc), true);
            } finally {
                viewer.addSelectionChangedListener(this);
            }
        }
    });
    viewer.setInput(fProviderDescriptors);
    viewer.refresh();
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) Shell(org.eclipse.swt.widgets.Shell) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 17 with ISafeRunnable

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

the class SpellingConfigurationBlock method performOk.

@Override
public void performOk() {
    for (Iterator<ISpellingPreferenceBlock> it = fProviderPreferences.values().iterator(); it.hasNext(); ) {
        final ISpellingPreferenceBlock block = it.next();
        ISafeRunnable runnable = new ISafeRunnable() {

            @Override
            public void run() throws Exception {
                block.performOk();
            }

            @Override
            public void handleException(Throwable x) {
            }
        };
        SafeRunner.run(runnable);
    }
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ISpellingPreferenceBlock(org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)

Example 18 with ISafeRunnable

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

the class SpellingConfigurationBlock method updateCheckboxDependencies.

private void updateCheckboxDependencies() {
    final boolean enabled = fEnablementCheckbox.getSelection();
    if (fComboGroup != null)
        setEnabled(fComboGroup, enabled);
    SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
    // $NON-NLS-1$
    String id = desc != null ? desc.getId() : "";
    final ISpellingPreferenceBlock preferenceBlock = fProviderPreferences.get(id);
    if (preferenceBlock != null) {
        ISafeRunnable runnable = new ISafeRunnable() {

            @Override
            public void run() throws Exception {
                preferenceBlock.setEnabled(enabled);
            }

            @Override
            public void handleException(Throwable x) {
            }
        };
        SafeRunner.run(runnable);
    }
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) ISpellingPreferenceBlock(org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)

Example 19 with ISafeRunnable

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

the class ResourceTextFileBufferManager method createEmptyDocumentFromFactory.

/**
 * Helper to get rid of deprecation warnings.
 *
 * @param file the file
 * @return the created empty document or <code>null</code> if none got created
 * @since 3.5
 * @deprecated As of 3.5
 */
@Deprecated
private IDocument createEmptyDocumentFromFactory(final IFile file) {
    final IDocument[] runnableResult = new IDocument[1];
    final org.eclipse.core.filebuffers.IDocumentFactory factory = ((ResourceExtensionRegistry) fRegistry).getDocumentFactory(file);
    if (factory != null) {
        ISafeRunnable runnable = new ISafeRunnable() {

            @Override
            public void run() throws Exception {
                runnableResult[0] = factory.createDocument();
            }

            @Override
            public void handleException(Throwable t) {
                IStatus status = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.TextFileBufferManager_error_documentFactoryFailed, t);
                FileBuffersPlugin.getDefault().getLog().log(status);
            }
        };
        SafeRunner.run(runnable);
    }
    return runnableResult[0];
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IDocument(org.eclipse.jface.text.IDocument)

Example 20 with ISafeRunnable

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

the class CompositeChange method perform.

/**
	 * {@inheritDoc}
	 * <p>
	 * The composite change sends <code>perform</code> to all its <em>enabled</em>
	 * children. If one of the children throws an exception the remaining children
	 * will not receive the <code>perform</code> call. In this case the method <code>
	 * getUndoUntilException</code> can be used to get an undo object containing the
	 * undo objects of all executed children.
	 * </p>
	 * <p>
	 * Client are allowed to extend this method.
	 * </p>
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    fUndoUntilException = null;
    List undos = new ArrayList(fChanges.size());
    //$NON-NLS-1$
    pm.beginTask("", fChanges.size());
    pm.setTaskName(RefactoringCoreMessages.CompositeChange_performingChangesTask_name);
    Change change = null;
    boolean canceled = false;
    try {
        for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) {
            change = (Change) iter.next();
            if (canceled && !internalProcessOnCancel(change))
                continue;
            if (change.isEnabled()) {
                Change undoChange = null;
                try {
                    undoChange = change.perform(new SubProgressMonitor(pm, 1));
                } catch (OperationCanceledException e) {
                    canceled = true;
                    if (!internalContinueOnCancel())
                        throw e;
                    undos = null;
                }
                if (undos != null) {
                    if (undoChange == null) {
                        undos = null;
                    } else {
                        undos.add(undoChange);
                    }
                }
            }
            // remove the change from the list of children to give
            // the garbage collector the change to collect the change. This
            // ensures that the memory consumption doesn't go up when
            // producing the undo change tree.
            iter.remove();
            // Make sure we dispose the change since it will now longer be
            // in the list of children when call CompositeChange#dispose()
            final Change changeToDispose = change;
            SafeRunner.run(new ISafeRunnable() {

                public void run() throws Exception {
                    changeToDispose.dispose();
                }

                public void handleException(Throwable exception) {
                    RefactoringCorePlugin.log(exception);
                }
            });
        }
        if (canceled)
            throw new OperationCanceledException();
        if (undos != null) {
            Collections.reverse(undos);
            return createUndoChange((Change[]) undos.toArray(new Change[undos.size()]));
        } else {
            return null;
        }
    } catch (CoreException e) {
        handleUndos(change, undos);
        internalHandleException(change, e);
        throw e;
    } catch (RuntimeException e) {
        handleUndos(change, undos);
        internalHandleException(change, e);
        throw e;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ArrayList(java.util.ArrayList) List(java.util.List) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

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