KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sqlnavigator > SqlPlugin


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.sqlnavigator;
21
22 import java.util.*;
23
24 import javax.swing.*;
25
26 import org.lucane.client.*;
27 import org.lucane.client.widgets.*;
28 import org.lucane.common.*;
29 import org.lucane.common.net.ObjectConnection;
30
31 public class SqlPlugin extends StandalonePlugin
32 {
33     private ConnectInfo service;
34     public Navigator navigator;
35
36     public SqlPlugin()
37     {
38     }
39     
40     
41     public Plugin newInstance(ConnectInfo[] friends)
42     {
43         return new SqlPlugin();
44     }
45
46     public void start()
47     {
48         this.service =Communicator.getInstance().getConnectInfo("org.lucane.applications.sqlnavigator");
49         this.navigator = new Navigator(this);
50         this.navigator.show();
51         this.navigator.write(getDriverInfo());
52         this.getTableNames();
53     }
54     
55     public void getTableNames()
56     {
57         try {
58             ObjectConnection oc = Communicator.getInstance().sendMessageTo(
59                     service, service.getName(), new SqlAction(SqlAction.GET_TABLE_NAMES));
60             Vector v= (Vector) oc.read();
61             
62             navigator.tables.setListData(v);
63             
64             oc.close();
65         } catch(Exception JavaDoc e) {
66             DialogBox.error(""+e);
67         }
68     }
69     
70     public String JavaDoc getDriverInfo()
71     {
72         String JavaDoc info = tr("error.driver");
73         
74         try {
75             ObjectConnection oc = Communicator.getInstance().sendMessageTo(
76                     service, service.getName(), new SqlAction(SqlAction.GET_DRIVER_INFO));
77             info = oc.readString();
78             oc.close();
79         } catch(Exception JavaDoc e) {
80             DialogBox.error(""+e);
81         }
82         
83         return info;
84     }
85     
86     public SqlResult executeQuery(String JavaDoc query)
87     {
88         SqlResult sr = null;
89         
90         try {
91             ObjectConnection oc = Communicator.getInstance().sendMessageTo(
92             service, service.getName(), new SqlAction(SqlAction.EXECUTE_QUERY, query));
93             sr = (SqlResult) oc.read();
94             oc.close();
95         } catch(Exception JavaDoc e) {
96             DialogBox.error(""+e);
97         }
98         
99         return sr;
100     }
101     
102     public JScrollPane getScrollPane(SqlResult sr)
103     {
104         if(sr == null)
105             return null;
106         
107         JTable jt = new JTable(sr.data, sr.columns);
108         jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
109         return new JScrollPane(jt);
110     }
111 }
Popular Tags