1 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 getColumnClass(int columnIndex) { 69 if (columnIndex == 0) 70 return Boolean .class; 71 else 72 return String .class; 73 } 74 75 public String 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 getValueAt(int row, int column) { 92 if (column == 0){ 93 return new Boolean (myState.servlets[row].active); 94 } 95 else{ 96 Object temp= myState.servlets[row].name; 97 return ((String )temp).substring(1); 98 99 } 100 101 } 102 103 104 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 105 if (columnIndex != 0) 106 return; 107 Boolean b = (Boolean ) aValue; 108 if (!myState.servlets[rowIndex].active) { 109 if (!b.booleanValue()) 110 return; 111 String 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 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 b = (Boolean ) getValueAt(row, 0); 128 setValueAt(new Boolean (!b.booleanValue()), row, 0); 129 } 130 131 132 private void startStop(String name, boolean active) { 133 System.out.println("In startStop"); 134 String 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 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 |