Search in sources :

Example 1 with SpellingEngineDescriptor

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;
}
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 2 with SpellingEngineDescriptor

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);
    }
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) ISpellingPreferenceBlock(org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)

Example 3 with SpellingEngineDescriptor

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];
}
Also used : ArrayList(java.util.ArrayList) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 4 with SpellingEngineDescriptor

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Control(org.eclipse.swt.widgets.Control) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)

Example 5 with SpellingEngineDescriptor

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();
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)

Aggregations

SpellingEngineDescriptor (org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)6 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ISpellingPreferenceBlock (org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)2 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 Image (org.eclipse.swt.graphics.Image)1 Control (org.eclipse.swt.widgets.Control)1 Shell (org.eclipse.swt.widgets.Shell)1