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