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

#2130 Compact SQL formatter


Former-commit-id: dc25cc73
上级 3bffdcb4
......@@ -3302,8 +3302,9 @@
</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.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"/>
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.tokenized.SQLTokenizedConfigurationPage" label="Default formatter" description="Default SQL formatter"/>
<formatter id="compact" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterCompact" label="Compact formatter" description="Compact SQL formatter. Similar to default formatter but with more compact output"/>
<formatter id="external" class="org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal" label="External formatter" description="External formatter. Uses configurable command-line executable to format SQL queries"/>
</extension>
<extension point="org.jkiss.dbeaver.dataManager">
......
......@@ -38,7 +38,7 @@ import org.jkiss.dbeaver.model.DBPDataSourceContainer;
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.external.SQLFormatterExternal;
import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.registry.sql.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -159,6 +159,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
@Override
public void widgetSelected(SelectionEvent e) {
showFormatterSettings();
performApply();
}
});
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
......@@ -193,13 +194,13 @@ public class PrefPageSQLFormat extends TargetPrefPage
externalCmdText,
new TextContentAdapter(),
new SimpleContentProposalProvider(new String[] {
GeneralUtils.variablePattern(SQLExternalFormatter.VAR_FILE)
GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE)
}));
UIUtils.setContentProposalToolTip(externalCmdText, CoreMessages.pref_page_sql_format_label_external_set_content_tool_tip, SQLExternalFormatter.VAR_FILE);
UIUtils.setContentProposalToolTip(externalCmdText, CoreMessages.pref_page_sql_format_label_external_set_content_tool_tip, SQLFormatterExternal.VAR_FILE);
externalUseFile = UIUtils.createLabelCheckbox(externalGroup,
CoreMessages.pref_page_sql_format_label_external_use_temp_file,
CoreMessages.pref_page_sql_format_label_external_use_temp_file_tip + GeneralUtils.variablePattern(SQLExternalFormatter.VAR_FILE),
CoreMessages.pref_page_sql_format_label_external_use_temp_file_tip + GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE),
false);
externalTimeout = UIUtils.createLabelSpinner(externalGroup,
CoreMessages.pref_page_sql_format_label_external_exec_timeout,
......@@ -344,7 +345,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
private void showFormatterSettings() {
SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
boolean isExternal = selFormatter.getId().equalsIgnoreCase(SQLExternalFormatter.FORMATTER_ID);
boolean isExternal = selFormatter.getId().equalsIgnoreCase(SQLFormatterExternal.FORMATTER_ID);
defaultGroup.setVisible(!isExternal);
externalGroup.setVisible(isExternal);
((GridData)defaultGroup.getLayoutData()).exclude = isExternal;
......
......@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.qm.QMConstants;
import org.jkiss.dbeaver.model.qm.QMObjectType;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils;
import org.osgi.framework.Bundle;
......@@ -160,7 +160,7 @@ public final class ModelPreferences
PrefUtils.setDefaultPreferenceValue(store, SQL_NAMED_PARAMETERS_PREFIX, String.valueOf(SQLConstants.DEFAULT_PARAMETER_PREFIX));
PrefUtils.setDefaultPreferenceValue(store, SQL_CONTROL_COMMAND_PREFIX, String.valueOf(SQLConstants.DEFAULT_CONTROL_COMMAND_PREFIX));
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_FORMATTER, SQLTokenizedFormatter.FORMATTER_ID);
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_FORMATTER, SQLFormatterTokenized.FORMATTER_ID);
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_KEYWORD_CASE, "");
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_EXTERNAL_CMD, "");
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_EXTERNAL_FILE, false);
......
......@@ -37,11 +37,11 @@ import java.util.List;
/**
* External SQL formatter
*/
public class SQLExternalFormatter implements SQLFormatter {
public class SQLFormatterExternal implements SQLFormatter {
public static final String FORMATTER_ID = "EXTERNAL";
private static final Log log = Log.getLog(SQLExternalFormatter.class);
private static final Log log = Log.getLog(SQLFormatterExternal.class);
public static final String VAR_FILE = "file";
@Override
......@@ -50,6 +50,11 @@ public class SQLExternalFormatter implements SQLFormatter {
final String command = store.getString(ModelPreferences.SQL_FORMAT_EXTERNAL_CMD);
int timeout = store.getInt(ModelPreferences.SQL_FORMAT_EXTERNAL_TIMEOUT);
boolean useFile = store.getBoolean(ModelPreferences.SQL_FORMAT_EXTERNAL_FILE);
if (CommonUtils.isEmpty(command)) {
// Nothing to format
return source;
}
try {
final FormatJob formatJob = new FormatJob(configuration, command, source, useFile);
formatJob.schedule();
......@@ -79,7 +84,7 @@ public class SQLExternalFormatter implements SQLFormatter {
public boolean finished;
public FormatJob(SQLFormatterConfiguration configuration, String command, String source, boolean useFile) {
super("External format: " + command);
super("External format - " + command);
this.command = command;
this.configuration = configuration;
this.source = source;
......
/*
* 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.model.sql.format.tokenized;
/**
* SQL formatter
*/
public class SQLFormatterCompact extends SQLFormatterTokenized {
public SQLFormatterCompact() {
setCompact(true);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册