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

Cell value save->apply


Former-commit-id: 34bb1ce3
上级 688457e3
......@@ -264,8 +264,8 @@ command.org.jkiss.dbeaver.core.resultset.rejectChanges.name=Reject changes
command.org.jkiss.dbeaver.core.resultset.rejectChanges.description=Reject data changes
command.org.jkiss.dbeaver.core.resultset.generateScript.name=Generate script
command.org.jkiss.dbeaver.core.resultset.generateScript.description=Generate changes script
command.org.jkiss.dbeaver.core.resultset.cell.save.name=Save cell value
command.org.jkiss.dbeaver.core.resultset.cell.save.description=Save cell value
command.org.jkiss.dbeaver.core.resultset.cell.save.name=Apply cell value
command.org.jkiss.dbeaver.core.resultset.cell.save.description=Apply cell value
command.org.jkiss.dbeaver.core.resultset.filterMenu.name=Filter menu
command.org.jkiss.dbeaver.core.resultset.filterMenu.description=Filer context menu
command.org.jkiss.dbeaver.core.resultset.referencesMenu.name=Referencing tables
......
......@@ -323,7 +323,7 @@ public class ViewValuePanel implements IResultSetPanel, IAdaptable {
previewController.updateValue(newValue, true);
presentation.updateValueView();
} catch (Exception e) {
DBUserInterface.getInstance().showError("Value save", "Can't save edited value", e);
DBUserInterface.getInstance().showError("Value apply", "Can't apply edited value", e);
} finally {
valueSaving = false;
}
......@@ -363,7 +363,7 @@ public class ViewValuePanel implements IResultSetPanel, IAdaptable {
ActionUtils.makeCommandContribution(presentation.getController().getSite(), ValueViewCommandHandler.CMD_SAVE_VALUE));
contributionManager.add(
new Action("Auto-flush value (from panel to grid)", Action.AS_CHECK_BOX) {
new Action("Auto-apply value", Action.AS_CHECK_BOX) {
{
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
}
......
......@@ -26,6 +26,7 @@ import org.jkiss.dbeaver.model.edit.DBERegistry;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.qm.QMController;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import java.io.File;
import java.io.IOException;
......@@ -60,6 +61,9 @@ public interface DBPPlatform
@NotNull
DBERegistry getEditorsRegistry();
@NotNull
SQLFormatterRegistry getSQLFormatterRegistry();
@NotNull
DBPPreferenceStore getPreferenceStore();
......
......@@ -30,9 +30,7 @@ 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.SQLFormatterConfiguration;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.utils.ContentUtils;
......@@ -45,7 +43,10 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -279,7 +280,7 @@ public final class SQLUtils {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(syntaxManager);
return new SQLTokenizedFormatter().format(query, configuration);
return configuration.createFormatter().format(query, configuration);
}
public static void appendLikeCondition(StringBuilder sql, String value, boolean not)
......
......@@ -16,17 +16,17 @@
*/
package org.jkiss.dbeaver.model.sql.format;
/**
* SQL Formatter
*/
public interface SQLFormatter {
/**
* Format the source SQL string.
*
* @param source original SQL string
*
* @return formatted version
*/
String format(String source, SQLFormatterConfiguration configuration);
/**
* Format the source SQL string.
*
* @param source original SQL string
* @return formatted version
*/
String format(String source, SQLFormatterConfiguration configuration);
}
......@@ -21,19 +21,24 @@ import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.ModelPreferences;
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;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* SQLFormatterConfiguration
*/
public class SQLFormatterConfiguration {
private String formatterId;
@NotNull
private DBPIdentifierCase keywordCase;
private String indentString = " ";
......@@ -41,10 +46,14 @@ public class SQLFormatterConfiguration {
@NotNull
private String sourceEncoding = GeneralUtils.DEFAULT_ENCODING;
private Map<String, Object> properties = new HashMap<>();
public SQLFormatterConfiguration(SQLSyntaxManager syntaxManager)
{
this.syntaxManager = syntaxManager;
this.keywordCase = syntaxManager.getKeywordCase();
this.formatterId = CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(ModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH);
}
public SQLSyntaxManager getSyntaxManager()
......@@ -52,6 +61,16 @@ public class SQLFormatterConfiguration {
return syntaxManager;
}
public String getFormatterId() {
return formatterId;
}
public void setFormatterId(String formatterId) {
this.formatterId = formatterId;
syntaxManager.getPreferenceStore().setValue(
ModelPreferences.SQL_FORMAT_FORMATTER, formatterId.toUpperCase(Locale.ENGLISH));
}
public String getIndentString()
{
return indentString;
......@@ -85,12 +104,23 @@ public class SQLFormatterConfiguration {
return syntaxManager.getDialect().getKeywordType(name) == DBPKeywordType.FUNCTION;
}
public Object getProperty(String name) {
return properties.get(name);
}
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public SQLFormatter createFormatter() {
final String formatterId = CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(ModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH);
if (SQLExternalFormatter.FORMATTER_ID.equals(formatterId)) {
return new SQLExternalFormatter();
} else {
return new SQLTokenizedFormatter();
}
}
public DBPPreferenceStore getPreferenceStore() {
return syntaxManager.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.model.sql.format;
import org.jkiss.dbeaver.DBException;
/**
* SQL Formatter registry
*/
public interface SQLFormatterRegistry {
SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) throws DBException;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册