1 6 7 package SOFA.SOFAnet.Browser; 8 9 import javax.swing.*; 10 import SOFA.SOFAnet.Repository.NodeNameFilter; 11 import SOFA.SOFAnet.Search.RMI.RMISearchConfiguration; 12 import java.util.*; 13 import java.awt.Component ; 14 import java.awt.Frame ; 15 16 20 public class RMISearchConfigurationEditDialog extends javax.swing.JDialog 21 { 22 private RMISearchConfiguration configuration; 23 private DefaultListModel content; 24 private NodeNameFilter nodeFilter; 25 private boolean isOK; 26 private boolean apply; 27 28 public static boolean showDialog(Component frameComp, RMISearchConfiguration configuration) 29 { 30 Frame frame = JOptionPane.getFrameForComponent(frameComp); 31 RMISearchConfigurationEditDialog dialog = new RMISearchConfigurationEditDialog(frame, true, configuration); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public RMISearchConfigurationEditDialog(java.awt.Frame parent, boolean modal, RMISearchConfiguration configuration) 39 { 40 super(parent, modal); 41 this.configuration = configuration; 42 content = new DefaultListModel(); 43 isOK = false; 44 apply = false; 45 nodeFilter = configuration.getNodeFilter(); 46 47 initComponents(); 48 49 if (nodeFilter != null) 50 { 51 nodeFilterCheckBox.setSelected(true); 52 nodeFilterButton.setEnabled(true); 53 } 54 else 55 { 56 nodeFilterCheckBox.setSelected(false); 57 nodeFilterButton.setEnabled(false); 58 } 59 60 if (nodeFilter != null) nodeFilter = (NodeNameFilter)nodeFilter.clone(); 61 else nodeFilter = new NodeNameFilter(); 62 63 List connections = configuration.getConnections(); 64 synchronized (connections) 65 { 66 Iterator it = connections.iterator(); 67 while (it.hasNext()) 68 { 69 RMISearchConfiguration.Connection connection = (RMISearchConfiguration.Connection)it.next(); 70 content.addElement(connection.clone()); 71 } 72 } 73 } 74 75 public boolean isOK() 76 { 77 return isOK; 78 } 79 80 public boolean apply() 81 { 82 return apply; 83 } 84 85 86 91 private void initComponents() { 93 jPanel1 = new javax.swing.JPanel (); 94 nodeFilterPanel = new javax.swing.JPanel (); 95 nodeFilterCheckBox = new javax.swing.JCheckBox (); 96 nodeFilterButton = new javax.swing.JButton (); 97 jLabel1 = new javax.swing.JLabel (); 98 jScrollPane1 = new javax.swing.JScrollPane (); 99 connectionsList = new javax.swing.JList (); 100 jPanel2 = new javax.swing.JPanel (); 101 jPanel4 = new javax.swing.JPanel (); 102 editButton = new javax.swing.JButton (); 103 addButton = new javax.swing.JButton (); 104 deleteSelectedButton = new javax.swing.JButton (); 105 jPanel3 = new javax.swing.JPanel (); 106 OKButton = new javax.swing.JButton (); 107 OKAndApplyButton = new javax.swing.JButton (); 108 cancelButton = new javax.swing.JButton (); 109 110 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 111 setTitle("RMI Search Subsystem Configuration"); 112 jPanel1.setLayout(new java.awt.GridLayout (2, 0)); 113 114 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 1, 1, 1))); 115 nodeFilterPanel.setLayout(new javax.swing.BoxLayout (nodeFilterPanel, javax.swing.BoxLayout.X_AXIS)); 116 117 nodeFilterCheckBox.setText("Node Filter"); 118 nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener () 119 { 120 public void actionPerformed(java.awt.event.ActionEvent evt) 121 { 122 nodeFilterCheckBoxActionPerformed(evt); 123 } 124 }); 125 126 nodeFilterPanel.add(nodeFilterCheckBox); 127 128 nodeFilterButton.setText("Edit Node Filter"); 129 nodeFilterButton.addActionListener(new java.awt.event.ActionListener () 130 { 131 public void actionPerformed(java.awt.event.ActionEvent evt) 132 { 133 nodeFilterButtonActionPerformed(evt); 134 } 135 }); 136 137 nodeFilterPanel.add(nodeFilterButton); 138 139 jPanel1.add(nodeFilterPanel); 140 141 jLabel1.setText("Connections:"); 142 jPanel1.add(jLabel1); 143 144 getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); 145 146 jScrollPane1.setMinimumSize(new java.awt.Dimension (260, 132)); 147 connectionsList.setModel(content); 148 connectionsList.addMouseListener(new java.awt.event.MouseAdapter () 149 { 150 public void mouseClicked(java.awt.event.MouseEvent evt) 151 { 152 connectionsListMouseClicked(evt); 153 } 154 }); 155 156 jScrollPane1.setViewportView(connectionsList); 157 158 getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); 159 160 jPanel2.setLayout(new java.awt.BorderLayout ()); 161 162 jPanel4.setLayout(new java.awt.GridLayout (3, 0)); 163 164 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Search Connections")); 165 editButton.setText("Edit Connection"); 166 editButton.addActionListener(new java.awt.event.ActionListener () 167 { 168 public void actionPerformed(java.awt.event.ActionEvent evt) 169 { 170 editButtonActionPerformed(evt); 171 } 172 }); 173 174 jPanel4.add(editButton); 175 176 addButton.setText("Add New Connection"); 177 addButton.addActionListener(new java.awt.event.ActionListener () 178 { 179 public void actionPerformed(java.awt.event.ActionEvent evt) 180 { 181 addButtonActionPerformed(evt); 182 } 183 }); 184 185 jPanel4.add(addButton); 186 187 deleteSelectedButton.setText("Delete Selected"); 188 deleteSelectedButton.addActionListener(new java.awt.event.ActionListener () 189 { 190 public void actionPerformed(java.awt.event.ActionEvent evt) 191 { 192 deleteSelectedButtonActionPerformed(evt); 193 } 194 }); 195 196 jPanel4.add(deleteSelectedButton); 197 198 jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH); 199 200 getContentPane().add(jPanel2, java.awt.BorderLayout.EAST); 201 202 OKButton.setText("OK"); 203 OKButton.addActionListener(new java.awt.event.ActionListener () 204 { 205 public void actionPerformed(java.awt.event.ActionEvent evt) 206 { 207 OKButtonActionPerformed(evt); 208 } 209 }); 210 211 jPanel3.add(OKButton); 212 213 OKAndApplyButton.setText("Save and Apply Configuration"); 214 OKAndApplyButton.addActionListener(new java.awt.event.ActionListener () 215 { 216 public void actionPerformed(java.awt.event.ActionEvent evt) 217 { 218 OKAndApplyButtonActionPerformed(evt); 219 } 220 }); 221 222 jPanel3.add(OKAndApplyButton); 223 224 cancelButton.setText("Cancel"); 225 cancelButton.addActionListener(new java.awt.event.ActionListener () 226 { 227 public void actionPerformed(java.awt.event.ActionEvent evt) 228 { 229 cancelButtonActionPerformed(evt); 230 } 231 }); 232 233 jPanel3.add(cancelButton); 234 235 getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH); 236 237 pack(); 238 } 240 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 243 } 245 private void saveResults() 246 { 247 if (!nodeFilterCheckBox.isSelected()) nodeFilter = null; 248 249 configuration.setNodeFilter(nodeFilter); 250 251 List connections = configuration.getConnections(); 252 connections.clear(); 253 Enumeration en = content.elements(); 254 while (en.hasMoreElements()) connections.add((RMISearchConfiguration.Connection)en.nextElement()); 255 } 256 257 private void OKAndApplyButtonActionPerformed(java.awt.event.ActionEvent evt) { saveResults(); 260 isOK = true; 261 apply = true; 262 dispose(); 263 } 265 private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) { saveResults(); 268 isOK = true; 269 dispose(); 270 } 272 private void connectionsListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) 275 { 276 editButton.doClick(); } 278 } 280 private void deleteSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selected = connectionsList.getSelectedValues(); 283 for (int i = 0; i < selected.length; i++) content.removeElement(selected[i]); 284 } 286 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { RMISearchConfiguration.Connection connection = new RMISearchConfiguration.Connection("", null); 289 if (RMISearchConfigurationConnectionEditDialog.showDialog(this, connection)) 290 { 291 content.addElement(connection); 292 } 293 } 295 private void editButtonActionPerformed(java.awt.event.ActionEvent evt) { RMISearchConfiguration.Connection connection = (RMISearchConfiguration.Connection)connectionsList.getSelectedValue(); 298 299 if (connection == null) 300 { 301 JOptionPane.showMessageDialog(this, "No Connection selected", "Warning", JOptionPane.WARNING_MESSAGE); 302 return; 303 } 304 305 if (RMISearchConfigurationConnectionEditDialog.showDialog(this, connection)) 306 { 307 } 308 } 310 private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor"); 313 } 315 private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected()); 318 } 320 321 private javax.swing.JButton OKAndApplyButton; 323 private javax.swing.JButton OKButton; 324 private javax.swing.JButton addButton; 325 private javax.swing.JButton cancelButton; 326 private javax.swing.JList connectionsList; 327 private javax.swing.JButton deleteSelectedButton; 328 private javax.swing.JButton editButton; 329 private javax.swing.JLabel jLabel1; 330 private javax.swing.JPanel jPanel1; 331 private javax.swing.JPanel jPanel2; 332 private javax.swing.JPanel jPanel3; 333 private javax.swing.JPanel jPanel4; 334 private javax.swing.JScrollPane jScrollPane1; 335 private javax.swing.JButton nodeFilterButton; 336 private javax.swing.JCheckBox nodeFilterCheckBox; 337 private javax.swing.JPanel nodeFilterPanel; 338 340 } 341 | Popular Tags |