|
From: SVN by r. <sv...@ca...> - 2008-02-14 21:05:32
|
Author: roy
Date: 2008-02-14 22:05:21 +0100 (Thu, 14 Feb 2008)
New Revision: 235
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
started background thread..
currently it is a little 'hackish'
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-13 07:23:46 UTC (rev 234)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-14 21:05:21 UTC (rev 235)
@@ -39,6 +39,7 @@
public class SQLShell extends Window {
private CommandThread commandThread;
+ private boolean showPrompt = true;
/**
* The (default) maximum matches to show in a selection dialog.
@@ -619,7 +620,7 @@
if (cCommand != null) {
output(sqlCommand.getUntrimmedCommandString());
commandThread = new CommandThread(cCommand) {
- public void run() {
+ public void execute() {
try {
output(cCommand.execute(sqlCommand));
} catch(Exception e) {
@@ -630,8 +631,7 @@
if (direct || cCommand instanceof QuitCommand || cCommand instanceof ConnectCommand) {
commandThread.run();
} else {
- //commandThread.start(); // TODO
- commandThread.run();
+ commandThread.start();
}
return true;
}
@@ -639,15 +639,14 @@
// execute sql command
output(sqlCommand.getUntrimmedCommandString());
commandThread = new CommandThread(new QueryCommand()) {
- public void run() {
+ public void execute() {
output(getCommand().execute(sqlCommand));
}
};
if (direct) {
commandThread.run();
} else {
- //commandThread.start(); // TODO
- commandThread.run();
+ commandThread.start();
}
return true;
} else if (command.equalsIgnoreCase("printStackTrace")) {
@@ -676,7 +675,7 @@
//add prompt
List<? extends CharSequence> currentLines = commandLines.getLines();
for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0) {
+ if (i == 0 && showPrompt) {
tmpList.add(PROMPT+"> "+currentLines.get(i));
} else {
String nrI = Integer.toString(i+1);
@@ -1302,12 +1301,25 @@
}
}
- private static class CommandThread extends Thread {
+ private abstract class CommandThread extends Thread {
private Command cmd;
public CommandThread(Command cmd) {
this.cmd = cmd;
}
+ public final void run() {
+ showPrompt = false;
+ try {
+ execute();
+ } finally {
+ showPrompt = true;
+ try { Thread.sleep(500);} catch(InterruptedException e) {} // hack
+ paint();
+ }
+ }
+
+ abstract void execute();
+
Command getCommand() {
return cmd;
}
|