01: /*
02: * $Author$
03: * $Id$
04: * This is free software, as software should be; you can redistribute
05: * it and/or modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08:
09: * See LICENSE.txt for the full license covering this software/program/code.
10: */
11:
12: package isql.commands;
13:
14: import isql.Command;
15: import util.PerlWrapper;
16: import isql.*;
17: import util.*;
18: import javax.swing.JTextArea;
19: import javax.swing.table.TableModel;
20: import java.awt.Font;
21: import java.util.*;
22:
23: /**
24: * The command object associated with the cache command, used to
25: * cache table information.
26: * @author rahul kumar <rahul_kumar@yahoo.com>
27: * @see XXX
28: */
29:
30: public class AbbrCommand implements Command {
31:
32: /** ctor/constructor.
33: */
34: public AbbrCommand() {
35: }
36:
37: public String[] getCommandList() {
38: return commands;
39: }
40:
41: public void execute(SQLForm form, String command, String SQLString) {
42: _form = form;
43: //SQLTabbedPane tp = _form.tp;
44: //SQLJDBC myjdbc = _form.myjdbc;
45:
46: String[] tmp = PerlWrapper.perlMatch("abbr\\s+(\\w+)\\s+(.+)",
47: SQLString);
48: if (tmp != null) {
49: _form.sd.appendAbbreviationTable(tmp[0], tmp[1]);
50: //tp.appendOutputArea('\n'+ "Added "+tmp[0]+" to abbr table.");
51: _form.setErrorArea('\n' + "Added " + tmp[0]
52: + " to abbr table.");
53: } else
54: showAbbreviations();
55:
56: }
57:
58: /** displays abbreviations on output area.
59: */
60: public void showAbbreviations() {
61:
62: Map ht = _form.sd.getAbbreviationTable();
63: Iterator e = ht.keySet().iterator();
64: StringBuffer sb = new StringBuffer(128);
65: sb.append("\nAbbreviations:\n");
66: while (e.hasNext()) {
67: String abbr = (String) e.next(); // get package name
68: sb.append(abbr).append(' ').append(ht.get(abbr)).append(
69: '\n');
70: }
71: _form.tp.appendOutputArea('\n' + sb.toString());
72: _form.tp.makeOutputAreaVisible();
73: }
74:
75: public String getUsage(String s) {
76: return usage;
77: }
78:
79: String commands[] = { "abbr" };
80: SQLForm _form;
81:
82: final String usage = "abbr <word> <expansion>";
83:
84: ////// START INSTANCE VARIABLES //////
85:
86: ////// START CONSTANTS AND CLASS LEVEL VARIABLES //////
87: static final String P = "AbbrCommand"; // used in exception strings
88:
89: } // end of class
|