001: /*
002: * $Author$
003: * $Id$
004: * This is free software, as software should be; you can redistribute
005: * it and/or modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008:
009: * See LICENSE.txt for the full license covering this software/program/code.
010: */
011:
012: package isql.commands;
013:
014: import isql.Command;
015: import util.PerlWrapper;
016: import isql.*;
017: import util.*;
018: import javax.swing.*;
019: import javax.swing.table.*;
020: import java.awt.*;
021: import java.util.*;
022:
023: /**
024: * The command object associated with some miscellaneous commands.
025: * Most of these are tiny, some are just test commands.
026: * @author rahul kumar <rahul_kumar@yahoo.com>
027: * @see XXX
028: */
029:
030: public class MiscCommand implements Command {
031:
032: /** ctor/constructor.
033: */
034: public MiscCommand() {
035: }
036:
037: public String[] getCommandList() {
038: return commands;
039: }
040:
041: public void execute(SQLForm form, String fword, String SQLString) {
042: _form = form;
043: SQLTabbedPane tp = _form.tp;
044: //SQLJDBC myjdbc = _form.myjdbc;
045:
046: if (fword.equals("system")) {
047: try {
048: tp.appendInputArea('\n' + IsqlUtil
049: .getExecOutput(ArrayUtil.split(SQLString
050: .substring(7), ' ')));
051: } catch (Exception exc) {
052: _form.setErrorArea('\n' + exc.toString());
053: }
054: return;
055: }
056: if (fword.equals("widen")) {
057: JTable jt = (JTable) tp.getActualComponent(4);
058: TableColumnModel cm = jt.getColumnModel();
059: if (cm == null) {
060: System.err.println("table is null");
061: return;
062: }
063: int cc = jt.getColumnCount();
064: for (int i = 0; i < cc; i++) {
065: TableColumn tc = cm.getColumn(i);
066: tc.setPreferredWidth(100);
067: }
068: return;
069: } // jt
070: if (fword.equals("frame")) {
071: InternalWindowPanel iwp = tp.getWindowPanel();
072: String pattern = null;
073: try {
074: pattern = SQLString.substring(6);
075: } catch (Exception exc) {
076: pattern = ".";
077: }
078: JInternalFrame[] jifs = iwp.getMatchingFrames(pattern);
079: for (int i = 0; i < jifs.length; i++) {
080: String tablename = jifs[i].getTitle().trim();
081: JScrollPane jsp = (JScrollPane) jifs[i]
082: .getContentPane();
083: JViewport jvp = jsp.getViewport();
084: //JTable jt = (JTable) comps[k];
085: Component co = jvp.getView();
086: if (!(co instanceof JTable))
087: continue;
088: JTable jt = (JTable) co;
089: TableColumnModel cm = jt.getColumnModel();
090: if (cm == null) {
091: System.err.println("table is null");
092: continue;
093: }
094: int cc = jt.getColumnCount();
095: for (int j = 0; j < cc; j++) {
096: TableColumn tc = cm.getColumn(j);
097: System.out.println(tablename + ":"
098: + jt.getColumnName(j).trim() + ":"
099: + tc.getWidth());
100: }
101: }
102: return;
103: } // frame
104:
105: }
106:
107: public String getUsage(String s) {
108: return usage;
109: }
110:
111: String commands[] = { "system", "frame", "widen" };
112: SQLForm _form;
113:
114: final String usage = "Usage:bookmark name (sql|file|system) text"
115: + " or bookmark name (get|run) or bookmark (list|help|repaint) or bookmark";
116:
117: ////// START INSTANCE VARIABLES //////
118:
119: ////// START CONSTANTS AND CLASS LEVEL VARIABLES //////
120: static final String P = "MiscCommand"; // used in exception strings
121:
122: } // end of class
|