You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(8) |
Oct
(34) |
Nov
(7) |
Dec
(2) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(29) |
Feb
(10) |
Mar
(14) |
Apr
(4) |
May
(2) |
Jun
|
Jul
(14) |
Aug
(25) |
Sep
(6) |
Oct
(18) |
Nov
(4) |
Dec
(14) |
| 2009 |
Jan
(28) |
Feb
(15) |
Mar
(15) |
Apr
(8) |
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
(12) |
Oct
(1) |
Nov
|
Dec
(22) |
| 2010 |
Jan
(14) |
Feb
|
Mar
(2) |
Apr
|
May
(7) |
Jun
|
Jul
(3) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: SVN by r. <sv...@ca...> - 2008-11-07 21:58:45
|
Author: roy
Date: 2008-11-07 22:31:58 +0100 (Fri, 07 Nov 2008)
New Revision: 326
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
added method insertText
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-16 21:16:38 UTC (rev 325)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-11-07 21:31:58 UTC (rev 326)
@@ -16,7 +16,6 @@
package nl.improved.sqlclient;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
@@ -492,10 +491,38 @@
*/
protected void repaint() {
if (isRunning()) {
- paint(getScreen());
+ waitAndPaint();
+ //paint(getScreen());
}
}
+ long wait = 0;
+ Thread t;
+ private class RepaintThread extends Thread {
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ if (wait <= (System.currentTimeMillis() +5) ) {
+ paint(screen);
+ return;
+ }
+ }
+ }
+ }
+
+ private synchronized void waitAndPaint() {
+ wait = System.currentTimeMillis();
+ if (t == null || !t.isAlive()) {
+ t = new RepaintThread();
+ t.start();
+ }
+ }
+
/**
* Paints the screen.
* @param screen the screen to be painted
@@ -654,63 +681,7 @@
} else {
newText = Character.toString(inp.getCharacter());
}
- if (newText.equals("\n")) {
- newLine(); // TODO Fix return in middle of an other line
- } else {
- Point cursorPosition = screen.getCursorPosition();
- List<StringBuffer> editableLines = getEditableCommand().getEditableLines();
- StringBuffer currentLine = editableLines.get(cursorPosition.y);
- if (cursorPosition.x > currentLine.length()) {
- for (int i = currentLine.length(); i < cursorPosition.x; i++) {
- currentLine.append(' ');
- }
- debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length());
- }
- currentLine.insert(cursorPosition.x, newText);
- cursorPosition.x += newText.length();
- // check if the new line is becoming too long
- if (currentLine.length() > screen.MAX_LINE_LENGTH) {
- // TODO search for lastspace that is not between '' ??
- int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" ");
- int lastChar = currentLine.charAt(lastSpace);
- if (lastSpace == -1) {
- lastSpace = currentLine.length();
- }
- // check if there are enough 'next' lines
- // if not.. add one
- if (editableLines.size()-1 == cursorPosition.y) {
- StringBuffer newLine = new StringBuffer();
- editableLines.add(newLine);
- }
- // check if the nextline has enough room for the new word
- // if not.. add a new line
- if (editableLines.get(cursorPosition.y+1).length()
- + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) {
- StringBuffer newLine = new StringBuffer();
- editableLines.add(cursorPosition.y+1, newLine);
- }
- // fetch the next line
- StringBuffer nextLine = editableLines.get(cursorPosition.y+1);
- // if the nextline already has some text.. add a space in front of it
- // if there is not already a 'breaking character' there
- if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) {
- nextLine.insert(0, ' ');
- }
- // insert the new text at the beginning
- nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length()));
- currentLine.delete(lastSpace, currentLine.length());
- if (lastChar == ' ') {
- nextLine.deleteCharAt(0);
- cursorPosition.x--;
- }
- // check if the cursor postition > the new line length
- // calculate new x and go to nextline
- if (cursorPosition.x >= lastSpace) {
- cursorPosition.x = cursorPosition.x - (lastSpace);
- cursorPosition.y++;
- }
- }
- }
+ insertText(newText);
}
}
} catch(Throwable t) {
@@ -719,6 +690,66 @@
repaint();
}
+ public void insertText(CharSequence newText) {
+ if (newText.equals("\n")) {
+ newLine(); // TODO Fix return in middle of an other line
+ } else {
+ Point cursorPosition = screen.getCursorPosition();
+ List<StringBuffer> editableLines = getEditableCommand().getEditableLines();
+ StringBuffer currentLine = editableLines.get(cursorPosition.y);
+ if (cursorPosition.x > currentLine.length()) {
+ for (int i = currentLine.length(); i < cursorPosition.x; i++) {
+ currentLine.append(' ');
+ }
+ debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length());
+ }
+ currentLine.insert(cursorPosition.x, newText);
+ cursorPosition.x += newText.length();
+ // check if the new line is becoming too long
+ if (currentLine.length() > screen.MAX_LINE_LENGTH) {
+ // TODO search for lastspace that is not between '' ??
+ int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" ");
+ int lastChar = currentLine.charAt(lastSpace);
+ if (lastSpace == -1) {
+ lastSpace = currentLine.length();
+ }
+ // check if there are enough 'next' lines
+ // if not.. add one
+ if (editableLines.size()-1 == cursorPosition.y) {
+ StringBuffer newLine = new StringBuffer();
+ editableLines.add(newLine);
+ }
+ // check if the nextline has enough room for the new word
+ // if not.. add a new line
+ if (editableLines.get(cursorPosition.y+1).length()
+ + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) {
+ StringBuffer newLine = new StringBuffer();
+ editableLines.add(cursorPosition.y+1, newLine);
+ }
+ // fetch the next line
+ StringBuffer nextLine = editableLines.get(cursorPosition.y+1);
+ // if the nextline already has some text.. add a space in front of it
+ // if there is not already a 'breaking character' there
+ if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) {
+ nextLine.insert(0, ' ');
+ }
+ // insert the new text at the beginning
+ nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length()));
+ currentLine.delete(lastSpace, currentLine.length());
+ if (lastChar == ' ') {
+ nextLine.deleteCharAt(0);
+ cursorPosition.x--;
+ }
+ // check if the cursor postition > the new line length
+ // calculate new x and go to nextline
+ if (cursorPosition.x >= lastSpace) {
+ cursorPosition.x = cursorPosition.x - (lastSpace);
+ cursorPosition.y++;
+ }
+ }
+ }
+ }
+
/**
* Return the editable version of the commandlines.
* If editing a previous command clone it and return the clone
|
|
From: SVN by r. <sv...@ca...> - 2008-10-16 21:16:49
|
Author: roy
Date: 2008-10-16 23:16:38 +0200 (Thu, 16 Oct 2008)
New Revision: 325
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
fix hide with using backspace
escape still works.. but hiding is really slow
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 15:06:52 UTC (rev 324)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-16 21:16:38 UTC (rev 325)
@@ -251,27 +251,17 @@
}
@Override
- public void processKeyEvent(KeyEvent evt) {
- super.processKeyEvent(evt);
-
- /*
- * SR: Ok, so I am aware that all this logic should have been placed in a KeyListener instead...
- * For some dark reason though it seems that if I add a keyListener to either this popup or the
- * menuitems individually, the listener never gets the desired key events.
- */
- if (evt.isConsumed()) {
- return;
+ public void hide() {
+ if (wasCancelled()) {
+ super.hide();
}
- if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
- MyPopupMenu.super.hide();
- evt.consume();
- }
}
- @Override
- public void hide() {}
-
- private String select() {
+ /**
+ * Use this method to block the user interface and return the selected value.
+ * @return the selected value
+ */
+ public String select() {
show();
return selectedValue;
}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-15 15:08:15
|
Author: rotman
Date: 2008-10-15 17:06:52 +0200 (Wed, 15 Oct 2008)
New Revision: 324
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
* Style fix for static field
* Attempt to make the popup disapear again on ESC
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 07:52:40 UTC (rev 323)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 15:06:52 UTC (rev 324)
@@ -167,7 +167,7 @@
return;
}
if (evt.isActionKey()) {
- if (evt.getKeyCode() == evt.VK_ENTER) {
+ if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
handleInput(new InputKey('\n'));
evt.consume();
} else if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
@@ -200,7 +200,7 @@
} else if (evt.getKeyCode() == KeyEvent.VK_END) {
handleInput(new InputKey(InputKey.SpecialKey.END));
evt.consume();
- }
+ }
return;
}
handleInput(new InputKey((char)evt.getKeyCode()));
@@ -250,7 +250,24 @@
}
}
+ @Override
+ public void processKeyEvent(KeyEvent evt) {
+ super.processKeyEvent(evt);
+ /*
+ * SR: Ok, so I am aware that all this logic should have been placed in a KeyListener instead...
+ * For some dark reason though it seems that if I add a keyListener to either this popup or the
+ * menuitems individually, the listener never gets the desired key events.
+ */
+ if (evt.isConsumed()) {
+ return;
+ }
+ if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ MyPopupMenu.super.hide();
+ evt.consume();
+ }
+ }
+
@Override
public void hide() {}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-15 07:52:48
|
Author: roy
Date: 2008-10-15 09:52:40 +0200 (Wed, 15 Oct 2008)
New Revision: 323
Modified:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
made selection work
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-14 19:30:34 UTC (rev 322)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-15 07:52:40 UTC (rev 323)
@@ -21,18 +21,15 @@
private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this);
+ public SQLShellComponent() {
+ setEditable(false);
+ }
@Override
public void processKeyEvent(KeyEvent arg0) {
//super.processKeyEvent(arg0);
sqlshellWindow.keyTyped(arg0);
}
- @Override
- public void processMouseEvent(MouseEvent arg0) {
- }
-
-
-
public static void main(String[] args) {
JFrame frame = new JFrame();
SQLShellComponent component = new SQLShellComponent();
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 19:30:44
|
Author: roy
Date: 2008-10-14 21:30:34 +0200 (Tue, 14 Oct 2008)
New Revision: 322
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
improved caret position (again.. sigh)
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:11:45 UTC (rev 321)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:30:34 UTC (rev 322)
@@ -91,11 +91,11 @@
newText.append(seq.toString());
if (i < commandLines.size()-1) {
newText.append("\n");
- totalLineCount++;
}
+ totalLineCount++;
}
- if (totalLineCount > getScreenHeight()-commandLines.size()) {
- totalLineCount = getScreenHeight()-commandLines.size();
+ if (totalLineCount > getScreenHeight()-1) {
+ totalLineCount = getScreenHeight()-1;
}
String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
@@ -105,12 +105,11 @@
}
Point cursorPos = screen.getCursorPosition();
try {
- int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y)+1);
+ int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y));
textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
} catch(Exception e) {
- debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y);
+ debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
}
- // TODO fix caretposition
textComponent.draw();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 19:11:55
|
Author: roy
Date: 2008-10-14 21:11:45 +0200 (Tue, 14 Oct 2008)
New Revision: 321
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
added logfile for charva (tmpdir/charva*.out) This file will be removed on exit
fixed cursor position when screenbuffer > screensize
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 18:57:36 UTC (rev 320)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:11:45 UTC (rev 321)
@@ -11,10 +11,16 @@
import charva.awt.event.KeyEvent;
import charvax.swing.JMenuItem;
import charvax.swing.JPopupMenu;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import nl.improved.sqlclient.AbstractSQLShellWindow;
import nl.improved.sqlclient.InputKey;
import nl.improved.sqlclient.Point;
@@ -27,6 +33,7 @@
*/
class CharvaSQLShellWindow extends AbstractSQLShellWindow {
private SQLShellComponent textComponent;
+ private OutputStream debugOut;
/**
* Constructor.
@@ -34,6 +41,13 @@
*/
public CharvaSQLShellWindow(SQLShellComponent textComponent) {
this.textComponent = textComponent;
+ try {
+ File tmpFile = File.createTempFile("charva", ".out");
+ tmpFile.deleteOnExit();
+ debugOut = new FileOutputStream(tmpFile);
+ } catch (IOException ex) {
+ Logger.getLogger(CharvaSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
}
@Override
@@ -80,8 +94,8 @@
totalLineCount++;
}
}
- if (totalLineCount > getScreenHeight()-1) {
- totalLineCount = getScreenHeight()-1;
+ if (totalLineCount > getScreenHeight()-commandLines.size()) {
+ totalLineCount = getScreenHeight()-commandLines.size();
}
String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
@@ -114,7 +128,13 @@
@Override
public void debug(String debug) {
-
+ if (debugOut != null) {
+ try {
+ debugOut.write((debug + "\n").getBytes());
+ } catch (IOException ex) {
+ Logger.getLogger(CharvaSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
}
@Override
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 18:57:46
|
Author: roy
Date: 2008-10-14 20:57:36 +0200 (Tue, 14 Oct 2008)
New Revision: 320
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
Log:
made passfield have focus when username is not empty
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-13 18:42:25 UTC (rev 319)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-14 18:57:36 UTC (rev 320)
@@ -85,6 +85,10 @@
add(cancelButton, gbc);
gbc.gridx = 1;
add(okButton, gbc);
+
+ if (username != null && username.length() > 0) {
+ passfield.requestFocus();
+ }
}
public void okButtonPressedSlot() {
|
|
From: SVN by r. <sv...@ca...> - 2008-10-13 18:42:36
|
Author: roy
Date: 2008-10-13 20:42:25 +0200 (Mon, 13 Oct 2008)
New Revision: 319
Modified:
sqlshell
Log:
new startup script
Modified: sqlshell
===================================================================
--- sqlshell 2008-10-13 18:40:23 UTC (rev 318)
+++ sqlshell 2008-10-13 18:42:25 UTC (rev 319)
@@ -22,21 +22,28 @@
WORKINGDIR=$(pwd)
# The directory where the JCurses jar and library are located.
-# Please note that JCurses requires tje jcurses.jar and libjcurses.so to
+# Please note that JCurses requires the jcurses.jar and libjcurses.so to
# be located in the same directory.
-JCURSES=${WORKINGDIR}/lib
+JCURSES=${WORKINGDIR}/lib/jcurses
+# The directory where the charva jar and library (dll/so file) are located.
+CHARVA=${WORKINGDIR}/lib/charva
# Where to find the SQLShell classes
-#SQLSHELL=${WORKINGDIR}/sqlshell.jar
-SQLSHELL=target/classes
+SQLSHELL=${WORKINGDIR}/sqlshell.jar
+##SQLSHELL=target/classes
# Jars providing drivers for the databases to support.
DRIVERS="${WORKINGDIR}/lib/hsqldb-1.8.0.jar"
# The classpath to use when running
-CP=${WORKINGDIR}:${SQLSHELL}:${JCURSES}/jcurses.jar
+#CP=${WORKINGDIR}:${SQLSHELL}:${JCURSES}/jcurses.jar
+#CP=${WORKINGDIR}:${SQLSHELL}:${JCURSES}/jcurses.jar
+CP=${WORKINGDIR}:${SQLSHELL}:${CHARVA}/charva.jar:${WORKINGDIR}/lib/commons-logging.jar
for DRIVER in ${DRIVERS} ; do
CP=${CP}:${DRIVER}
done
-${JAVA} -cp ${CP} nl.improved.sqlclient.SQLShell $@
+#Enable the file below to use the jcurses version
+#${JAVA} -cp ${CP} nl.improved.sqlclient.jcurses.SQLShell $@
+#Charva version
+${JAVA} -Djava.library.path=${CHARVA} -cp ${CP} nl.improved.sqlclient.charva.SQLShellComponent $@
|
|
From: SVN by r. <sv...@ca...> - 2008-10-13 18:40:32
|
Author: roy
Date: 2008-10-13 20:40:23 +0200 (Mon, 13 Oct 2008)
New Revision: 318
Modified:
makejars.sh
Log:
new version
Modified: makejars.sh
===================================================================
--- makejars.sh 2008-10-13 13:30:59 UTC (rev 317)
+++ makejars.sh 2008-10-13 18:40:23 UTC (rev 318)
@@ -1,6 +1,6 @@
#!/bin/bash
PROJECT=sqlshell
-VERSION=0.4
+VERSION=0.6
#cleanup
rm -Rf release
@@ -13,12 +13,13 @@
cp ../pom.xml source
cp ../README source
cp ../ChangeLog source
+cp ../docs/release-${VERSION}.txt source
cp ../${PROJECT} source
cp ../${PROJECT}.bat source
cd source
rm -Rf src/www
find . -name "*.svn" | xargs rm -Rf
-tar zcf ../${PROJECT}-src-${VERSION}.tgz .
+#tar zcf ../${PROJECT}-src-${VERSION}.tgz .
zip -r ../${PROJECT}-src-${VERSION}.zip .
cd ..
rm -Rf source
@@ -32,6 +33,7 @@
cp ../${PROJECT}.bat bin
cp ../README bin
cp ../ChangeLog bin
+cp ../docs/release-${VERSION}.txt bin
cp ../src/main/resources/db.properties bin
cp ../target/*.jar bin/${PROJECT}.jar
cp -Rf ../lib bin
@@ -47,7 +49,7 @@
chmod +x sqlshell
rm _sqlshell
cp -Rf ../../windows .
-tar zcf ../${PROJECT}-bin-${VERSION}.tgz .
+#tar zcf ../${PROJECT}-bin-${VERSION}.tgz .
zip -r ../${PROJECT}-bin-${VERSION}.zip .
cd ..
rm -Rf bin
|
|
From: SVN by r. <sv...@ca...> - 2008-10-13 13:31:13
|
Author: roy
Date: 2008-10-13 15:30:59 +0200 (Mon, 13 Oct 2008)
New Revision: 317
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
fixed some exceptions
ignore mouse cursor for now..
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-12 13:09:16 UTC (rev 316)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-13 13:30:59 UTC (rev 317)
@@ -1575,12 +1575,13 @@
*/
protected List<String> formatCommandLines(boolean showPrompt, String emptyLine, List<CharSequence> currentLines) {
List<String> tmpList = new ArrayList<String>();
- for (int i = 0; i < currentLines.size(); i++) {
+ List<CharSequence> pCurrentLines = new ArrayList<CharSequence>(currentLines);
+ for (int i = 0; i < pCurrentLines.size(); i++) {
if (i == 0 && showPrompt) {
- tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
+ tmpList.add(Screen.PROMPT+"> "+pCurrentLines.get(i));
} else {
String nrI = Integer.toString(i+1);
- tmpList.add(emptyLine.substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
+ tmpList.add(emptyLine.substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+pCurrentLines.get(i));
}
}
return tmpList;
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-12 13:09:16 UTC (rev 316)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-13 13:30:59 UTC (rev 317)
@@ -12,6 +12,7 @@
import charvax.swing.JMenuItem;
import charvax.swing.JPopupMenu;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import nl.improved.sqlclient.AbstractSQLShellWindow;
@@ -56,12 +57,12 @@
public void paint(Screen screen) {
int totalLineCount = 0;
StringBuilder newText = new StringBuilder();
- for (CharSequence seq: screen.getScreenBuffer()) {
+ for (CharSequence seq: new ArrayList<CharSequence>(screen.getScreenBuffer())) {
newText.append(seq.toString());
newText.append("\n");
totalLineCount++;
}
- for (SQLCommand s : getUnprocessedCommands()) {
+ for (SQLCommand s : new ArrayList<SQLCommand>(getUnprocessedCommands())) {
for (CharSequence seq: s.getLines()) {
newText.append(screen.getEmptyLine().substring(0, Screen.PROMPT.length()) + ">");
newText.append(seq.toString());
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-12 13:09:16 UTC (rev 316)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-13 13:30:59 UTC (rev 317)
@@ -9,6 +9,7 @@
import charva.awt.Point;
import charva.awt.Toolkit;
import charva.awt.event.KeyEvent;
+import charva.awt.event.MouseEvent;
import charvax.swing.JFrame;
import charvax.swing.JTextArea;
@@ -26,6 +27,12 @@
sqlshellWindow.keyTyped(arg0);
}
+ @Override
+ public void processMouseEvent(MouseEvent arg0) {
+ }
+
+
+
public static void main(String[] args) {
JFrame frame = new JFrame();
SQLShellComponent component = new SQLShellComponent();
|
|
From: SVN by r. <sv...@ca...> - 2008-10-12 13:09:25
|
Author: roy Date: 2008-10-12 15:09:16 +0200 (Sun, 12 Oct 2008) New Revision: 316 Modified: ChangeLog Log: mention changes Modified: ChangeLog =================================================================== --- ChangeLog 2008-10-12 12:30:37 UTC (rev 315) +++ ChangeLog 2008-10-12 13:09:16 UTC (rev 316) @@ -1,4 +1,4 @@ -0.6 +0.6 (2008-10-12) * Mysql case sensitivity fixes * Fix desc table for columns containing numbers * Added tab completion for connect @ @@ -9,6 +9,8 @@ * Tab completion case sensitive fix (For example jo<tab> -> Job) * Add tab completion to spool command * Fix error message in @ command when file could not be read + * Add persistent history + * Improved multithreading support by changing (default) toolkit used (charva) 0.5 (2008-03-14) * Allow for commands to start in the background, this will allow to continue |
|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:30:47
|
Author: roy Date: 2008-10-12 14:30:37 +0200 (Sun, 12 Oct 2008) New Revision: 315 Added: lib/charva-amd64/libTerminal.so Log: amd 64 linux file Added: lib/charva-amd64/libTerminal.so =================================================================== (Binary files differ) Property changes on: lib/charva-amd64/libTerminal.so ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:15:39
|
Author: roy Date: 2008-10-12 14:15:32 +0200 (Sun, 12 Oct 2008) New Revision: 314 Modified: pom.xml Log: 0.6 version Modified: pom.xml =================================================================== --- pom.xml 2008-10-12 12:15:13 UTC (rev 313) +++ pom.xml 2008-10-12 12:15:32 UTC (rev 314) @@ -19,7 +19,7 @@ <groupId>nl.improved</groupId> <artifactId>sqlshell</artifactId> <packaging>jar</packaging> - <version>0.6-SNAPSHOT</version> + <version>0.6</version> <name>SQLShell ~ the improved sqlclient</name> <url>http://sqlshell.sourceforge.org</url> <build> |
|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:15:21
|
Author: roy Date: 2008-10-12 14:15:13 +0200 (Sun, 12 Oct 2008) New Revision: 313 Added: sqlshell.bat Log: windows batch file Added: sqlshell.bat =================================================================== --- sqlshell.bat 2008-10-12 11:57:48 UTC (rev 312) +++ sqlshell.bat 2008-10-12 12:15:13 UTC (rev 313) @@ -0,0 +1,32 @@ +REM Copyright 2007 Roy van der Kuil (ro...@va...) and Stefan Rotman (st...@ro...) +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +REM Dir to use as base for relative locations +set WORKINGDIR=c:\sqlshell\ + +REM The directory where the JCurses jar and library are located. +REM Please note that JCurses requires tje jcurses.jar and libjcurses.so to +REM be located in the same directory. +set JCURSES=%WORKINGDIR%\lib + +REM Where to find the SQLShell classes +set SQLSHELL=%WORKINGDIR%\sqlshell.jar + +# REM providing drivers for the databases to support. +set DRIVERS="%WORKINGDIR%\lib\hsqldb-1.8.0.jar" + +REM The classpath to use when running +set CP=%WORKINGDIR%;%SQLSHELL%;%JCURSES%\jcurses.jar;%WORKINGDIR%\lib\charva\charva.jar;%WORKINGDIR%\lib\commons-logging.jar + +java -Djava.library.path=%WORKINGDIR%\lib\charva -classpath %CP%;%DRIVERS% nl.improved.sqlclient.charva.SQLShellComponent Property changes on: sqlshell.bat ___________________________________________________________________ Name: svn:executable + * |
|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:04:43
|
Author: roy Date: 2008-10-12 13:37:51 +0200 (Sun, 12 Oct 2008) New Revision: 311 Added: lib/charva-amd64/ Log: charva amd64 compiled library |
|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:04:38
|
Author: roy
Date: 2008-10-12 13:57:48 +0200 (Sun, 12 Oct 2008)
New Revision: 312
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
some fixes in method names
implemented pageup/down
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-12 11:37:51 UTC (rev 311)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-12 11:57:48 UTC (rev 312)
@@ -21,12 +21,16 @@
import nl.improved.sqlclient.Screen;
/**
- *
+ * The sqlshell window implementation for charva.
* @author roy
*/
class CharvaSQLShellWindow extends AbstractSQLShellWindow {
private SQLShellComponent textComponent;
+ /**
+ * Constructor.
+ * @param textComponent the text component for rendering the text
+ */
public CharvaSQLShellWindow(SQLShellComponent textComponent) {
this.textComponent = textComponent;
}
@@ -41,7 +45,10 @@
return Toolkit.getDefaultToolkit().getScreenRows()-1;
}
- void show() {
+ /**
+ * Force repaint of the screen.
+ */
+ void repaintScreen() {
paint(getScreen());
}
@@ -75,11 +82,11 @@
if (totalLineCount > getScreenHeight()-1) {
totalLineCount = getScreenHeight()-1;
}
- String trimmed = trim(newText);
+ String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
textComponent.append(trimmed.substring(textComponent.getText().length()));
} else {
- textComponent.replaceRange(trim(newText), 0, textComponent.getText().length());
+ textComponent.replaceRange(trimmed, 0, textComponent.getText().length());
}
Point cursorPos = screen.getCursorPosition();
try {
@@ -149,10 +156,10 @@
} else if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
handleInput(new InputKey(InputKey.SpecialKey.DELETE));
evt.consume();
- } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) {
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
handleInput(new InputKey(InputKey.SpecialKey.PAGE_DOWN));
evt.consume();
- } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) {
handleInput(new InputKey(InputKey.SpecialKey.PAGE_UP));
evt.consume();
} else if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
@@ -180,7 +187,7 @@
evt.consume();
}
- private String trim(StringBuilder text) {
+ private String trim(StringBuilder text, int pageUpCount) {
String strText = text.toString();
if (strText.indexOf('\n') < 0) {
return strText;
@@ -191,16 +198,21 @@
return strText;
}
StringBuilder newString = new StringBuilder();
+ int offset = Math.max(0, lines.length - ((pageUpCount +1) * maxHeight));
boolean endsWithReturn = strText.endsWith("\n");
- for (int i = lines.length - maxHeight; i < lines.length; i++) {
- newString.append(lines[i]);
- if (i < lines.length-1 || endsWithReturn) {
+ for (int i = 0; i < maxHeight; i++) {
+ newString.append(lines[i+offset]);
+ if (i+offset < lines.length-1 || endsWithReturn) {
newString.append('\n');
}
}
return newString.toString();
}
+ /**
+ * Hacked version of a charva (swing) popup menu.
+ * It returns the selected menu item on hide.
+ */
private static class MyPopupMenu extends JPopupMenu {
private String selectedValue;
public MyPopupMenu(Vector items) {
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-12 11:37:51 UTC (rev 311)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-12 11:57:48 UTC (rev 312)
@@ -34,7 +34,7 @@
component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()-2
, Toolkit.getDefaultToolkit().getScreenRows()-2));
frame.add(component);
- component.sqlshellWindow.show();
+ component.sqlshellWindow.repaintScreen();
frame.pack();
frame.show();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-11 12:29:37
|
Author: roy
Date: 2008-10-11 14:29:29 +0200 (Sat, 11 Oct 2008)
New Revision: 310
Added:
src/main/java/nl/improved/sqlclient/charva/
src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Modified:
pom.xml
src/main/java/nl/improved/sqlclient/
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/jcurses/
src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
Log:
code split
introduction to charva based sqlshell window
Modified: pom.xml
===================================================================
--- pom.xml 2008-10-11 11:20:20 UTC (rev 309)
+++ pom.xml 2008-10-11 12:29:29 UTC (rev 310)
@@ -43,6 +43,13 @@
<systemPath>${basedir}/lib/jcurses/jcurses.jar</systemPath>
</dependency>
<dependency>
+ <groupId>charva</groupId>
+ <artifactId>charva</artifactId>
+ <version>1.1.4</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/charva/charva.jar</systemPath>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
Property changes on: src/main/java/nl/improved/sqlclient
___________________________________________________________________
Name: svn:ignore
- .SQLPlusPlus.java.swp
.SQLPlus.java.swp
.DBConnector.java.swp
.SQLUtil.java.swp
.Point.java.swp
.SQLLineWrapper.java.swp
.SQLOutput.java.swp
.QueryExecutor.java.swp
.SQLShell.java.swp
+ .SQLPlusPlus.java.swp
.SQLPlus.java.swp
.DBConnector.java.swp
.SQLUtil.java.swp
.Point.java.swp
.SQLLineWrapper.java.swp
.SQLOutput.java.swp
.QueryExecutor.java.swp
.SQLShell.java.swp
.AbstractSQLShellWindow.java.swo
.AbstractSQLShellWindow.java.swp
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-11 11:20:20 UTC (rev 309)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-11 12:29:29 UTC (rev 310)
@@ -1567,6 +1567,26 @@
}
/**
+ * Format the command lines to fit on the screen and start with a line id.
+ * @param showPrompt true if the prompt is shown
+ * @param emptyLine an empty line string
+ * @param currentLines the current command lines to be formatted
+ * @return a formatted list of strings
+ */
+ protected List<String> formatCommandLines(boolean showPrompt, String emptyLine, List<CharSequence> currentLines) {
+ List<String> tmpList = new ArrayList<String>();
+ for (int i = 0; i < currentLines.size(); i++) {
+ if (i == 0 && showPrompt) {
+ tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
+ } else {
+ String nrI = Integer.toString(i+1);
+ tmpList.add(emptyLine.substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
+ }
+ }
+ return tmpList;
+ }
+
+ /**
* Writes in/output to a file.
*/
private class SpoolCommand implements Command {
Added: src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-11 11:20:20 UTC (rev 309)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-11 12:29:29 UTC (rev 310)
@@ -0,0 +1,136 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.charva;
+
+import charva.awt.GridBagConstraints;
+import charva.awt.GridBagLayout;
+import charva.awt.event.ActionEvent;
+import charva.awt.event.ActionListener;
+import charva.awt.event.KeyEvent;
+import charva.awt.event.KeyListener;
+import charvax.swing.JButton;
+import charvax.swing.JDialog;
+import charvax.swing.JLabel;
+import charvax.swing.JPasswordField;
+import charvax.swing.JTextField;
+
+/**
+ *
+ * @author roy
+ */
+public class CharvaLoginDialog extends JDialog {
+
+ private boolean exitOk = false;
+ private JTextField userfield;
+ private JPasswordField passfield;
+
+ /**
+ * Constructor.
+ * @param username the default value in the username field
+ * @param password the default value in the password field
+ */
+ public CharvaLoginDialog(final String username, final String password) {
+ setModal(true);
+ userfield = new JTextField(15);
+ setUsername(username);
+ passfield = new JPasswordField(15);
+ passfield.addKeyListener(new KeyListener() {
+
+ public void keyPressed(KeyEvent arg0) { }
+
+ public void keyTyped(KeyEvent evt) {
+ if(evt.isActionKey() && evt.getKeyCode() == KeyEvent.VK_ENTER) {
+ okButtonPressedSlot();
+ }
+ }
+ public void keyReleased(KeyEvent arg0) { }
+ });
+
+ setPassword(password);
+ JButton okButton = new JButton("Ok");
+
+ okButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ okButtonPressedSlot();
+ }
+ });
+ JButton cancelButton = new JButton("Cancel");
+ cancelButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ CharvaLoginDialog.this.exitOk = false;
+ CharvaLoginDialog.this.hide();
+ }
+ });
+ setLayout(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.gridx = 0;
+ add(new JLabel("Login:"), gbc);
+ gbc.gridx = 1;
+ add(userfield, gbc);
+ gbc.gridx = 0;
+ gbc.gridy = 1;
+ add(new JLabel("Password:"), gbc);
+ gbc.gridx = 1;
+ add(passfield, gbc);
+ gbc.gridx = 0;
+ gbc.gridy = 2;
+ add(cancelButton, gbc);
+ gbc.gridx = 1;
+ add(okButton, gbc);
+ }
+
+ public void okButtonPressedSlot() {
+ exitOk = true;
+ hide();
+ }
+
+
+
+ public void setUsername(String username) {
+ if (username == null) {
+ userfield.setText("");
+ } else {
+ userfield.setText(username);
+ }
+ }
+
+ /**
+ * Returns the username entered.
+ * @return the username entered.
+ */
+ public String getUsername() {
+ return userfield.getText();
+ }
+
+ public void setPassword(String password) {
+ if (password == null) {
+ passfield.setText("");
+ } else {
+ passfield.setText(password);
+ }
+ }
+
+ /**
+ * Returns the password entered.
+ * @return the password entered.
+ */
+ public String getPassword() {
+ return passfield.getText();
+ }
+
+ /**
+ * Returns true if the dialog has been closed to accept the input variables.
+ * @return true if the dialog has been closed to accept the input variables.n
+ */
+ public boolean endedSuccessfully() {
+ return exitOk;
+ }
+}
\ No newline at end of file
Added: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-11 11:20:20 UTC (rev 309)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-11 12:29:29 UTC (rev 310)
@@ -0,0 +1,230 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.charva;
+
+import charva.awt.Toolkit;
+import charva.awt.event.ActionEvent;
+import charva.awt.event.ActionListener;
+import charva.awt.event.KeyEvent;
+import charvax.swing.JMenuItem;
+import charvax.swing.JPopupMenu;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Vector;
+import nl.improved.sqlclient.AbstractSQLShellWindow;
+import nl.improved.sqlclient.InputKey;
+import nl.improved.sqlclient.Point;
+import nl.improved.sqlclient.SQLCommand;
+import nl.improved.sqlclient.Screen;
+
+/**
+ *
+ * @author roy
+ */
+class CharvaSQLShellWindow extends AbstractSQLShellWindow {
+ private SQLShellComponent textComponent;
+
+ public CharvaSQLShellWindow(SQLShellComponent textComponent) {
+ this.textComponent = textComponent;
+ }
+
+ @Override
+ public int getScreenWidth() {
+ return Toolkit.getDefaultToolkit().getScreenColumns()-1;
+ }
+
+ @Override
+ public int getScreenHeight() {
+ return Toolkit.getDefaultToolkit().getScreenRows()-1;
+ }
+
+ void show() {
+ paint(getScreen());
+ }
+
+ @Override
+ public void paint(Screen screen) {
+ int totalLineCount = 0;
+ StringBuilder newText = new StringBuilder();
+ for (CharSequence seq: screen.getScreenBuffer()) {
+ newText.append(seq.toString());
+ newText.append("\n");
+ totalLineCount++;
+ }
+ for (SQLCommand s : getUnprocessedCommands()) {
+ for (CharSequence seq: s.getLines()) {
+ newText.append(screen.getEmptyLine().substring(0, Screen.PROMPT.length()) + ">");
+ newText.append(seq.toString());
+ newText.append("\n");
+ totalLineCount++;
+ }
+ }
+ List<String> commandLines = formatCommandLines(screen.getShowPrompt()
+ , screen.getEmptyLine(),(List<CharSequence>) getCommand().getLines());
+ for (int i = 0; i < commandLines.size(); i++) {
+ CharSequence seq = commandLines.get(i);
+ newText.append(seq.toString());
+ if (i < commandLines.size()-1) {
+ newText.append("\n");
+ totalLineCount++;
+ }
+ }
+ if (totalLineCount > getScreenHeight()-1) {
+ totalLineCount = getScreenHeight()-1;
+ }
+ String trimmed = trim(newText);
+ if (trimmed.startsWith(textComponent.getText())) {
+ textComponent.append(trimmed.substring(textComponent.getText().length()));
+ } else {
+ textComponent.replaceRange(trim(newText), 0, textComponent.getText().length());
+ }
+ Point cursorPos = screen.getCursorPosition();
+ try {
+ int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y)+1);
+ textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
+ } catch(Exception e) {
+ debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y);
+ }
+ // TODO fix caretposition
+ textComponent.draw();
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ Toolkit.getDefaultToolkit().getTopWindow().hide();
+ }
+
+
+ @Override
+ public void beep() {
+ Toolkit.getDefaultToolkit().beep();
+ }
+
+ @Override
+ public void debug(String debug) {
+
+ }
+
+ @Override
+ public String select(List<String> items, Point p) {
+ Vector v = new Vector(items.size());
+ for(String item : items) {
+ JMenuItem mi = new JMenuItem(item);
+ mi.setActionCommand(item);
+ v.add(mi);
+ }
+ MyPopupMenu menu = new MyPopupMenu(v);
+ charva.awt.Point point = new charva.awt.Point(p.x, Math.max(2, p.y-items.size()));
+ menu.setLocation(point);
+ return menu.select();
+ }
+
+ @Override
+ protected String[] getLoginCredentials(String username, String password) throws SQLException {
+
+ CharvaLoginDialog charvaLoginDialog = new CharvaLoginDialog(username, password);
+ charvaLoginDialog.setLocationRelativeTo(textComponent);
+ charvaLoginDialog.show();
+ if (charvaLoginDialog.endedSuccessfully()) {
+ return new String[]{charvaLoginDialog.getUsername(), charvaLoginDialog.getPassword()};
+ }
+ return null;
+ }
+
+ public void keyTyped(KeyEvent evt) {
+ if (evt.isConsumed()) {
+ return;
+ }
+ if (evt.isActionKey()) {
+ if (evt.getKeyCode() == evt.VK_ENTER) {
+ handleInput(new InputKey('\n'));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
+ handleInput(new InputKey(InputKey.SpecialKey.BACKSPACE));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
+ handleInput(new InputKey(InputKey.SpecialKey.DELETE));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) {
+ handleInput(new InputKey(InputKey.SpecialKey.PAGE_DOWN));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
+ handleInput(new InputKey(InputKey.SpecialKey.PAGE_UP));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
+ handleInput(new InputKey(InputKey.SpecialKey.LEFT));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
+ handleInput(new InputKey(InputKey.SpecialKey.RIGHT));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
+ handleInput(new InputKey(InputKey.SpecialKey.DOWN));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_UP) {
+ handleInput(new InputKey(InputKey.SpecialKey.UP));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_HOME) {
+ handleInput(new InputKey(InputKey.SpecialKey.HOME));
+ evt.consume();
+ } else if (evt.getKeyCode() == KeyEvent.VK_END) {
+ handleInput(new InputKey(InputKey.SpecialKey.END));
+ evt.consume();
+ }
+ return;
+ }
+ handleInput(new InputKey((char)evt.getKeyCode()));
+ evt.consume();
+ }
+
+ private String trim(StringBuilder text) {
+ String strText = text.toString();
+ if (strText.indexOf('\n') < 0) {
+ return strText;
+ }
+ int maxHeight = getScreenHeight()-1;
+ String[] lines = strText.split("\n");
+ if (lines.length <= maxHeight) {
+ return strText;
+ }
+ StringBuilder newString = new StringBuilder();
+ boolean endsWithReturn = strText.endsWith("\n");
+ for (int i = lines.length - maxHeight; i < lines.length; i++) {
+ newString.append(lines[i]);
+ if (i < lines.length-1 || endsWithReturn) {
+ newString.append('\n');
+ }
+ }
+ return newString.toString();
+ }
+
+ private static class MyPopupMenu extends JPopupMenu {
+ private String selectedValue;
+ public MyPopupMenu(Vector items) {
+ super(items);
+
+ ActionListener acl = new ActionListener() {
+
+ public void actionPerformed(ActionEvent arg0) {
+ selectedValue = arg0.getActionCommand();
+ MyPopupMenu.super.hide();
+ }
+ };
+ for (int i = 0; i < items.size(); i++) {
+ ((JMenuItem)items.get(i)).addActionListener(acl);
+ }
+ }
+
+
+ @Override
+ public void hide() {}
+
+ private String select() {
+ show();
+ return selectedValue;
+ }
+ }
+}
Added: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-11 11:20:20 UTC (rev 309)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-11 12:29:29 UTC (rev 310)
@@ -0,0 +1,42 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.charva;
+
+import charva.awt.Dimension;
+import charva.awt.Point;
+import charva.awt.Toolkit;
+import charva.awt.event.KeyEvent;
+import charvax.swing.JFrame;
+import charvax.swing.JTextArea;
+
+/**
+ *
+ * @author roy
+ */
+public class SQLShellComponent extends JTextArea {
+
+ private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this);
+
+ @Override
+ public void processKeyEvent(KeyEvent arg0) {
+ //super.processKeyEvent(arg0);
+ sqlshellWindow.keyTyped(arg0);
+ }
+
+ public static void main(String[] args) {
+ JFrame frame = new JFrame();
+ SQLShellComponent component = new SQLShellComponent();
+ frame.add(component);
+ //frame.pack();
+ component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()-2
+ , Toolkit.getDefaultToolkit().getScreenRows()-2));
+ frame.add(component);
+ component.sqlshellWindow.show();
+ frame.pack();
+ frame.show();
+ }
+
+}
Property changes on: src/main/java/nl/improved/sqlclient/jcurses
___________________________________________________________________
Name: svn:ignore
+ .SQLShellWindow.java.swo
.SQLShellWindow.java.swp
Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-10-11 11:20:20 UTC (rev 309)
+++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-10-11 12:29:29 UTC (rev 310)
@@ -339,26 +339,6 @@
return result;
}
- /**
- * Format the command lines to fit on the screen and start with a line id.
- * @param showPrompt true if the prompt is shown
- * @param emptyLine an empty line string
- * @param currentLines the current command lines to be formatted
- * @return a formatted list of strings
- */
- private List<String> formatCommandLines(boolean showPrompt, String emptyLine, List<CharSequence> currentLines) {
- List<String> tmpList = new ArrayList<String>();
- for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0 && showPrompt) {
- tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
- } else {
- String nrI = Integer.toString(i+1);
- tmpList.add(emptyLine.substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
- }
- }
- return tmpList;
- }
-
public static void main(String[] args) {
SQLShellWindow shell = new SQLShellWindow();
shell.show();
|
|
From: SVN by r. <sv...@ca...> - 2008-10-11 12:20:32
|
Author: roy Date: 2008-10-11 13:20:20 +0200 (Sat, 11 Oct 2008) New Revision: 309 Added: lib/charva/ lib/charva/charva.jar lib/charva/libTerminal.so Log: added charva to compile path Added: lib/charva/charva.jar =================================================================== (Binary files differ) Property changes on: lib/charva/charva.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: lib/charva/libTerminal.so =================================================================== (Binary files differ) Property changes on: lib/charva/libTerminal.so ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
|
From: SVN by r. <sv...@ca...> - 2008-10-11 12:20:28
|
Author: roy
Date: 2008-10-11 13:18:11 +0200 (Sat, 11 Oct 2008)
New Revision: 308
Added:
lib/jcurses/
lib/jcurses/jcurses.jar
lib/jcurses/libjcurses.so
Removed:
lib/jcurses.jar
lib/libjcurses.so
Modified:
pom.xml
Log:
moved jcurses to a separate directory
Copied: lib/jcurses/jcurses.jar (from rev 273, lib/jcurses.jar)
Property changes on: lib/jcurses/jcurses.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:mergeinfo
+
Copied: lib/jcurses/libjcurses.so (from rev 273, lib/libjcurses.so)
Property changes on: lib/jcurses/libjcurses.so
___________________________________________________________________
Name: svn:executable
+
Name: svn:mime-type
+ application/octet-stream
Name: svn:mergeinfo
+
Deleted: lib/jcurses.jar
===================================================================
(Binary files differ)
Deleted: lib/libjcurses.so
===================================================================
(Binary files differ)
Modified: pom.xml
===================================================================
--- pom.xml 2008-09-17 06:00:52 UTC (rev 307)
+++ pom.xml 2008-10-11 11:18:11 UTC (rev 308)
@@ -40,7 +40,7 @@
<artifactId>jcurses</artifactId>
<version>0.9.5</version>
<scope>system</scope>
- <systemPath>${basedir}/lib/jcurses.jar</systemPath>
+ <systemPath>${basedir}/lib/jcurses/jcurses.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
|
|
From: SVN by r. <sv...@ca...> - 2008-09-16 23:01:04
|
Author: roy
Date: 2008-09-17 08:00:52 +0200 (Wed, 17 Sep 2008)
New Revision: 307
Modified:
src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
Log:
some more code refactoring
Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-09-15 19:11:19 UTC (rev 306)
+++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-09-17 06:00:52 UTC (rev 307)
@@ -19,19 +19,10 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import jcurses.event.ActionEvent;
-import jcurses.event.ActionListener;
import jcurses.system.CharColor;
import jcurses.system.InputChar;
import jcurses.system.Toolkit;
-import jcurses.widgets.Button;
-import jcurses.widgets.Dialog;
-import jcurses.widgets.GridLayoutManager;
-import jcurses.widgets.Label;
-import jcurses.widgets.PasswordField;
import jcurses.widgets.PopUpMenu;
-import jcurses.widgets.TextField;
-import jcurses.widgets.WidgetsConstants;
import jcurses.widgets.Window;
import nl.improved.sqlclient.AbstractSQLShellWindow;
import nl.improved.sqlclient.InputKey;
@@ -150,7 +141,7 @@
if (!dontRepaint && repaint) {
try {
synchronized(this) {
- _paint(screen);
+ paintImpl(screen);
}
} catch(Throwable t) {
error(t);
@@ -217,32 +208,31 @@
}
}
- private void _paint(Screen screen) {
+ /**
+ * Actual implementation of the paint screen method.
+ * This is different from the normal paint method since this will only
+ * (and should be) called from the main thread to overcome painting errors.
+ * @param screen the screen to paint
+ */
+ private void paintImpl(Screen screen) {
if (!isRunning()) {
return;
}
synchronized(lockObject) {
CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
- List<CharSequence> tmpList = new ArrayList<CharSequence>();
- List<CharSequence> screenBuffer = screen.getScreenBuffer();
- tmpList.addAll(screenBuffer);
+ List<CharSequence> tmpList = clone(screen.getScreenBuffer());
//add prompt
- List<SQLCommand> commands = getUnprocessedCommands();
- commands.add(getCommand());
- for (SQLCommand commandLines : commands) {
- //SQLCommand commandLines = getCommand();
- List<? extends CharSequence> currentLines = commandLines.getLines();
- for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0 && screen.getShowPrompt()) {
- tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
- } else {
- String nrI = Integer.toString(i+1);
- tmpList.add(screen.getEmptyLine().substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
- }
- }
+ List<SQLCommand> commandList = getUnprocessedCommands();
+ //commandList.add(getCommand());
+ boolean showPrompt = screen.getShowPrompt();
+ for (SQLCommand commandLines : commandList) {
+ List<CharSequence> currentLines = clone((List<CharSequence>) commandLines.getLines());
+ tmpList.addAll(formatCommandLines(showPrompt, screen.getEmptyLine(), currentLines));
}
+ List<CharSequence> currentCommandLines = clone((List<CharSequence>) getCommand().getLines());
+ tmpList.addAll(formatCommandLines(showPrompt, screen.getEmptyLine(), currentCommandLines));
int startLine;
if (tmpList.size() > Toolkit.getScreenHeight()-1) {
startLine = tmpList.size() - (Toolkit.getScreenHeight()-1);
@@ -270,9 +260,9 @@
color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.REVERSE, CharColor.REVERSE);
String cursorChar = " ";
Point cursorPosition = screen.getCursorPosition();
- SQLCommand commandLines = getCommand();
- if (commandLines.getLines().size() > 0) {
- String tmp = commandLines.getLines().get(cursorPosition.y).toString();
+ //SQLCommand commandLines = getCommand();
+ if (currentCommandLines.size() > 0) {
+ String tmp = currentCommandLines.get(cursorPosition.y).toString();
if (cursorPosition.x < 0) {
debug("Cursor position was: "+ cursorPosition +" fixing");
cursorPosition.x = 0;
@@ -281,7 +271,7 @@
cursorChar = tmp.substring(cursorPosition.x, cursorPosition.x+1);
}
}
- Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color);
+ Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(currentCommandLines.size() -cursorPosition.y)-startLine, color);
if (debugString != null) {
if (debugString.length() > Toolkit.getScreenWidth()) {
debugString = debugString.substring(0, Toolkit.getScreenWidth()-1);
@@ -293,6 +283,13 @@
}
}
+ /**
+ * Fetch the login detail information.
+ * @param username the default username
+ * @param password the default password
+ * @return the login credential string array
+ * @throws java.sql.SQLException
+ */
@Override
protected String[] getLoginCredentials(String username, String password) throws SQLException {
LoginDialog diag = new LoginDialog(username, password);
@@ -329,6 +326,39 @@
Toolkit.beep();
}
+ /**
+ * Clone a list of charsequence to make sure it isn't modified later (during paint).
+ * @param screenBuffer the screenBuffer to clone
+ * @return a cloned list of charsequence objects.
+ */
+ private static List<CharSequence> clone(List<CharSequence> screenBuffer) {
+ List<CharSequence> result = new ArrayList<CharSequence>(screenBuffer.size());
+ for(CharSequence cs : screenBuffer) {
+ result.add(cs.toString());
+ }
+ return result;
+ }
+
+ /**
+ * Format the command lines to fit on the screen and start with a line id.
+ * @param showPrompt true if the prompt is shown
+ * @param emptyLine an empty line string
+ * @param currentLines the current command lines to be formatted
+ * @return a formatted list of strings
+ */
+ private List<String> formatCommandLines(boolean showPrompt, String emptyLine, List<CharSequence> currentLines) {
+ List<String> tmpList = new ArrayList<String>();
+ for (int i = 0; i < currentLines.size(); i++) {
+ if (i == 0 && showPrompt) {
+ tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
+ } else {
+ String nrI = Integer.toString(i+1);
+ tmpList.add(emptyLine.substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
+ }
+ }
+ return tmpList;
+ }
+
public static void main(String[] args) {
SQLShellWindow shell = new SQLShellWindow();
shell.show();
@@ -339,4 +369,5 @@
}
*/
}
+
}
|
|
From: SVN by r. <sv...@ca...> - 2008-09-15 12:11:28
|
Author: roy
Date: 2008-09-15 21:11:19 +0200 (Mon, 15 Sep 2008)
New Revision: 306
Added:
src/main/java/nl/improved/sqlclient/jcurses/LoginDialog.java
Modified:
src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
Log:
small cleanup code step
Added: src/main/java/nl/improved/sqlclient/jcurses/LoginDialog.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/LoginDialog.java 2008-09-15 19:01:58 UTC (rev 305)
+++ src/main/java/nl/improved/sqlclient/jcurses/LoginDialog.java 2008-09-15 19:11:19 UTC (rev 306)
@@ -0,0 +1,138 @@
+package nl.improved.sqlclient.jcurses;
+
+import jcurses.event.ActionEvent;
+import jcurses.event.ActionListener;
+import jcurses.system.InputChar;
+import jcurses.widgets.Button;
+import jcurses.widgets.Dialog;
+import jcurses.widgets.GridLayoutManager;
+import jcurses.widgets.Label;
+import jcurses.widgets.PasswordField;
+import jcurses.widgets.TextField;
+import jcurses.widgets.WidgetsConstants;
+
+/**
+ * Simple login dialog used for jcurses implementation.
+ * It allows a user to enter the username/pwd
+ */
+public class LoginDialog extends Dialog {
+
+ private boolean exitOk = false;
+ private TextField userfield;
+ private PasswordField passfield;
+
+ /**
+ * Constructor.
+ * @param username the default value in the username field
+ * @param password the default value in the password field
+ */
+ public LoginDialog(final String username, final String password) {
+ super(10, 10, 50, 7, true, "Connect");
+ userfield = new TextField();
+ setUsername(username);
+ passfield = new PasswordField() {
+
+ @Override
+ protected void focus() {
+ super.focus();
+ }
+
+ @Override
+ protected boolean handleInput(InputChar ch) {
+ if (!ch.isSpecialCode() && ch.getCharacter() == '\n') {
+ okButtonPressedSlot();
+ return false;
+ }
+ return super.handleInput(ch);
+ }
+ };
+ setPassword(password);
+ Button okButton = new Button("Ok");
+ okButton.addListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ okButtonPressedSlot();
+ }
+ });
+ Button cancelButton = new Button("Cancel");
+ cancelButton.addListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ LoginDialog.this.exitOk = false;
+ LoginDialog.this.close();
+ }
+ });
+ GridLayoutManager glm = new GridLayoutManager(4, 3);
+ getRootPanel().setLayoutManager(glm);
+ glm.addWidget(new Label("Username"), 0, 0, 1, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
+ glm.addWidget(userfield, 1, 0, 3, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
+ glm.addWidget(new Label("Password"), 0, 1, 1, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
+ glm.addWidget(passfield, 1, 1, 3, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
+
+ glm.addWidget(okButton, 1, 2, 1, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
+ glm.addWidget(cancelButton, 2, 2, 1, 1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
+ }
+
+ public void okButtonPressedSlot() {
+ exitOk = true;
+ close();
+ }
+
+
+ /**
+ * Override to force focus on the correct input fields.
+ */
+ @Override
+ protected void activate() {
+ super.activate();
+ if (userfield.getText().length() == 0) {
+ userfield.getFocus();
+ } else if (passfield.getText().length() == 0) {
+ passfield.getFocus();
+ } else {
+ throw new IllegalStateException("We have login data, but get a login dailog anyway.");
+ }
+ }
+
+ public void setUsername(String username) {
+ if (username == null) {
+ userfield.setText("");
+ } else {
+ userfield.setText(username);
+ }
+ }
+
+ /**
+ * Returns the username entered.
+ * @return the username entered.
+ */
+ public String getUsername() {
+ return userfield.getText();
+ }
+
+ public void setPassword(String password) {
+ if (password == null) {
+ passfield.setText("");
+ } else {
+ passfield.setText(password);
+ }
+ }
+
+ /**
+ * Returns the password entered.
+ * @return the password entered.
+ */
+ public String getPassword() {
+ return passfield.getText();
+ }
+
+ /**
+ * Returns true if the dialog has been closed to accept the input variables.
+ * @return true if the dialog has been closed to accept the input variables.n
+ */
+ public boolean endedSuccessfully() {
+ return exitOk;
+ }
+}
Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-09-15 19:01:58 UTC (rev 305)
+++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-09-15 19:11:19 UTC (rev 306)
@@ -299,7 +299,7 @@
dontRepaint = true;
try {
diag.show();
- if (!diag.exitOk) {
+ if (!diag.endedSuccessfully()) {
throw new SQLException("Connect cancelled.");
}
return new String[] {diag.getUsername(), diag.getPassword() };
@@ -329,104 +329,6 @@
Toolkit.beep();
}
- private static class LoginDialog extends Dialog {
- private boolean exitOk = false;
- private TextField userfield;
- private PasswordField passfield;
-
- public LoginDialog(final String username, final String password) {
- super(10,10, 50, 7, true,"Connect");
- userfield = new TextField();
- setUsername(username);
- passfield = new PasswordField() {
-
- @Override
- protected void focus() {
- super.focus();
- }
-
- @Override
- protected boolean handleInput(InputChar ch) {
- if (!ch.isSpecialCode() && ch.getCharacter() == '\n') {
- okButtonPressedSlot();
- return false;
- }
- return super.handleInput(ch);
- }
- };
- setPassword(password);
-
- Button okButton = new Button("Ok");
- okButton.addListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- okButtonPressedSlot();
- }
- });
- Button cancelButton = new Button("Cancel");
- cancelButton.addListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- LoginDialog.this.exitOk = false;
- LoginDialog.this.close();
- }
- });
-
- GridLayoutManager glm = new GridLayoutManager(4,3);
- getRootPanel().setLayoutManager(glm);
-
- glm.addWidget(new Label("Username"), 0,0,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
- glm.addWidget(userfield, 1,0,3,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
- glm.addWidget(new Label("Password"), 0,1,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
- glm.addWidget(passfield, 1,1,3,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_LEFT);
-
- glm.addWidget(okButton, 1,2,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
- glm.addWidget(cancelButton, 2,2,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
-
- }
- public void okButtonPressedSlot() {
- exitOk = true;
- close();
- }
-
- @Override
- protected void activate() {
- super.activate();
-
- if (userfield.getText().length() == 0) {
- userfield.getFocus();
- } else if (passfield.getText().length() == 0) {
- passfield.getFocus();
- } else {
- throw new IllegalStateException("We have login data, but get a login dailog anyway.");
- }
- }
-
- public void setUsername(String username) {
- if (username == null) {
- userfield.setText("");
- } else {
- userfield.setText(username);
- }
- }
-
- public String getUsername() {
- return userfield.getText();
- }
-
- public void setPassword(String password) {
- if (password == null) {
- passfield.setText("");
- } else {
- passfield.setText(password);
- }
- }
-
- public String getPassword() {
- return passfield.getText();
- }
- }
-
public static void main(String[] args) {
SQLShellWindow shell = new SQLShellWindow();
shell.show();
|
|
From: SVN by r. <sv...@ca...> - 2008-09-15 12:02:11
|
Author: roy
Date: 2008-09-15 21:01:58 +0200 (Mon, 15 Sep 2008)
New Revision: 305
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
added binary support for read
added integer/float support for read
added 'save' command to save the previous history as addon to 'spool'
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-09-15 19:00:41 UTC (rev 304)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-09-15 19:01:58 UTC (rev 305)
@@ -16,6 +16,7 @@
package nl.improved.sqlclient;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
@@ -65,6 +66,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
@@ -155,6 +157,7 @@
commands.register("READ[\\s]*.*[A-Z]+.*", new ReadCommand());
commands.register("QUIT[\\s]*", new QuitCommand("quit"));
commands.register("EXIT[\\s]*", new QuitCommand("exit"));
+ commands.register("SAVE[\\s]*.*", new SaveCommand());
//commands.register("\\\\Q[\\s]*", new QuitCommand("\\q"));
commands.register("@.*", new ExecuteBatchCommand());
commands.register("(SELECT|UPDATE|ALTER|INSERT|DELETE).*;[\\s]*", new QueryCommand());
@@ -1715,6 +1718,7 @@
atts.addAttribute("","","name","",metaData.getColumnName(col));
if (metaData.getColumnType(col) == Types.DATE) {
atts.addAttribute("","","type","","date");
+ atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col));
hd.startElement("","","col",atts);
Date date = rs.getDate(col);
if (date != null) {
@@ -1723,6 +1727,7 @@
}
} else if (isBinary(metaData.getColumnType(col))) {
atts.addAttribute("","","type","","binary");
+ atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col));
hd.startElement("","","col",atts);
BASE64Encoder enc = new BASE64Encoder();
@@ -1744,7 +1749,8 @@
}
}
} else {
- atts.addAttribute("","","type","",metaData.getColumnTypeName(col));
+ atts.addAttribute("","","type","",Integer.toString(metaData.getColumnType(col)));
+ atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col));
hd.startElement("","","col",atts);
String value= rs.getString(col);
if (value != null) {
@@ -1868,12 +1874,43 @@
for (int colNr = 0; colNr < columns.getLength(); colNr++) {
Element column = (Element) columns.item(colNr);
Node type = column.getAttributes().getNamedItem("type");
- if (type != null && type.getNodeValue().equals("date")) {
- String nodeValue = column.getTextContent();
- if (nodeValue == null || nodeValue.equals("")) {
- pstmt.setDate(colNr+1, null);
+ if (type != null) {
+ String typeString = type.getNodeValue();
+ if (typeString.equals("date")) {
+ String nodeValue = column.getTextContent();
+ if (nodeValue == null || nodeValue.equals("")) {
+ pstmt.setDate(colNr+1, null);
+ } else {
+ pstmt.setDate(colNr+1, new Date(formatter.parse(nodeValue).getTime()));
+ }
+ } else if (typeString.equals("binary")) { // (isBinary(metaData.getColumnType(col)))
+ String nodeValue = column.getTextContent();
+ BASE64Decoder decoder = new BASE64Decoder();
+ byte[] value = decoder.decodeBuffer(nodeValue);
+ //pstmt.setBinaryStream(colNr+1, new ByteArrayInputStream(value));
+ pstmt.setBytes(colNr+1, value);
} else {
- pstmt.setDate(colNr+1, new Date(formatter.parse(nodeValue).getTime()));
+ String nodeValue = column.getTextContent();
+ int iType = Integer.parseInt(typeString);
+ switch (iType) {
+ case Types.INTEGER :
+ case Types.SMALLINT :
+ case Types.BIGINT :
+ pstmt.setInt(colNr+1, Integer.parseInt(nodeValue));
+ break;
+ case Types.DOUBLE : pstmt.setDouble(colNr+1, Double.parseDouble(nodeValue));
+ break;
+ case Types.VARCHAR :
+ case Types.CHAR :
+ case Types.LONGNVARCHAR :
+ case Types.NCHAR :
+ case Types.NVARCHAR :
+ pstmt.setString(colNr+1, nodeValue);
+ break;
+ default:
+ debug("WARNING Unhandled type: "+ typeString +" trying to fallback to String");
+ pstmt.setString(colNr+1, nodeValue);
+ }
}
} else {
//debug(nodeNr +" ? "+column.getTextContent());
@@ -2015,6 +2052,68 @@
}
/**
+ * Simple command to save the current visible screen history (commands and it"s output).
+ */
+ private class SaveCommand implements Command {
+ public CharSequence execute(SQLCommand cmd) {
+ String command = cmd.getCommandString().substring("save".length()).trim();
+ if (command.startsWith("history")) {
+ String fileName = toFileName(command.substring("history".length()).trim());
+ File f = new File(fileName);
+ if (f.exists() && !f.canWrite()) {
+ return "Unable to overwrite existing file : " + f.getAbsolutePath();
+ }
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(f);
+ for (CharSequence c : getScreen().getScreenBuffer()) {
+ writer.write(c.toString());
+ writer.write('\n');
+ }
+ return "History successfully written to : "+ f.getAbsolutePath();
+ } catch (IOException ex) {
+ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ return "Unable to write to file: "+ f.getAbsolutePath() +"("+ ex+")";
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException ex) {
+ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public CharSequence getCommandString() {
+ return "save";
+ }
+
+ public TabCompletionInfo getTabCompletionInfo(SQLCommand commandInfo, Point commandPoint) {
+ return null;
+ }
+
+ public CharSequence getHelp() {
+ return "history filename\nSaves the history of the screen to the filename provided\n"+
+ "This command is an addition to the 'dump' command. It doesn't write future output, "+
+ "but it saves the output that is still in the history of 'SQLShell' to the file specified.\n"+
+ "Please note that it doesn't write new command output to that file.\n"+
+ "For example:'save history ~/history.txt'";
+ }
+
+ public boolean abort() {
+ return false;
+ }
+
+ public boolean backgroundProcessSupported() {
+ return false;
+ }
+
+ }
+ /**
* Command class to execute a 'custom command'.
* this makes it possible to have 'automated' commands executed.
* E.g.:
@@ -2046,6 +2145,7 @@
}
}
+
/**
* Command thread responsible for executing commands in the background.
* It holds a reference to the current command that is being executed.
|
|
From: SVN by r. <sv...@ca...> - 2008-09-15 12:00:53
|
Author: roy
Date: 2008-09-15 21:00:41 +0200 (Mon, 15 Sep 2008)
New Revision: 304
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
Log:
added ( and ) as 'break' character
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-04 12:32:02 UTC (rev 303)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-15 19:00:41 UTC (rev 304)
@@ -26,7 +26,7 @@
*/
public class SQLUtil {
- final static char[] breakCharacters = new char[]{' ', '\t', '.', ','};
+ final static char[] breakCharacters = new char[]{' ', '\t', '.', ',', '(',')'};
/**
* A regular expression statement for name chars.
*/
|
|
From: SVN by r. <sv...@ca...> - 2008-09-04 12:32:20
|
Author: roy
Date: 2008-09-04 14:32:02 +0200 (Thu, 04 Sep 2008)
New Revision: 303
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
improve some tabcompletion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-01 09:53:07 UTC (rev 302)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-04 12:32:02 UTC (rev 303)
@@ -246,14 +246,19 @@
String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))|[\\s]*IN[\\s]*(.*)[\\s]*))";
if (upperCommandString.matches(regExp)) {
int lastIndex = tmpCommand.lastIndexOf(' ');
- lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ int lastBreakIndex = lastIndex;
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
String end = tmpCommand.substring(lastIndex+1);
+ if (lastBreakIndex < 0) lastBreakIndex = 0;
+ List tableNames = (lastIndex > lastBreakIndex) && lastBreakIndex >=0 ?
+ Arrays.asList(new String[]{tmpCommand.substring(lastBreakIndex,lastIndex).trim()}) :
+ parseTableNames(commandInfo, commandPoint);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
- , parseTableNames(commandInfo, commandPoint), end);
+ , tableNames, end);
}
//else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end = "";
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-09-01 09:53:07 UTC (rev 302)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-09-04 12:32:02 UTC (rev 303)
@@ -371,7 +371,7 @@
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
matches = info.getPossibleMatches();
- assertTrue(matches.contains("A"));
+ assertTrue(matches.toString(), matches.contains("A"));
assertEquals("x", info.getStart());
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE c like 'a%' and A.x"});
@@ -509,6 +509,18 @@
assertEquals("", info.getStart());
}
+ public void testGetTableName() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"select * from a where mytable.b"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("b", info.getStart());
+ assertTrue("Table name should match 'mytable', but was " + matches.get(0), matches.contains("mytable"));
+ }
+
/* public void testTabCompletionInfoDESC() {
List<String> sqlCommand = Arrays.asList(new String[]{"DESC "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2008-09-01 09:53:20
|
Author: roy
Date: 2008-09-01 11:53:07 +0200 (Mon, 01 Sep 2008)
New Revision: 302
Modified:
src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
Log:
store history in one place (user home dir /.sqlshell/)
Modified: src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
===================================================================
--- src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2008-08-29 09:51:53 UTC (rev 301)
+++ src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2008-09-01 09:53:07 UTC (rev 302)
@@ -39,7 +39,7 @@
/**
* Base path file name.
*/
- private final static String BASE_PATH = "history";
+ private final static String BASE_PATH = System.getProperty("user.home")+"/.sqlshell/history";
/**
* Default empty command.
|