Revision: 6567
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6567&view=rev
Author: gerdwagner
Date: 2012-02-07 22:23:38 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
CamelCase completion
Modified Paths:
--------------
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CompletionInfo.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionInfoCollection.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableAliasInfo.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableInfo.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/StandardCompletorModel.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferences.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesController.java
trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesPanel.java
trunk/sql12/plugins/codecompletion/src/main/resources/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CamelCaseMatcher.java
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-02-07 22:23:38 UTC (rev 6567)
@@ -9,6 +9,11 @@
Enhancements:
+Code Completion Plugin:
+ The Code Completion Plugin's preferences allows to switch on CamelCase completion
+ which is a common feature in many modern IDEs.
+ CamelCase completion may be useful if a RDBMS supports capital and small letters in database object names.
+
Hibernate Plugin:
- Redesign of HQL result display. Focus is now on displaying result objects instead of Hibernate generated SQL.
- User can choose if he wants to use the Session's JDBC connection or the one configured with Hibernate.
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CamelCaseMatcher.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CamelCaseMatcher.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CamelCaseMatcher.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -0,0 +1,84 @@
+package net.sourceforge.squirrel_sql.fw.completion;
+
+public class CamelCaseMatcher
+{
+ public static boolean matchesCamelCase(String testString, String dbObjectName)
+ {
+ int[] bufTest = new int[]{0};
+ int[] bufComp = new int[]{0};
+
+ String nextCamelCaseSubstring = getNextCamelCaseSubstring(testString, bufTest);
+
+ if(null == nextCamelCaseSubstring)
+ {
+ return false;
+ }
+
+ String dbObjCamelCaseSubstring = getNextCamelCaseSubstring(dbObjectName, bufComp);
+ while(null != dbObjCamelCaseSubstring && dbObjCamelCaseSubstring.startsWith(nextCamelCaseSubstring))
+ {
+ nextCamelCaseSubstring = getNextCamelCaseSubstring(testString, bufTest);
+
+ if(null == nextCamelCaseSubstring)
+ {
+ return true;
+ }
+ dbObjCamelCaseSubstring = getNextCamelCaseSubstring(dbObjectName, bufComp);
+
+ }
+
+ return false;
+ }
+
+ private static String getNextCamelCaseSubstring(String str, int[] nextBegPos)
+ {
+ if(0 == str.length())
+ {
+ return null;
+ }
+
+ int beg = nextBegPos[0];
+
+ if(beg == str.length())
+ {
+ return null;
+ }
+
+
+ for(++nextBegPos[0]; nextBegPos[0] < str.length(); ++nextBegPos[0])
+ {
+ if(Character.isUpperCase(str.charAt(nextBegPos[0])))
+ {
+ return str.substring(beg, nextBegPos[0]);
+ }
+ }
+
+ return str.substring(beg, nextBegPos[0]);
+ }
+
+ public static void main(String[] args)
+ {
+ System.out.println("1 true = " + CamelCaseMatcher.matchesCamelCase("WKP", "WKvPos"));
+ System.out.println("2 true = " + CamelCaseMatcher.matchesCamelCase("WK", "WKvPos"));
+ System.out.println("3 true = " + CamelCaseMatcher.matchesCamelCase("W", "WKvPos"));
+ System.out.println("4 true = " + CamelCaseMatcher.matchesCamelCase("WuKv", "WunKvPos"));
+ System.out.println("5 true = " + CamelCaseMatcher.matchesCamelCase("WuKP", "WunKvPos"));
+ System.out.println("6 false = " + CamelCaseMatcher.matchesCamelCase("WuP", "WunKvPos"));
+ System.out.println("7 true = " + CamelCaseMatcher.matchesCamelCase("WK", "WKvKvPos"));
+ System.out.println("8 true = " + CamelCaseMatcher.matchesCamelCase("WKK", "WKvKvPos"));
+ System.out.println("9 false = " + CamelCaseMatcher.matchesCamelCase("WKKK", "WKvKvPos"));
+ System.out.println("10 false = " + CamelCaseMatcher.matchesCamelCase("", "WKvKvPos"));
+ System.out.println("11 false = " + CamelCaseMatcher.matchesCamelCase(" ", "WKvKvPos"));
+ System.out.println("12 false = " + CamelCaseMatcher.matchesCamelCase(" W", "WKvKvPos"));
+ System.out.println("13 false = " + CamelCaseMatcher.matchesCamelCase("W ", "WKvKvPos"));
+ System.out.println("14 false = " + CamelCaseMatcher.matchesCamelCase("K", "WKvKvPos"));
+ System.out.println("15 false = " + CamelCaseMatcher.matchesCamelCase("K", "WKKP"));
+ System.out.println("16 true = " + CamelCaseMatcher.matchesCamelCase("W", "WKKP"));
+ System.out.println("17 true = " + CamelCaseMatcher.matchesCamelCase("WK", "WKKP"));
+ System.out.println("18 true = " + CamelCaseMatcher.matchesCamelCase("WKK", "WKKP"));
+ System.out.println("19 false = " + CamelCaseMatcher.matchesCamelCase("WKKK", "WKKP"));
+ System.out.println("20 true = " + CamelCaseMatcher.matchesCamelCase("WKKP", "WKKP"));
+ System.out.println("21 false = " + CamelCaseMatcher.matchesCamelCase("WKKPa", "WKKP"));
+ }
+
+}
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CompletionInfo.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CompletionInfo.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/completion/CompletionInfo.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -22,6 +22,7 @@
public abstract class CompletionInfo implements Comparable<CompletionInfo>
{
private String _upperCaseCompletionString;
+ private String _completionString;
public abstract String getCompareString();
@@ -32,45 +33,40 @@
public int compareTo(CompletionInfo other)
{
- if(null == _upperCaseCompletionString)
- {
- _upperCaseCompletionString = getCompareString().toUpperCase();
- }
+ initCache();
+ other.initCache();
- if(null == other._upperCaseCompletionString)
- {
- other._upperCaseCompletionString = other.getCompareString().toUpperCase();
- }
-
return _upperCaseCompletionString.compareTo(other._upperCaseCompletionString);
}
- /**
- * Param must be an upper case string if not the result will always be false
- */
- public boolean upperCaseCompletionStringStartsWith(String testString)
+ public boolean matchesCompletionStringStart(String testString, boolean matchCamelCase)
{
- if(null == _upperCaseCompletionString)
- {
- _upperCaseCompletionString = getCompareString().toUpperCase();
- }
+ initCache();
+ return _upperCaseCompletionString.startsWith(testString.toUpperCase()) || (matchCamelCase && matchesCamelCase(testString));
+ }
- return _upperCaseCompletionString.startsWith(testString);
+ private boolean matchesCamelCase(String testString)
+ {
+ return CamelCaseMatcher.matchesCamelCase(testString, _completionString);
}
- /**
- * Param must be an upper case string if not the result will always be false
- */
- public boolean upperCaseCompletionStringEquals(String testString)
+
+ public boolean matchesCompletionString(String testString)
{
+ initCache();
+ return _upperCaseCompletionString.equals(testString.toUpperCase());
+ }
+
+ private void initCache()
+ {
if(null == _upperCaseCompletionString)
{
- _upperCaseCompletionString = getCompareString().toUpperCase();
+ _completionString = getCompareString();
+ _upperCaseCompletionString = _completionString.toUpperCase();
}
-
- return _upperCaseCompletionString.equals(testString);
}
+
/**
* Default implementation
*/
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionInfoCollection.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionInfoCollection.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionInfoCollection.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -108,7 +108,7 @@
tables[i].getCatalogName(),
tables[i].getSchemaName(),
_useCompletionPrefs,
- _prefs.isShowRemarksInColumnCompletion());
+ _prefs);
if(null != dupl)
{
@@ -222,9 +222,9 @@
return new CodeCompletionInfo[0];
}
- String upperCasePrefix = prefix.trim().toUpperCase();
+ String trimmedPrefix = prefix.trim();
- if("".equals(upperCasePrefix))
+ if("".equals(trimmedPrefix))
{
Vector<CodeCompletionInfo> buf = new Vector<CodeCompletionInfo>();
buf.addAll(_aliasCompletionInfos);
@@ -248,7 +248,7 @@
for(int i=0; i < _aliasCompletionInfos.size(); ++i)
{
CodeCompletionInfo buf = _aliasCompletionInfos.get(i);
- if(buf.upperCaseCompletionStringStartsWith(upperCasePrefix))
+ if(buf.matchesCompletionStringStart(trimmedPrefix, _useCompletionPrefs && _prefs.isMatchCamelCase()))
{
ret.add(buf);
}
@@ -258,7 +258,7 @@
for(int i=0; i < completionInfos.size(); ++i)
{
CodeCompletionInfo buf = completionInfos.get(i);
- if(buf.upperCaseCompletionStringStartsWith(upperCasePrefix))
+ if(buf.matchesCompletionStringStart(trimmedPrefix, _useCompletionPrefs && _prefs.isMatchCamelCase()))
{
ret.add(buf);
@@ -295,7 +295,7 @@
{
if(false == aliasInfos[i].aliasName.startsWith("#"))
{
- _aliasCompletionInfos.add(new CodeCompletionTableAliasInfo(aliasInfos[i], _useCompletionPrefs, _prefs.isShowRemarksInColumnCompletion()));
+ _aliasCompletionInfos.add(new CodeCompletionTableAliasInfo(aliasInfos[i], _useCompletionPrefs, _prefs));
}
}
}
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableAliasInfo.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableAliasInfo.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableAliasInfo.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -18,6 +18,7 @@
package net.sourceforge.squirrel_sql.plugins.codecompletion;
import net.sourceforge.squirrel_sql.client.session.parser.kernel.TableAliasInfo;
+import net.sourceforge.squirrel_sql.plugins.codecompletion.prefs.CodeCompletionPreferences;
public class CodeCompletionTableAliasInfo extends CodeCompletionTableInfo
{
@@ -25,9 +26,9 @@
private String _toString;
- public CodeCompletionTableAliasInfo(TableAliasInfo aliasInfo, boolean useCompletionPrefs, boolean showRemarksInColumnCompletion)
+ public CodeCompletionTableAliasInfo(TableAliasInfo aliasInfo, boolean useCompletionPrefs, CodeCompletionPreferences prefs)
{
- super(aliasInfo.tableName, "TABLE", null, null, useCompletionPrefs, showRemarksInColumnCompletion);
+ super(aliasInfo.tableName, "TABLE", null, null, useCompletionPrefs, prefs);
_aliasInfo = aliasInfo;
_toString = _aliasInfo.aliasName + " (Alias for " + _aliasInfo.tableName + ")";
}
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableInfo.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableInfo.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/CodeCompletionTableInfo.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -22,6 +22,7 @@
import java.util.HashSet;
import net.sourceforge.squirrel_sql.client.session.ExtendedColumnInfo;
+import net.sourceforge.squirrel_sql.plugins.codecompletion.prefs.CodeCompletionPreferences;
public class CodeCompletionTableInfo extends CodeCompletionInfo
{
@@ -32,17 +33,17 @@
private String _catalog;
private String _schema;
private boolean _useCompletionPrefs;
- private boolean _showRemarksInColumnCompletion;
+ private CodeCompletionPreferences _prefs;
- public CodeCompletionTableInfo(String tableName, String tableType, String catalog, String schema, boolean useCompletionPrefs, boolean showRemarksInColumnCompletion)
+ public CodeCompletionTableInfo(String tableName, String tableType, String catalog, String schema, boolean useCompletionPrefs, CodeCompletionPreferences prefs)
{
_tableName = tableName;
_tableType = tableType;
_catalog = catalog;
_schema = schema;
_useCompletionPrefs = useCompletionPrefs;
- _showRemarksInColumnCompletion = showRemarksInColumnCompletion;
+ _prefs = prefs;
if(null != _tableType && !"TABLE".equals(_tableType))
@@ -100,7 +101,7 @@
boolean nullable = schemColInfos[i].isNullable();
CodeCompletionColumnInfo buf =
- new CodeCompletionColumnInfo(columnName, remarks, columnType, columnSize, decimalDigits, nullable, _useCompletionPrefs, _showRemarksInColumnCompletion);
+ new CodeCompletionColumnInfo(columnName, remarks, columnType, columnSize, decimalDigits, nullable, _useCompletionPrefs, _prefs.isShowRemarksInColumnCompletion());
String bufStr = buf.toString();
if (!uniqCols.contains(bufStr))
@@ -114,9 +115,9 @@
_colInfos = colInfosBuf;
}
- String upperCaseColNamePattern = colNamePattern.toUpperCase().trim();
+ String trimmedColNamePattern = colNamePattern.trim();
- if("".equals(upperCaseColNamePattern))
+ if("".equals(trimmedColNamePattern))
{
return _colInfos;
}
@@ -125,7 +126,7 @@
for (CodeCompletionInfo colInfo : _colInfos)
{
- if(colInfo.upperCaseCompletionStringStartsWith(upperCaseColNamePattern))
+ if(colInfo.matchesCompletionStringStart(trimmedColNamePattern, _useCompletionPrefs && _prefs.isMatchCamelCase()))
{
ret.add(colInfo);
}
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/StandardCompletorModel.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/StandardCompletorModel.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/StandardCompletorModel.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -148,8 +148,7 @@
private ArrayList<CodeCompletionInfo> getColumnsForName(String catalog, String schema, String name, String colNamePat, int colPos)
{
CodeCompletionInfo[] infos = _codeCompletionInfos.getInfosStartingWith(catalog, schema, name);
- String upperCaseTableNamePat = name.toUpperCase();
- CodeCompletionInfo toReturn = null;
+ CodeCompletionInfo toReturn = null;
if (colPos != -1)
{
// First check aliases
@@ -158,7 +157,7 @@
CodeCompletionInfo info = infos[j];
if (info instanceof CodeCompletionTableAliasInfo)
{
- if (info.upperCaseCompletionStringEquals(upperCaseTableNamePat))
+ if (info.matchesCompletionString(name))
{
// See if this is the same statement
CodeCompletionTableAliasInfo a = (CodeCompletionTableAliasInfo) info;
@@ -174,7 +173,7 @@
{
for (int i = 0; i < infos.length; ++i)
{
- if (infos[i].upperCaseCompletionStringEquals(upperCaseTableNamePat))
+ if (infos[i].matchesCompletionString(name))
{
toReturn = infos[i];
break;
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferences.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferences.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferences.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -15,6 +15,7 @@
private PrefixedConfig[] prefixedConfigs = new PrefixedConfig[0];
private int maxLastSelectedCompletionNames = 1;
private boolean _showRemarksInColumnCompletion;
+ private boolean _matchCamelCase;
public int getGeneralCompletionConfig()
{
@@ -55,4 +56,14 @@
{
_showRemarksInColumnCompletion = b;
}
+
+ public boolean isMatchCamelCase()
+ {
+ return _matchCamelCase;
+ }
+
+ public void setMatchCamelCase(boolean matchCamelCase)
+ {
+ _matchCamelCase = matchCamelCase;
+ }
}
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesController.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesController.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesController.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -70,6 +70,7 @@
_panel.txtMaxLastSelectedCompletionNames.setText("" + _prefs.getMaxLastSelectedCompletionNames());
_panel.chkShowRemarksInColumnCompletion.setSelected(_prefs.isShowRemarksInColumnCompletion());
+ _panel.chkMatchCamelCase.setSelected(_prefs.isMatchCamelCase());
_panel.btnNewRow.addActionListener(new ActionListener()
@@ -170,6 +171,7 @@
}
_prefs.setShowRemarksInColumnCompletion(_panel.chkShowRemarksInColumnCompletion.isSelected());
+ _prefs.setMatchCamelCase(_panel.chkMatchCamelCase.isSelected());
}
Modified: trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesPanel.java
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesPanel.java 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/java/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/CodeCompletionPreferencesPanel.java 2012-02-07 22:23:38 UTC (rev 6567)
@@ -25,6 +25,7 @@
JButton btnDeleteRows;
JTextField txtMaxLastSelectedCompletionNames;
JCheckBox chkShowRemarksInColumnCompletion;
+ JCheckBox chkMatchCamelCase;
public CodeCompletionPreferencesPanel()
@@ -90,6 +91,13 @@
gbc = new GridBagConstraints(0,10,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(15,5,5,5),0,0 );
add(createShowRemarksInColumnCompletionPanel(),gbc);
+
+ gbc = new GridBagConstraints(0,11,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(15,5,5,5),0,0 );
+ chkMatchCamelCase = new JCheckBox(s_stringMgr.getString("CodeCompletionPreferencesPanel.matchCamelCase"));
+ add(chkMatchCamelCase,gbc);
+
+ gbc = new GridBagConstraints(0,12,1,1,2,2,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(15,5,5,5),0,0 );
+ add(new JPanel(),gbc);
}
Modified: trunk/sql12/plugins/codecompletion/src/main/resources/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/I18NStrings.properties
===================================================================
--- trunk/sql12/plugins/codecompletion/src/main/resources/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/I18NStrings.properties 2012-02-01 19:49:15 UTC (rev 6566)
+++ trunk/sql12/plugins/codecompletion/src/main/resources/net/sourceforge/squirrel_sql/plugins/codecompletion/prefs/I18NStrings.properties 2012-02-07 22:23:38 UTC (rev 6567)
@@ -36,3 +36,5 @@
CodeCompletionPreferencesPanel.showRemarksInColumnCompletionNote=Choose this option to see column remarks in code completion lists.\nNote: If you change this option on a running Session you need to do a Session cache refresh (F5)
CodeCompletionPreferencesPanel.showRemarksInColumnCompletionChk=Show remarks in column completion
+
+CodeCompletionPreferencesPanel.matchCamelCase=Match completions CamelCase wise
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|