1 19 package org.netbeans.modules.websvc.core.webservices.ui.panels; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.util.Set ; 24 import javax.swing.DefaultListModel ; 25 import javax.swing.ListSelectionModel ; 26 import javax.swing.event.ListSelectionEvent ; 27 import javax.swing.event.ListSelectionListener ; 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 39 public class MessageHandlerPanel extends javax.swing.JPanel { 40 41 private Project project; 42 private String [] handlerClasses; 43 private boolean isJaxWS; 44 private DefaultListModel listModel; 45 private String componentName; 46 47 48 public MessageHandlerPanel(Project project, String [] handlerClasses, boolean isJaxWS, 49 String 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 (); 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 getListModel(){ 69 return listModel; 70 } 71 72 private int getSelectedRow() { 73 ListSelectionModel lsm = (ListSelectionModel )messageHandlerList.getSelectionModel(); 74 if (lsm.isSelectionEmpty()) { 75 return -1; 76 } else { 77 return lsm.getMinSelectionIndex(); 78 } 79 } 80 81 class RemoveButtonActionListener implements ActionListener { 82 public void actionPerformed(ActionEvent e) { 83 int selectedRow = getSelectedRow(); 84 if(selectedRow == -1) return; 85 String className = (String )listModel.getElementAt(selectedRow); 86 if(confirmDeletion(className)){ 87 listModel.removeElementAt(selectedRow); 88 } 89 } 90 91 private boolean confirmDeletion(String 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 { 103 DialogDescriptor dlgDesc = null; 104 public void actionPerformed(ActionEvent evt){ 105 WSHandlerDialog wsHandlerDialog = new WSHandlerDialog(project, isJaxWS); 106 wsHandlerDialog.show(); 107 if(wsHandlerDialog.okButtonPressed()){ 108 Set <String > selectedClasses = wsHandlerDialog.getSelectedClasses(); 109 for(String selectedClass : selectedClasses){ 110 listModel.addElement(selectedClass); 111 } 112 } 113 } 114 } 115 116 class HandlerListSelectionListener implements ListSelectionListener { 117 public void valueChanged(ListSelectionEvent e) { 118 119 } 120 121 } 122 127 private void initComponents() { 129 jScrollPane1 = new javax.swing.JScrollPane (); 130 messageHandlerList = new javax.swing.JList (); 131 addBtn = new javax.swing.JButton (); 132 removeBtn = new javax.swing.JButton (); 133 classesLabel = new javax.swing.JLabel (); 134 135 messageHandlerList.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 136 messageHandlerList.setModel(new javax.swing.AbstractListModel () { 137 String [] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; 138 public int getSize() { return strings.length; } 139 public Object 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 } 183 184 private javax.swing.JButton addBtn; 186 private javax.swing.JLabel classesLabel; 187 private javax.swing.JScrollPane jScrollPane1; 188 private javax.swing.JList messageHandlerList; 189 private javax.swing.JButton removeBtn; 190 192 } 193 | Popular Tags |