View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/RegistryObjectPanel.java,v 1.29 2003/08/24 22:14:58 farrukh_najmi Exp $ 3 */ 4 package com.sun.xml.registry.client.browser; 5 6 import com.sun.xml.registry.ebxml.infomodel.InternationalStringImpl; 7 import java.awt.*; 8 import java.awt.event.*; 9 import java.util.*; 10 import javax.xml.registry.*; 11 import javax.xml.registry.infomodel.*; 12 import javax.swing.*; 13 import javax.swing.event.*; 14 15 /*** 16 * Currently only used for Organizations. 17 * Holds organization informattion and a ClassificationsPanel. 18 * 19 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 20 */ 21 public class RegistryObjectPanel extends JBPanel { 22 23 JTextField idText = null; 24 JTextField nameText = null; 25 JTextArea descriptionText = null; 26 27 JTextField nameLocaleText = null; 28 JTextField descriptionLocaleText = null; 29 30 ClassificationsList classificationsList = null; 31 ExternalIdentifiersList extIdsList = null; 32 ExternalLinksList linksList = null; 33 SlotsList slotsList = null; 34 protected int row=0; 35 36 protected GridBagConstraints c = null; 37 protected GridBagLayout gbl = null; 38 39 /*** The Locale used to get/set LocalizedStrings from/to model. */ 40 private Locale localeOnSetModel = null; 41 private Locale nameLocaleOnSetModel = null; 42 private Locale descriptionLocaleOnSetModel = null; 43 44 /*** 45 * Used for displaying objects 46 */ 47 public RegistryObjectPanel() { 48 gbl = new GridBagLayout(); 49 c = new GridBagConstraints(); 50 setLayout(gbl); 51 52 JPanel namePanel = new JPanel(); 53 namePanel.setLayout(new BorderLayout()); 54 55 //The name Text 56 JLabel nameLabel = new JLabel("Name:", SwingConstants.LEFT); 57 namePanel.add(nameLabel, BorderLayout.WEST); 58 59 nameLocaleText = new JTextField(); 60 nameLocaleText.setEditable(false); 61 nameLocaleText.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 62 nameLocaleText.setAlignmentX(JTextField.CENTER_ALIGNMENT); 63 namePanel.add(nameLocaleText, BorderLayout.CENTER); 64 65 JButton showNameInternationalStringButton = new JButton("Details"); 66 showNameInternationalStringButton.addActionListener(new ActionListener() { 67 public void actionPerformed(ActionEvent ev) { 68 showNameInternationalString(); 69 } 70 }); 71 namePanel.add(showNameInternationalStringButton, BorderLayout.EAST); 72 73 c.gridx = 0; 74 c.gridy = 0; 75 c.gridwidth = 1; 76 c.gridheight = 1; 77 c.weightx = 1.0; 78 c.weighty = 0.0; 79 c.fill = GridBagConstraints.HORIZONTAL; 80 c.anchor = GridBagConstraints.WEST; 81 c.insets = new Insets(4, 4, 0, 4); 82 gbl.setConstraints(namePanel, c); 83 add(namePanel); 84 85 nameText = new JTextField(); 86 nameText.setEditable(editable); 87 c.gridx = 0; 88 c.gridy = 1; 89 c.gridwidth = 1; 90 c.gridheight = 1; 91 c.weightx = 0.5; 92 c.weighty = 0.0; 93 c.fill = GridBagConstraints.HORIZONTAL; 94 c.anchor = GridBagConstraints.EAST; 95 c.insets = new Insets(4, 4, 4, 4); 96 gbl.setConstraints(nameText, c); 97 add(nameText); 98 99 JPanel descriptionPanel = new JPanel(); 100 descriptionPanel.setLayout(new BorderLayout()); 101 102 //The description Text 103 JLabel descriptionLabel = new JLabel("Description:", SwingConstants.LEFT); 104 descriptionPanel.add(descriptionLabel, BorderLayout.WEST); 105 106 descriptionLocaleText = new JTextField(); 107 descriptionLocaleText.setEditable(false); 108 descriptionLocaleText.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); 109 descriptionLocaleText.setAlignmentX(JTextField.CENTER_ALIGNMENT); 110 descriptionPanel.add(descriptionLocaleText, BorderLayout.CENTER); 111 112 JButton showDescriptionInternationalStringButton = new JButton("Details"); 113 showDescriptionInternationalStringButton.addActionListener(new ActionListener() { 114 public void actionPerformed(ActionEvent ev) { 115 showDescriptionInternationalString(); 116 } 117 }); 118 descriptionPanel.add(showDescriptionInternationalStringButton, BorderLayout.EAST); 119 120 c.gridx = 0; 121 c.gridy = 2; 122 c.gridwidth = 1; 123 c.gridheight = 1; 124 c.weightx = 0.0; 125 c.weighty = 0.0; 126 c.fill = GridBagConstraints.HORIZONTAL; 127 c.anchor = GridBagConstraints.WEST; 128 c.insets = new Insets(4, 4, 0, 4); 129 gbl.setConstraints(descriptionPanel, c); 130 add(descriptionPanel); 131 132 descriptionText = new JTextArea(); 133 descriptionText.setEditable(editable); 134 descriptionText.setLineWrap(true); 135 descriptionText.setRows(2); 136 c.gridx = 0; 137 c.gridy = 3; 138 c.gridwidth = 1; 139 c.gridheight = 2; 140 c.weightx = 0.5; 141 c.weighty = 0.5; 142 c.fill = GridBagConstraints.BOTH; 143 c.anchor = GridBagConstraints.WEST; 144 c.insets = new Insets(4, 4, 0, 4); 145 gbl.setConstraints(descriptionText, c); 146 add(descriptionText); 147 148 JLabel idLabel = new JLabel("Unique Identifier:", SwingConstants.LEFT); 149 c.gridx = 1; 150 c.gridy = 2; 151 c.gridwidth = 1; 152 c.gridheight = 1; 153 c.weightx = 0.0; 154 c.weighty = 0.0; 155 c.fill = GridBagConstraints.NONE; 156 c.anchor = GridBagConstraints.WEST; 157 c.insets = new Insets(4, 4, 0, 4); 158 gbl.setConstraints(idLabel, c); 159 add(idLabel); 160 161 idText = new JTextField(); 162 idText.setEditable(false); 163 c.gridx = 1; 164 c.gridy = 3; 165 c.gridwidth = 1; 166 c.gridheight = 1; 167 c.weightx = 0.5; 168 c.weighty = 0.0; 169 c.fill = GridBagConstraints.HORIZONTAL; 170 c.anchor = GridBagConstraints.WEST; 171 c.insets = new Insets(4, 4, 0, 4); 172 gbl.setConstraints(idText, c); 173 add(idText); 174 175 JButton submitterButton = new JButton("Submitter..."); 176 //classificationsButton.setVerticalTextPosition(AbstractButton.BOTTOM); 177 //classificationsButton.setHorizontalTextPosition(AbstractButton.CENTER); 178 //classificationsButton.setMnemonic(KeyEvent.VK_M); 179 180 c.gridx = 1; 181 c.gridy = 4; 182 c.gridwidth = 1; 183 c.gridheight = 1; 184 c.weightx = 0.0; 185 c.weighty = 0.0; 186 c.fill = GridBagConstraints.NONE; 187 c.anchor = GridBagConstraints.EAST; 188 c.insets = new Insets(4, 4, 4, 4); 189 gbl.setConstraints(submitterButton, c); 190 //add(submitterButton); 191 192 //Classifications 193 JLabel classificationsLabel = new JLabel("Classifications:", SwingConstants.LEFT); 194 c.gridx = 0; 195 c.gridy = 5; 196 c.gridwidth = 1; 197 c.gridheight = 1; 198 c.weightx = 0.0; 199 c.weighty = 0.0; 200 c.fill = GridBagConstraints.NONE; 201 c.anchor = GridBagConstraints.WEST; 202 c.insets = new Insets(4, 4, 0, 4); 203 gbl.setConstraints(classificationsLabel, c); 204 add(classificationsLabel); 205 206 classificationsList = new ClassificationsList(); 207 classificationsList.setEditable(editable); 208 classificationsList.setVisibleRowCount(3); 209 JScrollPane classificationsListScrollPane = new JScrollPane(classificationsList); 210 211 c.gridx = 0; 212 c.gridy = 6; 213 c.gridwidth = 1; 214 c.gridheight = 1; 215 c.weightx = 0.5; 216 c.weighty = 0.5; 217 c.fill = GridBagConstraints.HORIZONTAL; 218 c.anchor = GridBagConstraints.WEST; 219 c.insets = new Insets(4, 4, 4, 4); 220 gbl.setConstraints(classificationsListScrollPane, c); 221 add(classificationsListScrollPane); 222 223 //External Ids 224 JLabel extIdsLabel = new JLabel("External Identifiers:", SwingConstants.LEFT); 225 c.gridx = 1; 226 c.gridy = 5; 227 c.gridwidth = 1; 228 c.gridheight = 1; 229 c.weightx = 0.0; 230 c.weighty = 0.0; 231 c.fill = GridBagConstraints.NONE; 232 c.anchor = GridBagConstraints.WEST; 233 c.insets = new Insets(4, 4, 0, 4); 234 gbl.setConstraints(extIdsLabel, c); 235 add(extIdsLabel); 236 237 extIdsList = new ExternalIdentifiersList(); 238 extIdsList.setEditable(editable); 239 extIdsList.setVisibleRowCount(3); 240 JScrollPane extIdsListScrollPane = new JScrollPane(extIdsList); 241 242 c.gridx = 1; 243 c.gridy = 6; 244 c.gridwidth = 1; 245 c.gridheight = 1; 246 c.weightx = 0.5; 247 c.weighty = 0.5; 248 c.fill = GridBagConstraints.HORIZONTAL; 249 c.anchor = GridBagConstraints.WEST; 250 c.insets = new Insets(4, 4, 4, 4); 251 gbl.setConstraints(extIdsListScrollPane, c); 252 add(extIdsListScrollPane); 253 254 //External Links 255 JLabel linksLabel = new JLabel("External Links:", SwingConstants.LEFT); 256 c.gridx = 0; 257 c.gridy = 7; 258 c.gridwidth = 1; 259 c.gridheight = 1; 260 c.weightx = 0.0; 261 c.weighty = 0.0; 262 c.fill = GridBagConstraints.NONE; 263 c.anchor = GridBagConstraints.WEST; 264 c.insets = new Insets(4, 4, 0, 4); 265 gbl.setConstraints(linksLabel, c); 266 add(linksLabel); 267 268 linksList = new ExternalLinksList(); 269 linksList.setEditable(editable); 270 linksList.setVisibleRowCount(3); 271 JScrollPane linksListScrollPane = new JScrollPane(linksList); 272 273 c.gridx = 0; 274 c.gridy = 8; 275 c.gridwidth = 1; 276 c.gridheight = 1; 277 c.weightx = 0.5; 278 c.weighty = 0.5; 279 c.fill = GridBagConstraints.HORIZONTAL; 280 c.anchor = GridBagConstraints.WEST; 281 c.insets = new Insets(4, 4, 4, 4); 282 gbl.setConstraints(linksListScrollPane, c); 283 add(linksListScrollPane); 284 285 //Slots 286 JLabel slotsLabel = new JLabel("Slots:", SwingConstants.LEFT); 287 c.gridx = 1; 288 c.gridy = 7; 289 c.gridwidth = 1; 290 c.gridheight = 1; 291 c.weightx = 0.0; 292 c.weighty = 0.0; 293 c.fill = GridBagConstraints.NONE; 294 c.anchor = GridBagConstraints.WEST; 295 c.insets = new Insets(4, 4, 0, 4); 296 gbl.setConstraints(slotsLabel, c); 297 add(slotsLabel); 298 299 slotsList = new SlotsList(); 300 slotsList.setEditable(editable); 301 slotsList.setVisibleRowCount(3); 302 JScrollPane slotsListScrollPane = new JScrollPane(slotsList); 303 304 c.gridx = 1; 305 c.gridy = 8; 306 c.gridwidth = 1; 307 c.gridheight = 1; 308 c.weightx = 0.5; 309 c.weighty = 0.5; 310 c.fill = GridBagConstraints.HORIZONTAL; 311 c.anchor = GridBagConstraints.WEST; 312 c.insets = new Insets(4, 4, 4, 4); 313 gbl.setConstraints(slotsListScrollPane, c); 314 add(slotsListScrollPane); 315 316 row = 9; 317 } 318 319 public void showNameInternationalString() { 320 try { 321 InternationalString iName = null; 322 if (model != null) { 323 iName = ((RegistryObject)model).getName(); 324 } 325 JBEditorDialog.showObjectDetails(this, iName, true, editable); 326 updateName((InternationalStringImpl)iName); 327 } catch (JAXRException e) { 328 RegistryBrowser.displayError(e); 329 } 330 } 331 332 public void showDescriptionInternationalString() { 333 try { 334 InternationalString iDescription = null; 335 if (model != null) { 336 iDescription = ((RegistryObject)model).getDescription(); 337 } 338 JBEditorDialog.showObjectDetails(this, iDescription, true, editable); 339 if (model != null) 340 updateDescription((InternationalStringImpl)iDescription); 341 } catch (JAXRException e) { 342 RegistryBrowser.displayError(e); 343 } 344 } 345 346 private void updateName(InternationalStringImpl name) throws JAXRException { 347 if (name != null) { 348 LocalizedString lName = name.getClosestLocalizedString(localeOnSetModel, null); 349 if (lName == null) { 350 nameText.setText(""); 351 nameLocaleOnSetModel = localeOnSetModel; 352 } else { 353 nameText.setText(lName.getValue()); 354 nameLocaleOnSetModel = lName.getLocale(); 355 } 356 nameLocaleText.setText("(" + nameLocaleOnSetModel + ")"); 357 } 358 } 359 360 private void updateDescription(InternationalStringImpl description) throws JAXRException { 361 if (description != null) { 362 LocalizedString lDescription = description.getClosestLocalizedString(localeOnSetModel, null); 363 if (lDescription == null) { 364 descriptionText.setText(""); 365 descriptionLocaleOnSetModel = localeOnSetModel; 366 } else { 367 descriptionText.setText(lDescription.getValue()); 368 descriptionLocaleOnSetModel = lDescription.getLocale(); 369 } 370 descriptionLocaleText.setText("(" + descriptionLocaleOnSetModel + ")"); 371 } 372 } 373 374 public void setModel(Object obj) throws JAXRException { 375 localeOnSetModel = RegistryBrowser.getInstance().getSelectedLocale(); 376 if (!(obj instanceof RegistryObject)) { 377 throw new InvalidRequestException("Expecting a RegistryObject. Got a " + obj.getClass().getName()); 378 } 379 super.setModel(obj); 380 381 RegistryObject ro = (RegistryObject)obj; 382 383 try { 384 ClassificationsListModel classificationsListModel = (ClassificationsListModel)classificationsList.getModel(); 385 ExternalIdentifiersListModel extIdsListModel = (ExternalIdentifiersListModel)extIdsList.getModel(); 386 ExternalLinksListModel linksListModel = (ExternalLinksListModel)linksList.getModel(); 387 SlotsListModel slotsListModel = (SlotsListModel)slotsList.getModel(); 388 389 if (ro != null) { 390 // TO DO: Review implementation specific restriction 391 updateName((InternationalStringImpl)ro.getName()); 392 393 // TO DO: Review implementation specific restriction 394 updateDescription((InternationalStringImpl)ro.getDescription()); 395 396 if (ro.getKey() != null) { 397 idText.setText(ro.getKey().getId()); 398 } 399 400 Collection c = ro.getClassifications(); 401 classificationsListModel.setModels(new ArrayList(c)); 402 403 404 Collection e = ro.getExternalIdentifiers(); 405 extIdsListModel.setModels(new ArrayList(e)); 406 407 Collection links = ro.getExternalLinks(); 408 linksListModel.setModels(new ArrayList(links)); 409 410 Collection slots = ro.getSlots(); 411 slotsListModel.setModels(new ArrayList(slots)); 412 } 413 } 414 catch (JAXRException e) { 415 RegistryBrowser.displayError(e); 416 } 417 } 418 419 public Object getModel() throws JAXRException { 420 super.getModel(); 421 422 if (model != null) { 423 com.sun.xml.registry.ebxml.infomodel.RegistryObjectImpl registryObject = 424 (com.sun.xml.registry.ebxml.infomodel.RegistryObjectImpl)model; 425 426 String nameStr = nameText.getText(); 427 428 InternationalString name = registryObject.getName(); 429 if (name != null) { 430 name.setValue(nameLocaleOnSetModel, nameStr); 431 } else { 432 registryObject.setName(registryObject.getLifeCycleManager() 433 .createInternationalString(nameLocaleOnSetModel, nameStr)); 434 } 435 436 InternationalString description = registryObject.getDescription(); 437 if (description!= null) { 438 description.setValue(descriptionLocaleOnSetModel, descriptionText.getText()); 439 } else { 440 registryObject.setDescription(registryObject.getLifeCycleManager() 441 .createInternationalString(descriptionLocaleOnSetModel, descriptionText.getText())); 442 } 443 444 ClassificationsListModel classificationsListModel = (ClassificationsListModel)classificationsList.getModel(); 445 registryObject.setClassifications(Arrays.asList(classificationsListModel.toArray())); 446 447 ExternalIdentifiersListModel extIdsListModel = (ExternalIdentifiersListModel)extIdsList.getModel(); 448 registryObject.setExternalIdentifiers(Arrays.asList(extIdsListModel.toArray())); 449 450 ExternalLinksListModel linksListModel = (ExternalLinksListModel)linksList.getModel(); 451 registryObject.setExternalLinks(Arrays.asList(linksListModel.toArray())); 452 453 SlotsListModel slotsListModel = (SlotsListModel)slotsList.getModel(); 454 registryObject.setSlots(Arrays.asList(slotsListModel.toArray())); 455 456 RegistryBrowser.getInstance().getRootPane().updateUI(); 457 } 458 459 return model; 460 } 461 462 protected void validateInput() throws JAXRException { 463 super.validateInput(); 464 RegistryObject registryObject = (RegistryObject)model; 465 466 String nameStr = nameText.getText(); 467 if (nameStr.length() > 256) { 468 throw new JAXRException("Error. RegistryObject.name length must be <= 256"); 469 } 470 471 String descStr = descriptionText.getText(); 472 if (descStr.length() > 256) { 473 throw new JAXRException("Error. RegistryObject.description length must be <= 256"); 474 } 475 476 } 477 478 public void clear() throws JAXRException { 479 super.clear(); 480 nameText.setText(""); 481 descriptionText.setText(""); 482 idText.setText(""); 483 } 484 485 /*** 486 * Sets whether this dialog is read-only or editable. 487 */ 488 public void setEditable(boolean editable) { 489 super.setEditable(editable); 490 491 nameText.setEditable(editable); 492 descriptionText.setEditable(editable); 493 494 classificationsList.setEditable(editable); 495 extIdsList.setEditable(editable); 496 linksList.setEditable(editable); 497 slotsList.setEditable(editable); 498 } 499 500 501 }

This page was automatically generated by Maven