Search in sources :

Example 6 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project eclipse.platform.text by eclipse.

the class SourceViewerDecorationSupport method install.

/**
 * Installs this decoration support on the given preference store. It assumes
 * that this support has completely been configured.
 *
 * @param store the preference store
 */
public void install(IPreferenceStore store) {
    fPreferenceStore = store;
    if (fPreferenceStore != null) {
        fPropertyChangeListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                handlePreferenceStoreChanged(event);
            }
        };
        fPreferenceStore.addPropertyChangeListener(fPropertyChangeListener);
    }
    updateTextDecorations();
    updateOverviewDecorations();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent)

Example 7 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project eclipse.platform.text by eclipse.

the class LineNumberColumn method initialize.

/**
 * Initializes the given line number ruler column from the preference store.
 */
private void initialize() {
    final IPreferenceStore store = getPreferenceStore();
    if (store == null)
        return;
    // initial set up
    updateForegroundColor(store, fDelegate);
    updateBackgroundColor(store, fDelegate);
    updateLineNumbersVisibility(fDelegate);
    updateQuickDiffVisibility(fDelegate);
    updateCharacterMode(store, fDelegate);
    updateRevisionRenderingMode(store, fDelegate);
    updateRevisionAuthorVisibility(store, fDelegate);
    updateRevisionIdVisibility(store, fDelegate);
    Map<Object, AnnotationPreference> annotationPrefs = getAnnotationPreferenceMap();
    // $NON-NLS-1$
    final AnnotationPreference changedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffChange");
    // $NON-NLS-1$
    final AnnotationPreference addedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffAddition");
    // $NON-NLS-1$
    final AnnotationPreference deletedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffDeletion");
    updateChangedColor(changedPref, store, fDelegate);
    updateAddedColor(addedPref, store, fDelegate);
    updateDeletedColor(deletedPref, store, fDelegate);
    fDelegate.redraw();
    // listen to changes
    fDispatcher = new PropertyEventDispatcher(store);
    fDispatcher.addPropertyChangeListener(FG_COLOR_KEY, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateForegroundColor(store, fDelegate);
            fDelegate.redraw();
        }
    });
    IPropertyChangeListener backgroundHandler = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateBackgroundColor(store, fDelegate);
            fDelegate.redraw();
        }
    };
    fDispatcher.addPropertyChangeListener(BG_COLOR_KEY, backgroundHandler);
    fDispatcher.addPropertyChangeListener(USE_DEFAULT_BG_KEY, backgroundHandler);
    fDispatcher.addPropertyChangeListener(LINE_NUMBER_KEY, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // only handle quick diff on/off information, but not ruler visibility (handled by AbstractDecoratedTextEditor)
            updateLineNumbersVisibility(fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateCharacterMode(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionRenderingMode(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_AUTHOR, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionAuthorVisibility(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_REVISION, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionIdVisibility(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateQuickDiffVisibility(fDelegate);
        }
    });
    if (changedPref != null) {
        fDispatcher.addPropertyChangeListener(changedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateChangedColor(changedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
    if (addedPref != null) {
        fDispatcher.addPropertyChangeListener(addedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateAddedColor(addedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
    if (deletedPref != null) {
        fDispatcher.addPropertyChangeListener(deletedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateDeletedColor(deletedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Example 8 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project knime-core by knime.

the class BorderStyleDialog method createColorSelector.

private void createColorSelector(final Composite parent) {
    Composite panel = new Composite(parent, SWT.FILL);
    GridData gData = new GridData(GridData.FILL_HORIZONTAL);
    panel.setLayoutData(gData);
    panel.setLayout(new GridLayout(2, false));
    Label msg = new Label(panel, SWT.LEFT);
    msg.setText("Border color (click to change):");
    msg.setLayoutData(gData);
    final ColorSelector sel = new ColorSelector(panel);
    sel.setColorValue(m_defColor.getRGB());
    sel.addListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            m_color = sel.getColorValue();
        }
    });
    m_color = m_defColor.getRGB();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridLayout(org.eclipse.swt.layout.GridLayout) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) ColorSelector(org.eclipse.jface.preference.ColorSelector)

Example 9 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project mylyn.docs by eclipse.

the class WikiTextUiPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    preferencesListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            preferences = null;
        }
    };
    getPreferenceStore().addPropertyChangeListener(preferencesListener);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent)

Example 10 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project mylyn.docs by eclipse.

the class MarkupEditor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
    sourceViewerConfiguration.initializeDefaultFonts();
    tabFolder = new CTabFolder(parent, SWT.BOTTOM);
    {
        sourceTab = new CTabItem(tabFolder, SWT.NONE);
        updateSourceTabLabel();
        viewer = new MarkupProjectionViewer(tabFolder, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles | SWT.WRAP);
        sourceTab.setControl(((Viewer) viewer).getControl());
        tabFolder.setSelection(sourceTab);
    }
    try {
        previewTab = new CTabItem(tabFolder, SWT.NONE);
        previewTab.setText(Messages.MarkupEditor_preview);
        previewTab.setToolTipText(Messages.MarkupEditor_preview_tooltip);
        browser = new Browser(tabFolder, SWT.NONE);
        // bug 260479: open hyperlinks in a browser
        browser.addLocationListener(new LocationListener() {

            public void changed(LocationEvent event) {
                event.doit = false;
            }

            public void changing(LocationEvent event) {
                // if it looks like an absolute URL
                if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
                    // $NON-NLS-1$
                    // workaround for browser problem (bug 262043)
                    // $NON-NLS-1$
                    int idxOfSlashHash = event.location.indexOf("/#");
                    if (idxOfSlashHash != -1) {
                        // allow javascript-based scrolling to work
                        if (!event.location.startsWith("file:///#")) {
                            // $NON-NLS-1$
                            event.doit = false;
                        }
                        return;
                    }
                    // workaround end
                    event.doit = false;
                    try {
                        PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
                        "org.eclipse.ui.browser").openURL(new URL(event.location));
                    } catch (Exception e) {
                        new URLHyperlink(new Region(0, 1), event.location).open();
                    }
                }
            }
        });
        previewTab.setControl(browser);
    } catch (SWTError e) {
        // disable preview, the exception is probably due to the internal browser not being available
        if (previewTab != null) {
            previewTab.dispose();
            previewTab = null;
        }
        logPreviewTabUnavailable(e);
    }
    tabFolder.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent selectionevent) {
            widgetSelected(selectionevent);
        }

        public void widgetSelected(SelectionEvent selectionevent) {
            if (isShowingPreview()) {
                updatePreview();
            }
        }
    });
    viewer.getTextWidget().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            updateOutlineSelection();
        }
    });
    viewer.getTextWidget().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (isRelevantKeyCode(e.keyCode)) {
                updateOutlineSelection();
            }
        }

        private boolean isRelevantKeyCode(int keyCode) {
            // for some reason not all key presses result in a selection change
            switch(keyCode) {
                case SWT.ARROW_DOWN:
                case SWT.ARROW_LEFT:
                case SWT.ARROW_RIGHT:
                case SWT.ARROW_UP:
                case SWT.PAGE_DOWN:
                case SWT.PAGE_UP:
                    return true;
            }
            return false;
        }
    });
    viewer.getTextWidget().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            updateOutlineSelection();
        }
    });
    IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
    if (focusService != null) {
        focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
    }
    viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
    viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
    getSourceViewerDecorationSupport(viewer);
    updateDocument();
    if (preferencesListener == null) {
        preferencesListener = new IPropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
                    return;
                }
                if (isFontPreferenceChange(event)) {
                    viewer.getTextWidget().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            reloadPreferences();
                        }
                    });
                }
            }
        };
        WikiTextUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferencesListener);
    }
    return viewer;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Viewer(org.eclipse.jface.viewers.Viewer) IFocusService(org.eclipse.ui.swt.IFocusService) CTabItem(org.eclipse.swt.custom.CTabItem) URL(java.net.URL) KeyEvent(org.eclipse.swt.events.KeyEvent) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) LocationListener(org.eclipse.swt.browser.LocationListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) SWTError(org.eclipse.swt.SWTError) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SWTException(org.eclipse.swt.SWTException) Point(org.eclipse.swt.graphics.Point) Region(org.eclipse.jface.text.Region) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Browser(org.eclipse.swt.browser.Browser) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)126 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)120 Composite (org.eclipse.swt.widgets.Composite)55 GridData (org.eclipse.swt.layout.GridData)44 Label (org.eclipse.swt.widgets.Label)39 GridLayout (org.eclipse.swt.layout.GridLayout)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)31 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 Button (org.eclipse.swt.widgets.Button)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)21 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)20 ColorSelector (org.eclipse.jface.preference.ColorSelector)14 ComboViewer (org.eclipse.jface.viewers.ComboViewer)12 Text (org.eclipse.swt.widgets.Text)11 Iterator (java.util.Iterator)10 ISelection (org.eclipse.jface.viewers.ISelection)10 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)10 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 SashForm (org.eclipse.swt.custom.SashForm)9