提交 3bffdcb4 编写于 作者: S serge-rider

#2130 SQL formatters config UI (revert)


Former-commit-id: 2e70b714
上级 0e345be6
......@@ -3302,7 +3302,7 @@
</extension>
<extension point="org.jkiss.dbeaver.sqlFormatter">
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.tokenized.ConfigurationPage" label="Default SQL formatter" description="Default tokenized SQL formatter"/>
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.tokenized.SQLTokenizedConfigurationPage" label="Default SQL formatter" description="Default tokenized SQL formatter"/>
<formatter id="external" class="org.jkiss.dbeaver.model.sql.format.external.SQLExternalFormatter" label="External formatter" description="External formatter. Uses configurable command-line executable to format SQL queries"/>
</extension>
......
......@@ -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;
}
......
/*
* 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;
}
}
/*
* 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();
}
}
......@@ -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);
......
......@@ -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)) {
......
......@@ -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);
}
......@@ -46,12 +46,20 @@ public class SQLFormatterConfiguration {
private Map<String, Object> 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() {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册