KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > ui > wizards > AddServerLocationPanel


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.oc4j.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils;
24 import org.openide.WizardDescriptor;
25 import org.openide.util.HelpCtx;
26 import java.awt.Component JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentFactory;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbPreferences;
35
36 /**
37  * @author pblaha
38  */

39 public class AddServerLocationPanel implements WizardDescriptor.Panel, ChangeListener JavaDoc {
40     
41     private final static String JavaDoc PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18
42

43     private OC4JInstantiatingIterator instantiatingIterator;
44     private AddServerLocationVisualPanel component;
45     private WizardDescriptor wizard;
46     private transient Set JavaDoc <ChangeListener JavaDoc>listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
47
48     public AddServerLocationPanel(OC4JInstantiatingIterator instantiatingIterator){
49         this.instantiatingIterator = instantiatingIterator;
50     }
51     
52     public void stateChanged(ChangeEvent JavaDoc ev) {
53         fireChangeEvent(ev);
54     }
55     
56     private void fireChangeEvent(ChangeEvent JavaDoc ev) {
57         Iterator JavaDoc it;
58         synchronized (listeners) {
59             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
60         }
61         while (it.hasNext()) {
62             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
63         }
64     }
65     
66     public Component JavaDoc getComponent() {
67         if (component == null) {
68             component = new AddServerLocationVisualPanel();
69             component.addChangeListener(this);
70         }
71         return component;
72     }
73     
74     public HelpCtx getHelp() {
75         return new HelpCtx("j2eeplugins_registering_app_server_oc4j_location"); //NOI18N
76
}
77     
78     public boolean isValid() {
79         String JavaDoc locationStr = ((AddServerLocationVisualPanel)getComponent()).getOC4JHomeLocation();
80         if (!OC4JPluginUtils.isGoodOC4JHomeLocation(new File JavaDoc(locationStr))) {
81             wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerLocationPanel.class, "MSG_InvalidServerLocation")); // NOI18N
82
return false;
83         } else {
84             wizard.putProperty(PROP_ERROR_MESSAGE, null);
85             instantiatingIterator.setOC4JHomeLocation(locationStr);
86             NbPreferences.forModule(OC4JDeploymentFactory.class).put(OC4JDeploymentFactory.PROP_SERVER_ROOT, locationStr);
87             return true;
88         }
89     }
90
91     public void removeChangeListener(ChangeListener JavaDoc l) {
92         synchronized (listeners) {
93             listeners.remove(l);
94         }
95     }
96     
97     public void addChangeListener(ChangeListener JavaDoc l) {
98         synchronized (listeners) {
99             listeners.add(l);
100         }
101     }
102     
103     public void readSettings(Object JavaDoc settings) {
104         if (wizard == null)
105             wizard = (WizardDescriptor)settings;
106     }
107     
108     public void storeSettings(Object JavaDoc settings) {
109     }
110 }
Popular Tags