1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Admin.RMI.*; 10 import SOFA.SOFAnet.Search.*; 11 import SOFA.SOFAnet.Repository.BundleInfo; 12 import javax.swing.*; 13 import java.rmi.RemoteException ; 14 import java.util.*; 15 import java.awt.Component ; 16 import java.awt.Frame ; 17 18 22 public class SearchDialog extends javax.swing.JDialog 23 { 24 private DefaultListModel content; 25 private RMIAdminInterface admin; 26 27 public static void showDialog(Component frameComp, RMIAdminInterface admin) 28 { 29 Frame frame = JOptionPane.getFrameForComponent(frameComp); 30 JDialog dialog = new SearchDialog(frame, true, admin); 31 dialog.setLocationRelativeTo(frameComp); 32 dialog.setVisible(true); 33 } 34 35 36 public SearchDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin) 37 { 38 super(parent, modal); 39 this.admin = admin; 40 content = new DefaultListModel(); 41 initComponents(); 42 } 43 44 49 private void initComponents() { 51 componentModeButtonGroup = new javax.swing.ButtonGroup (); 52 jPanel1 = new javax.swing.JPanel (); 53 jPanel7 = new javax.swing.JPanel (); 54 jPanel6 = new javax.swing.JPanel (); 55 strLabel = new javax.swing.JLabel (); 56 strTextField = new javax.swing.JTextField (); 57 patternCheckBox = new javax.swing.JCheckBox (); 58 componentCheckBox = new javax.swing.JCheckBox (); 59 componentModePanel = new javax.swing.JPanel (); 60 ccTryRadioButton = new javax.swing.JRadioButton (); 61 ccNoRadioButton = new javax.swing.JRadioButton (); 62 ccOnlyRadioButton = new javax.swing.JRadioButton (); 63 jPanel9 = new javax.swing.JPanel (); 64 settingsPanel = new javax.swing.JPanel (); 65 timoutLabel = new javax.swing.JLabel (); 66 timeoutTextField = new javax.swing.JTextField (); 67 shareGroupLabel = new javax.swing.JLabel (); 68 shareGroupTextField = new javax.swing.JTextField (); 69 firstOnlyCheckBox = new javax.swing.JCheckBox (); 70 jPanel8 = new javax.swing.JPanel (); 71 searchButton = new javax.swing.JButton (); 72 jPanel2 = new javax.swing.JPanel (); 73 jScrollPane1 = new javax.swing.JScrollPane (); 74 repliesList = new javax.swing.JList (); 75 jPanel4 = new javax.swing.JPanel (); 76 acquireButton = new javax.swing.JButton (); 77 jPanel3 = new javax.swing.JPanel (); 78 closeButton = new javax.swing.JButton (); 79 80 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 81 setTitle("Search"); 82 jPanel1.setLayout(new java.awt.BorderLayout ()); 83 84 jPanel7.setLayout(new java.awt.BorderLayout ()); 85 86 jPanel7.setBorder(new javax.swing.border.TitledBorder ("Search Request")); 87 jPanel6.setLayout(new java.awt.GridLayout (4, 0)); 88 89 strLabel.setText("Search String:"); 90 jPanel6.add(strLabel); 91 92 jPanel6.add(strTextField); 93 94 patternCheckBox.setText("Search String is Pattern"); 95 jPanel6.add(patternCheckBox); 96 97 componentCheckBox.setText("Search String is Component"); 98 componentCheckBox.addActionListener(new java.awt.event.ActionListener () 99 { 100 public void actionPerformed(java.awt.event.ActionEvent evt) 101 { 102 componentCheckBoxActionPerformed(evt); 103 } 104 }); 105 106 jPanel6.add(componentCheckBox); 107 108 jPanel7.add(jPanel6, java.awt.BorderLayout.NORTH); 109 110 componentModePanel.setLayout(new java.awt.GridLayout (3, 0)); 111 112 componentModePanel.setBorder(new javax.swing.border.TitledBorder ("Component Mode")); 113 componentModePanel.setEnabled(false); 114 ccTryRadioButton.setSelected(true); 115 ccTryRadioButton.setText("Try Complete Component (including subcomponents)"); 116 componentModeButtonGroup.add(ccTryRadioButton); 117 ccTryRadioButton.setEnabled(false); 118 componentModePanel.add(ccTryRadioButton); 119 120 ccNoRadioButton.setText("Single Component (without subcomponents)"); 121 componentModeButtonGroup.add(ccNoRadioButton); 122 ccNoRadioButton.setEnabled(false); 123 componentModePanel.add(ccNoRadioButton); 124 125 ccOnlyRadioButton.setText("Complete Component (with subcomponents)"); 126 componentModeButtonGroup.add(ccOnlyRadioButton); 127 ccOnlyRadioButton.setEnabled(false); 128 componentModePanel.add(ccOnlyRadioButton); 129 130 jPanel7.add(componentModePanel, java.awt.BorderLayout.CENTER); 131 132 jPanel1.add(jPanel7, java.awt.BorderLayout.CENTER); 133 134 jPanel9.setLayout(new java.awt.BorderLayout ()); 135 136 settingsPanel.setLayout(new java.awt.GridLayout (5, 0)); 137 138 settingsPanel.setBorder(new javax.swing.border.TitledBorder ("Search Settings")); 139 timoutLabel.setText("Timeout (in milliseconds):"); 140 settingsPanel.add(timoutLabel); 141 142 timeoutTextField.setText("3000"); 143 settingsPanel.add(timeoutTextField); 144 145 shareGroupLabel.setText("Share Group:"); 146 settingsPanel.add(shareGroupLabel); 147 148 settingsPanel.add(shareGroupTextField); 149 150 firstOnlyCheckBox.setSelected(true); 151 firstOnlyCheckBox.setText("First Reply Only"); 152 settingsPanel.add(firstOnlyCheckBox); 153 154 jPanel9.add(settingsPanel, java.awt.BorderLayout.NORTH); 155 156 searchButton.setText("Search"); 157 searchButton.addActionListener(new java.awt.event.ActionListener () 158 { 159 public void actionPerformed(java.awt.event.ActionEvent evt) 160 { 161 searchButtonActionPerformed(evt); 162 } 163 }); 164 165 jPanel8.add(searchButton); 166 167 jPanel9.add(jPanel8, java.awt.BorderLayout.SOUTH); 168 169 jPanel1.add(jPanel9, java.awt.BorderLayout.EAST); 170 171 getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); 172 173 jPanel2.setLayout(new java.awt.BorderLayout ()); 174 175 jPanel2.setBorder(new javax.swing.border.TitledBorder ("Replies")); 176 repliesList.setModel(content); 177 repliesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 178 repliesList.addMouseListener(new java.awt.event.MouseAdapter () 179 { 180 public void mouseClicked(java.awt.event.MouseEvent evt) 181 { 182 repliesListMouseClicked(evt); 183 } 184 }); 185 186 jScrollPane1.setViewportView(repliesList); 187 188 jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER); 189 190 acquireButton.setText("Acquire Selected Shared Bundle"); 191 acquireButton.addActionListener(new java.awt.event.ActionListener () 192 { 193 public void actionPerformed(java.awt.event.ActionEvent evt) 194 { 195 acquireButtonActionPerformed(evt); 196 } 197 }); 198 199 jPanel4.add(acquireButton); 200 201 jPanel2.add(jPanel4, java.awt.BorderLayout.SOUTH); 202 203 getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER); 204 205 closeButton.setText("Close"); 206 closeButton.addActionListener(new java.awt.event.ActionListener () 207 { 208 public void actionPerformed(java.awt.event.ActionEvent evt) 209 { 210 closeButtonActionPerformed(evt); 211 } 212 }); 213 214 jPanel3.add(closeButton); 215 216 getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH); 217 218 pack(); 219 } 221 private void repliesListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) 224 { 225 acquireButton.doClick(); } 227 } 229 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 232 } 234 private void acquireButtonActionPerformed(java.awt.event.ActionEvent evt) { SearchReplyItem reply = (SearchReplyItem)repliesList.getSelectedValue(); 237 if (reply != null) 238 { 239 AcquireSharedBundleDialog.showDialog(this, admin, reply.getBundleName(), reply.getNodeName()); 240 } 241 } 243 private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) { String strText = strTextField.getText().trim(); 246 boolean pattern = patternCheckBox.isSelected(); 247 boolean component = componentCheckBox.isSelected(); 248 int completeComponent = SearchPattern.CC_TRY; 249 if (ccNoRadioButton.isSelected()) completeComponent = SearchPattern.CC_NO; 250 if (ccOnlyRadioButton.isSelected()) completeComponent = SearchPattern.CC_ONLY; 251 252 if (strText.length() == 0) 253 { 254 JOptionPane.showMessageDialog(this, "Empty Search String", "Error", JOptionPane.ERROR_MESSAGE); 255 return; 256 } 257 258 if (!pattern) 259 { 260 BundleInfo bundleInfo = new BundleInfo(); 261 try 262 { 263 bundleInfo.fromBundleName(strText); 264 } 265 catch (BundleInfo.InvalidBundleNameException e) 266 { 267 if (component) JOptionPane.showMessageDialog(this, "Invalid name of component:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 268 else JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 269 return; 270 } 271 272 if (component && !bundleInfo.isComponent()) 273 { 274 JOptionPane.showMessageDialog(this, "Invalid name of component", "Error", JOptionPane.ERROR_MESSAGE); 275 return; 276 } 277 } 278 279 int timeout = 3000; 280 try 281 { 282 timeout = Integer.parseInt(timeoutTextField.getText()); 283 if (timeout <= 0) throw new NumberFormatException (); 284 } 285 catch (NumberFormatException e) 286 { 287 JOptionPane.showMessageDialog(this, "Invalid Timeout", "Error", JOptionPane.ERROR_MESSAGE); 288 return; 289 } 290 291 String shareGroup = shareGroupTextField.getText(); 292 boolean firstOnly = firstOnlyCheckBox.isSelected(); 293 294 SearchPattern searchPattern = new SearchPattern(); 295 searchPattern.setStr(strText); 296 searchPattern.setPattern(pattern); 297 searchPattern.setComponent(component); 298 searchPattern.setCompleteComponent(completeComponent); 299 300 SearchReplyItem[] replies = null; 301 try 302 { 303 replies = admin.search(searchPattern, firstOnly, shareGroup, timeout); 304 } 305 catch (RemoteException e) 306 { 307 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 308 dispose(); 309 return; 310 } 311 catch (RMIAdminException e) 312 { 313 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 314 dispose(); 315 return; 316 } 317 318 content.clear(); 319 if (replies != null) 320 { 321 content.ensureCapacity(replies.length); 322 for (int i = 0; i < replies.length; i++) content.addElement(replies[i]); 323 } 324 } 326 private void componentCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { boolean component = componentCheckBox.isSelected(); 329 componentModePanel.setEnabled(component); 330 ccTryRadioButton.setEnabled(component); 331 ccNoRadioButton.setEnabled(component); 332 ccOnlyRadioButton.setEnabled(component); 333 } 335 private javax.swing.JButton acquireButton; 337 private javax.swing.JRadioButton ccNoRadioButton; 338 private javax.swing.JRadioButton ccOnlyRadioButton; 339 private javax.swing.JRadioButton ccTryRadioButton; 340 private javax.swing.JButton closeButton; 341 private javax.swing.JCheckBox componentCheckBox; 342 private javax.swing.ButtonGroup componentModeButtonGroup; 343 private javax.swing.JPanel componentModePanel; 344 private javax.swing.JCheckBox firstOnlyCheckBox; 345 private javax.swing.JPanel jPanel1; 346 private javax.swing.JPanel jPanel2; 347 private javax.swing.JPanel jPanel3; 348 private javax.swing.JPanel jPanel4; 349 private javax.swing.JPanel jPanel6; 350 private javax.swing.JPanel jPanel7; 351 private javax.swing.JPanel jPanel8; 352 private javax.swing.JPanel jPanel9; 353 private javax.swing.JScrollPane jScrollPane1; 354 private javax.swing.JCheckBox patternCheckBox; 355 private javax.swing.JList repliesList; 356 private javax.swing.JButton searchButton; 357 private javax.swing.JPanel settingsPanel; 358 private javax.swing.JLabel shareGroupLabel; 359 private javax.swing.JTextField shareGroupTextField; 360 private javax.swing.JLabel strLabel; 361 private javax.swing.JTextField strTextField; 362 private javax.swing.JTextField timeoutTextField; 363 private javax.swing.JLabel timoutLabel; 364 366 } 367 | Popular Tags |