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;
}
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);
}
}
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);
}
}
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];
}
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;
}
}
Aggregations