1 19 20 30 31 34 package org.netbeans.modules.web.monitor.client; 35 36 import java.awt.event.*; 37 import javax.swing.event.TableModelEvent ; 38 import javax.swing.event.TableModelListener ; 39 import java.util.ResourceBundle ; 40 import java.awt.event.*; 41 import java.net.URL ; 42 import java.net.MalformedURLException ; 43 import org.openide.NotifyDescriptor; 44 import org.openide.DialogDisplayer; 45 import org.openide.util.NbBundle; 46 47 import org.netbeans.modules.web.monitor.data.*; 48 49 class EditPanelServer extends DataDisplay { 50 51 private final static boolean debug = false; 52 53 private boolean holdTableChanges = false; 54 private DisplayTable serverTable = null; 55 56 private MonitorData monitorData = null; 57 58 EditPanelServer() { 59 super(); 60 } 61 62 void setData(MonitorData md) { 63 64 this.monitorData = md; 65 setServerTable(); 66 this.removeAll(); 67 68 int gridy = -1; 69 70 addGridBagComponent(this, createTopSpacer(), 0, ++gridy, 71 fullGridWidth, 1, 0, 0, 72 java.awt.GridBagConstraints.WEST, 73 java.awt.GridBagConstraints.NONE, 74 topSpacerInsets, 75 0, 0); 76 77 addGridBagComponent(this, createHeaderLabel(NbBundle.getBundle(EditPanelServer.class).getString("MON_Exec_server"), NbBundle.getBundle(EditPanelServer.class).getString("MON_Exec_server_Mnemonic").charAt(0), NbBundle.getBundle(EditPanelServer.class).getString("ACS_MON_Exec_serverA11yDesc"), serverTable), 78 0, ++gridy, 79 fullGridWidth, 1, 0, 0, 80 java.awt.GridBagConstraints.WEST, 81 java.awt.GridBagConstraints.NONE, 82 labelInsets, 83 0, 0); 84 85 addGridBagComponent(this, serverTable, 0, ++gridy, 86 fullGridWidth, 1, 1.0, 0, 87 java.awt.GridBagConstraints.WEST, 88 java.awt.GridBagConstraints.HORIZONTAL, 89 tableInsets, 90 0, 0); 91 92 addGridBagComponent(this, createGlue(), 0, ++gridy, 93 1, 1, 1.0, 1.0, 94 java.awt.GridBagConstraints.WEST, 95 java.awt.GridBagConstraints.BOTH, 96 zeroInsets, 97 0, 0); 98 99 int gridx = -1; 100 addGridBagComponent(this, createGlue(), ++gridx, ++gridy, 101 1, 1, 1.0, 0, 102 java.awt.GridBagConstraints.WEST, 103 java.awt.GridBagConstraints.NONE, 104 buttonInsets, 105 0, 0); 106 107 108 this.setMaximumSize(this.getPreferredSize()); 110 this.repaint(); 111 } 112 113 void setServerTable() { 114 115 String [] servercats = { 116 NbBundle.getBundle(EditPanelServer.class).getString("MON_Server_name"), 117 NbBundle.getBundle(EditPanelServer.class).getString("MON_Server_port"), 118 }; 119 serverTable = new DisplayTable(servercats, DisplayTable.SERVER); 120 121 holdTableChanges = true; 122 EngineData ed = monitorData.getEngineData(); 123 if(ed != null) { 124 125 serverTable.setValueAt(ed.getAttributeValue("serverName"), 0, 1); serverTable.setValueAt(ed.getAttributeValue("serverPort"), 1, 1); } 128 else { 130 ServletData sd = monitorData.getServletData(); 131 serverTable.setValueAt(sd.getAttributeValue("serverName"), 0, 1); serverTable.setValueAt(sd.getAttributeValue("serverPort"), 1, 1); } 134 135 holdTableChanges = false; 136 137 serverTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelServer.class).getString("ACS_MON_Exec_serverTableA11yName")); 138 serverTable.setToolTipText(NbBundle.getBundle(EditPanelServer.class).getString("ACS_MON_Exec_serverTableA11yDesc")); 139 140 serverTable.addTableModelListener(new TableModelListener () { 141 public void tableChanged(TableModelEvent evt) { 142 143 if (holdTableChanges) return; 144 145 boolean inputOK = true; 146 147 String server = (String )serverTable.getValueAt(0, 1); 148 server = server.trim(); 149 String portStr = (String )serverTable.getValueAt(1, 1); 150 portStr = portStr.trim(); 151 152 153 if(server.equals("")) inputOK = false; if(portStr.equals("")) portStr = "80"; 156 int port = 0; 157 if(inputOK) { 158 try { 159 port = Integer.parseInt(portStr); 160 } 161 catch(NumberFormatException nfe) { 162 inputOK = false; 163 } 164 } 165 166 if(inputOK) { 167 try { 168 URL url = new URL ("http", server, port, ""); } 170 catch(MalformedURLException mue) { 171 inputOK = false; 172 } 173 } 174 175 if(inputOK) { 176 monitorData.setServerName(server); monitorData.setServerPort(portStr); } 179 else { 180 showErrorDialog(); 181 setData(monitorData); 182 } 183 }}); 184 } 185 186 public void repaint() { 187 super.repaint(); 188 } 191 192 void showErrorDialog() { 193 194 Object [] options = { NotifyDescriptor.OK_OPTION }; 195 196 NotifyDescriptor errorDialog = 197 new NotifyDescriptor((Object )NbBundle.getBundle(EditPanelServer.class).getString("MON_Bad_server"), 198 NbBundle.getBundle(EditPanelServer.class).getString("MON_Invalid_input"), 199 NotifyDescriptor.DEFAULT_OPTION, 200 NotifyDescriptor.ERROR_MESSAGE, 201 options, 202 NotifyDescriptor.OK_OPTION); 203 204 DialogDisplayer.getDefault().notify(errorDialog); 205 } 206 207 void log(String s) { 208 System.out.println("EditPanelServer::" + s); } 210 211 } | Popular Tags |