KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > beans > ListServerInstances


1 package org.netbeans.modules.j2ee.sun.ide.sunresources.beans;
2 /*
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
8  * or http://www.netbeans.org/cddl.txt.
9  *
10  * When distributing Covered Code, include this CDDL Header Notice in each file
11  * and include the License file at http://www.netbeans.org/cddl.txt.
12  * If applicable, add the following below the CDDL Header, with the fields
13  * enclosed by brackets [] replaced by your own identifying information:
14  * "Portions Copyrighted [year] [name of copyright owner]"
15  *
16  * The Original Software is NetBeans. The Initial Developer of the Original
17  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
18  * Microsystems, Inc. All Rights Reserved.
19  */

20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.JLabel JavaDoc;
22 import javax.swing.JButton JavaDoc;
23 import javax.swing.JTextArea JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25 import javax.swing.JScrollPane JavaDoc;
26
27 import java.awt.Insets JavaDoc;
28 import java.awt.Dialog JavaDoc;
29 import java.awt.Component JavaDoc;
30 import java.awt.BorderLayout JavaDoc;
31 import java.awt.GridBagLayout JavaDoc;
32 import java.awt.GridBagConstraints JavaDoc;
33
34 import java.util.Hashtable JavaDoc;
35 import java.util.Vector JavaDoc;
36 import java.text.MessageFormat JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 import org.openide.util.HelpCtx;
40 import org.openide.util.NbBundle;
41 import org.openide.DialogDescriptor;
42 import org.openide.DialogDisplayer;
43 import org.openide.NotifyDescriptor;
44 import javax.management.ObjectName JavaDoc;
45
46 import org.netbeans.modules.j2ee.sun.api.ServerInterface;
47 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
48 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
49
50 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
51 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.PropertyElement;
52 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
53 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.BaseResourceNode;
54 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject;
55
56 public class ListServerInstances extends JPanel JavaDoc implements WizardConstants{
57                 
58     final static java.util.ResourceBundle JavaDoc bundle = NbBundle.getBundle(ListServerInstances.class);
59     
60     Component JavaDoc initialFocusOwner = null;
61     String JavaDoc title;
62     Hashtable JavaDoc servers = new Hashtable JavaDoc();
63             
64     public ListServerInstances(String JavaDoc _title, SunResourceDataObject dObj, String JavaDoc type, InstanceProperties targetName) {
65         title = _title;
66         initComponents(dObj, type, targetName);
67         //HelpCtx.setHelpIDString(this, "S1_register.html");//NOI18N
68
}
69     
70     private void initComponents(final SunResourceDataObject resourceObj, final String JavaDoc resType, InstanceProperties targetName) {
71         Vector JavaDoc names = new Vector JavaDoc();
72         if(targetName == null){
73             showInvalidServerError();
74             return;
75         }
76         try{
77             SunDeploymentManagerInterface dm = (SunDeploymentManagerInterface)targetName.getDeploymentManager();
78             String JavaDoc servName = targetName.getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
79             names.addElement(servName);
80             servers.put(servName, dm);
81         }catch(java.lang.ClassCastException JavaDoc cce){
82             showInvalidServerError();
83             return;
84         }
85
86         JPanel JavaDoc p = new JPanel JavaDoc();
87         
88         JLabel JavaDoc nameLabel = new JLabel JavaDoc(bundle.getString("LBL_resource_name")); //NOI18N
89
//FIXME:this should show the name of the resource which may not be same as the name of the node
90
//get property from node
91
JLabel JavaDoc rsNameLabel = new JLabel JavaDoc(resourceObj.getName());
92         
93         //Now displaying only default server instance
94
//serverListCB = new JComboBox(names);
95
serverListCB = new JTextField JavaDoc();
96         serverListCB.setText(" " + names.get(0).toString()); //NOI18N
97

98         serverListCB.setEditable(false);
99         serverListCB.getAccessibleContext().setAccessibleName(bundle.getString("LBL_select_server")); //NOI18N
100
serverListCB.getAccessibleContext().setAccessibleDescription(bundle.getString( "LBL_select_server")); //NOI18N
101

102         JLabel JavaDoc selectLabel = new JLabel JavaDoc();
103         org.openide.awt.Mnemonics.setLocalizedText(selectLabel,bundle.getString("LBL_select_server")); //NOI18N
104
selectLabel.setLabelFor(serverListCB);
105         
106         msgArea = new JTextArea JavaDoc(4, 1);
107         msgArea.setLineWrap(true);
108         msgArea.setWrapStyleWord(true);
109         msgArea.setEditable(false);
110         msgArea.setBackground(p.getBackground());
111         
112         applyButton = new JButton JavaDoc();
113         org.openide.awt.Mnemonics.setLocalizedText(applyButton,bundle.getString("LBL_Register")); //NOI18N
114
applyButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
115             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
116                 applyButton.setEnabled(false);
117                 doRegistration(resourceObj, resType);
118                 applyButton.setEnabled(true);
119             }
120         });
121         
122         closeButton = new JButton JavaDoc();
123         org.openide.awt.Mnemonics.setLocalizedText(closeButton,bundle.getString("LBL_Close")); //NOI18N
124

