KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > webservices > ui > panels > MessageHandlerPanel


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 package org.netbeans.modules.websvc.core.webservices.ui.panels;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.DefaultListModel JavaDoc;
25 import javax.swing.ListSelectionModel JavaDoc;
26 import javax.swing.event.ListSelectionEvent JavaDoc;
27 import javax.swing.event.ListSelectionListener JavaDoc;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.modules.websvc.core.webservices.ui.WSHandlerDialog;
30 import org.openide.DialogDescriptor;
31 import org.openide.DialogDisplayer;
32 import org.openide.NotifyDescriptor;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author rico
38  */

39 public class MessageHandlerPanel extends javax.swing.JPanel JavaDoc {
40     
41     private Project project;
42     private String JavaDoc[] handlerClasses;
43     private boolean isJaxWS;
44     private DefaultListModel JavaDoc listModel;
45     private String JavaDoc componentName;
46     
47     /** Creates new form HandlerPanel */
48     public MessageHandlerPanel(Project project, String JavaDoc[] handlerClasses, boolean isJaxWS,
49             String JavaDoc componentName) {
50         this.project = project;
51         this.handlerClasses = handlerClasses;
52         this.isJaxWS = isJaxWS;
53         this.componentName = componentName;
54         initComponents();
55         addBtn.addActionListener(new AddButtonActionListener());
56         removeBtn.addActionListener(new RemoveButtonActionListener());
57         listModel = new DefaultListModel JavaDoc();
58         messageHandlerList.setModel(listModel);
59         populateHandlers();
60     }
61     
62     private void populateHandlers(){
63         for(int i = 0; i < handlerClasses.length; i++){
64             listModel.addElement(handlerClasses[i]);
65         }
66     }
67     
68     public DefaultListModel JavaDoc getListModel(){
69         return listModel;
70     }
71     
72     private int getSelectedRow() {
73         ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)messageHandlerList.getSelectionModel();
74         if (lsm.isSelectionEmpty()) {
75             return -1;
76         } else {
77             return lsm.getMinSelectionIndex();
78         }
79     }
80     
81     class RemoveButtonActionListener implements ActionListener JavaDoc{
82         public void actionPerformed(ActionEvent JavaDoc e) {
83             int selectedRow = getSelectedRow();
84             if(selectedRow == -1) return;
85             String JavaDoc className = (String JavaDoc)listModel.getElementAt(selectedRow);
86             if(confirmDeletion(className)){
87                 listModel.removeElementAt(selectedRow);
88             }
89         }
90         
91         private boolean confirmDeletion(String JavaDoc className) {
92             NotifyDescriptor.Confirmation notifyDesc =
93                     new NotifyDescriptor.Confirmation(NbBundle.getMessage
94                     (MessageHandlerPanel.class, "MSG_CONFIRM_DELETE", className, componentName),
95                     NbBundle.getMessage(MessageHandlerPanel.class, "TTL_CONFIRM_DELETE"),
96                     NotifyDescriptor.YES_NO_OPTION);
97             DialogDisplayer.getDefault().notify(notifyDesc);
98             return (notifyDesc.getValue() == NotifyDescriptor.YES_OPTION);
99         }
100     }
101     
102     class AddButtonActionListener implements ActionListener JavaDoc{
103         DialogDescriptor dlgDesc = null;
104         public void actionPerformed(ActionEvent JavaDoc evt){
105             WSHandlerDialog wsHandlerDialog = new WSHandlerDialog(project, isJaxWS);
106             wsHandlerDialog.show();
107             if(wsHandlerDialog.okButtonPressed()){
108                 Set JavaDoc<String JavaDoc> selectedClasses = wsHandlerDialog.getSelectedClasses();
109                 for(String JavaDoc selectedClass : selectedClasses){
110                     listModel.addElement(selectedClass);
111                 }
112             }
113         }
114     }
115     
116     class HandlerListSelectionListener implements ListSelectionListener JavaDoc{
117         public void valueChanged(ListSelectionEvent JavaDoc e) {
118   
119         }
120         
121     }
122     /** This method is called from within the constructor to
123      * initialize the form.
124      * WARNING: Do NOT modify this code. The content of this method is
125      * always regenerated by the Form Editor.
126      */

127     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
128
private void initComponents() {
129         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
130         messageHandlerList = new javax.swing.JList JavaDoc();
131         addBtn = new javax.swing.JButton JavaDoc();
132         removeBtn = new javax.swing.JButton JavaDoc();
133         classesLabel = new javax.swing.JLabel JavaDoc();
134
135         messageHandlerList.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
136         messageHandlerList.setModel(new javax.swing.AbstractListModel JavaDoc() {
137             String JavaDoc[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
138             public int getSize() { return strings.length; }
139             public Object JavaDoc getElementAt(int i) { return strings[i]; }
140         });
141         jScrollPane1.setViewportView(messageHandlerList);
142
143         addBtn.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/core/webservices/ui/panels/Bundle").getString("Add_DotDotDot_label"));
144
145         removeBtn.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/core/webservices/ui/panels/Bundle").getString("Remove_label"));
146
147         classesLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/core/webservices/ui/panels/Bundle").getString("LBL_HANDLER_CLASSES"));
148
149         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
150         this.setLayout(layout);
151         layout.setHorizontalGroup(
152             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153             .add(layout.createSequentialGroup()
154                 .add(20, 20, 20)
155                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156                     .add(classesLabel)
157                     .add(layout.createSequentialGroup()
158                         .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 271, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
159                         .add(28, 28, 28)
160                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161                             .add(addBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 112, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
162                             .add(removeBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))))
163                 .addContainerGap(28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
164         );
165         layout.setVerticalGroup(
166             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167             .add(layout.createSequentialGroup()
168                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
169                     .add(layout.createSequentialGroup()
170                         .add(101, 101, 101)
171                         .add(addBtn)
172                         .add(28, 28, 28)
173                         .add(removeBtn))
174                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
175                         .addContainerGap()
176                         .add(classesLabel)
177                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 13, Short.MAX_VALUE)
178                         .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 269, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
179                 .addContainerGap())
180         );
181     }// </editor-fold>//GEN-END:initComponents
182

183     
184     // Variables declaration - do not modify//GEN-BEGIN:variables
185
private javax.swing.JButton JavaDoc addBtn;
186     private javax.swing.JLabel JavaDoc classesLabel;
187     private javax.swing.JScrollPane JavaDoc jScrollPane1;
188     private javax.swing.JList JavaDoc messageHandlerList;
189     private javax.swing.JButton JavaDoc removeBtn;
190     // End of variables declaration//GEN-END:variables
191

192 }
193
Popular Tags