use of org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor 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.ui.texteditor.spelling.SpellingEngineDescriptor 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.ui.texteditor.spelling.SpellingEngineDescriptor in project eclipse.platform.text by eclipse.
the class SpellingEngineRegistry method reloadExtensions.
/**
* Reads all extensions.
* <p>
* This method can be called more than once in order to reload
* from a changed extension registry.
* </p>
*/
public synchronized void reloadExtensions() {
List<SpellingEngineDescriptor> descriptors = new ArrayList<>();
fDescriptorsMap = new HashMap<>();
fDefaultDescriptor = null;
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TextEditorPlugin.PLUGIN_ID, SPELLING_ENGINE_EXTENSION_POINT);
for (int i = 0; i < elements.length; i++) {
SpellingEngineDescriptor descriptor = new SpellingEngineDescriptor(elements[i]);
descriptors.add(descriptor);
fDescriptorsMap.put(descriptor.getId(), descriptor);
if (fDefaultDescriptor == null && descriptor.isDefault())
fDefaultDescriptor = descriptor;
}
fDescriptors = descriptors.toArray(new SpellingEngineDescriptor[descriptors.size()]);
fLoaded = true;
if (fDefaultDescriptor == null && fDescriptors.length > 0)
fDefaultDescriptor = fDescriptors[0];
}
use of org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor in project eclipse.platform.text by eclipse.
the class SpellingConfigurationBlock method updateListDependencies.
void updateListDependencies() {
SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
String id;
if (desc == null) {
// safety in case there is no such descriptor
// $NON-NLS-1$
id = "";
String message = TextEditorMessages.SpellingConfigurationBlock_error_not_exist;
EditorsPlugin.log(new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, IStatus.OK, message, null));
fCurrentBlock = new ErrorPreferences(message);
} else {
id = desc.getId();
fCurrentBlock = fProviderPreferences.get(id);
if (fCurrentBlock == null) {
try {
fCurrentBlock = desc.createPreferences();
fProviderPreferences.put(id, fCurrentBlock);
} catch (CoreException e) {
EditorsPlugin.log(e);
fCurrentBlock = new ErrorPreferences(e.getLocalizedMessage());
}
}
}
Control control = fProviderControls.get(id);
if (control == null) {
final Control[] result = new Control[1];
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void run() throws Exception {
result[0] = fCurrentBlock.createControl(fGroup);
}
@Override
public void handleException(Throwable x) {
}
};
SafeRunner.run(runnable);
control = result[0];
if (control == null) {
String message = TextEditorMessages.SpellingConfigurationBlock_info_no_preferences;
EditorsPlugin.log(new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, IStatus.OK, message, null));
control = new ErrorPreferences(message).createControl(fGroup);
} else {
fProviderControls.put(id, control);
}
}
Dialog.applyDialogFont(control);
fStackLayout.topControl = control;
control.pack();
fGroup.layout();
fGroup.getParent().layout();
fStatusMonitor.statusChanged(new StatusInfo());
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void run() throws Exception {
fCurrentBlock.initialize(fStatusMonitor);
}
@Override
public void handleException(Throwable x) {
}
};
SafeRunner.run(runnable);
}
use of org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor in project eclipse.platform.text by eclipse.
the class SpellingConfigurationBlock method restoreFromPreferences.
private void restoreFromPreferences() {
if (fEnablementCheckbox == null)
return;
boolean enabled = fStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED);
fEnablementCheckbox.setSelection(enabled);
if (fProviderViewer == null)
updateListDependencies();
else {
SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
if (desc != null)
fProviderViewer.setSelection(new StructuredSelection(desc), true);
}
updateCheckboxDependencies();
}
Aggregations