Revision: 6637
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6637&view=rev
Author: gerdwagner
Date: 2012-06-19 20:31:02 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------
Made SQL formating configurable
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlController.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPanel.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPref.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/KeywordBehaviourPrefCtrl.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformator.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfig.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfigFactory.java
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/preferences/codereformat/I18NStrings.properties
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/util/codereformat/I18NStrings.properties
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/plugins/editextras/src/main/resources/doc/readme.html
trunk/sql12/plugins/editextras/src/main/resources/doc/readme.txt
Removed Paths:
-------------
trunk/sql12/plugins/editextras/src/main/java/net/sourceforge/squirrel_sql/plugins/editextras/config/
trunk/sql12/plugins/editextras/src/main/resources/net/sourceforge/squirrel_sql/plugins/editextras/config/
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlController.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlController.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlController.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -70,8 +70,52 @@
keywordBehaviourPrefCtrl.addKeyWordBehaviourChangedListener(actionListener);
}
+ _formatSqlPanel.chkDoInsertValuesAlign.setSelected(_formatSqlPref.isDoInsertValuesAlign());
+ _formatSqlPanel.chkDoInsertValuesAlign.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ adjustInsertValuesState();
+ }
+ });
+ adjustInsertValuesState();
+
}
+ private void adjustInsertValuesState()
+ {
+ for (KeywordBehaviourPrefCtrl keywordBehaviourPrefCtrl : _formatSqlPanel.keywordBehaviourPrefCtrls)
+ {
+ String keyWord = keywordBehaviourPrefCtrl.getKeywordBehaviourPref().getKeyWord();
+ if (FormatSqlPref.INSERT.equals(keyWord))
+ {
+ if(_formatSqlPanel.chkDoInsertValuesAlign.isSelected())
+ {
+ keywordBehaviourPrefCtrl.setBehaviour(FormatSqlPanel.KeywordBehaviour.START_NEW_LINE);
+ keywordBehaviourPrefCtrl.setEnabled(false);
+ }
+ else
+ {
+ keywordBehaviourPrefCtrl.setEnabled(true);
+ }
+ }
+ else if (FormatSqlPref.VALUES.equals(keyWord))
+ {
+ if(_formatSqlPanel.chkDoInsertValuesAlign.isSelected())
+ {
+ keywordBehaviourPrefCtrl.setBehaviour(FormatSqlPanel.KeywordBehaviour.NO_INFLUENCE_ON_NEW_LINE);
+ keywordBehaviourPrefCtrl.setEnabled(false);
+ }
+ else
+ {
+ keywordBehaviourPrefCtrl.setEnabled(true);
+ }
+ }
+ }
+ refreshExampleSql(createFormatSqlPrefFromGui());
+ }
+
private void refreshExampleSql(FormatSqlPref formatSqlPref)
{
String sqls;CodeReformator codeReformator = new CodeReformator(CodeReformatorConfigFactory.createConfig(formatSqlPref));
@@ -149,6 +193,8 @@
}
ret.setKeywordBehaviourPrefs(buf.toArray(new KeywordBehaviourPref[buf.size()]));
+ ret.setDoInsertValuesAlign(_formatSqlPanel.chkDoInsertValuesAlign.isSelected());
+
return ret;
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPanel.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPanel.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPanel.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -66,6 +66,7 @@
JFormattedTextField txtIndentCount;
JFormattedTextField txtPreferedLineLength;
ArrayList<KeywordBehaviourPrefCtrl> keywordBehaviourPrefCtrls = new ArrayList<KeywordBehaviourPrefCtrl>();
+ JCheckBox chkDoInsertValuesAlign;
JTextArea txtExampleSqls = new JTextArea();
@@ -112,6 +113,10 @@
keywordBehaviourPrefCtrls.add(createKeywordBehaviourPrefCtrl(ret, keywordBehaviourPref, ++gridy));
}
+ gbc = new GridBagConstraints(1,++gridy,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5),0,0);
+ chkDoInsertValuesAlign = new JCheckBox(s_stringMgr.getString("codereformat.FormatSqlPanel.tryAlignInsertValueStatements"));
+ ret.add(chkDoInsertValuesAlign, gbc);
+
return ret;
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPref.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPref.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/FormatSqlPref.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -4,7 +4,10 @@
{
public static final String JOIN_DISPLAY_STRING = "INNER/LEFT/RIGHT JOIN";
+ public static final String INSERT = "INSERT";
+ public static final String VALUES = "VALUES";
+
private KeywordBehaviourPref[] _keywordBehaviourPrefs = new KeywordBehaviourPref[]
{
new KeywordBehaviourPref("SELECT", FormatSqlPanel.KeywordBehaviour.ALONE_IN_LINE.getID()),
@@ -19,15 +22,17 @@
new KeywordBehaviourPref("GROUP", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
new KeywordBehaviourPref("ORDER", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
- new KeywordBehaviourPref("INSERT", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
- new KeywordBehaviourPref("VALUES", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
new KeywordBehaviourPref("UPDATE", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
new KeywordBehaviourPref("DELETE", FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
+
+ new KeywordBehaviourPref(INSERT, FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID()),
+ new KeywordBehaviourPref(VALUES, FormatSqlPanel.KeywordBehaviour.START_NEW_LINE.getID())
};
private int _indent = 3;
private int _preferedLineLength = 80;
+ private boolean _doInsertValuesAlign = true;
public KeywordBehaviourPref[] getKeywordBehaviourPrefs()
{
@@ -59,4 +64,14 @@
{
return _preferedLineLength;
}
+
+ public boolean isDoInsertValuesAlign()
+ {
+ return _doInsertValuesAlign;
+ }
+
+ public void setDoInsertValuesAlign(boolean doInsertValuesAlign)
+ {
+ _doInsertValuesAlign = doInsertValuesAlign;
+ }
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/KeywordBehaviourPrefCtrl.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/KeywordBehaviourPrefCtrl.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/preferences/codereformat/KeywordBehaviourPrefCtrl.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -36,4 +36,14 @@
{
_cbo.addActionListener(l);
}
+
+ public void setBehaviour(FormatSqlPanel.KeywordBehaviour keywordBehaviour)
+ {
+ _cbo.setSelectedItem(keywordBehaviour);
+ }
+
+ public void setEnabled(boolean b)
+ {
+ _cbo.setEnabled(b);
+ }
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformator.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformator.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformator.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -59,7 +59,10 @@
String[] pieces =
getReformatedPieces(in, markerExcludeComma).toArray(new String[0]);
- pieces = doInsertSpecial(pieces);
+ if (_codeReformatorConfig.isDoInsertValuesAlign())
+ {
+ pieces = doInsertSpecial(pieces);
+ }
StringBuffer ret = new StringBuffer();
int braketCount = 0;
@@ -105,7 +108,7 @@
// i18n[editextras.reformatFailed=Reformat failed, normalized
// Strings differ]
- StringBuilder msg = new StringBuilder(s_stringMgr.getString("editextras.reformatFailed"));
+ StringBuilder msg = new StringBuilder(s_stringMgr.getString("codereformat.reformatFailed"));
msg.append(_lineSep);
msg.append(normalizedBefore);
msg.append(_lineSep);
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfig.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfig.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfig.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -16,18 +16,20 @@
private CommentSpec[] _commentSpecs;
private String _indent;
private int _trySplitLineLen;
+ private boolean _doInsertValuesAlign;
private PieceMarkerSpec[] keywordPieceMarkerSpec = new PieceMarkerSpec[0];
/**
* Use CodeReformatorConfigFactory to create instances of this class
*/
- CodeReformatorConfig(String statementSeparator, CommentSpec[] commentSpecs, String indent, int trySplitLineLen, ArrayList<PieceMarkerSpec> specs)
+ CodeReformatorConfig(String statementSeparator, CommentSpec[] commentSpecs, String indent, int trySplitLineLen, boolean doInsertValuesAlign, ArrayList<PieceMarkerSpec> specs)
{
_statementSeparator = statementSeparator;
_commentSpecs = commentSpecs;
_indent = indent;
_trySplitLineLen = trySplitLineLen;
+ _doInsertValuesAlign = doInsertValuesAlign;
keywordPieceMarkerSpec = specs.toArray(new PieceMarkerSpec[specs.size()]);
}
@@ -55,4 +57,9 @@
{
return keywordPieceMarkerSpec;
}
+
+ public boolean isDoInsertValuesAlign()
+ {
+ return _doInsertValuesAlign;
+ }
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfigFactory.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfigFactory.java 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/util/codereformat/CodeReformatorConfigFactory.java 2012-06-19 20:31:02 UTC (rev 6637)
@@ -60,7 +60,7 @@
specs.addAll(createPieceMarkerSpecs(keywordBehaviourPref));
}
- return new CodeReformatorConfig(statementSeparator, commentSpecs, indent, trySplitLineLen, specs);
+ return new CodeReformatorConfig(statementSeparator, commentSpecs, indent, trySplitLineLen, formatSqlPref.isDoInsertValuesAlign(), specs);
}
private static ArrayList<PieceMarkerSpec> createPieceMarkerSpecs(KeywordBehaviourPref keywordBehaviourPref)
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/preferences/codereformat/I18NStrings.properties
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/preferences/codereformat/I18NStrings.properties 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/preferences/codereformat/I18NStrings.properties 2012-06-19 20:31:02 UTC (rev 6637)
@@ -1,8 +1,9 @@
-codereformat.FormatSqlConfigPrefsTab.title=SQL formating
-codereformat.FormatSqlConfigPrefsTab.hint= Option for SQL formating (ctrl+f)
+codereformat.FormatSqlConfigPrefsTab.title=SQL formatting
+codereformat.FormatSqlConfigPrefsTab.hint= Option for SQL formatting (ctrl+f)
codereformat.FormatSqlPanel.indent=Indent space count
codereformat.FormatSqlPanel.preferedLineLen=Prefered line length
codereformat.FormatSqlPanel.keywordBehavior=Keyword behavior:
codereformat.aloneInLine=Alone in line
codereformat.startNewLine=Start new Line
-codereformat.noInfluenceOnNewLine=No influence on line break
\ No newline at end of file
+codereformat.noInfluenceOnNewLine=No influence on line break
+codereformat.FormatSqlPanel.tryAlignInsertValueStatements=Try align INSERT-VALUES statements
\ No newline at end of file
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/util/codereformat/I18NStrings.properties
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/util/codereformat/I18NStrings.properties 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/util/codereformat/I18NStrings.properties 2012-06-19 20:31:02 UTC (rev 6637)
@@ -1,2 +1,2 @@
-editextras.reformatFailed=Reformat failed, normalized Strings differ
+codereformat.reformatFailed=Reformat failed, normalized Strings differ
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-06-19 20:31:02 UTC (rev 6637)
@@ -9,6 +9,8 @@
Enhancements:
+3488629: SQL formatting can be configured. See menu File--> Global Preferences --> Tab SQL formatting
+
Installer: The DB Copy, DB Diff and Refactoring Plugin have been made standard Plugins.
Graph Plugin: Tables can be selected by rectangle selection like icons on a desktop of modern operating systems.
Modified: trunk/sql12/plugins/editextras/src/main/resources/doc/readme.html
===================================================================
--- trunk/sql12/plugins/editextras/src/main/resources/doc/readme.html 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/plugins/editextras/src/main/resources/doc/readme.html 2012-06-19 20:31:02 UTC (rev 6637)
@@ -14,7 +14,6 @@
<P STYLE="font-weight: medium">This plugin provides auxiliary
functions for the SQL Editor:</P>
<UL>
- <LI><P STYLE="font-weight: medium">Formating SQL code</P>
<LI><P STYLE="font-weight: medium">Adding / removing Java string
delimiters</P>
<LI><P STYLE="font-weight: medium">Creating JDBC escape syntax for
Modified: trunk/sql12/plugins/editextras/src/main/resources/doc/readme.txt
===================================================================
--- trunk/sql12/plugins/editextras/src/main/resources/doc/readme.txt 2012-06-19 18:31:32 UTC (rev 6636)
+++ trunk/sql12/plugins/editextras/src/main/resources/doc/readme.txt 2012-06-19 20:31:02 UTC (rev 6637)
@@ -1,7 +1,6 @@
This plugin provides
- Search and replace
- Adding and removing Java quotes
-- Formating SQL
The functions are accessable through Menu Session --> SQL Entry Editing --> ...
or through the shortcuts named in the menus.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|