01: /*
02: * VariablePrompter.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.sql;
13:
14: import java.util.Set;
15:
16: import workbench.sql.VariablePool;
17: import workbench.storage.DataStore;
18:
19: /**
20: * Examine SQL statements whether they need parameters to be entered.
21: * If the passed SQL Statement contains Workbench specific variables
22: * the user is prompted to enter them.
23: * @see workbench.sql.VariablePool
24: *
25: * @author support@sql-workbench.net
26: */
27: public class VariablePrompter {
28: private Set toPrompt;
29: private VariablePool pool = VariablePool.getInstance();
30: private String sql;
31:
32: public VariablePrompter() {
33: }
34:
35: public void setSql(String input) {
36: this .sql = input;
37: this .toPrompt = null;
38: }
39:
40: public boolean hasPrompt() {
41: return this .pool.hasPrompt(this .sql);
42: }
43:
44: public boolean needsInput() {
45: if (!this .hasPrompt())
46: return false;
47: if (this .toPrompt == null) {
48: this .toPrompt = this .pool
49: .getVariablesNeedingPrompt(this .sql);
50: }
51: return (this .toPrompt.size() > 0);
52: }
53:
54: public boolean getPromptValues() {
55: if (this .toPrompt == null) {
56: this .toPrompt = this .pool
57: .getVariablesNeedingPrompt(this .sql);
58: }
59: if (this .toPrompt.size() == 0)
60: return true;
61:
62: DataStore vars = this.pool.getVariablesDataStore(this.toPrompt);
63:
64: return VariablesEditor.showVariablesDialog(vars);
65: }
66:
67: }
|