1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import org.netbeans.core.spi.multiview.*; 23 import org.openide.nodes.*; 24 import org.netbeans.modules.j2ee.dd.api.web.*; 25 import org.netbeans.modules.j2ee.ddloaders.web.*; 26 import org.netbeans.modules.xml.multiview.ui.*; 27 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; 28 import org.netbeans.modules.xml.multiview.Error; 29 import org.openide.util.NbBundle; 30 import org.netbeans.api.project.SourceGroup; 31 import org.openide.util.NbBundle; 32 import org.openide.util.RequestProcessor; 33 import org.openide.util.HelpCtx; 34 35 38 public class PagesMultiViewElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener { 39 private SectionView view; 40 private ToolBarDesignEditor comp; 41 private DDDataObject dObj; 42 private WebApp webApp; 43 private PagesPanelFactory factory; 44 private javax.swing.Action addAction, removeAction; 45 private boolean needInit=true; 46 private int index; 47 private RequestProcessor.Task repaintingTask; 48 private static final String PAGES_MV_ID=DDDataObject.DD_MULTIVIEW_PREFIX+DDDataObject.MULTIVIEW_PAGES; 49 private static final String HELP_ID_PREFIX=DDDataObject.HELP_ID_PREFIX_PAGES; 50 51 52 public PagesMultiViewElement(final DDDataObject dObj, int index) { 53 super(dObj); 54 this.dObj=dObj; 55 this.index=index; 56 comp = new ToolBarDesignEditor(); 57 factory = new PagesPanelFactory(comp, dObj); 58 addAction = new AddAction(dObj, NbBundle.getMessage(PagesMultiViewElement.class,"LBL_addJspPG")); 59 removeAction = new RemoveAction(NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove")); 60 setVisualEditor(comp); 61 repaintingTask = RequestProcessor.getDefault().create(new Runnable () { 62 public void run() { 63 javax.swing.SwingUtilities.invokeLater(new Runnable () { 64 public void run() { 65 repaintView(); 66 } 67 }); 68 } 69 }); 70 } 71 72 73 public SectionView getSectionView() { 74 return view; 75 } 76 77 public void componentShowing() { 78 super.componentShowing(); 79 dObj.setLastOpenView(index); 80 if (needInit || !dObj.isDocumentParseable()) { 81 repaintView(); 82 needInit = false; 83 } 84 } 85 86 private void repaintView() { 87 webApp = dObj.getWebApp(); 88 view =new PagesView(webApp); 89 comp.setContentView(view); 90 Object lastActive = comp.getLastActive(); 91 if (lastActive!=null) { 92 ((SectionView)view).openPanel(lastActive); 93 } else { 94 ((SectionView)view).openPanel("welcome_files"); } 96 view.checkValidity(); 97 dObj.checkParseable(); 98 } 99 100 public void componentOpened() { 101 super.componentOpened(); 102 dObj.getWebApp().addPropertyChangeListener(this); 103 } 104 105 public void componentClosed() { 106 super.componentClosed(); 107 dObj.getWebApp().removePropertyChangeListener(this); 108 } 109 110 public void propertyChange(java.beans.PropertyChangeEvent evt) { 111 if (!dObj.isChangedFromUI()) { 112 String name = evt.getPropertyName(); 113 if ( name.indexOf("WelcomeFileList")>0 || name.indexOf("JspConfig")>0 || name.indexOf("ErrorPage")>0 || name.indexOf("version")>0 ) { if (PAGES_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) { 119 repaintingTask.schedule(100); 120 } else { 121 needInit=true; 122 } 123 } 124 } 125 } 126 127 class PagesView extends SectionView { 128 private SectionContainer jspPGCont; 129 private Node groupsNode, welcomeFilesNode, errorPagesNode; 130 131 PagesView(WebApp webApp) { 132 super(factory); 133 JspConfig jspConfig=null; 134 JspPropertyGroup[] groups=null; 135 boolean jspConfigSupported=true; 136 try { 137 jspConfig = webApp.getSingleJspConfig(); 138 139 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) { 140 jspConfigSupported=false; 141 } 142 143 welcomeFilesNode = new WelcomeFilesNode(); 144 addSection(new SectionPanel(this,welcomeFilesNode,"welcome_files")); 146 errorPagesNode = new ErrorPagesNode(); 147 addSection(new SectionPanel(this,errorPagesNode,"error_pages")); 149 Children rootChildren = new Children.Array(); 150 151 if (jspConfigSupported) { 152 if (jspConfig==null) { 153 groups = new JspPropertyGroup[0]; 154 } else groups = jspConfig.getJspPropertyGroup(); 155 Node[] nodes = new Node[groups.length]; 156 Children ch = new Children.Array(); 157 for (int i=0;i<nodes.length;i++) { 158 nodes[i] = new JspPGNode(this,groups[i]); 159 } 160 ch.add(nodes); 161 groupsNode = new SectionContainerNode(ch); 163 groupsNode.setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_jspPropGroups")); 164 groupsNode.setName(HELP_ID_PREFIX+"jspPropertyGroupsNode"); jspPGCont = new SectionContainer(this,groupsNode, 166 NbBundle.getMessage(PagesMultiViewElement.class,"TTL_jspPropGroups")); 167 jspPGCont.setHeaderActions(new javax.swing.Action []{addAction}); 168 169 SectionPanel[] pan = new SectionPanel[groups.length]; 171 for (int i=0;i<nodes.length;i++) { 172 pan[i] = new SectionPanel(this, nodes[i], getJspGroupTitle(groups[i]),groups[i]); 173 pan[i].setHeaderActions(new javax.swing.Action []{removeAction}); 174 jspPGCont.addSection(pan[i]); 175 } 176 addSection(jspPGCont); 177 rootChildren.add(new Node[]{welcomeFilesNode,errorPagesNode,groupsNode}); 178 } else { 179 addAction.setEnabled(false); 180 rootChildren.add(new Node[]{welcomeFilesNode,errorPagesNode}); 181 } 182 AbstractNode root = new AbstractNode(rootChildren); 183 setRoot(root); 184 } 185 186 Node getJspPGsNode() { 187 return groupsNode; 188 } 189 190 Node getWelcomeFilesNode() { 191 return welcomeFilesNode; 192 } 193 194 SectionContainer getJspGroupsContainer(){ 195 return jspPGCont; 196 } 197 198 String getJspGroupTitle(JspPropertyGroup jspGroup) { 199 String name=jspGroup.getDefaultDisplayName(); 200 if (name==null) name = NbBundle.getMessage(PagesMultiViewElement.class,"NODE_JSP_GROUP"); 201 202 String [] patterns = jspGroup.getUrlPattern(); 203 StringBuffer buf = new StringBuffer (); 204 for (int i=0;i<patterns.length;i++) { 205 if (i>0) buf.append(", "); 206 buf.append(patterns[i]); 207 } 208 return NbBundle.getMessage(PagesMultiViewElement.class,"TTL_JSP_GROUP", name, buf.toString()); 209 } 210 211 String getJspGroupNodeName(JspPropertyGroup jspGroup) { 212 String displayName=jspGroup.getDefaultDisplayName(); 213 if (displayName!=null) return displayName; 214 else return NbBundle.getMessage(PagesMultiViewElement.class,"NODE_JSP_GROUP"); 215 } 216 217 public Error validateView() { 218 return SectionValidator.validatePages(webApp); 219 } 220 221 } 222 223 private class JspPGNode extends org.openide.nodes.AbstractNode { 224 private JspPropertyGroup group; 225 JspPGNode(PagesView view, JspPropertyGroup group) { 226 super(org.openide.nodes.Children.LEAF); 227 this.group=group; 228 setDisplayName(view.getJspGroupNodeName(group)); 229 setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/jspObject.gif"); } 231 public HelpCtx getHelpCtx() { 232 return new HelpCtx(HELP_ID_PREFIX+"jspPropertyGroupNode"); } 234 } 235 236 private class WelcomeFilesNode extends org.openide.nodes.AbstractNode { 237 WelcomeFilesNode() { 238 super(org.openide.nodes.Children.LEAF); 239 setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_welcomeFiles")); 240 setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/htmlObject.gif"); } 242 public HelpCtx getHelpCtx() { 243 return new HelpCtx(HELP_ID_PREFIX+"welcomeFilesNode"); } 245 } 246 247 private class ErrorPagesNode extends org.openide.nodes.AbstractNode { 248 ErrorPagesNode() { 249 super(org.openide.nodes.Children.LEAF); 250 setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_errorPages")); 251 setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/htmlObject.gif"); } 253 public HelpCtx getHelpCtx() { 254 return new HelpCtx(HELP_ID_PREFIX+"errorPagesNode"); } 256 } 257 258 private class AddAction extends javax.swing.AbstractAction { 259 260 AddAction(final DDDataObject dObj, String actionName) { 261 super(actionName); 262 char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_addJspPG_mnem").charAt(0); 263 putValue(MNEMONIC_KEY,new Integer ((int)mnem)); 264 } 265 public void actionPerformed(java.awt.event.ActionEvent evt) { 266 267 String [] labels = new String []{ 268 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_displayName"), 269 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_description"), 270 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_urlPatterns") 271 }; 272 char[] mnem = new char[] { 273 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_displayName_mnem").charAt(0), 274 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_description_mnem").charAt(0), 275 NbBundle.getMessage(PagesMultiViewElement.class,"LBL_urlPatterns_mnem").charAt(0) 276 }; 277 boolean[] buttons = new boolean[]{false,false,true}; 278 SimpleDialogPanel.DialogDescriptor descriptor = new SimpleDialogPanel.DialogDescriptor(labels); 279 descriptor.setMnemonics(mnem); 280 descriptor.setButtons(buttons); 281 descriptor.setTextField(new boolean[]{true,false,true}); 282 283 final SimpleDialogPanel dialogPanel = new SimpleDialogPanel(descriptor); 284 dialogPanel.getCustomizerButtons()[0].addActionListener(new java.awt.event.ActionListener () { 285 public void actionPerformed(java.awt.event.ActionEvent evt) { 286 try { 287 SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj); 288 org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups); 289 if (fo!=null) { 290 String fileName = "/"+DDUtils.getResourcePath(groups,fo,'/',true); String oldValue = dialogPanel.getValues()[2]; 292 if (fileName.length()>0) { 293 String newValue = DDUtils.addItem(oldValue,fileName,false); 294 if (!oldValue.equals(newValue)) { 295 dialogPanel.getTextComponents()[2].setText(newValue); 296 } 297 } 298 } 299 } catch (java.io.IOException ex) {} 300 } 301 }); 302 EditDialog dialog = new EditDialog(dialogPanel,NbBundle.getMessage(PagesMultiViewElement.class,"TTL_JspPropertyGroup"),true) { 303 protected String validate() { 304 String [] values = dialogPanel.getValues(); 305 String urlPatterns = values[2].trim(); 306 return SectionValidator.validateNewJspPropertyGroup(urlPatterns); 307 } 308 }; 309 dialog.setValid(false); 311 javax.swing.event.DocumentListener docListener = new EditDialog.DocListener(dialog); 312 dialogPanel.getTextComponents()[2].getDocument().addDocumentListener(docListener); 313 314 java.awt.Dialog d = org.openide.DialogDisplayer.getDefault().createDialog(dialog); 315 d.setVisible(true); 316 dialogPanel.getTextComponents()[2].getDocument().removeDocumentListener(docListener); 317 318 if (dialog.getValue().equals(EditDialog.OK_OPTION)) { 319 dObj.modelUpdatedFromUI(); 320 dObj.setChangedFromUI(true); 321 String [] values = dialogPanel.getValues(); 322 String name = values[0]; 323 String description = values[1]; 324 String urls = values[2].trim(); 325 try { 326 JspConfig jspConfig=null; 327 try { 328 jspConfig = webApp.getSingleJspConfig(); 329 if (jspConfig==null) { 330 jspConfig = (JspConfig)webApp.createBean("JspConfig"); webApp.setJspConfig(jspConfig); 332 } 333 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {} 334 JspPropertyGroup group = (JspPropertyGroup)jspConfig.createBean("JspPropertyGroup"); if (name.length()>0) group.setDisplayName((String )name); 336 if (description.length()>0) group.setDescription((String )description); 337 338 String [] patterns = DDUtils.getStringArray(urls); 339 group.setUrlPattern(patterns); 340 jspConfig.addJspPropertyGroup(group); 341 342 PagesView view = (PagesView)comp.getContentView(); 343 Node node = new JspPGNode(view, group); 344 view.getJspPGsNode().getChildren().add(new Node[]{node}); 345 346 SectionPanel pan = new SectionPanel(view, node, view.getJspGroupTitle(group),group); 347 pan.setHeaderActions(new javax.swing.Action []{removeAction}); 348 view.getJspGroupsContainer().addSection(pan, true); 349 } catch (ClassNotFoundException ex){} 350 finally { 351 dObj.setChangedFromUI(false); 352 } 353 } 354 } 355 } 356 357 private class RemoveAction extends javax.swing.AbstractAction { 358 359 RemoveAction(String actionName) { 360 super(actionName); 361 char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove_mnem").charAt(0); 362 putValue(MNEMONIC_KEY,new Integer ((int)mnem)); 363 } 364 365 public void actionPerformed(java.awt.event.ActionEvent evt) { 366 org.openide.DialogDescriptor desc = new ConfirmDialog( 367 NbBundle.getMessage(PagesMultiViewElement.class,"TXT_removeJspGroupConfirm")); 368 java.awt.Dialog dialog = org.openide.DialogDisplayer.getDefault().createDialog(desc); 369 dialog.setVisible(true); 370 if (org.openide.DialogDescriptor.OK_OPTION.equals(desc.getValue())) { 371 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 372 JspPropertyGroup group = (JspPropertyGroup)sectionPanel.getKey(); 373 try { 374 dObj.modelUpdatedFromUI(); 376 dObj.setChangedFromUI(true); 377 webApp.getSingleJspConfig().removeJspPropertyGroup(group); 378 379 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 381 } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {} 382 finally { 383 dObj.setChangedFromUI(false); 384 } 385 } 386 } 387 } 388 } 389 | Popular Tags |