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

#2130 SQL formatters model/registry


Former-commit-id: b57bc9e5
上级 7e12a18e
......@@ -12,6 +12,7 @@ extension-point.org.jkiss.dbeaver.dataTransfer.name = Data Transfer Provider
extension-point.org.jkiss.dbeaver.dataFormatter.name = Data Formatters
extension-point.org.jkiss.dbeaver.aggregateFunction.name = Aggregate Functions
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL script commands
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL formatters
extension-point.org.jkiss.dbeaver.resourceHandler.name = Resource Handlers
extension-point.org.jkiss.dbeaver.networkHandler.name = Network Handlers
extension-point.org.jkiss.dbeaver.resources.name = Resources
......
......@@ -28,13 +28,14 @@
<extension-point id="org.jkiss.dbeaver.dataTransfer" name="%extension-point.org.jkiss.dbeaver.dataTransfer.name" schema="schema/org.jkiss.dbeaver.dataTransfer.exsd"/>
<extension-point id="org.jkiss.dbeaver.dataFormatter" name="%extension-point.org.jkiss.dbeaver.dataFormatter.name" schema="schema/org.jkiss.dbeaver.dataFormatter.exsd"/>
<extension-point id="org.jkiss.dbeaver.aggregateFunction" name="%extension-point.org.jkiss.dbeaver.aggregateFunction.name" schema="schema/org.jkiss.dbeaver.aggregateFunction.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlCommand" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlCommand.exsd"/>
<extension-point id="org.jkiss.dbeaver.resourceHandler" name="%extension-point.org.jkiss.dbeaver.resourceHandler.name" schema="schema/org.jkiss.dbeaver.resourceHandler.exsd"/>
<extension-point id="org.jkiss.dbeaver.networkHandler" name="%extension-point.org.jkiss.dbeaver.networkHandler.name" schema="schema/org.jkiss.dbeaver.networkHandler.exsd"/>
<extension-point id="org.jkiss.dbeaver.resources" name="%extension-point.org.jkiss.dbeaver.resources.name" schema="schema/org.jkiss.dbeaver.resources.exsd"/>
<extension-point id="org.jkiss.dbeaver.resultset.presentation" name="%extension-point.org.jkiss.dbeaver.resultset.presentation.name" schema="schema/org.jkiss.dbeaver.resultset.presentation.exsd"/>
<extension-point id="org.jkiss.dbeaver.resultset.panel" name="%extension-point.org.jkiss.dbeaver.resultset.panel.name" schema="schema/org.jkiss.dbeaver.resultset.panel.exsd"/>
<extension-point id="org.jkiss.dbeaver.sql.covert" name="%extension-point.org.jkiss.dbeaver.sql.covertname" schema="schema/org.jkiss.dbeaver.sql.convert.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlCommand" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlCommand.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlFormatter" name="%extension-point.org.jkiss.dbeaver.sqlFormatter.name" schema="schema/org.jkiss.dbeaver.sqlFormatter.exsd"/>
<extension-point id="org.jkiss.dbeaver.tools" name="%extension-point.org.jkiss.dbeaver.tools.name" schema="schema/org.jkiss.dbeaver.tools.exsd"/>
<extension-point id="org.jkiss.dbeaver.product.bundles" name="%extension-point.org.jkiss.dbeaver.product.bundles.name" schema="schema/org.jkiss.dbeaver.product.bundles.exsd"/>
<extension-point id="org.jkiss.dbeaver.workbenchHandler" name="%extension-point.org.jkiss.dbeaver.workbenchHandler.name" schema="schema/org.jkiss.dbeaver.workbenchHandler.exsd"/>
......@@ -3300,6 +3301,11 @@
<command id="include" class="org.jkiss.dbeaver.runtime.sql.commands.SQLCommandInclude" label="Include" description="Include another SQL script file"/>
</extension>
<extension point="org.jkiss.dbeaver.sqlFormatter">
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter" 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>
<extension point="org.jkiss.dbeaver.dataManager">
<!--
<manager class="org.jkiss.dbeaver.ui.data.managers.BooleanValueManager" id="org.jkiss.dbeaver.ui.data.managers.BooleanValueManager">
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jkiss.dbeaver.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.jkiss.dbeaver.core" id="org.jkiss.dbeaver.sqlFormatter" name="SQL Formatter"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence>
<element ref="formatter" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="formatter">
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="propertyGroup" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="identifier"/>
</appInfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.model.data.DBDDataFormatter"/>
</appInfo>
</annotation>
</attribute>
<attribute name="sampleClass" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.jkiss.dbeaver.model.data.DBDDataFormatterSample"/>
</appInfo>
</annotation>
</attribute>
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="property">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
<attribute name="type" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="required" type="boolean">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="defaultValue" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="validValues" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="propertyGroup">
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="property"/>
</sequence>
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -40,11 +40,13 @@ import org.jkiss.dbeaver.model.qm.QMController;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.registry.PluginServiceRegistry;
import org.jkiss.dbeaver.registry.ProjectRegistry;
import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry;
import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.runtime.IPluginService;
import org.jkiss.dbeaver.runtime.jobs.KeepAliveJob;
import org.jkiss.dbeaver.runtime.net.GlobalProxySelector;
......@@ -349,6 +351,11 @@ public class DBeaverCore implements DBPPlatform {
return EntityEditorsRegistry.getInstance();
}
@Override
public SQLFormatterRegistry getSQLFormatterRegistry() {
return SQLFormatterConfigurationRegistry.getInstance();
}
@NotNull
@Override
public DBPPreferenceStore getPreferenceStore() {
......
/*
* 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.registry.sql;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import java.util.ArrayList;
import java.util.List;
public class SQLFormatterConfigurationRegistry implements SQLFormatterRegistry
{
private static final Log log = Log.getLog(SQLFormatterConfigurationRegistry.class);
private static final String TAG_FORMATTER = "formatter"; //$NON-NLS-1$
private static SQLFormatterConfigurationRegistry instance = null;
public synchronized static SQLFormatterConfigurationRegistry getInstance()
{
if (instance == null) {
instance = new SQLFormatterConfigurationRegistry();
instance.loadExtensions(Platform.getExtensionRegistry());
}
return instance;
}
private final List<SQLFormatterDescriptor> formatters = new ArrayList<>();
private SQLFormatterConfigurationRegistry()
{
}
private void loadExtensions(IExtensionRegistry registry)
{
IConfigurationElement[] extConfigs = registry.getConfigurationElementsFor(SQLFormatterDescriptor.EXTENSION_ID);
for (IConfigurationElement ext : extConfigs) {
// Load formatters
if (TAG_FORMATTER.equals(ext.getName())) {
this.formatters.add(
new SQLFormatterDescriptor(ext));
}
}
}
public void dispose()
{
formatters.clear();
}
public List<SQLFormatterDescriptor> getFormatters() {
return formatters;
}
public SQLFormatterDescriptor getFormatter(String id) {
for (SQLFormatterDescriptor formatter : formatters) {
if (formatter.getId().equalsIgnoreCase(id)) {
return formatter;
}
}
return null;
}
@Override
@Nullable
public SQLFormatter createFormatter(SQLFormatterConfiguration configuration) {
final String formatterId = configuration.getFormatterId();
SQLFormatterDescriptor formatterDesc = getFormatter(formatterId);
if (formatterDesc == null) {
log.error("Formatter '" + formatterId + "' not found");
return null;
}
try {
return formatterDesc.createFormatter();
} catch (DBException e) {
log.error("Error creating formatter", e);
return null;
}
}
@Override
@Nullable
public SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) {
final String formatterId = configuration.getFormatterId();
SQLFormatterDescriptor formatterDesc = getFormatter(formatterId);
if (formatterDesc == null) {
log.error("Formatter '" + formatterId + "' not found");
return null;
}
try {
SQLFormatter formatter = formatterDesc.createFormatter();
SQLFormatterConfigurer configurer = formatterDesc.createConfigurer();
if (configurer != null) {
configurer.configure(formatter, configuration);
}
return formatter;
} catch (DBException e) {
log.error("Error creating and configuring formatter", e);
return null;
}
}
}
/*
* 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.registry.sql;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
/**
* SQL Formatter configurer
*/
public interface SQLFormatterConfigurer {
void configure(SQLFormatter formatter, SQLFormatterConfiguration configuration);
}
/*
* 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.registry.sql;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jgit.annotations.Nullable;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
import org.jkiss.dbeaver.registry.RegistryConstants;
import org.jkiss.utils.CommonUtils;
/**
* SQLFormatterDescriptor
*/
public class SQLFormatterDescriptor extends AbstractContextDescriptor {
public static final String EXTENSION_ID = "org.jkiss.dbeaver.sqlFormatter"; //$NON-NLS-1$
private final String id;
private final String label;
private final String description;
private final AbstractDescriptor.ObjectType formatterImplClass;
private final AbstractDescriptor.ObjectType configurerImplClass;
public SQLFormatterDescriptor(IConfigurationElement config)
{
super(config);
this.id = config.getAttribute("id");
this.label = config.getAttribute("label");
this.description = config.getAttribute("description");
this.formatterImplClass = new AbstractDescriptor.ObjectType(config.getAttribute("class"));
if (!CommonUtils.isEmpty(config.getAttribute("configurerClass"))) {
this.configurerImplClass = new AbstractDescriptor.ObjectType(config.getAttribute("configurerClass"));
} else {
this.configurerImplClass = null;
}
}
public String getId() {
return id;
}
public String getLabel() {
return label;
}
public String getDescription() {
return description;
}
@NotNull
public SQLFormatter createFormatter()
throws DBException
{
return formatterImplClass.createInstance(SQLFormatter.class);
}
@Nullable
public SQLFormatterConfigurer createConfigurer()
throws DBException
{
if (configurerImplClass == null) {
return null;
}
return configurerImplClass.createInstance(SQLFormatterConfigurer.class);
}
}
......@@ -19,9 +19,11 @@ package org.jkiss.dbeaver.ui.editors.sql.syntax;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorSourceViewerConfiguration;
/**
......@@ -55,7 +57,11 @@ public class SQLFormattingStrategy extends ContextBasedFormattingStrategy
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(sqlSyntax);
configuration.setIndentString(indentPrefixes[0]);
SQLFormatter formatter = configuration.createFormatter();
SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createAndConfigureFormatter(configuration);
if (formatter == null) {
DBeaverUI.getInstance().showError("SQL Format", "Can't create SQL formatter. See error log.");
return content;
}
return formatter.format(content, configuration);
}
......
......@@ -31,6 +31,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IEditorSite;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
......@@ -38,7 +39,8 @@ import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.format.external.SQLExternalFormatter;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.registry.sql.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.StringEditorInput;
import org.jkiss.dbeaver.ui.editors.SubEditorSite;
......@@ -48,9 +50,9 @@ import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.dbeaver.core.CoreMessages;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
/**
......@@ -81,6 +83,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
private SQLEditorBase sqlViewer;
private Composite defaultGroup;
private Composite externalGroup;
private List<SQLFormatterDescriptor> formatters;
public PrefPageSQLFormat()
{
......@@ -148,8 +151,10 @@ public class PrefPageSQLFormat extends TargetPrefPage
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
formatterSelector = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
formatterSelector.add(capitalizeCaseName(SQLTokenizedFormatter.FORMATTER_ID));
formatterSelector.add(capitalizeCaseName(SQLExternalFormatter.FORMATTER_ID));
formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
for (SQLFormatterDescriptor formatterDesc : formatters) {
formatterSelector.add(capitalizeCaseName(formatterDesc.getLabel()));
}
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
......@@ -259,8 +264,15 @@ public class PrefPageSQLFormat extends TargetPrefPage
afKeywordCase.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_KEYWORD_CASE_AUTO));
afExtractFromSource.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_EXTRACT_FROM_SOURCE));
String formatterId = store.getString(ModelPreferences.SQL_FORMAT_FORMATTER);
for (int i = 0; i < formatters.size(); i++) {
if (formatters.get(i).getId().equalsIgnoreCase(formatterId)) {
formatterSelector.select(i);
break;
}
}
if (formatterSelector.getSelectionIndex() < 0) formatterSelector.select(0);
UIUtils.setComboSelection(formatterSelector, capitalizeCaseName(store.getString(ModelPreferences.SQL_FORMAT_FORMATTER)));
final String caseName = store.getString(ModelPreferences.SQL_FORMAT_KEYWORD_CASE);
if (CommonUtils.isEmpty(caseName)) {
keywordCaseCombo.select(0);
......@@ -286,7 +298,8 @@ public class PrefPageSQLFormat extends TargetPrefPage
store.setValue(SQLPreferenceConstants.SQL_FORMAT_KEYWORD_CASE_AUTO, afKeywordCase.getSelection());
store.setValue(SQLPreferenceConstants.SQL_FORMAT_EXTRACT_FROM_SOURCE, afExtractFromSource.getSelection());
store.setValue(ModelPreferences.SQL_FORMAT_FORMATTER, formatterSelector.getText().toUpperCase(Locale.ENGLISH));
store.setValue(ModelPreferences.SQL_FORMAT_FORMATTER,
formatters.get(formatterSelector.getSelectionIndex()).getId().toUpperCase(Locale.ENGLISH));
final String caseName;
if (keywordCaseCombo.getSelectionIndex() == 0) {
......@@ -330,11 +343,12 @@ public class PrefPageSQLFormat extends TargetPrefPage
}
private void showFormatterSettings() {
final boolean isDefFormatter = formatterSelector.getSelectionIndex() == 0;
defaultGroup.setVisible(isDefFormatter);
externalGroup.setVisible(!isDefFormatter);
((GridData)defaultGroup.getLayoutData()).exclude = !isDefFormatter;
((GridData)externalGroup.getLayoutData()).exclude = isDefFormatter;
SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
boolean isExternal = selFormatter.getId().equalsIgnoreCase(SQLExternalFormatter.FORMATTER_ID);
defaultGroup.setVisible(!isExternal);
externalGroup.setVisible(isExternal);
((GridData)defaultGroup.getLayoutData()).exclude = isExternal;
((GridData)externalGroup.getLayoutData()).exclude = !isExternal;
defaultGroup.getParent().layout();
}
......
......@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSObject;
......@@ -280,7 +281,11 @@ public final class SQLUtils {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(syntaxManager);
return configuration.createFormatter().format(query, configuration);
SQLFormatter formatter = dataSource.getDataSource().getContainer().getPlatform().getSQLFormatterRegistry().createFormatter(configuration);
if (formatter == null) {
return query;
}
return formatter.format(query, configuration);
}
public static void appendLikeCondition(StringBuilder sql, String value, boolean not)
......
......@@ -23,8 +23,6 @@ import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.DBPKeywordType;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.format.external.SQLExternalFormatter;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
......@@ -112,14 +110,6 @@ public class SQLFormatterConfiguration {
this.properties = properties;
}
public SQLFormatter createFormatter() {
if (SQLExternalFormatter.FORMATTER_ID.equals(formatterId)) {
return new SQLExternalFormatter();
} else {
return new SQLTokenizedFormatter();
}
}
public DBPPreferenceStore getPreferenceStore() {
return syntaxManager.getPreferenceStore();
}
......
......@@ -16,13 +16,24 @@
*/
package org.jkiss.dbeaver.model.sql.format;
import org.jkiss.dbeaver.DBException;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
/**
* SQL Formatter registry
*/
public interface SQLFormatterRegistry {
SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) throws DBException;
/**
* Creates new formatter. Uses default config and doesn't interact with user for any configuration.
*/
@Nullable
SQLFormatter createFormatter(@NotNull SQLFormatterConfiguration configuration);
/**
* Creates and configures new formatter. Interacts with user in needed.
*/
@Nullable
SQLFormatter createAndConfigureFormatter(@NotNull SQLFormatterConfiguration configuration);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册