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: package org.netbeans.modules.identity.server.manager.ui;
043:
044: import java.beans.PropertyVetoException;
045: import java.io.IOException;
046: import java.util.ArrayList;
047: import java.util.List;
048: import javax.swing.JComponent;
049: import javax.swing.JTextField;
050: import org.netbeans.modules.identity.server.manager.api.ServerInstance;
051: import org.netbeans.modules.identity.server.manager.api.ServerManager;
052: import org.openide.util.NbBundle;
053:
054: /**
055: * UI panel for editing the configuration data of a ServerInstance.
056: *
057: * Created on June 22, 2006, 3:40 PM
058: *
059: * @author ptliu
060: */
061: public class ServerConfigEditorPanel extends javax.swing.JPanel
062: implements EditDialogDescriptor.Panel {
063:
064: private static final int MAX_PORT = 65535;
065:
066: private static final int MIN_PORT = 0;
067:
068: private final List listeners = new ArrayList();
069:
070: private ServerInstance instance;
071:
072: /**
073: * Creates new form ServerConfigEditorPanel
074: */
075: public ServerConfigEditorPanel(ServerInstance instance) {
076: initComponents();
077:
078: this .instance = instance;
079: init();
080: }
081:
082: public JComponent[] getEditableComponents() {
083: return new JTextField[] { hostTF, portTF, contextRootTF,
084: usernameTF, passwordTF };
085: }
086:
087: public void init() {
088: hostTF.setText(instance.getHost());
089: portTF.setText(instance.getPort());
090: contextRootTF.setText(instance.getContextRoot());
091: usernameTF.setText(instance.getUserName());
092: passwordTF.setText(instance.getPassword());
093:
094: // if (instance.isLocal()) {
095: // hostTF.setEditable(false);
096: // portTF.setEditable(false);
097: // contextRootTF.setEditable(false);
098: // usernameTF.setEditable(false);
099: // passwordTF.setEditable(false);
100: // } else {
101: hostTF.setEditable(false);
102: // }
103: }
104:
105: public String checkValues() {
106: String host = hostTF.getText();
107:
108: if (host == null || host.trim().length() == 0) {
109: return NbBundle.getMessage(ServerConfigEditorPanel.class,
110: "MSG_EnterHost");
111: } else {
112: if (host.split("\\s").length > 1) { //NOI18N
113: return NbBundle.getMessage(
114: ServerConfigEditorPanel.class,
115: "MSG_InvalidHost");
116: }
117: }
118:
119: String port = portTF.getText();
120:
121: if (port == null || port.trim().length() == 0) {
122: return NbBundle.getMessage(ServerConfigEditorPanel.class,
123: "MSG_EnterPort");
124: }
125:
126: try {
127: int portNumber = Integer.parseInt(port.trim());
128:
129: if (portNumber < MIN_PORT || portNumber > MAX_PORT) {
130: return NbBundle.getMessage(
131: ServerConfigEditorPanel.class,
132: "MSG_InvalidPort");
133: }
134: } catch (NumberFormatException ex) {
135: return NbBundle.getMessage(ServerConfigEditorPanel.class,
136: "MSG_InvalidPort");
137: }
138:
139: String contextRoot = contextRootTF.getText();
140:
141: if (contextRoot == null || contextRoot.trim().length() == 0) {
142: return NbBundle.getMessage(ServerConfigEditorPanel.class,
143: "MSG_EnterContextRoot");
144: }
145:
146: String username = usernameTF.getText();
147:
148: if (username == null || username.trim().length() == 0) {
149: return NbBundle.getMessage(ServerConfigEditorPanel.class,
150: "MSG_EnterUsername");
151: }
152:
153: String password = new String(passwordTF.getPassword());
154:
155: if (password == null || password.trim().length() == 0) {
156: return NbBundle.getMessage(ServerConfigEditorPanel.class,
157: "MSG_EnterPassword");
158: }
159:
160: return null;
161: }
162:
163: public void updateInstance() {
164: boolean isModified = false;
165:
166: String value = hostTF.getText().trim();
167: if (!instance.getHost().equals(value)) {
168: isModified = true;
169: instance.setHost(value);
170: }
171:
172: value = portTF.getText().trim();
173: if (!instance.getPort().equals(value)) {
174: isModified = true;
175: instance.setPort(value);
176: }
177:
178: value = contextRootTF.getText().trim();
179: if (!instance.getContextRoot().equals(value)) {
180: isModified = true;
181: instance.setContextRoot(value);
182: }
183:
184: value = usernameTF.getText().trim();
185: if (!instance.getUserName().equals(value)) {
186: isModified = true;
187: instance.setUserName(value);
188: }
189:
190: if (!instance.getPassword().equals(passwordTF.getPassword())) {
191: isModified = true;
192: instance.setPassword(new String(passwordTF.getPassword()));
193: }
194:
195: if (isModified) {
196: try {
197: ServerManager.getDefault()
198: .writeInstanceToFile(instance);
199: } catch (IOException ex) {
200: ex.printStackTrace();
201: }
202: }
203: }
204:
205: /** This method is called from within the constructor to
206: * initialize the form.
207: * WARNING: Do NOT modify this code. The content of this method is
208: * always regenerated by the Form Editor.
209: */
210: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
211: private void initComponents() {
212:
213: hostLabel = new javax.swing.JLabel();
214: hostTF = new javax.swing.JTextField();
215: portLabel = new javax.swing.JLabel();
216: portTF = new javax.swing.JTextField();
217: usernameLabel = new javax.swing.JLabel();
218: usernameTF = new javax.swing.JTextField();
219: passwordLabel = new javax.swing.JLabel();
220: passwordTF = new javax.swing.JPasswordField();
221: contextRootLabel = new javax.swing.JLabel();
222: contextRootTF = new javax.swing.JTextField();
223:
224: hostLabel.setLabelFor(hostTF);
225: java.util.ResourceBundle bundle = java.util.ResourceBundle
226: .getBundle("org/netbeans/modules/identity/server/manager/ui/Bundle"); // NOI18N
227: org.openide.awt.Mnemonics.setLocalizedText(hostLabel, bundle
228: .getString("LBL_Host")); // NOI18N
229:
230: portLabel.setLabelFor(portTF);
231: org.openide.awt.Mnemonics.setLocalizedText(portLabel, bundle
232: .getString("LBL_Port")); // NOI18N
233:
234: usernameLabel.setLabelFor(usernameTF);
235: org.openide.awt.Mnemonics.setLocalizedText(usernameLabel,
236: bundle.getString("LBL_AdminUserName")); // NOI18N
237:
238: passwordLabel.setLabelFor(passwordTF);
239: org.openide.awt.Mnemonics.setLocalizedText(passwordLabel,
240: bundle.getString("LBL_AdminPassword")); // NOI18N
241:
242: contextRootLabel.setLabelFor(contextRootTF);
243: org.openide.awt.Mnemonics.setLocalizedText(contextRootLabel,
244: bundle.getString("LBL_ContextRoot")); // NOI18N
245:
246: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
247: this );
248: this .setLayout(layout);
249: layout
250: .setHorizontalGroup(layout
251: .createParallelGroup(
252: org.jdesktop.layout.GroupLayout.LEADING)
253: .add(
254: layout
255: .createSequentialGroup()
256: .addContainerGap()
257: .add(
258: layout
259: .createParallelGroup(
260: org.jdesktop.layout.GroupLayout.LEADING)
261: .add(
262: layout
263: .createSequentialGroup()
264: .add(
265: hostLabel)
266: .add(
267: 53,
268: 53,
269: 53)
270: .add(
271: hostTF,
272: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
273: 301,
274: Short.MAX_VALUE))
275: .add(
276: layout
277: .createSequentialGroup()
278: .add(
279: portLabel)
280: .add(
281: 55,
282: 55,
283: 55)
284: .add(
285: portTF,
286: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
287: 301,
288: Short.MAX_VALUE))
289: .add(
290: layout
291: .createSequentialGroup()
292: .add(
293: contextRootLabel)
294: .addPreferredGap(
295: org.jdesktop.layout.LayoutStyle.RELATED)
296: .add(
297: contextRootTF,
298: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
299: 301,
300: Short.MAX_VALUE))
301: .add(
302: layout
303: .createSequentialGroup()
304: .add(
305: usernameLabel)
306: .add(
307: 20,
308: 20,
309: 20)
310: .add(
311: usernameTF,
312: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
313: 301,
314: Short.MAX_VALUE))
315: .add(
316: layout
317: .createSequentialGroup()
318: .add(
319: passwordLabel)
320: .add(
321: 23,
322: 23,
323: 23)
324: .add(
325: passwordTF,
326: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
327: 301,
328: Short.MAX_VALUE)))
329: .addContainerGap()));
330: layout
331: .setVerticalGroup(layout
332: .createParallelGroup(
333: org.jdesktop.layout.GroupLayout.LEADING)
334: .add(
335: layout
336: .createSequentialGroup()
337: .addContainerGap()
338: .add(
339: layout
340: .createParallelGroup(
341: org.jdesktop.layout.GroupLayout.BASELINE)
342: .add(hostLabel)
343: .add(
344: hostTF,
345: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
346: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
347: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
348: .addPreferredGap(
349: org.jdesktop.layout.LayoutStyle.RELATED)
350: .add(
351: layout
352: .createParallelGroup(
353: org.jdesktop.layout.GroupLayout.BASELINE)
354: .add(portLabel)
355: .add(
356: portTF,
357: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
358: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
359: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
360: .addPreferredGap(
361: org.jdesktop.layout.LayoutStyle.RELATED)
362: .add(
363: layout
364: .createParallelGroup(
365: org.jdesktop.layout.GroupLayout.BASELINE)
366: .add(
367: contextRootLabel)
368: .add(
369: contextRootTF,
370: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
371: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
372: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
373: .addPreferredGap(
374: org.jdesktop.layout.LayoutStyle.RELATED)
375: .add(
376: layout
377: .createParallelGroup(
378: org.jdesktop.layout.GroupLayout.BASELINE)
379: .add(
380: usernameLabel)
381: .add(
382: usernameTF,
383: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
384: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
385: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
386: .addPreferredGap(
387: org.jdesktop.layout.LayoutStyle.RELATED)
388: .add(
389: layout
390: .createParallelGroup(
391: org.jdesktop.layout.GroupLayout.BASELINE)
392: .add(
393: passwordLabel)
394: .add(
395: passwordTF,
396: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
397: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
398: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
399: .addContainerGap(
400: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
401: Short.MAX_VALUE)));
402: }// </editor-fold>//GEN-END:initComponents
403:
404: // Variables declaration - do not modify//GEN-BEGIN:variables
405: private javax.swing.JLabel contextRootLabel;
406: private javax.swing.JTextField contextRootTF;
407: private javax.swing.JLabel hostLabel;
408: private javax.swing.JTextField hostTF;
409: private javax.swing.JLabel passwordLabel;
410: private javax.swing.JPasswordField passwordTF;
411: private javax.swing.JLabel portLabel;
412: private javax.swing.JTextField portTF;
413: private javax.swing.JLabel usernameLabel;
414: private javax.swing.JTextField usernameTF;
415: // End of variables declaration//GEN-END:variables
416:
417: }
|