KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > WelcomeFilesPanel


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.ddloaders.web.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.web.JspPropertyGroup;
23 import org.netbeans.modules.j2ee.dd.api.web.*;
24 import org.netbeans.modules.j2ee.ddloaders.web.*;
25 import org.netbeans.modules.xml.multiview.ui.*;
26 import org.netbeans.api.project.SourceGroup;
27
28 /**
29  * @author mkuchtiak
30  */

31 public class WelcomeFilesPanel extends SectionInnerPanel {
32     DDDataObject dObj;
33     /** Creates new form JspPGPanel */
34     public WelcomeFilesPanel(SectionView sectionView, DDDataObject dObj) {
35         super(sectionView);
36         this.dObj=dObj;
37         initComponents();
38         addModifier(wfTF);
39         // welcome files initialization
40
getWelcomeFiles();
41         LinkButton linkButton = new LinkButton(this, null,null);
42         linkButton.setMnemonic(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_goToSource_mnem").charAt(0));
43         linkButton.setText(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_goToSources"));
44         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
45         gridBagConstraints.gridx = 1;
46         gridBagConstraints.gridy = 2;
47         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
48         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
49         add(linkButton, gridBagConstraints);
50     }
51     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
52         return wfTF;
53     }
54     
55     
56     /** This will be called before model is changed from this panel
57      */

58     protected void startUIChange() {
59         dObj.setChangedFromUI(true);
60     }
61     
62     /** This will be called after model is changed from this panel
63      */

64     protected void endUIChange() {
65         dObj.modelUpdatedFromUI();
66         dObj.setChangedFromUI(false);
67     }
68
69     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
70         WebApp webApp = dObj.getWebApp();
71         String JavaDoc text = (String JavaDoc)value;
72         setWelcomeFiles(webApp,text);
73     }
74     
75     private void setWelcomeFiles(WebApp webApp, String JavaDoc text) {
76         if (text.length()==0) {
77             webApp.setWelcomeFileList(null);
78         } else {
79             java.util.List JavaDoc wfList = new java.util.ArrayList JavaDoc();
80             java.util.StringTokenizer JavaDoc tok = new java.util.StringTokenizer JavaDoc(text,",");
81             while (tok.hasMoreTokens()) {
82                 String JavaDoc wf = tok.nextToken().trim();
83                 if (wf.length()>0 && !wfList.contains(wf)) wfList.add(wf);
84             }
85             if (wfList.size()==0) {
86                 try {
87                     WelcomeFileList welcomeFileList = (WelcomeFileList)webApp.createBean("WelcomeFileList"); //NOI18N
88
webApp.setWelcomeFileList(welcomeFileList);
89                 } catch (ClassNotFoundException JavaDoc ex) {}
90             }
91             else {
92                 String JavaDoc[] welcomeFiles = new String JavaDoc[wfList.size()];
93                 wfList.toArray(welcomeFiles);
94                 WelcomeFileList welcomeFileList = webApp.getSingleWelcomeFileList();
95                 if (welcomeFileList==null) {
96                     try {
97                         welcomeFileList = (WelcomeFileList)webApp.createBean("WelcomeFileList"); //NOI18N
98
welcomeFileList.setWelcomeFile(welcomeFiles);
99                         webApp.setWelcomeFileList(welcomeFileList);
100                     } catch (ClassNotFoundException JavaDoc ex) {}
101                 } else welcomeFileList.setWelcomeFile(welcomeFiles);
102             }
103         }
104     }
105     
106     public void linkButtonPressed(Object JavaDoc obj, String JavaDoc id) {
107         java.util.StringTokenizer JavaDoc tok = new java.util.StringTokenizer JavaDoc(wfTF.getText(),",");
108         DDUtils.openEditorForFiles(dObj,tok);
109     }
110     
111     private void getWelcomeFiles() {
112         WebApp webApp = dObj.getWebApp();
113         WelcomeFileList wfList = webApp.getSingleWelcomeFileList();
114         if (wfList==null) {
115             wfTF.setText("");
116             return;
117         } else {
118             String JavaDoc[] welcomeFiles = wfList.getWelcomeFile();
119             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
120             for (int i=0;i<welcomeFiles.length;i++) {
121                 if (i>0) buf.append(", ");
122                 buf.append(welcomeFiles[i].trim());
123             }
124             wfTF.setText(buf.toString());
125         }
126     }
127     
128     
129     
130     /** This method is called from within the constructor to
131      * initialize the form.
132      * WARNING: Do NOT modify this code. The content of this method is
133      * always regenerated by the Form Editor.
134      */

135     private void initComponents() {//GEN-BEGIN:initComponents
136
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
137
138         wfLabel = new javax.swing.JLabel JavaDoc();
139         wfTF = new javax.swing.JTextField JavaDoc();
140         browseButton = new javax.swing.JButton JavaDoc();
141         wfDescription = new javax.swing.JLabel JavaDoc();
142         filler = new javax.swing.JPanel JavaDoc();
143
144         setLayout(new java.awt.GridBagLayout JavaDoc());
145
146         wfLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_welcomeFiles_mnem").charAt(0));
147         wfLabel.setLabelFor(wfTF);
148         wfLabel.setText(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_welcomeFiles"));
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridx = 0;
151         gridBagConstraints.gridy = 0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 6);
153         add(wfLabel, gridBagConstraints);
154
155         wfTF.setColumns(50);
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 1;
158         gridBagConstraints.gridy = 0;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
161         add(wfTF, gridBagConstraints);
162
163         browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_browse_mnem").charAt(0));
164         browseButton.setText(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "LBL_browse"));
165         browseButton.setMargin(new java.awt.Insets JavaDoc(0, 14, 0, 14));
166         browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
167             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
168                 browseButtonActionPerformed(evt);
169             }
170         });
171
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 2;
174         gridBagConstraints.gridy = 0;
175         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 6, 0, 0);
176         add(browseButton, gridBagConstraints);
177
178         wfDescription.setText(org.openide.util.NbBundle.getMessage(WelcomeFilesPanel.class, "DESC_welcomeFiles"));
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.gridx = 1;
181         gridBagConstraints.gridy = 1;
182         gridBagConstraints.gridwidth = 2;
183         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
184         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185         add(wfDescription, gridBagConstraints);
186
187         filler.setOpaque(false);
188         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
189         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
190         gridBagConstraints.weightx = 1.0;
191         add(filler, gridBagConstraints);
192
193     }//GEN-END:initComponents
194

