1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Repository.InputTrigger; 10 import SOFA.SOFAnet.Repository.Licence; 11 import SOFA.SOFAnet.Repository.NodeNameFilter; 12 import SOFA.SOFAnet.Repository.ShareGroups; 13 import javax.swing.*; 14 import java.util.*; 15 import java.awt.Component ; 16 import java.awt.Frame ; 17 18 22 public class InputTriggerShareActionPropertiesEditDialog extends javax.swing.JDialog 23 { 24 private ActionShareParameters asParameters; 25 private NodeNameFilter asNodeFilter; 26 private ShareGroups asShareGroups; 27 private boolean isOK; 28 29 public static class ActionShareParameters 30 { 31 private int asNoLicences; 32 private ShareGroups asShareGroups; 33 private NodeNameFilter asNodeFilter; 34 private boolean asEquality; 35 36 public ActionShareParameters(InputTrigger inputTrigger) 37 { 38 asNoLicences = inputTrigger.getAsNoLicences(); 39 asShareGroups = inputTrigger.getAsShareGroups(); 40 asNodeFilter = inputTrigger.getAsNodeFilter(); 41 asEquality = inputTrigger.getAsEquality(); 42 } 43 44 public void save(InputTrigger inputTrigger) 45 { 46 inputTrigger.setAsNoLicences(asNoLicences); 47 inputTrigger.setAsShareGroups(asShareGroups); 48 inputTrigger.setAsNodeFilter(asNodeFilter); 49 inputTrigger.setAsEquality(asEquality); 50 } 51 52 public int getAsNoLicences() 53 { 54 return asNoLicences; 55 } 56 57 public ShareGroups getAsShareGroups() 58 { 59 return asShareGroups; 60 } 61 62 public NodeNameFilter getAsNodeFilter() 63 { 64 return asNodeFilter; 65 } 66 67 public boolean getAsEquality() 68 { 69 return asEquality; 70 } 71 72 public void setAsNoLicences(int asNoLicences) 73 { 74 if (asNoLicences <= 0 && asNoLicences != Licence.ALL_LICENCES) asNoLicences = Licence.ONE_IMPLICIT_LICENCE; 75 this.asNoLicences = asNoLicences; 76 } 77 78 public void setAsShareGroups(ShareGroups asShareGroups) 79 { 80 this.asShareGroups = asShareGroups; 81 } 82 83 public void setAsNodeFilter(NodeNameFilter asNodeFilter) 84 { 85 this.asNodeFilter = asNodeFilter; 86 } 87 88 public void setAsEquality(boolean asEquality) 89 { 90 this.asEquality = asEquality; 91 } 92 93 } 94 95 public static boolean showDialog(Component frameComp, ActionShareParameters asParameters) 96 { 97 Frame frame = JOptionPane.getFrameForComponent(frameComp); 98 InputTriggerShareActionPropertiesEditDialog dialog = new InputTriggerShareActionPropertiesEditDialog(frame, true, asParameters); 99 dialog.setLocationRelativeTo(frameComp); 100 dialog.setVisible(true); 101 return dialog.isOK(); 102 } 103 104 105 public InputTriggerShareActionPropertiesEditDialog(java.awt.Frame parent, boolean modal, ActionShareParameters asParameters) 106 { 107 super(parent, modal); 108 this.asParameters = asParameters; 109 asNodeFilter = asParameters.getAsNodeFilter(); 110 asShareGroups = asParameters.getAsShareGroups(); 111 isOK = false; 112 113 initComponents(); 114 115 int numLic = asParameters.getAsNoLicences(); 116 if (numLic == Licence.ONE_IMPLICIT_LICENCE) 117 { 118 asNumberOfLicencesCheckBox.setSelected(false); 119 asNumberOfLicencesTextField.setText(""); 120 asNumberOfLicencesTextField.setEnabled(false); 121 asNumberOfLicencesLabel.setEnabled(false); 122 } 123 else 124 if (numLic == Licence.ALL_LICENCES) 125 { 126 asNumberOfLicencesCheckBox.setSelected(true); 127 asNumberOfLicencesTextField.setText("*"); 128 asNumberOfLicencesTextField.setEnabled(true); 129 asNumberOfLicencesLabel.setEnabled(true); 130 } 131 else 132 { 133 asNumberOfLicencesCheckBox.setSelected(true); 134 asNumberOfLicencesTextField.setText(Integer.toString(numLic)); 135 asNumberOfLicencesTextField.setEnabled(true); 136 asNumberOfLicencesLabel.setEnabled(true); 137 } 138 139 if (asNodeFilter != null) 140 { 141 asNodeFilterCheckBox.setSelected(true); 142 asNodeFilterButton.setEnabled(true); 143 } 144 else 145 { 146 asNodeFilterCheckBox.setSelected(false); 147 asNodeFilterButton.setEnabled(false); 148 } 149 150 if (asShareGroups != null) 151 { 152 asShareGroupsCheckBox.setSelected(true); 153 asShareGroupsButton.setEnabled(true); 154 } 155 else 156 { 157 asShareGroupsCheckBox.setSelected(false); 158 asShareGroupsButton.setEnabled(false); 159 } 160 161 asEqualityCheckBox.setSelected(asParameters.getAsEquality()); 162 163 if (asNodeFilter != null) asNodeFilter = (NodeNameFilter)asNodeFilter.clone(); 164 else asNodeFilter = new NodeNameFilter(); 165 if (asShareGroups != null) asShareGroups = (ShareGroups)asShareGroups.clone(); 166 else asShareGroups = new ShareGroups(); 167 } 168 169 public boolean isOK() 170 { 171 return isOK; 172 } 173 174 179 private void initComponents() { 181 jPanel1 = new javax.swing.JPanel (); 182 asNumberOfLicencesPanel = new javax.swing.JPanel (); 183 asNumberOfLicencesCheckBox = new javax.swing.JCheckBox (); 184 asNumberOfLicencesTextField = new javax.swing.JTextField (); 185 asNumberOfLicencesLabel = new javax.swing.JLabel (); 186 asShareGroupsPanel = new javax.swing.JPanel (); 187 asShareGroupsCheckBox = new javax.swing.JCheckBox (); 188 asShareGroupsButton = new javax.swing.JButton (); 189 asNodeFilterPanel = new javax.swing.JPanel (); 190 asNodeFilterCheckBox = new javax.swing.JCheckBox (); 191 asNodeFilterButton = new javax.swing.JButton (); 192 asEqualityCheckBox = new javax.swing.JCheckBox (); 193 jPanel2 = new javax.swing.JPanel (); 194 OKButton = new javax.swing.JButton (); 195 cancelButton = new javax.swing.JButton (); 196 197 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 198 setTitle("Share Action Properties"); 199 jPanel1.setLayout(new java.awt.GridLayout (4, 0)); 200 201 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5))); 202 asNumberOfLicencesPanel.setLayout(new javax.swing.BoxLayout (asNumberOfLicencesPanel, javax.swing.BoxLayout.X_AXIS)); 203 204 asNumberOfLicencesCheckBox.setText("Number of Licences"); 205 asNumberOfLicencesCheckBox.addActionListener(new java.awt.event.ActionListener () 206 { 207 public void actionPerformed(java.awt.event.ActionEvent evt) 208 { 209 asNumberOfLicencesCheckBoxActionPerformed(evt); 210 } 211 }); 212 213 asNumberOfLicencesPanel.add(asNumberOfLicencesCheckBox); 214 215 asNumberOfLicencesPanel.add(asNumberOfLicencesTextField); 216 217 asNumberOfLicencesLabel.setText("(use '*' or 'all' for all licences)"); 218 asNumberOfLicencesPanel.add(asNumberOfLicencesLabel); 219 220 jPanel1.add(asNumberOfLicencesPanel); 221 222 asShareGroupsPanel.setLayout(new javax.swing.BoxLayout (asShareGroupsPanel, javax.swing.BoxLayout.X_AXIS)); 223 224 asShareGroupsCheckBox.setText("Share Groups"); 225 asShareGroupsCheckBox.addActionListener(new java.awt.event.ActionListener () 226 { 227 public void actionPerformed(java.awt.event.ActionEvent evt) 228 { 229 asShareGroupsCheckBoxActionPerformed(evt); 230 } 231 }); 232 233 asShareGroupsPanel.add(asShareGroupsCheckBox); 234 235 asShareGroupsButton.setText("Edit Share Groups"); 236 asShareGroupsButton.setEnabled(false); 237 asShareGroupsButton.addActionListener(new java.awt.event.ActionListener () 238 { 239 public void actionPerformed(java.awt.event.ActionEvent evt) 240 { 241 asShareGroupsButtonActionPerformed(evt); 242 } 243 }); 244 245 asShareGroupsPanel.add(asShareGroupsButton); 246 247 jPanel1.add(asShareGroupsPanel); 248 249 asNodeFilterPanel.setLayout(new javax.swing.BoxLayout (asNodeFilterPanel, javax.swing.BoxLayout.X_AXIS)); 250 251 asNodeFilterCheckBox.setText("Node Filter"); 252 asNodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener () 253 { 254 public void actionPerformed(java.awt.event.ActionEvent evt) 255 { 256 asNodeFilterCheckBoxActionPerformed(evt); 257 } 258 }); 259 260 asNodeFilterPanel.add(asNodeFilterCheckBox); 261 262 asNodeFilterButton.setText("Edit Node Filter"); 263 asNodeFilterButton.setEnabled(false); 264 asNodeFilterButton.addActionListener(new java.awt.event.ActionListener () 265 { 266 public void actionPerformed(java.awt.event.ActionEvent evt) 267 { 268 asNodeFilterButtonActionPerformed(evt); 269 } 270 }); 271 272 asNodeFilterPanel.add(asNodeFilterButton); 273 274 jPanel1.add(asNodeFilterPanel); 275 276 asEqualityCheckBox.setSelected(true); 277 asEqualityCheckBox.setText("Equality of Manager and Clients"); 278 jPanel1.add(asEqualityCheckBox); 279 280 getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); 281 282 jPanel2.setMinimumSize(new java.awt.Dimension (200, 35)); 283 jPanel2.setPreferredSize(new java.awt.Dimension (400, 35)); 284 OKButton.setText("OK"); 285 OKButton.addActionListener(new java.awt.event.ActionListener () 286 { 287 public void actionPerformed(java.awt.event.ActionEvent evt) 288 { 289 OKButtonActionPerformed(evt); 290 } 291 }); 292 293 jPanel2.add(OKButton); 294 295 cancelButton.setText("Cancel"); 296 cancelButton.addActionListener(new java.awt.event.ActionListener () 297 { 298 public void actionPerformed(java.awt.event.ActionEvent evt) 299 { 300 cancelButtonActionPerformed(evt); 301 } 302 }); 303 304 jPanel2.add(cancelButton); 305 306 getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); 307 308 pack(); 309 } 311 private void asNumberOfLicencesCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { asNumberOfLicencesTextField.setEnabled(asNumberOfLicencesCheckBox.isSelected()); 314 asNumberOfLicencesLabel.setEnabled(asNumberOfLicencesCheckBox.isSelected()); 315 } 317 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 320 } 322 private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) { boolean asNumberOfLicencesSelected = asNumberOfLicencesCheckBox.isSelected(); 325 String asNumberOfLicencesText = asNumberOfLicencesTextField.getText().trim().toLowerCase(); 326 boolean asEquality = asEqualityCheckBox.isSelected(); 327 328 int asNumberOfLicences = Licence.ONE_IMPLICIT_LICENCE; 329 if (asNumberOfLicencesSelected && asNumberOfLicencesText.length() != 0) 330 { 331 if (asNumberOfLicencesText.compareTo("*") == 0 || asNumberOfLicencesText.compareTo("all") == 0) asNumberOfLicences = Licence.ALL_LICENCES; 332 else 333 { 334 try 335 { 336 asNumberOfLicences = Integer.parseInt(asNumberOfLicencesText); 337 if (asNumberOfLicences < 0) throw new NumberFormatException ("Negative 'Number of Licences' is not allowed"); 338 } 339 catch (NumberFormatException e) 340 { 341 JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Licences':\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 342 return; 343 } 344 } 345 } 346 347 if (!asNodeFilterCheckBox.isSelected()) asNodeFilter = null; 348 if (!asShareGroupsCheckBox.isSelected()) asShareGroups = null; 349 350 asParameters.setAsNoLicences(asNumberOfLicences); 351 asParameters.setAsNodeFilter(asNodeFilter); 352 asParameters.setAsShareGroups(asShareGroups); 353 asParameters.setAsEquality(asEquality); 354 355 isOK = true; 356 dispose(); 357 } 359 private void asNodeFilterButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, asNodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor"); 362 } 364 private void asShareGroupsButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, asShareGroups.getList(), "Share Group", "Share Groups Editor"); 367 } 369 private void asNodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { asNodeFilterButton.setEnabled(asNodeFilterCheckBox.isSelected()); 372 } 374 private void asShareGroupsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { asShareGroupsButton.setEnabled(asShareGroupsCheckBox.isSelected()); 377 } 379 private javax.swing.JButton OKButton; 381 private javax.swing.JCheckBox asEqualityCheckBox; 382 private javax.swing.JButton asNodeFilterButton; 383 private javax.swing.JCheckBox asNodeFilterCheckBox; 384 private javax.swing.JPanel asNodeFilterPanel; 385 private javax.swing.JCheckBox asNumberOfLicencesCheckBox; 386 private javax.swing.JLabel asNumberOfLicencesLabel; 387 private javax.swing.JPanel asNumberOfLicencesPanel; 388 private javax.swing.JTextField asNumberOfLicencesTextField; 389 private javax.swing.JButton asShareGroupsButton; 390 private javax.swing.JCheckBox asShareGroupsCheckBox; 391 private javax.swing.JPanel asShareGroupsPanel; 392 private javax.swing.JButton cancelButton; 393 private javax.swing.JPanel jPanel1; 394 private javax.swing.JPanel jPanel2; 395 397 } 398 | Popular Tags |