KickJava   Java API By Example, From Geeks To Geeks.

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


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.FilterMapping;
23 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
24 import org.netbeans.modules.j2ee.dd.api.web.Filter;
25 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
26 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
27 import org.netbeans.modules.xml.multiview.ui.EditDialog;
28 import org.netbeans.modules.xml.multiview.ui.SimpleDialogPanel;
29 import org.netbeans.modules.xml.multiview.ui.SectionView;
30 import org.netbeans.modules.xml.multiview.ui.SectionPanel;
31 import org.openide.util.NbBundle;
32 import org.openide.DialogDescriptor;
33
34 /**
35  *
36  * @author mk115033
37  * Created on October 1, 2002, 3:52 PM
38  */

39 public class FilterMappingsTablePanel extends DefaultTablePanel {
40     private FilterMappingsTableModel model;
41     private WebApp webApp;
42     private DDDataObject dObj;
43     private SectionView view;
44     
45     /** Creates new form FilterMappingsTablePanel */
46     public FilterMappingsTablePanel(final SectionView view, final DDDataObject dObj, final FilterMappingsTableModel model) {
47         super(model);
48         this.model=model;
49         this.dObj=dObj;
50         this.view=view;
51         webApp = dObj.getWebApp();
52         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
53             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
54                 
55                 int row = getTable().getSelectedRow();
56                 String JavaDoc filterName = (String JavaDoc)model.getValueAt(row,0);
57                 dObj.modelUpdatedFromUI();
58                 dObj.setChangedFromUI(true);
59                 model.removeRow(row);
60                 dObj.setChangedFromUI(false);
61                 // updating filter's panel title
62
Filter filter = (Filter)webApp.findBeanByName("Filter","FilterName",filterName); //NOI18N
63
if (filter!=null) {
64                     SectionPanel panel = view.findSectionPanel(filter);
65                     panel.setTitle(((FiltersMultiViewElement.FiltersView)view).getFilterTitle(filter));
66                 }
67             }
68         });
69         addButton.addActionListener(new TableActionListener(true));
70         editButton.addActionListener(new TableActionListener(false));
71     }
72
73     void setModel(WebApp webApp, FilterMapping[] mappings) {
74         model.setData(webApp,mappings);
75         this.webApp=webApp;
76     }
77     
78     private class TableActionListener implements java.awt.event.ActionListener JavaDoc {
79         private boolean add;
80         TableActionListener(boolean add) {
81             this.add=add;
82         }
83         
84         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
85             String JavaDoc[] allFilters = DDUtils.getFilterNames(webApp);
86             String JavaDoc[] allServlets = DDUtils.getServletNames(webApp);
87             int row = (add?-1:getTable().getSelectedRow());
88             FilterMapping mapping = null;
89             if (add) {
90                 try {
91                    mapping = (FilterMapping)webApp.createBean("FilterMapping"); //NOI18N
92
} catch (ClassNotFoundException JavaDoc ex) {}
93             } else {
94                 mapping = webApp.getFilterMapping(row);
95             }
96             final FilterMappingPanel dialogPanel = new FilterMappingPanel(mapping,allFilters,allServlets);
97             final EditDialog dialog = new EditDialog(dialogPanel,
98                 NbBundle.getMessage(FilterMappingsTablePanel.class,"TTL_filterMapping"),
99                 add) {
100                 protected String JavaDoc validate() {
101                     if (!dialogPanel.hasFilterNames())
102                          return NbBundle.getMessage(FilterMappingsTablePanel.class,"LBL_no_filters");
103                     String JavaDoc urlPattern = dialogPanel.getUrlPattern();
104                     if (dialogPanel.getUrlRB().isSelected() && urlPattern.length()==0)
105                         return NbBundle.getMessage(FilterMappingsTablePanel.class,"TXT_missingURL");
106                     return null;
107                 }
108             };
109             if (allFilters==null || allFilters.length==0 ) // Disable OK with error message
110
dialog.checkValues();
111             else if (add) //
112
dialog.setValid(false); // Disable OK
113
javax.swing.event.DocumentListener JavaDoc docListener = new EditDialog.DocListener(dialog);
114             dialogPanel.getUrlTF().getDocument().addDocumentListener(docListener);
115             dialogPanel.getUrlRB().addActionListener(new java.awt.event.ActionListener JavaDoc() {
116                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
117                     dialog.checkValues();
118                 }
119             });
120             dialogPanel.getServletNameRB().addActionListener(new java.awt.event.ActionListener JavaDoc() {
121                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
122                     dialog.checkValues();
123                 }
124             });
125             java.awt.Dialog JavaDoc d = org.openide.DialogDisplayer.getDefault().createDialog(dialog);
126             d.setVisible(true);
127             dialogPanel.getUrlTF().getDocument().removeDocumentListener(docListener);
128             if (dialog.getValue().equals(EditDialog.OK_OPTION)) {
129                 dObj.modelUpdatedFromUI();
130                 dObj.setChangedFromUI(true);
131                 String JavaDoc filterName = dialogPanel.getFilterName();
132                 String JavaDoc urlPattern = dialogPanel.getUrlPattern();
133                 String JavaDoc servletName = dialogPanel.getServletName();
134                 String JavaDoc[] dispatcher = dialogPanel.getDispatcherTypes();
135                 if (add) {
136                     model.addRow(new Object JavaDoc[]{filterName,urlPattern,servletName,dispatcher});
137                 } else {
138                     String JavaDoc oldName = (String JavaDoc)model.getValueAt(row,0);
139                     model.editRow(row, new Object JavaDoc[]{filterName,urlPattern,servletName,dispatcher});
140                     // udating title for filter panel with old name
141
if (!filterName.equals(oldName)) {
142                         Filter filter = (Filter)webApp.findBeanByName("Filter","FilterName",oldName); //NOI18N
143
if (filter!=null) {
144                             SectionPanel panel = view.findSectionPanel(filter);
145                             panel.setTitle(((FiltersMultiViewElement.FiltersView)view).getFilterTitle(filter));
146                         }
147                     }
148                 }
149                 dObj.setChangedFromUI(false);
150                 // updating filter's panel title
151
Filter filter = (Filter)webApp.findBeanByName("Filter","FilterName",filterName); //NOI18N
152
if (filter!=null) {
153                     SectionPanel panel = view.findSectionPanel(filter);
154                     panel.setTitle(((FiltersMultiViewElement.FiltersView)view).getFilterTitle(filter));
155                 }
156             }
157         }
158     }
159 }
160
Popular Tags