001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /**
043: * EditPanelServer.java
044: *
045: *
046: * Created: Mon Feb 5 13:34:46 2001
047: *
048: * @author Ana von Klopp
049: * @author Simran Gleason
050: * @version
051: */
052:
053: /**
054: * Contains the Server sub-panel for the EditPanel
055: */package org.netbeans.modules.web.monitor.client;
056:
057: import java.awt.event.*;
058: import javax.swing.event.TableModelEvent;
059: import javax.swing.event.TableModelListener;
060: import java.util.ResourceBundle;
061: import java.awt.event.*;
062: import java.net.URL;
063: import java.net.MalformedURLException;
064: import org.openide.NotifyDescriptor;
065: import org.openide.DialogDisplayer;
066: import org.openide.util.NbBundle;
067:
068: import org.netbeans.modules.web.monitor.data.*;
069:
070: class EditPanelServer extends DataDisplay {
071:
072: private final static boolean debug = false;
073:
074: private boolean holdTableChanges = false;
075: private DisplayTable serverTable = null;
076:
077: private MonitorData monitorData = null;
078:
079: EditPanelServer() {
080: super ();
081: }
082:
083: void setData(MonitorData md) {
084:
085: this .monitorData = md;
086: setServerTable();
087: this .removeAll();
088:
089: int gridy = -1;
090:
091: addGridBagComponent(this , createTopSpacer(), 0, ++gridy,
092: fullGridWidth, 1, 0, 0,
093: java.awt.GridBagConstraints.WEST,
094: java.awt.GridBagConstraints.NONE, topSpacerInsets, 0, 0);
095:
096: addGridBagComponent(this , createHeaderLabel(NbBundle.getBundle(
097: EditPanelServer.class).getString("MON_Exec_server"),
098: NbBundle.getBundle(EditPanelServer.class).getString(
099: "MON_Exec_server_Mnemonic").charAt(0), NbBundle
100: .getBundle(EditPanelServer.class).getString(
101: "ACS_MON_Exec_serverA11yDesc"),
102: serverTable), 0, ++gridy, fullGridWidth, 1, 0, 0,
103: java.awt.GridBagConstraints.WEST,
104: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
105:
106: addGridBagComponent(this , serverTable, 0, ++gridy,
107: fullGridWidth, 1, 1.0, 0,
108: java.awt.GridBagConstraints.WEST,
109: java.awt.GridBagConstraints.HORIZONTAL, tableInsets, 0,
110: 0);
111:
112: addGridBagComponent(this , createGlue(), 0, ++gridy, 1, 1, 1.0,
113: 1.0, java.awt.GridBagConstraints.WEST,
114: java.awt.GridBagConstraints.BOTH, zeroInsets, 0, 0);
115:
116: int gridx = -1;
117: addGridBagComponent(this , createGlue(), ++gridx, ++gridy, 1, 1,
118: 1.0, 0, java.awt.GridBagConstraints.WEST,
119: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
120:
121: // Housekeeping
122: this .setMaximumSize(this .getPreferredSize());
123: this .repaint();
124: }
125:
126: void setServerTable() {
127:
128: String[] servercats = {
129: NbBundle.getBundle(EditPanelServer.class).getString(
130: "MON_Server_name"),
131: NbBundle.getBundle(EditPanelServer.class).getString(
132: "MON_Server_port"), };
133: serverTable = new DisplayTable(servercats, DisplayTable.SERVER);
134:
135: holdTableChanges = true;
136: EngineData ed = monitorData.getEngineData();
137: if (ed != null) {
138:
139: serverTable.setValueAt(ed.getAttributeValue("serverName"),
140: 0, 1); //NOI18N
141: serverTable.setValueAt(ed.getAttributeValue("serverPort"),
142: 1, 1); //NOI18N
143: }
144: // for backwards compatibility
145: else {
146: ServletData sd = monitorData.getServletData();
147: serverTable.setValueAt(sd.getAttributeValue("serverName"),
148: 0, 1); //NOI18N
149: serverTable.setValueAt(sd.getAttributeValue("serverPort"),
150: 1, 1); //NOI18N
151: }
152:
153: holdTableChanges = false;
154:
155: serverTable.getAccessibleContext().setAccessibleName(
156: NbBundle.getBundle(EditPanelServer.class).getString(
157: "ACS_MON_Exec_serverTableA11yName"));
158: serverTable.setToolTipText(NbBundle.getBundle(
159: EditPanelServer.class).getString(
160: "ACS_MON_Exec_serverTableA11yDesc"));
161:
162: serverTable.addTableModelListener(new TableModelListener() {
163: public void tableChanged(TableModelEvent evt) {
164:
165: if (holdTableChanges)
166: return;
167:
168: boolean inputOK = true;
169:
170: String server = (String) serverTable.getValueAt(0, 1);
171: server = server.trim();
172: String portStr = (String) serverTable.getValueAt(1, 1);
173: portStr = portStr.trim();
174:
175: if (server.equals(""))
176: inputOK = false; //NOI18N
177: if (portStr.equals(""))
178: portStr = "80"; //NOI18N
179:
180: int port = 0;
181: if (inputOK) {
182: try {
183: port = Integer.parseInt(portStr);
184: } catch (NumberFormatException nfe) {
185: inputOK = false;
186: }
187: }
188:
189: if (inputOK) {
190: try {
191: URL url = new URL("http", server, port, ""); //NOI18N
192: } catch (MalformedURLException mue) {
193: inputOK = false;
194: }
195: }
196:
197: if (inputOK) {
198: monitorData.setServerName(server); //NOI18N
199: monitorData.setServerPort(portStr); //NOI18N
200: } else {
201: showErrorDialog();
202: setData(monitorData);
203: }
204: }
205: });
206: }
207:
208: public void repaint() {
209: super .repaint();
210: //if (editPanel != null)
211: //editPanel.repaint();
212: }
213:
214: void showErrorDialog() {
215:
216: Object[] options = { NotifyDescriptor.OK_OPTION };
217:
218: NotifyDescriptor errorDialog = new NotifyDescriptor(
219: (Object) NbBundle.getBundle(EditPanelServer.class)
220: .getString("MON_Bad_server"), NbBundle
221: .getBundle(EditPanelServer.class).getString(
222: "MON_Invalid_input"),
223: NotifyDescriptor.DEFAULT_OPTION,
224: NotifyDescriptor.ERROR_MESSAGE, options,
225: NotifyDescriptor.OK_OPTION);
226:
227: DialogDisplayer.getDefault().notify(errorDialog);
228: }
229:
230: void log(String s) {
231: System.out.println("EditPanelServer::" + s); //NOI18N
232: }
233:
234: } // EditPanelServer
|