Search in sources :

Example 11 with DBPPreferenceListener

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceListener in project dbeaver by dbeaver.

the class SQLEditorSourceViewerConfiguration method createContentAssistant.

@NotNull
private SQLContentAssistant createContentAssistant(ISourceViewer sourceViewer) {
    DBPPreferenceStore store = editor.getActivePreferenceStore();
    final DBPPreferenceStore configStore = store;
    final SQLContentAssistant assistant = new SQLContentAssistant();
    assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    // Set content assist processors for various content types.
    if (completionProcessor == null) {
        this.completionProcessor = new SQLCompletionProcessor(editor);
    }
    try {
        assistant.addContentAssistProcessor(completionProcessor, IDocument.DEFAULT_CONTENT_TYPE);
        assistant.addContentAssistProcessor(completionProcessor, SQLParserPartitions.CONTENT_TYPE_SQL_QUOTED);
    } catch (Throwable e) {
        // addContentAssistProcessor API was added in 4.12
        // Let's support older Eclipse versions
        assistant.setContentAssistProcessor(completionProcessor, IDocument.DEFAULT_CONTENT_TYPE);
    }
    // Configure how content assist information will appear.
    assistant.enableAutoActivation(store.getBoolean(SQLPreferenceConstants.ENABLE_AUTO_ACTIVATION));
    assistant.setAutoActivationDelay(store.getInt(SQLPreferenceConstants.AUTO_ACTIVATION_DELAY));
    assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
    assistant.setSorter(new SQLCompletionSorter());
    assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    // In the future, a preference page will be added to customize foreground and background.
    Color foreground = new Color(UIUtils.getDisplay(), 0, 0, 0);
    Color background = new Color(UIUtils.getDisplay(), 255, 255, 255);
    assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
    assistant.setContextInformationPopupForeground(foreground);
    assistant.setContextInformationPopupBackground(background);
    // Set auto insert mode.
    assistant.enableAutoInsert(store.getBoolean(SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO));
    assistant.setShowEmptyList(true);
    final DBPPreferenceListener prefListener = event -> {
        switch(event.getProperty()) {
            case SQLPreferenceConstants.ENABLE_AUTO_ACTIVATION:
                assistant.enableAutoActivation(configStore.getBoolean(SQLPreferenceConstants.ENABLE_AUTO_ACTIVATION));
                break;
            case SQLPreferenceConstants.AUTO_ACTIVATION_DELAY:
                assistant.setAutoActivationDelay(configStore.getInt(SQLPreferenceConstants.AUTO_ACTIVATION_DELAY));
                break;
            case SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO:
                assistant.enableAutoInsert(configStore.getBoolean(SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO));
                break;
        }
    };
    ((SQLCompletionProcessor) completionProcessor).initAssistant(assistant);
    configStore.addPropertyChangeListener(prefListener);
    editor.getTextViewer().getControl().addDisposeListener(e -> configStore.removePropertyChangeListener(prefListener));
    return assistant;
}
Also used : TextSourceViewerConfiguration(org.eclipse.ui.editors.text.TextSourceViewerConfiguration) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Token(org.eclipse.jface.text.rules.Token) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) SQLStringAutoIndentStrategy(org.jkiss.dbeaver.ui.editors.sql.indent.SQLStringAutoIndentStrategy) SQLConstants(org.jkiss.dbeaver.model.sql.SQLConstants) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) org.eclipse.jface.text(org.eclipse.jface.text) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Nullable(org.jkiss.code.Nullable) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) BufferedRuleBasedScanner(org.eclipse.jface.text.rules.BufferedRuleBasedScanner) NotNull(org.jkiss.code.NotNull) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) IInformationPresenter(org.eclipse.jface.text.information.IInformationPresenter) SQLAnnotationHover(org.jkiss.dbeaver.ui.editors.sql.util.SQLAnnotationHover) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) RGB(org.eclipse.swt.graphics.RGB) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) IContentFormatter(org.eclipse.jface.text.formatter.IContentFormatter) SQLParserPartitions(org.jkiss.dbeaver.model.sql.parser.SQLParserPartitions) IAnnotationHover(org.eclipse.jface.text.source.IAnnotationHover) InformationPresenter(org.eclipse.jface.text.information.InformationPresenter) IFormattingStrategy(org.eclipse.jface.text.formatter.IFormattingStrategy) org.eclipse.jface.text.hyperlink(org.eclipse.jface.text.hyperlink) ArrayUtils(org.jkiss.utils.ArrayUtils) IInformationProvider(org.eclipse.jface.text.information.IInformationProvider) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) Color(org.eclipse.swt.graphics.Color) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) SQLCommentAutoIndentStrategy(org.jkiss.dbeaver.ui.editors.sql.indent.SQLCommentAutoIndentStrategy) SQLAutoIndentStrategy(org.jkiss.dbeaver.ui.editors.sql.indent.SQLAutoIndentStrategy) org.jkiss.dbeaver.ui.editors.sql.syntax(org.jkiss.dbeaver.ui.editors.sql.syntax) Color(org.eclipse.swt.graphics.Color) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) NotNull(org.jkiss.code.NotNull)

Example 12 with DBPPreferenceListener

use of org.jkiss.dbeaver.model.preferences.DBPPreferenceListener in project dbeaver by dbeaver.

the class BinaryPanelEditor method createControl.

@Override
public HexEditControl createControl(IValueController valueController) {
    HexEditControl hControl = new HexEditControl(valueController.getEditPlaceholder(), SWT.BORDER);
    DBPPreferenceListener preferencesChangeListener = new DBPPreferenceListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (HexPreferencesPage.PROP_DEF_WIDTH.equals(event.getProperty())) {
                String defValue = (String) event.getNewValue();
                hControl.setDefWidth(Integer.valueOf(defValue));
            }
        }
    };
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.addPropertyChangeListener(preferencesChangeListener);
    return hControl;
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)

Aggregations

DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)12 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)9 Color (org.eclipse.swt.graphics.Color)4 HexEditControl (org.jkiss.dbeaver.ui.editors.binary.HexEditControl)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 org.eclipse.jface.text (org.eclipse.jface.text)2 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)2 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)2 IContentFormatter (org.eclipse.jface.text.formatter.IContentFormatter)2 IFormattingStrategy (org.eclipse.jface.text.formatter.IFormattingStrategy)2 org.eclipse.jface.text.hyperlink (org.eclipse.jface.text.hyperlink)2 IInformationPresenter (org.eclipse.jface.text.information.IInformationPresenter)2 IInformationProvider (org.eclipse.jface.text.information.IInformationProvider)2 InformationPresenter (org.eclipse.jface.text.information.InformationPresenter)2 IPresentationReconciler (org.eclipse.jface.text.presentation.IPresentationReconciler)2 PresentationReconciler (org.eclipse.jface.text.presentation.PresentationReconciler)2 IReconciler (org.eclipse.jface.text.reconciler.IReconciler)2 MonoReconciler (org.eclipse.jface.text.reconciler.MonoReconciler)2 BufferedRuleBasedScanner (org.eclipse.jface.text.rules.BufferedRuleBasedScanner)2 DefaultDamagerRepairer (org.eclipse.jface.text.rules.DefaultDamagerRepairer)2