1 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 31 public class WelcomeFilesPanel extends SectionInnerPanel { 32 DDDataObject dObj; 33 34 public WelcomeFilesPanel(SectionView sectionView, DDDataObject dObj) { 35 super(sectionView); 36 this.dObj=dObj; 37 initComponents(); 38 addModifier(wfTF); 39 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 gridBagConstraints = new java.awt.GridBagConstraints (); 45 gridBagConstraints.gridx = 1; 46 gridBagConstraints.gridy = 2; 47 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 48 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 49 add(linkButton, gridBagConstraints); 50 } 51 public javax.swing.JComponent getErrorComponent(String errorId) { 52 return wfTF; 53 } 54 55 56 58 protected void startUIChange() { 59 dObj.setChangedFromUI(true); 60 } 61 62 64 protected void endUIChange() { 65 dObj.modelUpdatedFromUI(); 66 dObj.setChangedFromUI(false); 67 } 68 69 public void setValue(javax.swing.JComponent source, Object value) { 70 WebApp webApp = dObj.getWebApp(); 71 String text = (String )value; 72 setWelcomeFiles(webApp,text); 73 } 74 75 private void setWelcomeFiles(WebApp webApp, String text) { 76 if (text.length()==0) { 77 webApp.setWelcomeFileList(null); 78 } else { 79 java.util.List wfList = new java.util.ArrayList (); 80 java.util.StringTokenizer tok = new java.util.StringTokenizer (text,","); 81 while (tok.hasMoreTokens()) { 82 String 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"); webApp.setWelcomeFileList(welcomeFileList); 89 } catch (ClassNotFoundException ex) {} 90 } 91 else { 92 String [] welcomeFiles = new String [wfList.size()]; 93 wfList.toArray(welcomeFiles); 94 WelcomeFileList welcomeFileList = webApp.getSingleWelcomeFileList(); 95 if (welcomeFileList==null) { 96 try { 97 welcomeFileList = (WelcomeFileList)webApp.createBean("WelcomeFileList"); welcomeFileList.setWelcomeFile(welcomeFiles); 99 webApp.setWelcomeFileList(welcomeFileList); 100 } catch (ClassNotFoundException ex) {} 101 } else welcomeFileList.setWelcomeFile(welcomeFiles); 102 } 103 } 104 } 105 106 public void linkButtonPressed(Object obj, String id) { 107 java.util.StringTokenizer tok = new java.util.StringTokenizer (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 [] welcomeFiles = wfList.getWelcomeFile(); 119 StringBuffer buf = new StringBuffer (); 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 135 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 137 138 wfLabel = new javax.swing.JLabel (); 139 wfTF = new javax.swing.JTextField (); 140 browseButton = new javax.swing.JButton (); 141 wfDescription = new javax.swing.JLabel (); 142 filler = new javax.swing.JPanel (); 143 144 setLayout(new java.awt.GridBagLayout ()); 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 (); 150 gridBagConstraints.gridx = 0; 151 gridBagConstraints.gridy = 0; 152 gridBagConstraints.insets = new java.awt.Insets (5, 10, 0, 6); 153 add(wfLabel, gridBagConstraints); 154 155 wfTF.setColumns(50); 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 1; 158 gridBagConstraints.gridy = 0; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 160 gridBagConstraints.insets = new java.awt.Insets (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 (0, 14, 0, 14)); 166 browseButton.addActionListener(new java.awt.event.ActionListener () { 167 public void actionPerformed(java.awt.event.ActionEvent evt) { 168 browseButtonActionPerformed(evt); 169 } 170 }); 171 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 2; 174 gridBagConstraints.gridy = 0; 175 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (); 189 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 190 gridBagConstraints.weightx = 1.0; 191 add(filler, gridBagConstraints); 192 193 } 195 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 198 SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj); 199 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 200 if (fo!=null) { 201 String fileName = DDUtils.getResourcePath(groups,fo,'/',true); 202 String oldWF = wfTF.getText(); 203 if (fileName.length()>0) { 204 String 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 ex) {} 215 } 217 218 private javax.swing.JButton browseButton; 220 private javax.swing.JPanel filler; 221 private javax.swing.JLabel wfDescription; 222 private javax.swing.JLabel wfLabel; 223 private javax.swing.JTextField wfTF; 224 226 } 227 | Popular Tags |