KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > EditPanelServer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * EditPanelServer.java
22  *
23  *
24  * Created: Mon Feb 5 13:34:46 2001
25  *
26  * @author Ana von Klopp
27  * @author Simran Gleason
28  * @version
29  */

30
31 /**
32  * Contains the Server sub-panel for the EditPanel
33  */

34 package org.netbeans.modules.web.monitor.client;
35
36 import java.awt.event.*;
37 import javax.swing.event.TableModelEvent JavaDoc;
38 import javax.swing.event.TableModelListener JavaDoc;
39 import java.util.ResourceBundle JavaDoc;
40 import java.awt.event.*;
41 import java.net.URL JavaDoc;
42 import java.net.MalformedURLException JavaDoc;
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     // Housekeeping
109
this.setMaximumSize(this.getPreferredSize());
110     this.repaint();
111     }
112
113     void setServerTable() {
114
115     String JavaDoc[] 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); //NOI18N
126
serverTable.setValueAt(ed.getAttributeValue("serverPort"), 1, 1); //NOI18N
127
}
128     // for backwards compatibility
129
else {
130         ServletData sd = monitorData.getServletData();
131         serverTable.setValueAt(sd.getAttributeValue("serverName"), 0, 1); //NOI18N
132
serverTable.setValueAt(sd.getAttributeValue("serverPort"), 1, 1); //NOI18N
133
}
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 JavaDoc() {
141         public void tableChanged(TableModelEvent JavaDoc evt) {
142
143         if (holdTableChanges) return;
144          
145         boolean inputOK = true;
146         
147         String JavaDoc server = (String JavaDoc)serverTable.getValueAt(0, 1);
148         server = server.trim();
149         String JavaDoc portStr = (String JavaDoc)serverTable.getValueAt(1, 1);
150         portStr = portStr.trim();
151         
152  
153         if(server.equals("")) inputOK = false; //NOI18N
154
if(portStr.equals("")) portStr = "80"; //NOI18N
155

156         int port = 0;
157         if(inputOK) {
158             try {
159             port = Integer.parseInt(portStr);
160             }
161             catch(NumberFormatException JavaDoc nfe) {
162             inputOK = false;
163             }
164         }
165         
166         if(inputOK) {
167             try {
168             URL JavaDoc url = new URL JavaDoc("http", server, port, ""); //NOI18N
169
}
170             catch(MalformedURLException JavaDoc mue) {
171             inputOK = false;
172             }
173         }
174
175         if(inputOK) {
176             monitorData.setServerName(server); //NOI18N
177
monitorData.setServerPort(portStr); //NOI18N
178
}
179         else {
180             showErrorDialog();
181             setData(monitorData);
182         }
183         }});
184     }
185
186     public void repaint() {
187     super.repaint();
188     //if (editPanel != null)
189
//editPanel.repaint();
190
}
191
192     void showErrorDialog() {
193
194     Object JavaDoc[] options = { NotifyDescriptor.OK_OPTION };
195     
196     NotifyDescriptor errorDialog =
197         new NotifyDescriptor((Object JavaDoc)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 JavaDoc s) {
208     System.out.println("EditPanelServer::" + s); //NOI18N
209
}
210
211 } // EditPanelServer
212
Popular Tags