diff --git a/plugins/org.jkiss.dbeaver.core/plugin.xml b/plugins/org.jkiss.dbeaver.core/plugin.xml index fdd0388f47149b791dcdf76f773b33a5ee60e0c4..39be91eea176a6d1f027247c43a6ffdbea94099f 100644 --- a/plugins/org.jkiss.dbeaver.core/plugin.xml +++ b/plugins/org.jkiss.dbeaver.core/plugin.xml @@ -3302,7 +3302,7 @@ - + diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/BaseFormatterConfigurationPage.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/BaseFormatterConfigurationPage.java index b885fcf4159f15fd7d1138dfc3d4682048c9fb54..21d2d360ea551e9a2f4d3668b4aa464559c30bd1 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/BaseFormatterConfigurationPage.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/BaseFormatterConfigurationPage.java @@ -17,6 +17,7 @@ package org.jkiss.dbeaver.ui.editors.sql.format; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.layout.GridLayout; @@ -44,7 +45,7 @@ public abstract class BaseFormatterConfigurationPage extends ActiveWizardPage im public final void createControl(Composite parent) { setTitle("SQL Format Configuration"); setDescription(getWizard().getFormaterName()); - Composite composite = createFormatSettings(parent); + Composite composite = createFormatSettings(parent, getWizard().getConfiguration()); @@ -56,7 +57,9 @@ public abstract class BaseFormatterConfigurationPage extends ActiveWizardPage im return (ConfigWizard)super.getWizard(); } - protected abstract Composite createFormatSettings(Composite parent); + protected abstract Composite createFormatSettings(Composite parent, SQLFormatterConfiguration configuration); + + protected abstract void saveFormatSettings(SQLFormatterConfiguration configuration); @Override public boolean configure(String formatName, SQLFormatter formatter, SQLFormatterConfiguration configuration) { @@ -89,6 +92,11 @@ public abstract class BaseFormatterConfigurationPage extends ActiveWizardPage im @Override public boolean performFinish() { + for (IWizardPage page : getPages()) { + if (page instanceof BaseFormatterConfigurationPage) { + ((BaseFormatterConfigurationPage) page).saveFormatSettings(this.configuration); + } + } return true; } diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/ConfigurationPage.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/ConfigurationPage.java deleted file mode 100644 index 354bd8d612b2cecc490fed1bd3d30f8764b00e97..0000000000000000000000000000000000000000 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/ConfigurationPage.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * DBeaver - Universal Database Manager - * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jkiss.dbeaver.ui.editors.sql.format.tokenized; - -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Spinner; -import org.jkiss.dbeaver.ui.UIUtils; -import org.jkiss.dbeaver.ui.editors.sql.format.BaseFormatterConfigurationPage; - -public class ConfigurationPage extends BaseFormatterConfigurationPage { - - - @Override - protected Composite createFormatSettings(Composite parent) { - Group settings = UIUtils.createControlGroup(parent, "Settings", 2, GridData.FILL_HORIZONTAL, 0); - - Button useSpaces = UIUtils.createCheckbox(settings, "Insert spaces for tabs", "Insert spaces for tabs", false, 2); - Spinner indentSize = UIUtils.createLabelSpinner(settings, "Indent size", "Insert spaces for tabs", 4, 0, 100); - - return parent; - } -} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/SQLTokenizedConfigurationPage.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/SQLTokenizedConfigurationPage.java new file mode 100644 index 0000000000000000000000000000000000000000..1eea5da5eea595431455c72589ae86cf0469e946 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/format/tokenized/SQLTokenizedConfigurationPage.java @@ -0,0 +1,77 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.ui.editors.sql.format.tokenized; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; +import org.jkiss.dbeaver.core.CoreMessages; +import org.jkiss.dbeaver.model.DBPIdentifierCase; +import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration; +import org.jkiss.dbeaver.ui.UIUtils; +import org.jkiss.dbeaver.ui.editors.sql.format.BaseFormatterConfigurationPage; + +public class SQLTokenizedConfigurationPage extends BaseFormatterConfigurationPage { + + private Spinner indentSizeSpinner; + private Button useSpacesCheck; + private Button compactFormatCheck; + private Combo keywordCaseCombo; + + @Override + protected Composite createFormatSettings(Composite parent, SQLFormatterConfiguration configuration) { + Group settings = UIUtils.createControlGroup(parent, "Settings", 2, GridData.FILL_HORIZONTAL, 0); + + keywordCaseCombo = UIUtils.createLabelCombo(settings, CoreMessages.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())); + } + DBPIdentifierCase keywordCase = configuration.getKeywordCase(); + if (keywordCase == null) { + keywordCaseCombo.select(0); + } else { + UIUtils.setComboSelection( + keywordCaseCombo, + DBPIdentifierCase.capitalizeCaseName(keywordCase.name())); + } + + IPreferenceStore preferenceStore = getPreferenceStore(); + boolean useSpaces = preferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS); + int tabWidth = preferenceStore .getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH); + + this.indentSizeSpinner = UIUtils.createLabelSpinner(settings, "Indent size", "Insert spaces for tabs", tabWidth, 0, 100); + this.useSpacesCheck = UIUtils.createCheckbox(settings, "Insert spaces for tabs", "Insert spaces for tabs", useSpaces, 2); + this.compactFormatCheck = UIUtils.createCheckbox(settings, "Compact formatting", "Compact formatting. Less line feeds and indentation", false, 2); + + return parent; + } + + @Override + protected void saveFormatSettings(SQLFormatterConfiguration configuration) { + // Save formatter settings + } + + private IPreferenceStore getPreferenceStore() { + return EditorsPlugin.getDefault().getPreferenceStore(); + } + +} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java index 60db32c3cbc7e797a2c8db0533a88f11e38806d1..440e911b91aea63003c0c5586fcd66ccc50b1cad 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java @@ -57,9 +57,8 @@ public class SQLFormattingStrategy extends ContextBasedFormattingStrategy SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(sqlSyntax); configuration.setIndentString(indentPrefixes[0]); - SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createAndConfigureFormatter(configuration); + SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createFormatter(configuration); if (formatter == null) { - //DBeaverUI.getInstance().showError("SQL Format", "Can't create SQL formatter. See error log."); return content; } return formatter.format(content, configuration); diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java index bed6008794e4a069d41b9ea4bd0e8851a660e008..d2aa671a8c8ba085041a92cd652eb3493110c619 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java @@ -153,7 +153,7 @@ public class PrefPageSQLFormat extends TargetPrefPage formatterSelector = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY); formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters(); for (SQLFormatterDescriptor formatterDesc : formatters) { - formatterSelector.add(capitalizeCaseName(formatterDesc.getLabel())); + formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel())); } formatterSelector.addSelectionListener(new SelectionAdapter() { @Override @@ -172,7 +172,7 @@ public class PrefPageSQLFormat extends TargetPrefPage keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); keywordCaseCombo.add("Database"); for (DBPIdentifierCase c :DBPIdentifierCase.values()) { - keywordCaseCombo.add(capitalizeCaseName(c.name())); + keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name())); } keywordCaseCombo.addSelectionListener(new SelectionAdapter() { @Override @@ -277,7 +277,7 @@ public class PrefPageSQLFormat extends TargetPrefPage if (CommonUtils.isEmpty(caseName)) { keywordCaseCombo.select(0); } else { - UIUtils.setComboSelection(keywordCaseCombo, capitalizeCaseName(caseName)); + UIUtils.setComboSelection(keywordCaseCombo, DBPIdentifierCase.capitalizeCaseName(caseName)); } externalCmdText.setText(store.getString(ModelPreferences.SQL_FORMAT_EXTERNAL_CMD)); @@ -352,10 +352,6 @@ public class PrefPageSQLFormat extends TargetPrefPage defaultGroup.getParent().layout(); } - private static String capitalizeCaseName(String name) { - return CommonUtils.capitalizeWord(name.toLowerCase(Locale.ENGLISH)); - } - private void formatSQL() { try { try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) { diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBPIdentifierCase.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBPIdentifierCase.java index cb50ea5afa9e533d8605552bf493148c1d7e692b..c2b7d15b40b77d279adaa94a0b857d5c7dbccdae 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBPIdentifierCase.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBPIdentifierCase.java @@ -17,6 +17,8 @@ package org.jkiss.dbeaver.model; +import org.jkiss.utils.CommonUtils; + import java.util.Locale; /** @@ -45,6 +47,10 @@ public enum DBPIdentifierCase { } }; + public static String capitalizeCaseName(String name) { + return CommonUtils.capitalizeWord(name.toLowerCase(Locale.ENGLISH)); + } + public abstract String transform(String value); } diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java index 071d462a1fce3e3bec149b70b5354a1139515369..ee93e6c45dbdc98b19dafd107640786fd6ff7bfb 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java @@ -46,12 +46,20 @@ public class SQLFormatterConfiguration { private Map properties = new HashMap<>(); + /** + * Create formatter config with default (set in properties) formatter + */ public SQLFormatterConfiguration(SQLSyntaxManager syntaxManager) + { + this(syntaxManager, CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(ModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH)); + } + + public SQLFormatterConfiguration(SQLSyntaxManager syntaxManager, String formatterId) { this.syntaxManager = syntaxManager; this.keywordCase = syntaxManager.getKeywordCase(); - this.formatterId = CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(ModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH); + this.formatterId = formatterId; } public SQLSyntaxManager getSyntaxManager() @@ -113,4 +121,13 @@ public class SQLFormatterConfiguration { public DBPPreferenceStore getPreferenceStore() { return syntaxManager.getPreferenceStore(); } + + public void loadSettings() { + + } + + public void saveSettings() { + + } + }