KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > ui > AddDomainPortsDefPanel


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 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28
29 import org.openide.WizardDescriptor;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /** A single panel descriptor for a wizard.
34  * You probably want to make a wizard iterator to hold it.
35  *
36  * @author vkraemer
37  */

38 public class AddDomainPortsDefPanel implements WizardDescriptor.Panel,
39         ChangeListener JavaDoc {
40     
41     /** The visual component that displays this panel.
42      * If you need to access the component from this class,
43      * just use getComponent().
44      */

45     private CreateServerVisualPanel component;
46     private WizardDescriptor wiz;
47 // private TargetServerData targetData;
48

49     /** Create the wizard panel descriptor. */
50     public AddDomainPortsDefPanel() { //TargetServerData data) {
51
// targetData = data;
52
}
53     
54     // Get the visual component for the panel. In this template, the component
55
// is kept separate. This can be more efficient: if the wizard is created
56
// but never displayed, or not all panels are displayed, it is better to
57
// create only those which really need to be visible.
58
public Component JavaDoc getComponent() {
59         if (component == null) {
60 // targetData.setHost("localhost"); //NOI18N
61
component = new CreateServerVisualPanel();
62             component.addChangeListener(this);
63         }
64         return component;
65     }
66     
67     public HelpCtx getHelp() {
68         return new HelpCtx("AS_RegServ_DefinePorts"); //NOI18N
69
}
70     
71     public boolean isValid() {
72         //msgLabel.setText(""); //NOI18N
73
// make sure the values are unique
74
Set JavaDoc portsUsed = new HashSet JavaDoc(7);
75         portsUsed.add(component.getAdminPort());
76         
77         if (isPortReused(portsUsed, component.getAdminJmxPort(), "ERR_AdminJmxPort"))
78             return false;
79         
80         if (isPortReused(portsUsed, component.getInstanceHttpPort(), "ERR_InstancePort"))
81             return false;
82         
83         
84         if (isPortReused(portsUsed, component.getJmsPort(), "ERR_JmsPort"))
85             return false;
86         
87         if (isPortReused(portsUsed,component.getOrbPort(), "ERR_OrbListenerPort"))
88             return false;
89         
90         
91         if (isPortReused(portsUsed,component.getHttpSslPort(), "ERR_HttpSslPort"))
92             return false;
93         
94         if (isPortReused(portsUsed,component.getOrbSslPort(), "ERR_OrbSslPort"))
95             return false;
96         if (isPortReused(portsUsed,component.getOrbMutualAuthPort(), "ERR_OrbMutualAutPort"))
97             return false;
98         
99         wiz.putProperty(AddDomainWizardIterator.ADMIN_JMX_PORT,
100                 component.getAdminJmxPort().toString());
101         wiz.putProperty(AddDomainWizardIterator.HTTP_SSL_PORT,
102                 component.getHttpSslPort().toString());
103         wiz.putProperty(AddDomainWizardIterator.INSTANCE_PORT,
104                 component.getInstanceHttpPort().toString());
105         wiz.putProperty(AddDomainWizardIterator.JMS_PORT,
106                 component.getJmsPort().toString());
107         wiz.putProperty(AddDomainWizardIterator.ORB_LISTENER_PORT,
108                 component.getOrbPort().toString());
109         wiz.putProperty(AddDomainWizardIterator.ORB_SSL_PORT,
110                 component.getOrbSslPort().toString());
111         wiz.putProperty(AddDomainWizardIterator.ORB_MUTUAL_AUTH_PORT,
112                 component.getOrbMutualAuthPort().toString());
113         wiz.putProperty(AddDomainWizardIterator.PORT,
114                 component.getAdminPort().toString());
115         
116         wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,null);
117         wiz.putProperty(AddDomainWizardIterator.HOST,"localhost"); //NOI18N
118
return true;
119     }
120
121
122     private boolean isPortReused(Set JavaDoc portsUsed, Object JavaDoc newVal, String JavaDoc id) {
123         if (portsUsed.contains(newVal)) {
124             // create the error message
125
wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
126                         NbBundle.getMessage(AddDomainPortsDefPanel.class, id));
127             return true;
128         } else {
129             portsUsed.add(newVal);
130             return false;
131         }
132
133     }
134  
135     private final Set JavaDoc listeners = new HashSet JavaDoc(1);
136     
137     public final void addChangeListener(ChangeListener JavaDoc l) {
138         synchronized (listeners) {
139             listeners.add(l);
140         }
141     }
142     public final void removeChangeListener(ChangeListener JavaDoc l) {
143         synchronized (listeners) {
144             listeners.remove(l);
145         }
146     }
147     
148     protected final void fireChangeEvent() {
149         Iterator JavaDoc it;
150         synchronized (listeners) {
151             it = new HashSet JavaDoc(listeners).iterator();
152         }
153         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
154         while (it.hasNext()) {
155             ((ChangeListener JavaDoc) it.next()).stateChanged(ev);
156         }
157     }
158     
159     // You can use a settings object to keep track of state.
160
// Normally the settings object will be the WizardDescriptor,
161
// so you can use WizardDescriptor.getProperty & putProperty
162
// to store information entered by the user.
163
public void readSettings(Object JavaDoc settings) {
164         wiz = (WizardDescriptor) settings;
165     }
166     public void storeSettings(Object JavaDoc settings) {
167     }
168
169     public void stateChanged(ChangeEvent JavaDoc e) {
170         fireChangeEvent();
171     }
172     
173 }
174
Popular Tags