Browse files

[MOD] GUI: improved feedback for various user interactions

  • Loading branch information...
1 parent 37c74b1 commit fa77a50b1d2a86d02dc948468cd8719a5c0abe29 @ChristianGruen ChristianGruen committed Jun 17, 2012
View
8 .classpath
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry excluding="**/*.html" kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry excluding="**/*.html" kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
View
4 .travis.yml
@@ -8,3 +8,7 @@ notifications:
on_failure: always
recipients:
- bxb@inf.uni-konstanz.de
+jdk:
+ - openjdk7
+ - openjdk6
+ - oraclejdk7
View
6 src/main/java/org/basex/BaseX.java
@@ -78,7 +78,7 @@ public BaseX(final String... args) throws IOException {
// commas are escaped by a second comma
val = bind.append(val.replaceAll(",", ",,")).toString();
prop = Prop.BINDINGS;
- } else if(c == 'c' || c == 'C') {
+ } else if(c == 'c') {
// evaluate commands
final IO io = IO.get(val);
if(io.exists() && !io.isDir()) {
@@ -107,7 +107,7 @@ public BaseX(final String... args) throws IOException {
// change output stream
if(out != System.out) out.close();
out = new PrintOutput(val);
- } else if(c == 'q' || c == 'Q') {
+ } else if(c == 'q') {
// evaluate query
final IO io = IO.get(val);
if(io.exists() && !io.isDir()) {
@@ -254,7 +254,7 @@ protected final void parseArguments(final String... args) throws IOException {
arg.usage();
}
} else {
- c = 'Q';
+ c = 'q';
v = arg.string();
}
if(v != null) {
View
11 src/main/java/org/basex/BaseXGUI.java
@@ -10,6 +10,7 @@
import org.basex.core.*;
import org.basex.core.cmd.*;
import org.basex.gui.*;
+import org.basex.gui.dialog.*;
import org.basex.io.*;
import org.basex.util.*;
import org.basex.util.list.*;
@@ -65,9 +66,6 @@ public BaseXGUI(final String... args) throws BaseXException {
context.prop.set(Prop.CACHEQUERY, true);
// reduce number of results to save memory
context.prop.set(Prop.MAXHITS, gprop.num(GUIProp.MAXHITS));
- // overwrite some properties
- gprop.set(GUIProp.EXECRT, false);
- gprop.set(GUIProp.FILTERRT, false);
// initialize fonts and colors
GUIConstants.init(gprop);
@@ -83,17 +81,16 @@ public void run() {
// open specified document or database
boolean xml = false;
for(final String file : files) {
- final String input = file.replace('\\', '/');
- final IOFile io = new IOFile(input);
+ final IOFile io = new IOFile(file);
boolean xq = false;
- for(final String suf : IO.XQSUFFIXES) xq |= input.endsWith(suf);
+ for(final String suf : IO.XQSUFFIXES) xq |= file.endsWith(suf);
if(xq) {
gui.editor.open(io);
} else if(!xml) {
// only parse first xml file
- gui.execute(new Check(input));
gprop.set(GUIProp.CREATEPATH, io.path());
gprop.set(GUIProp.CREATENAME, io.dbname());
+ DialogProgress.execute(gui, new Check(file));
xml = true;
}
}
View
8 src/main/java/org/basex/core/cmd/Check.java
@@ -10,13 +10,13 @@
* @author BaseX Team 2005-12, BSD License
* @author Christian Gruen
*/
-public final class Check extends Command {
+public final class Check extends ACreate {
/**
* Default constructor.
* @param path file path
*/
public Check(final String path) {
- super(Perm.NONE, path);
+ super(path);
}
@Override
@@ -30,8 +30,8 @@ protected boolean run() {
// choose OPEN if user has no create permissions, or if database exists
final boolean create = context.user.has(Perm.CREATE);
- final Command cmd = !create || mprop.dbpath(qi.db).exists() ?
- new Open(qi.db) : new CreateDB(qi.db, qi.io.exists() ? qi.original : "");
+ final Command cmd = progress(!create || mprop.dbpath(qi.db).exists() ?
+ new Open(qi.db) : new CreateDB(qi.db, qi.io.exists() ? qi.original : null));
// execute command
final boolean ok = cmd.run(context);
View
10 src/main/java/org/basex/gui/GUI.java
@@ -452,15 +452,15 @@ boolean exec(final Command cmd, final boolean edit) {
}
if(thread == threadID && !interrupted) {
- // assign textual output if no node result was created
- if(nodes == null) {
- if(!text.visible()) GUICommands.C_SHOWTEXT.execute(this);
- text.setText(ao, cmd);
- }
// show status info
status.setText(Util.info(TIME_NEEDED_X, time));
// show number of hits
if(result != null) setResults(result.size());
+
+ // assign textual output if no node result was created
+ if(!text.visible() && nodes == null && ao.size() != 0)
+ GUICommands.C_SHOWTEXT.execute(this);
+ text.setText(ao, cmd, result);
}
}
} catch(final Exception ex) {
View
5 src/main/java/org/basex/gui/GUICommands.java
@@ -41,8 +41,7 @@ public void execute(final GUI gui) {
if(!dialog.ok()) return;
final String in = gui.gprop.get(GUIProp.CREATEPATH);
final String db = gui.gprop.get(GUIProp.CREATENAME);
- DialogProgress.execute(dialog, CREATING_DB,
- new CreateDB(db, in.isEmpty() ? null : in));
+ DialogProgress.execute(gui, new CreateDB(db, in.isEmpty() ? null : in));
}
},
@@ -98,7 +97,7 @@ public void execute(final GUI gui) {
}
}
- DialogProgress.execute(dialog, EXPORT, new Export(root.path()));
+ DialogProgress.execute(gui, new Export(root.path()));
}
@Override
View
4 src/main/java/org/basex/gui/dialog/DialogAdd.java
@@ -78,10 +78,10 @@ public void run() {
dialog.resources.refreshNewFolder(trg);
}
};
- DialogProgress.execute(dialog, "", run, new Add(trg, src));
+ DialogProgress.execute(dialog, run, new Add(trg, src));
} else if (comp == optimize) {
- DialogProgress.execute(dialog, "", new Optimize());
+ DialogProgress.execute(dialog, new Optimize());
} else {
boolean ok = general.action(comp, false);
View
4 src/main/java/org/basex/gui/dialog/DialogManage.java
@@ -236,15 +236,15 @@ public void action(final Object cmp) {
// run all commands
if(!cmds.isEmpty()) {
- DialogProgress.execute(this, "", cmds.toArray(new Command[cmds.size()]));
+ DialogProgress.execute(this, cmds.toArray(new Command[cmds.size()]));
}
}
@Override
public void close() {
final String db = choice.getValue();
if(gui.context.mprop.dbexists(db)) {
- DialogProgress.execute(this, "", new Open(db));
+ DialogProgress.execute(this, new Open(db));
dispose();
}
}
View
2 src/main/java/org/basex/gui/dialog/DialogPackages.java
@@ -146,7 +146,7 @@ public void action(final Object cmp) {
// run all commands
if(!cmds.isEmpty()) {
- DialogProgress.execute(this, "", cmds.toArray(new Command[cmds.size()]));
+ DialogProgress.execute(this, cmds.toArray(new Command[cmds.size()]));
}
}
}
View
72 src/main/java/org/basex/gui/dialog/DialogProgress.java
@@ -22,7 +22,7 @@
/** Maximum value of progress bar. */
private static final int MAX = 600;
/** Refresh action. */
- private final Timer timer = new Timer(100, this);
+ private final Timer timer = new Timer(50, this);
/** Information label. */
private BaseXLabel info;
/** Memory usage. */
@@ -35,23 +35,20 @@
/**
* Default constructor.
* @param main main window
- * @param title dialog title
* @param cmd progress reference
*/
- private DialogProgress(final GUI main, final String title, final Command cmd) {
- super(main, title);
+ private DialogProgress(final GUI main, final Command cmd) {
+ super(main, "");
init(main, cmd);
}
/**
* Default constructor.
* @param dialog dialog window
- * @param title dialog title
* @param cmd progress reference
*/
- private DialogProgress(final BaseXDialog dialog, final String title,
- final Command cmd) {
- super(dialog, title);
+ private DialogProgress(final BaseXDialog dialog, final Command cmd) {
+ super(dialog, "");
init(dialog, cmd);
}
@@ -121,38 +118,53 @@ public void actionPerformed(final ActionEvent e) {
* Runs the specified commands, decorated by a progress dialog, and
* calls {@link BaseXDialog#action} if the dialog is closed.
* @param dialog reference to the dialog window
- * @param title dialog title (may be an empty string)
* @param cmds commands to be run
*/
- public static void execute(final BaseXDialog dialog, final String title,
+ public static void execute(final BaseXDialog dialog, final Command... cmds) {
+ execute(dialog, null, cmds);
+ }
+
+ /**
+ * Runs the specified commands, decorated by a progress dialog, and
+ * calls {@link BaseXDialog#action} if the dialog is closed.
+ * @param gui reference to the main window
+ * @param cmds commands to be run
+ */
+ public static void execute(final GUI gui, final Command... cmds) {
+ execute(gui, null, null, cmds);
+ }
+
+ /**
+ * Runs the specified commands, decorated by a progress dialog, and
+ * calls {@link BaseXDialog#action} if the dialog is closed.
+ * @param dialog reference to the calling dialog window
+ * @param post post-processing step
+ * @param cmds commands to be run
+ */
+ public static void execute(final BaseXDialog dialog, final Runnable post,
final Command... cmds) {
- execute(dialog, title, null, cmds);
+ execute(dialog.gui, dialog, post, cmds);
}
/**
* Runs the specified commands, decorated by a progress dialog, and
* calls {@link BaseXDialog#action} if the dialog is closed.
- * @param dialog reference to the dialog window
- * @param title dialog title (may be an empty string)
+ * @param gui reference to the main window
+ * @param dialog reference to the dialog window (may be {@code null})
* @param post post-processing step
* @param cmds commands to be run
*/
- public static void execute(final BaseXDialog dialog, final String title,
+ public static void execute(final GUI gui, final BaseXDialog dialog,
final Runnable post, final Command... cmds) {
- final GUI gui = dialog.gui;
for(final Command cmd : cmds) {
// reset views
final boolean newData = cmd.newData(gui.context);
if(newData) gui.notify.init();
// create wait dialog
- final DialogProgress wait;
- if(dialog.isVisible()) {
- wait = new DialogProgress(dialog, title, cmd);
- } else {
- wait = new DialogProgress(gui, title, cmd);
- }
+ final DialogProgress wait = dialog != null ? new DialogProgress(dialog, cmd) :
+ new DialogProgress(gui, cmd);
// start command thread
new Thread() {
@@ -161,9 +173,17 @@ public void run() {
// execute command
final Performance perf = new Performance();
gui.updating = cmd.updating(gui.context);
- final boolean ok = cmd.run(gui.context);
- gui.updating = false;
- final String info = cmd.info();
+ boolean ok = true;
+ String info;
+ try {
+ cmd.execute(gui.context);
+ info = cmd.info();
+ } catch(final BaseXException ex) {
+ ok = false;
+ info = ex.getMessage();
+ } finally {
+ gui.updating = false;
+ }
// return status information
final String time = perf.toString();
@@ -185,9 +205,7 @@ public void run() {
if(newData) gui.notify.init();
else if(cmd.updating(gui.context)) gui.notify.update();
}
-
- dialog.setEnabled(true);
- dialog.action(dialog);
+ if(dialog != null) dialog.action(dialog);
if(post != null) post.run();
}
}
View
2 src/main/java/org/basex/gui/dialog/DialogProps.java
@@ -235,7 +235,7 @@ public void action(final Object cmp) {
ft.setOptions();
}
infos[i].setText(Token.token(PLEASE_WAIT_D));
- DialogProgress.execute(this, "", cmd);
+ DialogProgress.execute(this, cmd);
return;
}
}
View
4 src/main/java/org/basex/gui/dialog/DialogResources.java
@@ -283,7 +283,7 @@ public void run() {
refreshNewFolder(n.path());
}
};
- DialogProgress.execute(dialog, "", run, new Delete(n.path()));
+ DialogProgress.execute(dialog, run, new Delete(n.path()));
}
@Override
@@ -315,7 +315,7 @@ public void run() {
refreshNewFolder(p);
}
};
- DialogProgress.execute(dialog, "", run, new Rename(n.path(), p));
+ DialogProgress.execute(dialog, run, new Rename(n.path(), p));
}
@Override
View
37 src/main/java/org/basex/gui/view/text/TextView.java
@@ -133,12 +133,11 @@ protected boolean db() {
* @param n nodes to display
*/
private void setText(final Nodes n) {
- ns = n;
if(visible()) {
try {
final ArrayOutput ao = new ArrayOutput().max(gui.gprop.num(GUIProp.MAXTEXT));
if(n != null) n.serialize(Serializer.get(ao));
- setText(ao, null);
+ setText(ao);
} catch(final IOException ex) {
Util.debug(ex);
}
@@ -151,8 +150,27 @@ private void setText(final Nodes n) {
* Sets the output text.
* @param out cached output
* @param c command
+ * @param r result
*/
- public void setText(final ArrayOutput out, final Command c) {
+ public void setText(final ArrayOutput out, final Command c, final Result r) {
+ setText(out);
+ // cache command or node set
+ cmd = null;
+ ns = null;
+ final int mh = gui.context.prop.num(Prop.MAXHITS);
+ if(mh >= 0 && r != null && r.size() >= mh) {
+ cmd = c;
+ } else if(out.finished()) {
+ if(r instanceof Nodes) ns = (Nodes) r;
+ else cmd = c;
+ }
+ }
+
+ /**
+ * Sets the output text.
+ * @param out cached output
+ */
+ private void setText(final ArrayOutput out) {
final byte[] buf = out.buffer();
final int size = (int) out.size();
final byte[] chop = token(DOTS);
@@ -162,23 +180,22 @@ public void setText(final ArrayOutput out, final Command c) {
area.setText(buf, size);
header.setText(TEXT + (out.finished() ? CHOPPED : ""));
home.setEnabled(gui.context.data() != null);
- if(!out.finished()) {
- cmd = null;
- ns = null;
- } else {
- cmd = c;
- }
}
@Override
public void actionPerformed(final ActionEvent e) {
final BaseXFileChooser fc = new BaseXFileChooser(SAVE_AS,
gui.gprop.get(GUIProp.SAVEPATH), gui);
+
final IO file = fc.select(Mode.FSAVE);
if(file == null) return;
gui.gprop.set(GUIProp.SAVEPATH, file.path());
PrintOutput out = null;
+ gui.cursor(CURSORWAIT, true);
+ final int mh = gui.context.prop.num(Prop.MAXHITS);
+ gui.context.prop.set(Prop.MAXHITS, -1);
+
try {
out = new PrintOutput(file.toString());
if(cmd != null) {
@@ -193,6 +210,8 @@ public void actionPerformed(final ActionEvent e) {
BaseXDialog.error(gui, FILE_NOT_SAVED);
} finally {
if(out != null) try { out.close(); } catch(final IOException ex) { }
+ gui.context.prop.set(Prop.MAXHITS, mh);
+ gui.cursor(CURSORARROW, true);
}
}
}
View
4 src/main/java/org/basex/query/QueryContext.java
@@ -436,12 +436,12 @@ public void close() {
@Override
public String tit() {
- return EVALUATING_C;
+ return SAVE;
}
@Override
public String det() {
- return EVALUATING_C;
+ return PLEASE_WAIT_D;
}
@Override
View
4 src/main/java/org/basex/query/QueryProcessor.java
@@ -296,11 +296,11 @@ public FDoc plan() {
@Override
public String tit() {
- return EVALUATING_C;
+ return PLEASE_WAIT_D;
}
@Override
public String det() {
- return EVALUATING_C;
+ return PLEASE_WAIT_D;
}
}
View
3 src/main/java/org/basex/query/func/FNValidate.java
@@ -151,7 +151,8 @@ private Item dtd(final QueryContext ctx) throws QueryException {
}
final SAXParserFactory sf = SAXParserFactory.newInstance();
sf.setValidating(true);
- sf.newSAXParser().parse(in.inputSource(), new SchemaHandler());
+ final InputSource is = in.inputSource();
+ sf.newSAXParser().parse(is, new SchemaHandler());
return null;
} catch(final QueryException ex) {
throw ex;
View
2 src/test/java/org/basex/test/BaseXTest.java
@@ -109,7 +109,7 @@ public void commandErr() throws IOException {
@Test
public void commands() throws IOException {
INPUT.write(token("xquery 1" + Prop.NL + "xquery 2" + Prop.NL));
- equals("12", "-C" + INPUT.path());
+ equals("12", "-c" + INPUT.path());
}
/**

0 comments on commit fa77a50

Please sign in to comment.