KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.openide.WizardDescriptor;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /** Panel to query for a domain directory.
34  * Used to query the user for a local instance's domain directory.
35  */

36 class AddDomainDirectoryPanel implements WizardDescriptor.FinishablePanel,
37         ChangeListener JavaDoc {
38     
39     /**
40      * The visual component that displays this panel. If you need to access the
41      * component from this class, just use getComponent().
42      */

43     private AddInstanceVisualDirectoryPanel component;
44     private WizardDescriptor wiz;
45     private boolean creatingPersonalInstance;
46     
47     AddDomainDirectoryPanel(boolean creatingPersonalInstance) {
48         this.creatingPersonalInstance = creatingPersonalInstance;
49     }
50     
51     // Get the visual component for the panel. In this template, the component
52
// is kept separate. This can be more efficient: if the wizard is created
53
// but never displayed, or not all panels are displayed, it is better to
54
// create only those which really need to be visible.
55
public Component JavaDoc getComponent() {
56         if (component == null) {
57             component = new AddInstanceVisualDirectoryPanel(creatingPersonalInstance);
58             component.addChangeListener(this);
59         }
60         return component;
61     }
62     
63     public HelpCtx getHelp() {
64         if (creatingPersonalInstance)
65             return new HelpCtx("AS_RegServ_EnterPIDir"); //NOI18N
66
else
67             return new HelpCtx("AS_RegServ_EnterDomainDir");
68     }
69         
70     /** Is the directory usable.
71      *
72      * see Util.rootOfUsableDomain(File)
73      *
74      */

75     public boolean isValid() {
76         File JavaDoc domainDir = new File JavaDoc(component.getInstanceDirectory());
77         if (!creatingPersonalInstance) {
78             if (component.getInstanceDirectory().length() < 1) {
79                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
80                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
81                         "Msg_EneterValidDomainDir", //NOI18N
82
component.getInstanceDirectory()));
83                 component.setAdminPort("");
84                 return false;
85             }
86             if (!Util.rootOfUsableDomain(domainDir)) {
87                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
88                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
89                         "Msg_InValidDomainDir", //NOI18N
90
component.getInstanceDirectory()));
91                 component.setAdminPort(""); // NOI18N
92
return false;
93             }
94             Util.fillDescriptorFromDomainXml(wiz, domainDir);
95             String JavaDoc port = (String JavaDoc)wiz.getProperty(AddDomainWizardIterator.PORT);
96             component.setAdminPort(port);
97             if ("".equals(port)) { // NOI18N
98
wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
99                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
100                         "Msg_UnsupportedDomain", //NOI18N
101
component.getInstanceDirectory()));
102                 return false;
103             }
104             return true;
105         } else {
106             File JavaDoc parent = domainDir.getParentFile();
107             if (domainDir.exists()) {
108                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
109                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
110                         "Msg_ExistingDomainDir", //NOI18N
111
domainDir.getAbsolutePath()));
112                 return false;
113             }
114             if (null == parent) {
115                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
116                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
117                         "Msg_InValidDomainDir", //NOI18N
118
component.getInstanceDirectory()));
119                 return false;
120             }
121             if (!parent.exists()) {
122                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
123                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
124                         "Msg_InValidDomainDirParent", //NOI18N
125
parent.getAbsolutePath()));
126                 return false;
127             }
128             if (!parent.canWrite()) {
129                 wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,
130                         NbBundle.getMessage(AddDomainDirectoryPanel.class,
131                         "Msg_InValidDomainDirParent", //NOI18N
132
parent.getAbsolutePath()));
133                 return false;
134             }
135             wiz.putProperty(AddDomainWizardIterator.DOMAIN,domainDir.getName());
136             wiz.putProperty(AddDomainWizardIterator.INSTALL_LOCATION,
137                     domainDir.getParentFile().getAbsolutePath());
138             wiz.putProperty(AddDomainWizardIterator.PROP_ERROR_MESSAGE,null);
139             return true;
140         }
141     }
142     
143     // Event handling
144
//
145
private final Set JavaDoc/*<ChangeListener>*/ listeners =
146             new HashSet JavaDoc/*<ChangeListener>*/(1);
147     public final void addChangeListener(ChangeListener JavaDoc l) {
148         synchronized (listeners) {
149             listeners.add(l);
150         }
151     }
152     public final void removeChangeListener(ChangeListener JavaDoc l) {
153         synchronized (listeners) {
154             listeners.remove(l);
155         }
156     }
157     protected final void fireChangeEvent() {
158         Iterator JavaDoc/*<ChangeListener>*/ it;
159         synchronized (listeners) {
160             it = new HashSet JavaDoc/*<ChangeListener>*/(listeners).iterator();
161         }
162         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
163         while (it.hasNext()) {
164             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
165         }
166     }
167
168     // You can use a settings object to keep track of state. Normally the
169
// settings object will be the WizardDescriptor, so you can use
170
// WizardDescriptor.getProperty & putProperty to store information entered
171
// by the user.
172
public void readSettings(Object JavaDoc settings) {
173         wiz = (WizardDescriptor) settings;
174     }
175     
176     public void storeSettings(Object JavaDoc settings) {
177         // TODO implement?
178
}
179
180     public void stateChanged(ChangeEvent JavaDoc e) {
181         fireChangeEvent();
182     }
183
184     /** This panel is a finishable panel for registering an existing instance.
185      *
186      * If the user is trying to create an instance we may be in trouble
187      */

188     public boolean isFinishPanel() {
189         return !creatingPersonalInstance;
190     }
191 }
192
Popular Tags