KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > debugger > applet > ServletTableModel


1 /*-----------------------------------------------------------------------------
2  * Enhydra Java Application Server
3  * Copyright 1997-2000 Lutris Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  * This product includes Enhydra software developed by Lutris
17  * Technologies, Inc. and its contributors.
18  * 4. Neither the name of Lutris Technologies nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *-----------------------------------------------------------------------------
34  * $Id: ServletTableModel.java,v 1.1 2004/04/06 15:24:32 rale Exp $
35  *-----------------------------------------------------------------------------
36  */

37
38
39
40
41
42 package com.lutris.appserver.debugger.applet;
43
44 import java.net.*;
45 import java.io.*;
46 import javax.swing.*;
47 import javax.swing.table.*;
48 import com.lutris.appserver.debugger.applet.io.*;
49
50
51 public class ServletTableModel extends AbstractTableModel {
52
53     private Snapshot myState;
54
55     public ServletTableModel() {
56         myState = new Snapshot();
57     }
58
59
60     public int getRowCount() {
61         return myState.servlets.length;
62     }
63
64     public int getColumnCount() {
65         return 2;
66     }
67
68     public Class JavaDoc getColumnClass(int columnIndex) {
69         if (columnIndex == 0)
70             return Boolean JavaDoc.class;
71         else
72             return String JavaDoc.class;
73     }
74
75     public String JavaDoc getColumnName(int column) {
76         if (column == 0)
77             return "Debug";
78         else
79             return "Servlet Name";
80     }
81
82     public boolean isCellEditable(int rowIndex, int columnIndex) {
83         if (columnIndex == 0)
84             return true;
85         else
86             return false;
87     }
88   
89
90
91     public Object JavaDoc getValueAt(int row, int column) {
92         if (column == 0){
93             return new Boolean JavaDoc(myState.servlets[row].active);
94           }
95         else{
96       Object JavaDoc temp= myState.servlets[row].name;
97      return ((String JavaDoc)temp).substring(1);
98        
99        }
100        
101     }
102
103    
104     public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {
105         if (columnIndex != 0)
106             return;
107         Boolean JavaDoc b = (Boolean JavaDoc) aValue;
108         if (!myState.servlets[rowIndex].active) {
109             if (!b.booleanValue())
110                 return;
111             String JavaDoc name = myState.servlets[rowIndex].name;
112 System.out.println("START " + name);
113             startStop(name, true);
114         } else {
115             if (b.booleanValue())
116                 return;
117             String JavaDoc name = myState.servlets[rowIndex].name;
118 System.out.println("STOP " + name);
119             startStop(name, false);
120         }
121         if (!Updater.threadRunning())
122             Updater.updateState(0);
123     }
124
125
126     public void toggleRow(int row) {
127         Boolean JavaDoc b = (Boolean JavaDoc) getValueAt(row, 0);
128         setValueAt(new Boolean JavaDoc(!b.booleanValue()), row, 0);
129     }
130
131
132     private void startStop(String JavaDoc name, boolean active) {
133 System.out.println("In startStop");
134         String JavaDoc cmd;
135         if (active) {
136             cmd = "start";
137             Globals.japplet.showStatus("Attaching to " + name + "...");
138         } else {
139             cmd = "stop";
140             Globals.japplet.showStatus("Releasing " + name + "...");
141         }
142         try {
143             URL target = new URL(Globals.japplet.getDocumentBase(), "DebugServer.po?action=" + cmd + "&name=" + name);
144             URLConnection conn = target.openConnection();
145             InputStream in = conn.getInputStream();
146             while (in.read() != -1) {
147             }
148         } catch (Throwable JavaDoc t) {
149 System.err.println("START/STOP err: " + t);
150         }
151        
152         Globals.japplet.showStatus("");
153     }
154                 
155
156     public void updateToSnapshot(Snapshot s) {
157         myState = s;
158 System.out.println("Firing table changed");
159         fireTableDataChanged();
160 Globals.applicationTable.repaint();
161     }
162
163 }
164
Popular Tags