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-2007 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: * ModifyEJBsInsides.java
043: *
044: * Created on September 9, 2004, 8:50 AM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import org.netbeans.modules.visualweb.ejb.datamodel.EjbDataModel;
050: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * This class defines the panel for the user to input the Ejb Group data.
055: *
056: * @author cao
057: */
058: public class ModifyEjbGroupPanel extends javax.swing.JPanel {
059: // Remember the originals so that we can check whehter they are changed
060: private String orgName;
061: private String orgHost;
062: private int orgPort;
063:
064: public ModifyEjbGroupPanel(EjbGroup group) {
065: initComponents();
066:
067: orgName = group.getName();
068: orgHost = group.getServerHost();
069: orgPort = group.getIIOPPort();
070:
071: groupNameTextField.setText(group.getName());
072: serverHostTextField.setText(group.getServerHost());
073: iiopPortTextField
074: .setText(Integer.toString(group.getIIOPPort()));
075: }
076:
077: public ModifyEjbGroupPanel() {
078: this (null);
079: }
080:
081: public String getGroupName() {
082: return groupNameTextField.getText().trim();
083: }
084:
085: public String getServerHost() {
086: return serverHostTextField.getText().trim();
087: }
088:
089: public String getIIOPPort() {
090: return iiopPortTextField.getText().trim();
091: }
092:
093: public boolean validateData(StringBuffer errorMsg) {
094: // Make sure all the required fields are not empty and valid
095:
096: boolean valid = true;
097:
098: if (getGroupName() == null || getGroupName().length() == 0) {
099: if (valid) {
100: groupNameTextField.requestFocus();
101: valid = false;
102: }
103:
104: errorMsg.append(NbBundle.getMessage(
105: ModifyEjbGroupPanel.class, "EMPTY_GROUP_NAME"));
106: errorMsg.append("\n");
107: }
108: // Make sure the user modifies to a unique name
109: else if (!orgName.equals(getGroupName())
110: && EjbDataModel.getInstance().getEjbGroup(
111: getGroupName()) != null) {
112: if (valid) {
113: groupNameTextField.requestFocus();
114: groupNameTextField.selectAll();
115: valid = false;
116: }
117:
118: errorMsg.append(NbBundle.getMessage(
119: ModifyEjbGroupPanel.class, "NAME_NOT_UNIQUE", "\'"
120: + getGroupName() + "\'"));
121: errorMsg.append("\n");
122: }
123:
124: if (getServerHost() == null || getServerHost().length() == 0) {
125: if (valid) {
126: serverHostTextField.requestFocus();
127: valid = false;
128: }
129:
130: errorMsg.append(NbBundle.getMessage(
131: ModifyEjbGroupPanel.class, "EMPTY_SERVER_HOST"));
132: errorMsg.append("\n");
133: }
134: // Make sure the server host is still valid
135: else if (!orgHost.equals(getServerHost())
136: && getServerHost().indexOf(' ') != -1) {
137: // Can not contain spaces
138: if (valid) {
139: serverHostTextField.requestFocus();
140: serverHostTextField.selectAll();
141: valid = false;
142: }
143:
144: errorMsg.append(NbBundle.getMessage(
145: ModifyEjbGroupPanel.class, "SPACES_IN_SERVER_HOST",
146: "\'" + getServerHost() + "\'"));
147: errorMsg.append("\n");
148: }
149:
150: if (getIIOPPort() == null || getIIOPPort().length() == 0) {
151: if (valid) {
152: iiopPortTextField.requestFocus();
153: valid = false;
154: }
155:
156: errorMsg.append(NbBundle.getMessage(
157: ModifyEjbGroupPanel.class, "EMPTY_IIOP_PORT"));
158: errorMsg.append("\n");
159: } else {
160: // Make it is a number
161: try {
162: int portNum = Integer.parseInt(getIIOPPort());
163: } catch (NumberFormatException ex) {
164: if (valid) {
165: iiopPortTextField.requestFocus();
166: iiopPortTextField.selectAll();
167: valid = false;
168: }
169:
170: errorMsg.append(NbBundle.getMessage(
171: ModifyEjbGroupPanel.class,
172: "IIOP_PORT_NOT_NUMBER"));
173: errorMsg.append("\n");
174: }
175: }
176:
177: return valid;
178: }
179:
180: /** This method is called from within the constructor to
181: * initialize the form.
182: * WARNING: Do NOT modify this code. The content of this method is
183: * always regenerated by the Form Editor.
184: */
185: private void initComponents() {//GEN-BEGIN:initComponents
186: java.awt.GridBagConstraints gridBagConstraints;
187:
188: groupNameLabel = new javax.swing.JLabel();
189: groupNameTextField = new javax.swing.JTextField();
190: serverHostLabel = new javax.swing.JLabel();
191: serverHostTextField = new javax.swing.JTextField();
192: iiopPortTextField = new javax.swing.JTextField();
193: iiopPortLabel = new javax.swing.JLabel();
194: paddingPanel = new javax.swing.JPanel();
195:
196: setLayout(new java.awt.GridBagLayout());
197:
198: setPreferredSize(new java.awt.Dimension(350, 120));
199: getAccessibleContext().setAccessibleName(
200: java.util.ResourceBundle.getBundle(
201: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
202: .getString("MODIFY_EJB_GROUP"));
203: getAccessibleContext().setAccessibleDescription(
204: java.util.ResourceBundle.getBundle(
205: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
206: .getString("MODIFY_EJB_GROUP"));
207: groupNameLabel.setDisplayedMnemonic(java.util.ResourceBundle
208: .getBundle(
209: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
210: .getString("EJB_GROUP_NAME_MNEMONIC").charAt(0));
211: groupNameLabel.setLabelFor(groupNameTextField);
212: groupNameLabel.setText(java.util.ResourceBundle.getBundle(
213: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
214: .getString("EJB_GROUP_NAME_LABEL"));
215: gridBagConstraints = new java.awt.GridBagConstraints();
216: gridBagConstraints.gridx = 0;
217: gridBagConstraints.gridy = 0;
218: gridBagConstraints.gridwidth = 3;
219: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
220: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
221: add(groupNameLabel, gridBagConstraints);
222: groupNameLabel.getAccessibleContext().setAccessibleDescription(
223: java.util.ResourceBundle.getBundle(
224: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
225: .getString("EJB_GROUP_NAME_DESC"));
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridx = 3;
229: gridBagConstraints.gridy = 0;
230: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
231: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
232: gridBagConstraints.weightx = 1.0;
233: gridBagConstraints.insets = new java.awt.Insets(12, 5, 0, 12);
234: add(groupNameTextField, gridBagConstraints);
235: groupNameTextField
236: .getAccessibleContext()
237: .setAccessibleDescription(
238: java.util.ResourceBundle
239: .getBundle(
240: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
241: .getString("EJB_GROUP_NAME_DESC"));
242:
243: serverHostLabel.setDisplayedMnemonic(java.util.ResourceBundle
244: .getBundle(
245: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
246: .getString("SERVER_HOST_MNEMONIC").charAt(0));
247: serverHostLabel.setLabelFor(serverHostTextField);
248: serverHostLabel.setText(java.util.ResourceBundle.getBundle(
249: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
250: .getString("SERVER_HOST_LABEL"));
251: gridBagConstraints = new java.awt.GridBagConstraints();
252: gridBagConstraints.gridx = 0;
253: gridBagConstraints.gridy = 2;
254: gridBagConstraints.gridwidth = 2;
255: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
256: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
257: add(serverHostLabel, gridBagConstraints);
258: serverHostLabel
259: .getAccessibleContext()
260: .setAccessibleDescription(
261: java.util.ResourceBundle
262: .getBundle(
263: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
264: .getString("SERVER_HOST_DESC"));
265:
266: gridBagConstraints = new java.awt.GridBagConstraints();
267: gridBagConstraints.gridx = 3;
268: gridBagConstraints.gridy = 2;
269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
271: gridBagConstraints.weightx = 1.0;
272: gridBagConstraints.insets = new java.awt.Insets(12, 5, 0, 12);
273: add(serverHostTextField, gridBagConstraints);
274: serverHostTextField
275: .getAccessibleContext()
276: .setAccessibleDescription(
277: java.util.ResourceBundle
278: .getBundle(
279: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
280: .getString("SERVER_HOST_DESC"));
281:
282: gridBagConstraints = new java.awt.GridBagConstraints();
283: gridBagConstraints.gridx = 3;
284: gridBagConstraints.gridy = 4;
285: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
286: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
287: gridBagConstraints.weightx = 1.0;
288: gridBagConstraints.insets = new java.awt.Insets(10, 5, 0, 12);
289: add(iiopPortTextField, gridBagConstraints);
290: iiopPortTextField
291: .getAccessibleContext()
292: .setAccessibleDescription(
293: java.util.ResourceBundle
294: .getBundle(
295: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
296: .getString("IIOP_PORT_DESC"));
297:
298: iiopPortLabel.setDisplayedMnemonic(java.util.ResourceBundle
299: .getBundle(
300: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
301: .getString("IIOP_PORT_MNEMONIC_R").charAt(0));
302: iiopPortLabel.setLabelFor(iiopPortTextField);
303: iiopPortLabel.setText(java.util.ResourceBundle.getBundle(
304: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
305: .getString("IIOP_PORT_LABEL"));
306: gridBagConstraints = new java.awt.GridBagConstraints();
307: gridBagConstraints.gridx = 0;
308: gridBagConstraints.gridy = 4;
309: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
310: gridBagConstraints.insets = new java.awt.Insets(10, 12, 0, 0);
311: add(iiopPortLabel, gridBagConstraints);
312: iiopPortLabel.getAccessibleContext().setAccessibleDescription(
313: java.util.ResourceBundle.getBundle(
314: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
315: .getString("IIOP_PORT_DESC"));
316:
317: gridBagConstraints = new java.awt.GridBagConstraints();
318: gridBagConstraints.gridx = 0;
319: gridBagConstraints.gridy = 8;
320: gridBagConstraints.gridwidth = 4;
321: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
322: gridBagConstraints.weightx = 1.0;
323: gridBagConstraints.weighty = 1.0;
324: add(paddingPanel, gridBagConstraints);
325:
326: }//GEN-END:initComponents
327:
328: // Variables declaration - do not modify//GEN-BEGIN:variables
329: private javax.swing.JLabel groupNameLabel;
330: private javax.swing.JTextField groupNameTextField;
331: private javax.swing.JLabel iiopPortLabel;
332: private javax.swing.JTextField iiopPortTextField;
333: private javax.swing.JPanel paddingPanel;
334: private javax.swing.JLabel serverHostLabel;
335: private javax.swing.JTextField serverHostTextField;
336: // End of variables declaration//GEN-END:variables
337:
338: }
|