125         p.setLayout(new GridBagLayout JavaDoc());
126         
127         GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
128         GridBagConstraints JavaDoc gbc1 = new GridBagConstraints JavaDoc();
129         gbc.fill = gbc1.fill = GridBagConstraints.HORIZONTAL;
130         
131         gbc.anchor = GridBagConstraints.WEST;
132         gbc.gridwidth = 3;
133         gbc.gridheight = 1;
134         
135         
136         gbc1.anchor = GridBagConstraints.EAST;
137         gbc1.gridwidth = GridBagConstraints.REMAINDER;
138         
139         gbc.insets = new Insets JavaDoc(12, 12, 10, 0);
140         gbc1.insets = new Insets JavaDoc(12, 12, 10, 12);
141         
142         p.add(nameLabel, gbc);
143         p.add(rsNameLabel, gbc1);
144         
145         gbc.insets = new Insets JavaDoc(0, 12, 10, 0);
146         gbc1.insets = new Insets JavaDoc(0, 12, 10, 12);
147         
148         p.add(selectLabel, gbc);
149         p.add(serverListCB, gbc1);
150         
151         
152         gbc1.gridheight=2;
153         gbc1.weighty = 0.5;
154         p.add(new JLabel JavaDoc(""), gbc1); //dummy //NOI18N
155

156         gbc.insets = new Insets JavaDoc(0, 12, 10, 12);
157         gbc.gridwidth =4;
158         gbc.weightx = 0.5;
159         p.add(new JScrollPane JavaDoc(msgArea), gbc);
160         
161         this.setLayout(new BorderLayout JavaDoc());
162         this.add(p, "Center"); //NOI18N
163

164 // HelpCtx.setHelpIDString(this, "S1_register.html");//NOI18N
165

166         Object JavaDoc options[] = {applyButton, closeButton};
167         
168         DialogDescriptor dd = new DialogDescriptor(this, title, true, options, applyButton, DialogDescriptor.BOTTOM_ALIGN, HelpCtx.findHelp(this), null);
169         dd.setClosingOptions(new Object JavaDoc[] {closeButton});
170         
171         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dd);
172         dialog.setLocation(350, 350);
173         
174         dialog.pack();
175         dialog.setVisible(true);
176         
177         dialog.getAccessibleContext().setAccessibleName(bundle.getString("DSC_ListServers"));//NOI18N
178
dialog.getAccessibleContext().setAccessibleDescription(bundle.getString("DSC_ListServers"));//NOI18N
179

180     }
181     
182     //Handles case when Register is called from xml file. No checks for registered CP or JDBC
183
public void doRegistration(SunResourceDataObject resourceObj, String JavaDoc resType) {
184         String JavaDoc serverNm = ((String JavaDoc) serverListCB.getText()).trim();
185         try{
186             msgArea.setText(bundle.getString("Msg_RegDS")); //NOI18N
187
setTopManagerStatus(bundle.getString( "Msg_RegDS"));//NOI18N
188
Resources res = getResourceGraph(resourceObj);
189             SunDeploymentManagerInterface sunDm = getSunDm(serverNm);
190             if(res != null){
191                 ResourceUtils.register(res, sunDm, false, resType);
192                 setTopManagerStatus(bundle.getString( "Msg_RegDone"));//NOI18N
193
msgArea.setText(bundle.getString( "Msg_RegDone")); //NOI18N
194
}
195         }catch(Exception JavaDoc ex){
196             String JavaDoc errorMsg = MessageFormat.format(bundle.getString( "Msg_RegFailure"), new Object JavaDoc[]{ex.getLocalizedMessage()}); //NOI18N
197
msgArea.setText(errorMsg);
198             setTopManagerStatus(errorMsg);
199         }
200     }
201        
202     private void setTopManagerStatus(String JavaDoc msg){
203         org.openide.awt.StatusDisplayer.getDefault().setStatusText(msg);
204     }
205     
206     private Resources getResourceGraph(SunResourceDataObject resourceObj){
207         BaseResourceNode resNode = (BaseResourceNode)resourceObj.getNodeDelegate();
208         return resNode.getBeanGraph();
209     }
210        
211     private SunDeploymentManagerInterface getSunDm(String JavaDoc serverName){
212         SunDeploymentManagerInterface eightDM = (SunDeploymentManagerInterface)servers.get(serverName);
213         return eightDM;
214     }
215         
216     private void showInvalidServerError(){
217         NotifyDescriptor d = new NotifyDescriptor.Message(bundle.getString("Msg_invalid_server"), NotifyDescriptor.INFORMATION_MESSAGE);
218         d.setTitle(bundle.getString("Title_invalid_server"));
219         DialogDisplayer.getDefault().notify(d);
220         setTopManagerStatus(bundle.getString("Msg_invalid_server"));//NOI18N
221
}
222         
223     private JButton JavaDoc applyButton;
224     private JButton JavaDoc closeButton;
225     private JTextArea JavaDoc msgArea;
226     //private JComboBox serverListCB ;
227
private JTextField JavaDoc serverListCB ;
228 }
229
230
Popular Tags