View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/UserPanel.java,v 1.9 2003/08/24 22:14:58 farrukh_najmi Exp $ 3 */ 4 package com.sun.xml.registry.client.browser; 5 6 import java.awt.*; 7 import java.awt.event.*; 8 import java.util.*; 9 import javax.xml.registry.*; 10 import javax.xml.registry.infomodel.*; 11 import javax.swing.*; 12 import javax.swing.event.*; 13 14 /*** 15 * Panel for User 16 * 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class UserPanel extends RegistryObjectPanel { 20 21 PersonNamePanel personNamePanel = null; 22 PostalAddressPanel addressPanel = null; 23 TelephoneNumberPanel phonePanel = null; 24 EmailAddressPanel emailPanel = null; 25 26 private int firstChildIndex = 0; 27 28 29 /*** 30 * Used for displaying Userobjects 31 */ 32 public UserPanel() { 33 super(); 34 35 firstChildIndex = getComponents().length; 36 37 setBorder(BorderFactory.createTitledBorder("User Details")); 38 39 //PersonNamePanel 40 personNamePanel = new PersonNamePanel(); 41 personNamePanel.setBorder(BorderFactory.createTitledBorder("Name")); 42 c.gridx = 0; 43 c.gridy = row+0; 44 c.gridwidth = 1; 45 c.gridheight = 1; 46 c.weightx = 0.5; 47 c.weighty = 0.0; 48 c.fill = GridBagConstraints.BOTH; 49 c.anchor = GridBagConstraints.WEST; 50 c.insets = new Insets(4, 4, 0, 4); 51 gbl.setConstraints(personNamePanel, c); 52 add(personNamePanel); 53 54 //EmailAddressPanel 55 emailPanel = new EmailAddressPanel(); 56 emailPanel.setBorder(BorderFactory.createTitledBorder("Email Address")); 57 c.gridx = 1; 58 c.gridy = row+0; 59 c.gridwidth = 1; 60 c.gridheight = 1; 61 c.weightx = 0.5; 62 c.weighty = 0.0; 63 c.fill = GridBagConstraints.BOTH; 64 c.anchor = GridBagConstraints.WEST; 65 c.insets = new Insets(4, 4, 0, 4); 66 gbl.setConstraints(emailPanel, c); 67 add(emailPanel); 68 69 //PostalAddressPanel 70 addressPanel = new PostalAddressPanel(); 71 addressPanel.setBorder(BorderFactory.createTitledBorder("Postal Address")); 72 c.gridx = 0; 73 c.gridy = row+1; 74 c.gridwidth = 1; 75 c.gridheight = 1; 76 c.weightx = 0.5; 77 c.weighty = 0.0; 78 c.fill = GridBagConstraints.BOTH; 79 c.anchor = GridBagConstraints.WEST; 80 c.insets = new Insets(4, 4, 0, 4); 81 gbl.setConstraints(addressPanel, c); 82 add(addressPanel); 83 84 //TelephoneNumberPanel 85 phonePanel = new TelephoneNumberPanel(); 86 phonePanel.setBorder(BorderFactory.createTitledBorder("Telephone Number")); 87 c.gridx = 1; 88 c.gridy = row+1; 89 c.gridwidth = 1; 90 c.gridheight = 1; 91 c.weightx = 0.5; 92 c.weighty = 0.0; 93 c.fill = GridBagConstraints.BOTH; 94 c.anchor = GridBagConstraints.WEST; 95 c.insets = new Insets(4, 4, 0, 4); 96 gbl.setConstraints(phonePanel, c); 97 add(phonePanel); 98 99 row += 2; 100 } 101 102 //Used by UserRegistrationPanel to hide detail not needed. 103 protected void hideRegistryObjectAttributes() { 104 Component[] children = getComponents(); 105 106 for (int i=0; i<firstChildIndex; i++) { 107 this.remove(children[i]); 108 } 109 } 110 111 public User getUser() throws JAXRException { 112 User user = null; 113 114 if (model != null) { 115 user = (User)getModel(); 116 } 117 return user; 118 } 119 120 public void setUser(User user) throws JAXRException { 121 setModel(user); 122 } 123 124 public void setModel(Object obj) throws JAXRException { 125 if (!(obj instanceof User)) { 126 throw new InvalidRequestException("Expecting a User. Got a " + obj.getClass().getName()); 127 } 128 super.setModel(obj); 129 130 User user = (User)obj; 131 132 133 try { 134 if (user != null) { 135 PersonName personName = user.getPersonName(); 136 if (personName == null) { 137 personName = user.getLifeCycleManager().createPersonName("","",""); 138 user.setPersonName(personName); 139 } 140 141 personNamePanel.setModel(personName); 142 143 Collection addrs = user.getPostalAddresses(); 144 145 if (addrs != null) { 146 PostalAddress address = null; 147 if (addrs.size() == 0) { 148 address = user.getLifeCycleManager().createPostalAddress("","","","","","",""); 149 //Fix JAXR API 2.0 ?? user.addPostalAddress(); 150 addrs = new ArrayList(); 151 addrs.add(address); 152 user.setPostalAddresses(addrs); 153 } 154 else { 155 address = (PostalAddress)(addrs.iterator().next()); 156 } 157 addressPanel.setModel( address); 158 } 159 160 Collection emails = user.getEmailAddresses(); 161 if (emails != null) { 162 EmailAddress email = null; 163 if (emails.size() == 0) { 164 email = user.getLifeCycleManager().createEmailAddress(""); 165 //Fix JAXR API 2.0 ?? user.addPostalAddress(); 166 emails = new ArrayList(); 167 emails.add(email); 168 user.setEmailAddresses(emails); 169 } 170 else { 171 email = (EmailAddress)(emails.iterator().next()); 172 } 173 174 emailPanel.setModel(email ); 175 } 176 177 Collection phones = user.getTelephoneNumbers(null); 178 if (phones != null) { 179 TelephoneNumber phone = null; 180 if (phones.size() == 0) { 181 phone = user.getLifeCycleManager().createTelephoneNumber(); 182 //Fix JAXR API 2.0 ?? user.addPostalAddress(); 183 phones = new ArrayList(); 184 phones.add(phone); 185 user.setTelephoneNumbers(phones); 186 } 187 else { 188 phone = (TelephoneNumber)(phones.iterator().next()); 189 } 190 phonePanel.setModel(phones.iterator().next() ); 191 } 192 } 193 } 194 catch (JAXRException e) { 195 RegistryBrowser.displayError(e); 196 } 197 198 } 199 200 public Object getModel() throws JAXRException { 201 super.getModel(); 202 if (model != null) { 203 personNamePanel.getModel(); 204 addressPanel.getModel(); 205 206 emailPanel.getModel(); 207 phonePanel.getModel(); 208 RegistryBrowser.getInstance().getRootPane().updateUI(); 209 } 210 211 return model; 212 } 213 214 protected void validateInput() throws JAXRException { 215 super.validateInput(); 216 217 User user = (User)model; 218 219 personNamePanel.validateInput(); 220 addressPanel.validateInput(); 221 222 emailPanel.validateInput(); 223 phonePanel.validateInput(); 224 } 225 226 public void clear() throws JAXRException { 227 super.clear(); 228 229 personNamePanel.clear(); 230 addressPanel.clear(); 231 232 emailPanel.clear(); 233 phonePanel.clear(); 234 } 235 236 /*** 237 * Sets whether this dialog is read-only or editable. 238 */ 239 public void setEditable(boolean editable) { 240 super.setEditable(editable); 241 242 personNamePanel.setEditable(editable); 243 addressPanel.setEditable(editable); 244 emailPanel.setEditable(editable); 245 phonePanel.setEditable(editable); 246 } 247 248 }

This page was automatically generated by Maven