KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > wizard > AddServerInstanceWizard


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.deployment.impl.ui.wizard;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import org.netbeans.modules.j2ee.deployment.impl.Server;
27 import org.netbeans.modules.j2ee.deployment.plugins.api.OptionalDeploymentManagerFactory;
28 import org.openide.WizardDescriptor;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Andrei Badea
34  */

35 public class AddServerInstanceWizard extends WizardDescriptor {
36     public final static String JavaDoc PROP_DISPLAY_NAME = "ServInstWizard_displayName"; // NOI18N
37
public final static String JavaDoc PROP_SERVER = "ServInstWizard_server"; // NOI18N
38

39     private final static String JavaDoc PROP_AUTO_WIZARD_STYLE = "WizardPanel_autoWizardStyle"; // NOI18N
40
private final static String JavaDoc PROP_CONTENT_DISPLAYED = "WizardPanel_contentDisplayed"; // NOI18N
41
private final static String JavaDoc PROP_CONTENT_NUMBERED = "WizardPanel_contentNumbered"; // NOI18N
42
private final static String JavaDoc PROP_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
43
private final static String JavaDoc PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; // NOI18N
44
private final static String JavaDoc PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
45

46     private AddServerInstanceWizardIterator iterator;
47     private ServerChooserPanel chooser;
48
49     public AddServerInstanceWizard() {
50         this(new AddServerInstanceWizardIterator());
51         
52         putProperty(PROP_AUTO_WIZARD_STYLE, Boolean.TRUE);
53         putProperty(PROP_CONTENT_DISPLAYED, Boolean.TRUE);
54         putProperty(PROP_CONTENT_NUMBERED, Boolean.TRUE);
55         
56         setTitle(NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_Title"));
57         setTitleFormat(new MessageFormat JavaDoc(NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_TitleFormat")));
58         
59         initialize();
60     }
61     
62     private AddServerInstanceWizard(AddServerInstanceWizardIterator iterator) {
63         super(iterator);
64         this.iterator = iterator;
65     }
66     
67     public void setErrorMessage(String JavaDoc message) {
68         putProperty(PROP_ERROR_MESSAGE, message);
69     }
70     
71     protected void updateState() {
72         super.updateState();
73         
74         String JavaDoc[] contentData = getContentData();
75         if (contentData != null) {
76             putProperty(PROP_CONTENT_DATA, contentData);
77             putProperty(PROP_CONTENT_SELECTED_INDEX, new Integer JavaDoc(getContentSelectedIndex()));
78         }
79     }
80
81     private ServerChooserPanel getChooser() {
82         if (chooser == null)
83             chooser = new ServerChooserPanel();
84
85         return chooser;
86     }
87     
88     private String JavaDoc[] getContentData() {
89         JComponent JavaDoc first;
90         String JavaDoc[] firstContentData;
91         
92         first = (JComponent JavaDoc)getChooser().getComponent();
93         firstContentData = (String JavaDoc[])first.getClientProperty(PROP_CONTENT_DATA);
94         
95         if (iterator.current().equals(getChooser())) {
96             return firstContentData;
97         } else {
98             JComponent JavaDoc component = (JComponent JavaDoc)iterator.current().getComponent();
99             String JavaDoc[] componentContentData = (String JavaDoc[])component.getClientProperty(PROP_CONTENT_DATA);
100             if (componentContentData == null)
101                 return firstContentData;
102             
103             String JavaDoc[] contentData = new String JavaDoc[componentContentData.length + 1];
104             contentData[0] = firstContentData[0];
105             System.arraycopy(componentContentData, 0, contentData, 1, componentContentData.length);
106             return contentData;
107         }
108     }
109
110     private int getContentSelectedIndex() {
111         if (iterator.current().equals(getChooser())) {
112             return 0;
113         } else {
114             JComponent JavaDoc component = (JComponent JavaDoc)iterator.current().getComponent();
115             Integer JavaDoc componentIndex = (Integer JavaDoc)component.getClientProperty(PROP_CONTENT_SELECTED_INDEX);
116             if (componentIndex != null)
117                 return componentIndex.intValue() + 1;
118             else
119                 return 1;
120         }
121     }
122     
123     private static class AddServerInstanceWizardIterator implements WizardDescriptor.InstantiatingIterator {
124         private AddServerInstanceWizard wd;
125         public boolean showingChooser;
126         private WizardDescriptor.InstantiatingIterator iterator;
127         private HashMap JavaDoc iterators;
128         
129         public AddServerInstanceWizardIterator() {
130             showingChooser = true;
131             iterators = new HashMap JavaDoc();
132         }
133         
134         public void addChangeListener(ChangeListener JavaDoc l) {
135         }
136         
137         public WizardDescriptor.Panel current() {
138             if (showingChooser)
139                 return wd.getChooser();
140             else
141                 if (iterator != null)
142                     return iterator.current();
143                 else
144                     return null;
145         }
146         
147         public boolean hasNext() {
148             if (showingChooser)
149                 return true;
150             else
151                 if (iterator != null)
152                     return iterator.hasNext();
153                 else
154                     return false;
155         }
156         
157         public boolean hasPrevious() {
158             if (showingChooser)
159                 return false;
160             else
161                 return true;
162         }
163         
164         public String JavaDoc name() {
165             return null;
166         }
167         
168         public void nextPanel() {
169             if (iterator == null)
170                 iterator = getServerIterator();
171             else {
172                 if (!showingChooser)
173                     iterator.nextPanel();
174             }
175             showingChooser = false;
176         }
177         
178         public void previousPanel() {
179             if (iterator.hasPrevious())
180                 iterator.previousPanel();
181             else {
182                 showingChooser = true;
183                 iterator = null;
184             }
185         }
186         
187         public void removeChangeListener(ChangeListener JavaDoc l) {
188         }
189         
190         public void uninitialize(WizardDescriptor wizard) {
191         }
192
193         public void initialize(WizardDescriptor wizard) {
194             wd = (AddServerInstanceWizard)wizard;
195             
196             JComponent JavaDoc chooser = (JComponent JavaDoc)wd.getChooser().getComponent();
197             chooser.putClientProperty(PROP_CONTENT_DATA, new String JavaDoc[] {
198                 NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_ChooseServer"),
199                 NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_ASIW_Ellipsis")
200             });
201         }
202
203         public java.util.Set JavaDoc instantiate() throws java.io.IOException JavaDoc {
204             if (iterator != null) {
205                 return iterator.instantiate();
206             }
207             else
208                 return null;
209         }
210         
211         private WizardDescriptor.InstantiatingIterator getServerIterator() {
212             Server server = getSelectedServer();
213             if (server == null)
214                 return null;
215             
216             WizardDescriptor.InstantiatingIterator iterator = (WizardDescriptor.InstantiatingIterator)iterators.get(server);
217             if (iterator != null)
218                 return iterator;
219             
220             OptionalDeploymentManagerFactory factory = server.getOptionalFactory();
221             if (factory != null) {
222                 iterator = factory.getAddInstanceIterator();
223                 iterator.initialize(wd);
224                 iterators.put(server, iterator);
225                 return iterator;
226             }
227             else
228                 return null;
229         }
230         
231         private Server getSelectedServer() {
232             return (Server)wd.getProperty(PROP_SERVER);
233         }
234     }
235 }
236
Popular Tags