KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui;
20
21 import java.awt.Component JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 /** Queries the user for the name and password when registering an instance.
32  *
33  */

34 class AddDomainNamePasswordPanel implements WizardDescriptor.Panel, ChangeListener JavaDoc {
35
36     /**
37      * The visual component that displays this panel. If you need to access the
38      * component from this class, just use getComponent().
39      */

40     private AddInstanceVisualNamePasswordPanel component;
41     
42     private WizardDescriptor wiz;
43     
44     // Get the visual component for the panel. In this template, the component
45
// is kept separate. This can be more efficient: if the wizard is created
46
// but never displayed, or not all panels are displayed, it is better to
47
// create only those which really need to be visible.
48
public Component JavaDoc getComponent() {
49         if (component == null) {
50             component = new AddInstanceVisualNamePasswordPanel();
51             component.addChangeListener(this);
52         }
53         return component;
54     }
55     
56     public HelpCtx getHelp() {
57         return new HelpCtx("AS_RegServ_EnterNameAndPassword"); //NOI18N
58
}
59     
60     /** Determine if the content is valid.
61      *
62      * If the page appears for personal domain the password length must be zero
63      * length or have 8 or more characters.
64      */

65     public boolean isValid() {
66         String JavaDoc password = component.getPWord().trim();
67         String JavaDoc username = component.getUName().trim();
68         boolean retVal = true;
69         if (wiz.getProperty(AddDomainWizardIterator.TYPE) == AddDomainWizardIterator.PERSONAL) {
70             int len = password.length();
71             if (retVal && (len > 0) && (len < 8)) {
72                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
73                         NbBundle.getMessage(AddDomainNamePasswordPanel.class,
74                         "MSG_PasswordLength")); //NOI18N
75
retVal = false;
76             }
77             if (retVal && username.length() < 1 && len > 0) {
78                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
79                         NbBundle.getMessage(AddDomainNamePasswordPanel.class,
80                         "MSG_AdminNameLength")); //NOI18N
81
retVal = false;
82             }
83         }
84         
85         if (retVal) {
86             wiz.putProperty(AddDomainWizardIterator.USER_NAME,username);
87             wiz.putProperty(AddDomainWizardIterator.PASSWORD,password);
88             wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE, null);
89         }
90         return retVal;
91     }
92     
93     // Event handling
94
//
95
private final Set JavaDoc/*<ChangeListener>*/ listeners = new HashSet JavaDoc/*<ChangeListener>*/(1);
96     public final void addChangeListener(ChangeListener JavaDoc l) {
97         synchronized (listeners) {
98             listeners.add(l);
99         }
100     }
101     public final void removeChangeListener(ChangeListener JavaDoc l) {
102         synchronized (listeners) {
103             listeners.remove(l);
104         }
105     }
106     protected final void fireChangeEvent() {
107         Iterator JavaDoc/*<ChangeListener>*/ it;
108         synchronized (listeners) {
109             it = new HashSet JavaDoc/*<ChangeListener>*/(listeners).iterator();
110         }
111         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
112         while (it.hasNext()) {
113             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
114         }
115     }
116     
117     // You can use a settings object to keep track of state. Normally the
118
// settings object will be the WizardDescriptor, so you can use
119
// WizardDescriptor.getProperty & putProperty to store information entered
120
// by the user.
121
public void readSettings(Object JavaDoc settings) {
122         wiz = (WizardDescriptor) settings;
123         getComponent();
124         component.setPWord((String JavaDoc) wiz.getProperty(AddDomainWizardIterator.PASSWORD));
125         component.setUName((String JavaDoc) wiz.getProperty(AddDomainWizardIterator.USER_NAME));
126     }
127     public void storeSettings(Object JavaDoc settings) {
128         // TODO implement?
129
}
130     
131     public void stateChanged(ChangeEvent JavaDoc e) {
132         fireChangeEvent();
133     }
134     
135 }
136
137
Popular Tags