1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui; 20 21 import javax.swing.DefaultComboBoxModel ; 22 import org.netbeans.modules.j2ee.websphere6.dd.beans.AuthorizationsType; 23 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmiConstants; 24 import org.netbeans.modules.j2ee.websphere6.dd.beans.SpecialSubjectType; 25 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject; 26 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 27 import org.netbeans.modules.xml.multiview.ui.SectionView; 28 import org.netbeans.modules.xml.multiview.Error; 29 30 34 public class WSAuthorizationsPanel extends SectionInnerPanel 35 implements DDXmiConstants, 36 java.awt.event.ActionListener , 37 java.awt.event.ItemListener { 38 39 WSMultiViewDataObject dObj; 40 AuthorizationsType auth; 41 private static String [] Types=SPECIAL_SUBJECTS_TYPES; 42 43 44 public WSAuthorizationsPanel(SectionView view, WSMultiViewDataObject dObj,AuthorizationsType auth) { 45 super(view); 46 initComponents(); 47 this.auth=auth; 48 this.dObj=dObj; 49 50 specialTypeComboBox.setModel(new DefaultComboBoxModel (Types)); 51 52 usergroupRadioButton.addActionListener(this); 53 specialTypesRadioButton.addActionListener(this); 54 specialTypeComboBox.addItemListener(this); 55 56 authNameField.setText(auth.getXmiId()); 57 roleNameField.setText(auth.getRoleHref()); 58 59 if(auth.getSpecialSubjects()!=null) { 60 specialTypeComboBox.setSelectedItem(auth.getSpecialSubjects().getType()); 61 specialTypeIdField.setText(auth.getSpecialSubjects().getXmiId()); 62 specialTypeNameField.setText(auth.getSpecialSubjects().getName()); 63 specialTypesRadioButton.setSelected(true); 64 } 65 if(auth.getUsers()!=null) { 66 usersIdField.setText(auth.getUsersXmiId()); 67 usersNameField.setText(auth.getUsersName()); 68 usergroupRadioButton.setSelected(true); 69 } 70 if(auth.getGroups()!=null) { 71 groupsIdField.setText(auth.getGroupsXmiId()); 72 groupsNameField.setText(auth.getGroupsName()); 73 usergroupRadioButton.setSelected(true); 74 } 75 addModifier(authNameField); 76 addModifier(roleNameField); 77 addModifier(usersIdField); 78 addModifier(usersNameField); 79 addModifier(groupsIdField); 80 addModifier(groupsNameField); 81 addModifier(specialTypeIdField); 82 addModifier(specialTypeNameField); 83 84 addValidatee(authNameField); 85 addValidatee(roleNameField); 86 87 addValidatee(usersIdField); 88 addValidatee(usersNameField); 89 90 addValidatee(groupsIdField); 91 addValidatee(groupsNameField); 92 93 addValidatee(specialTypeIdField); 94 addValidatee(specialTypeNameField); 95 96 setEnabledComponents(); 97 } 98 99 public void setValue(javax.swing.JComponent source, Object value) { 100 if (source==authNameField) { 101 auth.setXmiId((String )value); 102 } else if (source==roleNameField) { 103 auth.setRoleHref((String )value); 104 } else if (source==groupsIdField) { 105 auth.setGroupsXmiId((String )value); 106 } else if (source==groupsNameField) { 107 auth.setGroupsName((String )value); 108 } else if (source==usersIdField) { 109 auth.setUsersXmiId((String )value); 110 } else if (source==usersNameField) { 111 auth.setUsersName((String )value); 112 } else if (source==specialTypeIdField) { 113 auth.getSpecialSubjects().setXmiId((String )value); 114 } else if (source==specialTypeNameField) { 115 auth.getSpecialSubjects().setName((String )value); 116 } 117 118 119 } 120 public void actionPerformed(java.awt.event.ActionEvent e) { 121 String time_id="_"+java.lang.System.currentTimeMillis(); 122 123 if(usergroupRadioButton.isSelected()) { 124 auth.setSpecialSubjects(null); 125 if(usersNameField.getText().equals("")) { 126 usersIdField.setText(USERS_NAME+time_id); 127 usersNameField.setText(USERS_DEFAULT_NAME); 128 } 129 if(groupsNameField.getText().equals("")) { 130 groupsIdField.setText(GROUPS_NAME+time_id); 131 groupsNameField.setText(GROUPS_DEFAULT_NAME); 132 } 133 134 auth.setUsersName(usersNameField.getText()); 135 auth.setUsersXmiId(usersIdField.getText()); 136 auth.setGroupsName(groupsNameField.getText()); 137 auth.setGroupsXmiId(groupsIdField.getText()); 138 } else if(specialTypesRadioButton.isSelected()) { 139 auth.setUsers(null); 140 auth.setGroups(null); 141 SpecialSubjectType sst=new SpecialSubjectType(); 142 if(specialTypeNameField.getText().equals("")){ 143 specialTypeNameField.setText(SPECIAL_SUBJECTS_TYPE_EVERYONE); 144 } 145 if(specialTypeIdField.getText().equals("")) { 146 specialTypeIdField.setText(SPECIAL_SUBJECTS_TYPE_EVERYONE+time_id); 147 } 148 sst.setName(specialTypeNameField.getText()); 149 sst.setXmiId(specialTypeIdField.getText()); 150 sst.setType((String )specialTypeComboBox.getSelectedItem()); 151 auth.setSpecialSubjects(sst); 152 } 153 setEnabledComponents(); 154 dObj.modelUpdatedFromUI(); 155 } 156 157 public void itemStateChanged(java.awt.event.ItemEvent e) { 158 dObj.setChangedFromUI(true); 159 if(e.getSource()==specialTypeComboBox) { 160 SpecialSubjectType sst=auth.getSpecialSubjects(); 161 String selectedItem=(String )specialTypeComboBox.getSelectedItem(); 162 String replacedString=""; 163 sst.setType(selectedItem); 164 165 for(int j=0;j<Types.length;j++) { 166 if(Types[j]!=selectedItem) { 167 if(sst.getName().lastIndexOf(Types[j])!=-1) { 168 replacedString=sst.getName().replaceAll(Types[j],selectedItem); 169 sst.setName(replacedString); 170 specialTypeNameField.setText(replacedString); 171 } 172 if(sst.getXmiId().lastIndexOf(Types[j])!=-1) { 173 replacedString=sst.getXmiId().replaceAll(Types[j],selectedItem); 174 sst.setXmiId(replacedString); 175 specialTypeIdField.setText(replacedString); 176 } 177 } 178 } 179 } 180 dObj.modelUpdatedFromUI(); 181 dObj.setChangedFromUI(false); 182 } 183 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 184 if(comp==authNameField) { 185 String val = (String )value; 186 if (val.length()==0) { 187 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Auth Name", comp)); 188 return; 189 } 190 getSectionView().getErrorPanel().clearError(); 191 } 192 if(comp==roleNameField) { 193 String val = (String )value; 194 if (val.length()==0) { 195 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Role Name", comp)); 196 return; 197 } 198 getSectionView().getErrorPanel().clearError(); 199 } 200 if(comp==usersNameField) { 201 String val = (String )value; 202 if (val.length()==0) { 203 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Users Name", comp)); 204 return; 205 } 206 getSectionView().getErrorPanel().clearError(); 207 } 208 if(comp==usersIdField) { 209 String val = (String )value; 210 if (val.length()==0) { 211 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Users Id", comp)); 212 return; 213 } 214 getSectionView().getErrorPanel().clearError(); 215 } 216 if(comp==groupsNameField) { 217 String val = (String )value; 218 if (val.length()==0) { 219 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Groups Name", comp)); 220 return; 221 } 222 getSectionView().getErrorPanel().clearError(); 223 } 224 if(comp==groupsIdField) { 225 String val = (String )value; 226 if (val.length()==0) { 227 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Groups Id", comp)); 228 return; 229 } 230 getSectionView().getErrorPanel().clearError(); 231 } 232 if(comp==specialTypeIdField) { 233 String val = (String )value; 234 if (val.length()==0) { 235 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Special Type Id", comp)); 236 return; 237 } 238 getSectionView().getErrorPanel().clearError(); 239 } 240 if(comp==specialTypeNameField) { 241 String val = (String )value; 242 if (val.length()==0) { 243 getSectionView().getErrorPanel().setError(new Error (Error.MISSING_VALUE_MESSAGE, "Special Type Name", comp)); 244 return; 245 } 246 getSectionView().getErrorPanel().clearError(); 247 } 248 249 250 } 251 252 public void linkButtonPressed(Object ddBean, String ddProperty) { 253 } 254 255 public javax.swing.JComponent getErrorComponent(String errorId) { 256 if("Auth Name".equals(errorId)) return authNameField; 257 if("Role Name".equals(errorId)) return roleNameField; 258 if("Users Name".equals(errorId)) return usersNameField; 259 if("Users Id".equals(errorId)) return usersIdField; 260 if("Groups Name".equals(errorId)) return groupsNameField; 261 if("Groups Id".equals(errorId)) return groupsIdField; 262 if("Special Type Name".equals(errorId)) return specialTypeNameField; 263 if("Special Type Id".equals(errorId)) return specialTypeIdField; 264 return null; 265 } 266 267 private void setEnabledComponents() { 268 boolean stateUserGroup=usergroupRadioButton.isSelected(); 269 boolean stateSpecialType=specialTypesRadioButton.isSelected(); 270 271 272 if((stateUserGroup && !stateSpecialType) || ((!stateUserGroup && stateSpecialType))) { 273 jLabel3.setEnabled(stateUserGroup); 274 jLabel4.setEnabled(stateUserGroup); 275 jLabel7.setEnabled(stateUserGroup); 276 jLabel8.setEnabled(stateUserGroup); 277 usersIdField.setEnabled(stateUserGroup); 278 usersNameField.setEnabled(stateUserGroup); 279 groupsIdField.setEnabled(stateUserGroup); 280 groupsNameField.setEnabled(stateUserGroup); 281 282 jLabel9.setEnabled(stateSpecialType); 283 jLabel10.setEnabled(stateSpecialType); 284 jLabel11.setEnabled(stateSpecialType); 285 specialTypeIdField.setEnabled(stateSpecialType); 286 specialTypeNameField.setEnabled(stateSpecialType); 287 specialTypeComboBox.setEnabled(stateSpecialType); 288 289 290 } 291 292 } 293 295 protected void startUIChange() { 296 dObj.setChangedFromUI(true); 297 } 298 299 301 protected void endUIChange() { 302 dObj.modelUpdatedFromUI(); 303 dObj.setChangedFromUI(false); 304 } 305 310 private void initComponents() { 312 java.awt.GridBagConstraints gridBagConstraints; 313 314 typeGroup = new javax.swing.ButtonGroup (); 315 jLabel1 = new javax.swing.JLabel (); 316 authNameField = new javax.swing.JTextField (); 317 jLabel2 = new javax.swing.JLabel (); 318 roleNameField = new javax.swing.JTextField (); 319 usergroupRadioButton = new javax.swing.JRadioButton (); 320 specialTypesRadioButton = new javax.swing.JRadioButton (); 321 jLabel3 = new javax.swing.JLabel (); 322 jLabel4 = new javax.swing.JLabel (); 323 usersNameField = new javax.swing.JTextField (); 324 usersIdField = new javax.swing.JTextField (); 325 jLabel7 = new javax.swing.JLabel (); 326 jLabel8 = new javax.swing.JLabel (); 327 groupsNameField = new javax.swing.JTextField (); 328 groupsIdField = new javax.swing.JTextField (); 329 jLabel9 = new javax.swing.JLabel (); 330 jLabel10 = new javax.swing.JLabel (); 331 jLabel11 = new javax.swing.JLabel (); 332 specialTypeIdField = new javax.swing.JTextField (); 333 specialTypeNameField = new javax.swing.JTextField (); 334 specialTypeComboBox = new javax.swing.JComboBox (); 335 336 setLayout(new java.awt.GridBagLayout ()); 337 338 jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_AuthorizationName")); 339 gridBagConstraints = new java.awt.GridBagConstraints (); 340 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 341 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 5); 342 add(jLabel1, gridBagConstraints); 343 344 gridBagConstraints = new java.awt.GridBagConstraints (); 345 gridBagConstraints.gridx = 8; 346 gridBagConstraints.gridy = 0; 347 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 348 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 349 gridBagConstraints.weightx = 1.0; 350 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 351 add(authNameField, gridBagConstraints); 352 353 jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_RoleName")); 354 gridBagConstraints = new java.awt.GridBagConstraints (); 355 gridBagConstraints.gridx = 0; 356 gridBagConstraints.gridy = 1; 357 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 358 gridBagConstraints.insets = new java.awt.Insets (5, 12, 7, 5); 359 add(jLabel2, gridBagConstraints); 360 361 gridBagConstraints = new java.awt.GridBagConstraints (); 362 gridBagConstraints.gridx = 8; 363 gridBagConstraints.gridy = 1; 364 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 365 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 366 gridBagConstraints.weightx = 1.0; 367 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 368 add(roleNameField, gridBagConstraints); 369 370 typeGroup.add(usergroupRadioButton); 371 usergroupRadioButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_UsersGroups")); 372 usergroupRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 373 usergroupRadioButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 374 gridBagConstraints = new java.awt.GridBagConstraints (); 375 gridBagConstraints.gridx = 0; 376 gridBagConstraints.gridy = 2; 377 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 378 gridBagConstraints.insets = new java.awt.Insets (7, 12, 2, 0); 379 add(usergroupRadioButton, gridBagConstraints); 380 381 typeGroup.add(specialTypesRadioButton); 382 specialTypesRadioButton.setSelected(true); 383 specialTypesRadioButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_SpecialType")); 384 specialTypesRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 385 specialTypesRadioButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 386 gridBagConstraints = new java.awt.GridBagConstraints (); 387 gridBagConstraints.gridx = 0; 388 gridBagConstraints.gridy = 12; 389 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 390 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 391 add(specialTypesRadioButton, gridBagConstraints); 392 393 jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_UsersName")); 394 gridBagConstraints = new java.awt.GridBagConstraints (); 395 gridBagConstraints.gridx = 0; 396 gridBagConstraints.gridy = 4; 397 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 398 add(jLabel3, gridBagConstraints); 399 400 jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_UsersId")); 401 gridBagConstraints = new java.awt.GridBagConstraints (); 402 gridBagConstraints.gridx = 0; 403 gridBagConstraints.gridy = 5; 404 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 405 add(jLabel4, gridBagConstraints); 406 407 gridBagConstraints = new java.awt.GridBagConstraints (); 408 gridBagConstraints.gridx = 8; 409 gridBagConstraints.gridy = 4; 410 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 411 gridBagConstraints.weightx = 1.0; 412 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 413 add(usersNameField, gridBagConstraints); 414 415 gridBagConstraints = new java.awt.GridBagConstraints (); 416 gridBagConstraints.gridx = 8; 417 gridBagConstraints.gridy = 5; 418 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 419 gridBagConstraints.weightx = 1.0; 420 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 421 add(usersIdField, gridBagConstraints); 422 423 jLabel7.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_GroupsName")); 424 gridBagConstraints = new java.awt.GridBagConstraints (); 425 gridBagConstraints.gridx = 0; 426 gridBagConstraints.gridy = 8; 427 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 428 gridBagConstraints.insets = new java.awt.Insets (7, 0, 0, 0); 429 add(jLabel7, gridBagConstraints); 430 431 jLabel8.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_GroupsId")); 432 gridBagConstraints = new java.awt.GridBagConstraints (); 433 gridBagConstraints.gridx = 0; 434 gridBagConstraints.gridy = 9; 435 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 436 add(jLabel8, gridBagConstraints); 437 438 gridBagConstraints = new java.awt.GridBagConstraints (); 439 gridBagConstraints.gridx = 8; 440 gridBagConstraints.gridy = 8; 441 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 442 gridBagConstraints.weightx = 1.0; 443 gridBagConstraints.insets = new java.awt.Insets (7, 5, 0, 10); 444 add(groupsNameField, gridBagConstraints); 445 446 gridBagConstraints = new java.awt.GridBagConstraints (); 447 gridBagConstraints.gridx = 8; 448 gridBagConstraints.gridy = 9; 449 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 450 gridBagConstraints.weightx = 1.0; 451 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 452 add(groupsIdField, gridBagConstraints); 453 454 jLabel9.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_Id")); 455 gridBagConstraints = new java.awt.GridBagConstraints (); 456 gridBagConstraints.gridx = 0; 457 gridBagConstraints.gridy = 13; 458 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 459 add(jLabel9, gridBagConstraints); 460 461 jLabel10.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_Name")); 462 gridBagConstraints = new java.awt.GridBagConstraints (); 463 gridBagConstraints.gridx = 0; 464 gridBagConstraints.gridy = 14; 465 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 466 add(jLabel10, gridBagConstraints); 467 468 jLabel11.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/websphere6/dd/loaders/ui/Bundle").getString("LBL_Type")); 469 gridBagConstraints = new java.awt.GridBagConstraints (); 470 gridBagConstraints.gridx = 0; 471 gridBagConstraints.gridy = 15; 472 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 473 add(jLabel11, gridBagConstraints); 474 475 gridBagConstraints = new java.awt.GridBagConstraints (); 476 gridBagConstraints.gridx = 8; 477 gridBagConstraints.gridy = 13; 478 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 479 gridBagConstraints.weightx = 1.0; 480 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 481 add(specialTypeIdField, gridBagConstraints); 482 483 gridBagConstraints = new java.awt.GridBagConstraints (); 484 gridBagConstraints.gridx = 8; 485 gridBagConstraints.gridy = 14; 486 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 487 gridBagConstraints.weightx = 1.0; 488 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 489 add(specialTypeNameField, gridBagConstraints); 490 491 specialTypeComboBox.setMinimumSize(new java.awt.Dimension (150, 20)); 492 specialTypeComboBox.setPreferredSize(new java.awt.Dimension (150, 22)); 493 gridBagConstraints = new java.awt.GridBagConstraints (); 494 gridBagConstraints.gridx = 8; 495 gridBagConstraints.gridy = 15; 496 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 497 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 10); 498 add(specialTypeComboBox, gridBagConstraints); 499 500 } 502 503 private javax.swing.JTextField authNameField; 505 private javax.swing.JTextField groupsIdField; 506 private javax.swing.JTextField groupsNameField; 507 private javax.swing.JLabel jLabel1; 508 private javax.swing.JLabel jLabel10; 509 private javax.swing.JLabel jLabel11; 510 private javax.swing.JLabel jLabel2; 511 private javax.swing.JLabel jLabel3; 512 private javax.swing.JLabel jLabel4; 513 private javax.swing.JLabel jLabel7; 514 private javax.swing.JLabel jLabel8; 515 private javax.swing.JLabel jLabel9; 516 private javax.swing.JTextField roleNameField; 517 private javax.swing.JComboBox specialTypeComboBox; 518 private javax.swing.JTextField specialTypeIdField; 519 private javax.swing.JTextField specialTypeNameField; 520 private javax.swing.JRadioButton specialTypesRadioButton; 521 private javax.swing.ButtonGroup typeGroup; 522 private javax.swing.JRadioButton usergroupRadioButton; 523 private javax.swing.JTextField usersIdField; 524 private javax.swing.JTextField usersNameField; 525 527 } 528 | Popular Tags |