Source Code Cross Referenced for EditPanelHeaders.java in  » IDE-Netbeans » web.core » org » netbeans » modules » web » monitor » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » web.core » org.netbeans.modules.web.monitor.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        /**
043:         * EditPanelHeaders.java
044:         *
045:         *
046:         * Created: Fri Feb 9 2001
047:         *
048:         * @author Ana von Klopp
049:         * @author Simran Gleason
050:         * @version
051:         */
052:
053:        /**
054:         * Contains the Request sub-panel for the EditPanel
055:         */package org.netbeans.modules.web.monitor.client;
056:
057:        import java.awt.event.ActionEvent;
058:        import java.awt.event.ActionListener;
059:        import java.util.ResourceBundle;
060:        import javax.swing.JButton;
061:        import javax.swing.JScrollPane;
062:        import javax.swing.ListSelectionModel;
063:        import javax.swing.event.ListSelectionEvent;
064:        import javax.swing.event.ListSelectionListener;
065:        import javax.swing.event.TableModelEvent;
066:        import javax.swing.event.TableModelListener;
067:
068:        import org.openide.util.NbBundle;
069:        import org.openide.DialogDisplayer;
070:        import org.openide.NotifyDescriptor;
071:
072:        import org.netbeans.modules.web.monitor.data.*;
073:
074:        class EditPanelHeaders extends DataDisplay {
075:
076:            private final static boolean debug = false;
077:
078:            private DisplayTable headerTable = null;
079:            private MonitorData monitorData = null;
080:            private boolean setParams = false;
081:
082:            //
083:            // Widgets
084:            //
085:            JButton newHeaderB;
086:            JButton editHeaderB;
087:            JButton deleteHeaderB;
088:
089:            EditPanelHeaders() {
090:                super ();
091:            }
092:
093:            // Replace this. Inefficient and prevents us from maintaining
094:            // sorting. 
095:            void redisplayData() {
096:                setData(monitorData);
097:                this .revalidate();
098:                this .repaint();
099:            }
100:
101:            void setData(MonitorData md) {
102:
103:                this .monitorData = md;
104:                setHeaderTable();
105:                if (debug)
106:                    log("setData()"); // NOI18N
107:
108:                this .removeAll();
109:
110:                int gridy = -1;
111:                int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
112:
113:                addGridBagComponent(this , createTopSpacer(), 0, ++gridy,
114:                        fullGridWidth, 1, 0, 0,
115:                        java.awt.GridBagConstraints.WEST,
116:                        java.awt.GridBagConstraints.NONE, topSpacerInsets, 0, 0);
117:
118:                String msg = NbBundle.getBundle(EditPanelHeaders.class)
119:                        .getString("MON_HTTP_Headers");
120:                addGridBagComponent(this , createSortButtonLabel(msg,
121:                        headerTable, NbBundle.getBundle(EditPanelHeaders.class)
122:                                .getString("MON_HTTP_Headers_2_Mnemonic")
123:                                .charAt(0), NbBundle.getBundle(
124:                                EditPanelHeaders.class).getString(
125:                                "ACS_MON_HTTP_HeadersA11yDesc")), 0, ++gridy,
126:                        1, 1, 0, 0, java.awt.GridBagConstraints.WEST,
127:                        java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
128:
129:                JScrollPane scrollpane = new JScrollPane(headerTable);
130:                addGridBagComponent(this , scrollpane, 0, ++gridy,
131:                        fullGridWidth, 1, 1.0, 1.0,
132:                        java.awt.GridBagConstraints.WEST,
133:                        //java.awt.GridBagConstraints.HORIZONTAL, 
134:                        java.awt.GridBagConstraints.BOTH, tableInsets, 0, 0);
135:
136:                newHeaderB = new JButton(NbBundle.getBundle(
137:                        EditPanelHeaders.class).getString("MON_New_header"));
138:                newHeaderB.setMnemonic(NbBundle.getBundle(
139:                        EditPanelHeaders.class).getString(
140:                        "MON_New_header_Mnemonic").charAt(0));
141:                newHeaderB.setToolTipText(NbBundle.getBundle(
142:                        EditPanelHeaders.class).getString(
143:                        "ACS_MON_New_headerA11yDesc"));
144:                newHeaderB.addActionListener(new ActionListener() {
145:                    public void actionPerformed(ActionEvent e) {
146:                        String title = NbBundle.getBundle(
147:                                EditPanelHeaders.class).getString(
148:                                "MON_New_header");
149:                        ParamEditor pe = new ParamEditor("",
150:                                "", //NOI18N
151:                                ParamEditor.Editable.BOTH,
152:                                ParamEditor.Condition.HEADER, title);
153:
154:                        if (debug)
155:                            log("Now showing dialog");// NOI18N
156:
157:                        pe.showDialog();
158:
159:                        if (debug)
160:                            log("Dialog closed"); // NOI18N
161:
162:                        if (pe.getDialogOK()) {
163:
164:                            if (debug)
165:                                log("Dialog returned OK"); // NOI18N
166:
167:                            String name = pe.getName();
168:                            int status = 0;
169:
170:                            if (name.equalsIgnoreCase("cookie"))
171:                                status = monitorData.getRequestData()
172:                                        .addCookie(pe.getValue());
173:                            else
174:                                status = monitorData.getRequestData()
175:                                        .getHeaders().addParam(pe.getName(),
176:                                                pe.getValue());
177:
178:                            if (debug)
179:                                log("Headers are " + // NOI18N
180:                                        monitorData.getRequestData()
181:                                                .getHeaders().toString());
182:                            // if(status == 1) { /
183:                            //  The new value was added to an existing header
184:                            // }
185:                            // if(status == -1) {
186:                            //  The new value was not added because it was
187:                            //  already in there.
188:                            //}
189:
190:                            redisplayData();
191:                        }
192:                    }
193:                });
194:
195:                deleteHeaderB = new JButton(NbBundle.getBundle(
196:                        EditPanelHeaders.class).getString("MON_Delete_header"));
197:                deleteHeaderB.setMnemonic(NbBundle.getBundle(
198:                        EditPanelHeaders.class).getString(
199:                        "MON_Delete_header_Mnemonic").charAt(0));
200:                deleteHeaderB.setToolTipText(NbBundle.getBundle(
201:                        EditPanelHeaders.class).getString(
202:                        "MON_New_header_Mnemonic"));
203:
204:                deleteHeaderB.addActionListener(new ActionListener() {
205:
206:                    public void actionPerformed(ActionEvent e) {
207:
208:                        int numRows = headerTable.getRowCount();
209:
210:                        StringBuffer buf = new StringBuffer(NbBundle.getBundle(
211:                                EditPanelHeaders.class).getString(
212:                                "MON_Confirm_Delete_Headers"));
213:                        buf.append("\n"); // NOI18N
214:
215:                        for (int i = 0; i < numRows; ++i) {
216:
217:                            if (headerTable.isRowSelected(i)) {
218:                                buf.append(headerTable.getValueAt(i, 0));
219:                                buf.append(" "); // NOI18N
220:                                buf.append(headerTable.getValueAt(i, 1));
221:                                buf.append("\n"); // NOI18N
222:                            }
223:                        }
224:
225:                        showConfirmDialog(buf.toString());
226:
227:                        if (setParams) {
228:
229:                            Headers hd = monitorData.getRequestData()
230:                                    .getHeaders();
231:
232:                            for (int i = 0; i < numRows; ++i) {
233:                                if (headerTable.isRowSelected(i)) {
234:
235:                                    String name = (String) headerTable
236:                                            .getValueAt(i, 0);
237:                                    String value = (String) headerTable
238:                                            .getValueAt(i, 1);
239:
240:                                    // Note that we get the params each
241:                                    // time through that we don't run into
242:                                    // null pointer exceptions. 
243:                                    Param[] myParams = hd.getParam();
244:                                    Param param = findParam(myParams, name,
245:                                            value);
246:                                    if (param != null)
247:                                        hd.removeParam(param);
248:                                }
249:                            }
250:                            redisplayData();
251:                        }
252:                    }
253:                });
254:
255:                int gridx = -1;
256:                addGridBagComponent(this , createGlue(), ++gridx, ++gridy, 1, 1,
257:                        1.0, 0, java.awt.GridBagConstraints.WEST,
258:                        java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
259:                addGridBagComponent(this , newHeaderB, ++gridx, gridy, 1, 1, 0,
260:                        0, java.awt.GridBagConstraints.EAST,
261:                        java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
262:
263:                addGridBagComponent(this , deleteHeaderB, ++gridx, gridy, 1, 1,
264:                        0, 0, java.awt.GridBagConstraints.EAST,
265:                        java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
266:
267:                setEnablings();
268:
269:                this .setMaximumSize(this .getPreferredSize());
270:                this .repaint();
271:            }
272:
273:            void showConfirmDialog(String msg) {
274:
275:                Object[] options = { NotifyDescriptor.OK_OPTION,
276:                        NotifyDescriptor.CANCEL_OPTION };
277:
278:                NotifyDescriptor confirmDialog = new NotifyDescriptor(
279:                        (Object) msg, NbBundle
280:                                .getBundle(EditPanelHeaders.class).getString(
281:                                        "MON_Confirmation_Required"),
282:                        NotifyDescriptor.OK_CANCEL_OPTION,
283:                        NotifyDescriptor.QUESTION_MESSAGE, options,
284:                        NotifyDescriptor.CANCEL_OPTION);
285:
286:                DialogDisplayer.getDefault().notify(confirmDialog);
287:                if (confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION))
288:                    setParams = true;
289:                else
290:                    setParams = false;
291:            }
292:
293:            void showErrorDialog() {
294:
295:                Object[] options = { NotifyDescriptor.OK_OPTION };
296:
297:                NotifyDescriptor errorDialog = new NotifyDescriptor(
298:                        (Object) NbBundle.getBundle(EditPanelHeaders.class)
299:                                .getString("MON_Bad_header"), NbBundle
300:                                .getBundle(EditPanelHeaders.class).getString(
301:                                        "MON_Invalid_input"),
302:                        NotifyDescriptor.DEFAULT_OPTION,
303:                        NotifyDescriptor.ERROR_MESSAGE, options,
304:                        NotifyDescriptor.OK_OPTION);
305:
306:                DialogDisplayer.getDefault().notify(errorDialog);
307:            }
308:
309:            void setEnablings() {
310:
311:                // Always enable the Add button.
312:                newHeaderB.setEnabled(true);
313:
314:                // The delete row button is enabled if any rows are selected.
315:                int selectedRows[] = headerTable.getSelectedRows();
316:                deleteHeaderB.setEnabled(selectedRows.length > 0);
317:            }
318:
319:            void setHeaderTable() {
320:
321:                Param[] params = monitorData.getRequestData().getHeaders()
322:                        .getParam();
323:                if (params == null)
324:                    params = new Param[0];
325:
326:                headerTable = new DisplayTable(params, DisplayTable.HEADERS,
327:                        true);
328:                headerTable.getAccessibleContext().setAccessibleName(
329:                        NbBundle.getBundle(EditPanelHeaders.class).getString(
330:                                "ACS_MON_HTTP_HeadersTableA11yName"));
331:                headerTable.setToolTipText(NbBundle.getBundle(
332:                        EditPanelHeaders.class).getString(
333:                        "ACS_MON_HTTP_HeadersTableA11yDesc"));
334:
335:                ListSelectionModel selma = headerTable.getSelectionModel();
336:                selma.addListSelectionListener(new ListSelectionListener() {
337:                    public void valueChanged(ListSelectionEvent evt) {
338:                        if (debug)
339:                            log("got list selection event"); // NOI18N
340:                        setEnablings();
341:                    }
342:                });
343:
344:                headerTable.addTableModelListener(new TableModelListener() {
345:                    public void tableChanged(TableModelEvent evt) {
346:
347:                        if (debug)
348:                            log("got table changed event"); //NOI18N
349:                        updateHeaders();
350:                    }
351:                });
352:            }
353:
354:            private void updateHeaders() {
355:
356:                int num = headerTable.getRowCount();
357:                Headers hd = monitorData.getRequestData().getHeaders();
358:                Param[] params = hd.getParam();
359:
360:                boolean inputOK = true;
361:
362:                for (int i = 0; i < num; i++) {
363:                    String name = (String) headerTable.getValueAt(i, 0);
364:                    name = name.trim();
365:
366:                    if (debug)
367:                        log("Name is " + name); //NOI18N
368:
369:                    if (name.equals("")) { // NOI18N
370:                        headerTable.setValueAt(params[i].getName(), i, 0);
371:                        inputOK = false;
372:                    }
373:                    String value = (String) headerTable.getValueAt(i, 1);
374:                    value = value.trim();
375:
376:                    if (debug)
377:                        log("Value is " + value); //NOI18N
378:
379:                    if (value.equals("")) { // NOI18N
380:                        headerTable.setValueAt(params[i].getValue(), i, 1);
381:                        inputOK = false;
382:                    }
383:
384:                    if (!inputOK) {
385:                        showErrorDialog();
386:                        return;
387:                    }
388:                    params[i].setName(name);
389:                    params[i].setValue(value);
390:                }
391:            }
392:
393:            public void repaint() {
394:                super .repaint();
395:                //if (editPanel != null) 
396:                //editPanel.repaint();
397:            }
398:
399:            void log(String s) {
400:                System.out.println("EditPanelHeaders::" + s); //NOI18N
401:            }
402:
403:        } // EditPanelHeader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.