195     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
196
// TODO add your handling code here:
197
try {
198             SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj);
199             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
200             if (fo!=null) {
201                 String JavaDoc fileName = DDUtils.getResourcePath(groups,fo,'/',true);
202                 String JavaDoc oldWF = wfTF.getText();
203                 if (fileName.length()>0) {
204                     String JavaDoc newWF = DDUtils.addItem(oldWF,fileName,true);
205                     if (!oldWF.equals(newWF)) {
206                         wfTF.setText(newWF);
207                         dObj.modelUpdatedFromUI();
208                         dObj.setChangedFromUI(true);
209                         setWelcomeFiles(dObj.getWebApp(), newWF);
210                         dObj.setChangedFromUI(false);
211                     }
212                 }
213             }
214         } catch (java.io.IOException JavaDoc ex) {}
215     }//GEN-LAST:event_browseButtonActionPerformed
216

217     
218     // Variables declaration - do not modify//GEN-BEGIN:variables
219
private javax.swing.JButton JavaDoc browseButton;
220     private javax.swing.JPanel JavaDoc filler;
221     private javax.swing.JLabel JavaDoc wfDescription;
222     private javax.swing.JLabel JavaDoc wfLabel;
223     private javax.swing.JTextField JavaDoc wfTF;
224     // End of variables declaration//GEN-END:variables
225

226 }
227
Popular Tags