use of org.jkiss.dbeaver.model.DBPIdentifierCase in project dbeaver by serge-rider.
the class PrefPageSQLFormat method createPreferenceContent.
@Override
protected Control createPreferenceContent(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 3, 5);
formatterSelector = UIUtils.createLabelCombo(composite, SQLEditorMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
formatters.sort(Comparator.comparing(SQLFormatterDescriptor::getLabel));
for (SQLFormatterDescriptor formatterDesc : formatters) {
formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel()));
}
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showFormatterSettings();
performApply();
}
});
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatCurrentQueryCheck = UIUtils.createCheckbox(composite, "Format active query only", "Formats only active query or selected text. Otherwise formats entire SQL script", true, 1);
Composite formatterGroup = UIUtils.createPlaceholder(composite, 1, 5);
formatterGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
((GridData) formatterGroup.getLayoutData()).horizontalSpan = 3;
/*
{
Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 4, 5);
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
keywordCaseCombo = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Database");
for (DBPIdentifierCase c :DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
*/
// External formatter
{
formatterConfigPlaceholder = UIUtils.createPlaceholder(formatterGroup, 2, 5);
formatterConfigPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
formatterConfigPlaceholder.setLayout(new FillLayout());
}
{
// SQL preview
Composite previewGroup = new Composite(composite, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
previewGroup.setLayoutData(gd);
previewGroup.setLayout(new FillLayout());
sqlViewer = new SQLEditorBase() {
@Override
public DBCExecutionContext getExecutionContext() {
final DBPDataSourceContainer container = getDataSourceContainer();
if (container != null) {
final DBPDataSource dataSource = container.getDataSource();
if (dataSource != null) {
return DBUtils.getDefaultContext(dataSource.getDefaultInstance(), false);
}
}
return null;
}
};
try {
try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
final String sqlText = ContentUtils.readToString(sqlStream, StandardCharsets.UTF_8);
IEditorSite subSite = new SubEditorSite(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
}
} catch (Exception e) {
log.error(e);
}
sqlViewer.createPartControl(previewGroup);
Object text = sqlViewer.getAdapter(Control.class);
if (text instanceof StyledText) {
((StyledText) text).setWordWrap(true);
}
sqlViewer.reloadSyntaxRules();
previewGroup.addDisposeListener(e -> sqlViewer.dispose());
{
// Styles
// Composite afGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_style, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
// ((GridData)afGroup.getLayoutData()).horizontalSpan = 2;
styleBoldKeywords = UIUtils.createCheckbox(composite, SQLEditorMessages.pref_page_sql_format_label_bold_keywords, SQLEditorMessages.pref_page_sql_format_label_bold_keywords_tip, false, 2);
styleBoldKeywords.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
}
return composite;
}
use of org.jkiss.dbeaver.model.DBPIdentifierCase in project dbeaver by serge-rider.
the class SQLTokenizedFormatterConfigurationPage method createFormatSettings.
@Override
protected Composite createFormatSettings(Composite parent) {
Group settings = UIUtils.createControlGroup(parent, SQLEditorMessages.pref_page_sql_format_label_settings, 4, GridData.FILL_HORIZONTAL, 0);
SelectionListener selectListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changeListener.run();
}
};
keywordCaseCombo = UIUtils.createLabelCombo(settings, SQLEditorMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Default");
for (DBPIdentifierCase c : DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(selectListener);
this.indentSizeSpinner = UIUtils.createLabelSpinner(settings, SQLEditorMessages.pref_page_sql_format_label_indent_size, SQLEditorMessages.pref_page_sql_format_label_indent_size, 4, 0, 100);
indentSizeSpinner.addSelectionListener(selectListener);
this.useSpacesCheck = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_spaces_for_tabs, SQLEditorMessages.pref_page_sql_format_label_insert_spaces_for_tabs, true, 2);
useSpacesCheck.addSelectionListener(selectListener);
this.lineFeedBeforeCommaCheck = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_line_feed_before_commas, SQLEditorMessages.pref_page_sql_format_label_insert_line_feed_before_commas, true, 2);
lineFeedBeforeCommaCheck.addSelectionListener(selectListener);
this.breakLineBeforeCloseBracket = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_add_line_feed_before_close_bracket, SQLEditorMessages.pref_page_sql_format_label_add_line_feed_before_close_bracket, true, 2);
breakLineBeforeCloseBracket.addSelectionListener(selectListener);
this.insertDelimiterInEmptyLines = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_delimiters_in_empty_lines, SQLEditorMessages.pref_page_sql_format_tip_insert_delimiters_in_empty_lines, true, 2);
insertDelimiterInEmptyLines.addSelectionListener(selectListener);
return parent;
}
use of org.jkiss.dbeaver.model.DBPIdentifierCase in project dbeaver by dbeaver.
the class PrefPageSQLFormat method createPreferenceContent.
@Override
protected Control createPreferenceContent(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 3, 5);
formatterSelector = UIUtils.createLabelCombo(composite, SQLEditorMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
formatters.sort(Comparator.comparing(SQLFormatterDescriptor::getLabel));
for (SQLFormatterDescriptor formatterDesc : formatters) {
formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel()));
}
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showFormatterSettings();
performApply();
}
});
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
formatCurrentQueryCheck = UIUtils.createCheckbox(composite, "Format active query only", "Formats only active query or selected text. Otherwise formats entire SQL script", true, 1);
Composite formatterGroup = UIUtils.createPlaceholder(composite, 1, 5);
formatterGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
((GridData) formatterGroup.getLayoutData()).horizontalSpan = 3;
/*
{
Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 4, 5);
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
keywordCaseCombo = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Database");
for (DBPIdentifierCase c :DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
*/
// External formatter
{
formatterConfigPlaceholder = UIUtils.createPlaceholder(formatterGroup, 2, 5);
formatterConfigPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
formatterConfigPlaceholder.setLayout(new FillLayout());
}
{
// SQL preview
Composite previewGroup = new Composite(composite, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
previewGroup.setLayoutData(gd);
previewGroup.setLayout(new FillLayout());
sqlViewer = new SQLEditorBase() {
@Override
public DBCExecutionContext getExecutionContext() {
final DBPDataSourceContainer container = getDataSourceContainer();
if (container != null) {
final DBPDataSource dataSource = container.getDataSource();
if (dataSource != null) {
return DBUtils.getDefaultContext(dataSource.getDefaultInstance(), false);
}
}
return null;
}
};
try {
try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
final String sqlText = ContentUtils.readToString(sqlStream, StandardCharsets.UTF_8);
IEditorSite subSite = new SubEditorSite(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
}
} catch (Exception e) {
log.error(e);
}
sqlViewer.createPartControl(previewGroup);
Object text = sqlViewer.getAdapter(Control.class);
if (text instanceof StyledText) {
((StyledText) text).setWordWrap(true);
}
sqlViewer.reloadSyntaxRules();
previewGroup.addDisposeListener(e -> sqlViewer.dispose());
{
// Styles
// Composite afGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_style, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
// ((GridData)afGroup.getLayoutData()).horizontalSpan = 2;
styleBoldKeywords = UIUtils.createCheckbox(composite, SQLEditorMessages.pref_page_sql_format_label_bold_keywords, SQLEditorMessages.pref_page_sql_format_label_bold_keywords_tip, false, 2);
styleBoldKeywords.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
}
return composite;
}
use of org.jkiss.dbeaver.model.DBPIdentifierCase in project dbeaver by dbeaver.
the class SQLTokenizedFormatterConfigurationPage method createFormatSettings.
@Override
protected Composite createFormatSettings(Composite parent) {
Group settings = UIUtils.createControlGroup(parent, SQLEditorMessages.pref_page_sql_format_label_settings, 4, GridData.FILL_HORIZONTAL, 0);
SelectionListener selectListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changeListener.run();
}
};
keywordCaseCombo = UIUtils.createLabelCombo(settings, SQLEditorMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Default");
for (DBPIdentifierCase c : DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(selectListener);
this.indentSizeSpinner = UIUtils.createLabelSpinner(settings, SQLEditorMessages.pref_page_sql_format_label_indent_size, SQLEditorMessages.pref_page_sql_format_label_indent_size, 4, 0, 100);
indentSizeSpinner.addSelectionListener(selectListener);
this.useSpacesCheck = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_spaces_for_tabs, SQLEditorMessages.pref_page_sql_format_label_insert_spaces_for_tabs, true, 2);
useSpacesCheck.addSelectionListener(selectListener);
this.lineFeedBeforeCommaCheck = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_line_feed_before_commas, SQLEditorMessages.pref_page_sql_format_label_insert_line_feed_before_commas, true, 2);
lineFeedBeforeCommaCheck.addSelectionListener(selectListener);
this.breakLineBeforeCloseBracket = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_add_line_feed_before_close_bracket, SQLEditorMessages.pref_page_sql_format_label_add_line_feed_before_close_bracket, true, 2);
breakLineBeforeCloseBracket.addSelectionListener(selectListener);
this.insertDelimiterInEmptyLines = UIUtils.createCheckbox(settings, SQLEditorMessages.pref_page_sql_format_label_insert_delimiters_in_empty_lines, SQLEditorMessages.pref_page_sql_format_tip_insert_delimiters_in_empty_lines, true, 2);
insertDelimiterInEmptyLines.addSelectionListener(selectListener);
return parent;
}
use of org.jkiss.dbeaver.model.DBPIdentifierCase in project dbeaver by dbeaver.
the class SQLTokenizedFormatterConfigurationPage method loadSettings.
@Override
public void loadSettings(DBPPreferenceStore preferenceStore) {
super.loadSettings(preferenceStore);
final String caseName = preferenceStore.getString(ModelPreferences.SQL_FORMAT_KEYWORD_CASE);
DBPIdentifierCase keywordCase = CommonUtils.isEmpty(caseName) ? null : DBPIdentifierCase.valueOf(caseName);
if (keywordCase == null) {
keywordCaseCombo.select(0);
} else {
UIUtils.setComboSelection(keywordCaseCombo, DBPIdentifierCase.capitalizeCaseName(keywordCase.name()));
}
lineFeedBeforeCommaCheck.setSelection(preferenceStore.getBoolean(ModelPreferences.SQL_FORMAT_LF_BEFORE_COMMA));
breakLineBeforeCloseBracket.setSelection(preferenceStore.getBoolean(ModelPreferences.SQL_FORMAT_BREAK_BEFORE_CLOSE_BRACKET));
insertDelimiterInEmptyLines.setSelection(preferenceStore.getBoolean(ModelPreferences.SQL_FORMAT_INSERT_DELIMITERS_IN_EMPTY_LINES));
{
// Text editor settings
IPreferenceStore textEditorPrefs = getTextEditorsPreferenceStore();
this.indentSizeSpinner.setSelection(textEditorPrefs.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));
useSpacesCheck.setSelection(textEditorPrefs.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS));
}
}
Aggregations