View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/OrganizationPanel.java,v 1.15 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.swing.*; 10 import javax.xml.registry.*; 11 import javax.xml.registry.infomodel.*; 12 13 /*** 14 * Panel used in a popup dialog that holds the information 15 * about an organization such as its registry object and 16 * registry entry information 17 * 18 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 19 */ 20 public class OrganizationPanel extends RegistryObjectPanel { 21 22 RegistryObjectPanel roPanel = null; 23 24 JBList phonesList = null; 25 JBList addrsList = null; 26 27 JTextField primContactText = null; 28 29 JBEditorDialog postalAddressDialog = null; 30 JBEditorDialog primaryContactDialog = null; 31 32 33 /*** 34 * Creates new OrganizationPanel 35 */ 36 public OrganizationPanel() { 37 super(); 38 39 setBorder(BorderFactory.createTitledBorder("Organization Details")); 40 41 JLabel addrLabel = new JLabel("Postal Address:", SwingConstants.LEFT); 42 c.gridx = 0; 43 c.gridy = row+0; 44 c.gridwidth = 1; 45 c.gridheight = 1; 46 c.weightx = 0.0; 47 c.weighty = 0.0; 48 c.fill = GridBagConstraints.NONE; 49 c.anchor = GridBagConstraints.WEST; 50 c.insets = new Insets(4, 4, 0, 4); 51 gbl.setConstraints(addrLabel, c); 52 add(addrLabel); 53 54 addrsList = new JBList(LifeCycleManager.POSTAL_ADDRESS, new JBListModel()); 55 addrsList.setVisibleRowCount(3); 56 c.gridx = 0; 57 c.gridy = row+1; 58 c.gridwidth = 2; 59 c.gridheight = 1; 60 c.weightx = 0.5; 61 c.weighty = 0.0; 62 c.fill = GridBagConstraints.HORIZONTAL; 63 c.anchor = GridBagConstraints.CENTER; 64 c.insets = new Insets(4, 4, 0, 4); 65 gbl.setConstraints(addrsList, c); 66 add(addrsList); 67 68 //Telephone Number 69 JLabel phonesLabel = new JLabel("Telephone Numbers:", SwingConstants.LEFT); 70 c.gridx = 0; 71 c.gridy = row+2; 72 c.gridwidth = 1; 73 c.gridheight = 1; 74 c.weightx = 0.0; 75 c.weighty = 0.0; 76 c.fill = GridBagConstraints.NONE; 77 c.anchor = GridBagConstraints.WEST; 78 c.insets = new Insets(4, 4, 0, 4); 79 gbl.setConstraints(phonesLabel, c); 80 add(phonesLabel); 81 82 phonesList = new JBList(LifeCycleManager.TELEPHONE_NUMBER, new JBListModel()); 83 phonesList.setVisibleRowCount(2); 84 JScrollPane phonesListScrollPane = new JScrollPane(phonesList); 85 c.gridx = 0; 86 c.gridy = row+3; 87 c.gridwidth = 2; 88 c.gridheight = 1; 89 c.weightx = 0.5; 90 c.weighty = 0.5; 91 c.fill = GridBagConstraints.HORIZONTAL; 92 c.anchor = GridBagConstraints.WEST; 93 c.insets = new Insets(4, 4, 4, 4); 94 gbl.setConstraints(phonesListScrollPane, c); 95 add(phonesListScrollPane); 96 97 //Primary contact 98 JLabel primContactLabel = new JLabel("Primary Contact:", SwingConstants.LEFT); 99 c.gridx = 0; 100 c.gridy = row+4; 101 c.gridwidth = 1; 102 c.gridheight = 1; 103 c.weightx = 0.0; 104 c.weighty = 0.0; 105 c.fill = GridBagConstraints.NONE; 106 c.anchor = GridBagConstraints.WEST; 107 c.insets = new Insets(4, 4, 0, 4); 108 gbl.setConstraints(primContactLabel, c); 109 add(primContactLabel); 110 111 primContactText = new JTextField(); 112 primContactText.setEditable(false); 113 c.gridx = 0; 114 c.gridy = row+5; 115 c.gridwidth = 1; 116 c.gridheight = 1; 117 c.weightx = 0.5; 118 c.weighty = 0.0; 119 c.fill = GridBagConstraints.HORIZONTAL; 120 c.anchor = GridBagConstraints.CENTER; 121 c.insets = new Insets(4, 4, 0, 4); 122 gbl.setConstraints(primContactText, c); 123 add(primContactText); 124 125 JButton primContactButton = new JButton("Contact Details..."); 126 primContactButton.addActionListener(new ActionListener() { 127 public void actionPerformed(ActionEvent ev) { 128 try { 129 getPrimaryContactDialog().setVisible(true); 130 } 131 catch (JAXRException e) { 132 RegistryBrowser.displayError(e); 133 } 134 } 135 }); 136 c.gridx = 1; 137 c.gridy = row+5; 138 c.gridwidth = 1; 139 c.gridheight = 2; 140 c.weightx = 0.0; 141 c.weighty = 0.0; 142 c.fill = GridBagConstraints.NONE; 143 c.anchor = GridBagConstraints.CENTER; 144 c.insets = new Insets(4, 4, 0, 4); 145 gbl.setConstraints(primContactButton, c); 146 add(primContactButton); 147 } 148 149 private JBEditorDialog getPostalAddressDialog() throws JAXRException { 150 if (postalAddressDialog == null) { 151 Window window = SwingUtilities.getWindowAncestor(this); 152 if (window instanceof JFrame) { 153 postalAddressDialog = new JBEditorDialog((JFrame)window, false); 154 } 155 else if (window instanceof JDialog) { 156 postalAddressDialog = new JBEditorDialog((JDialog)window, false); 157 } 158 postalAddressDialog.setLocation(50, 50); 159 160 161 if (model != null) { 162 postalAddressDialog.setModel(getOrganization().getPostalAddress()); 163 } 164 postalAddressDialog.setEditable(editable); 165 } 166 return postalAddressDialog; 167 } 168 169 private JBEditorDialog getPrimaryContactDialog() throws JAXRException { 170 if (primaryContactDialog == null) { 171 Window window = SwingUtilities.getWindowAncestor(this); 172 if (window instanceof JFrame) { 173 primaryContactDialog = new JBEditorDialog((JFrame)window, false); 174 } 175 else if (window instanceof JDialog) { 176 primaryContactDialog = new JBEditorDialog((JDialog)window, false); 177 } 178 primaryContactDialog.setLocation(50, 50); 179 180 //if (model != null) { 181 primaryContactDialog.setModel(getOrganization().getPrimaryContact()); 182 //} 183 primaryContactDialog.setEditable(editable); 184 } 185 return primaryContactDialog; 186 } 187 188 Organization getOrganization() throws JAXRException { 189 Organization organization = null; 190 191 if (model != null) { 192 organization = (Organization)getModel(); 193 } 194 return organization; 195 } 196 197 public void setModel(Object obj) throws JAXRException { 198 if (!(obj instanceof Organization)) { 199 throw new InvalidRequestException("Expecting a Organization. Got a " + obj.getClass().getName()); 200 } 201 super.setModel(obj); 202 203 Organization org = (Organization)obj; 204 205 try { 206 int registryLevel = RegistryBrowser.getInstance().client.getCapabilityProfile().getCapabilityLevel(); 207 208 DefaultListModel phonesModel = (DefaultListModel)phonesList.getModel(); 209 DefaultListModel addrsModel = (DefaultListModel)addrsList.getModel(); 210 211 if (org != null) { 212 PostalAddress addr = org.getPostalAddress(); 213 String addrStr = ""; 214 if (addr != null) { 215 addrsModel.addElement(addr); 216 } 217 218 Collection phones = org.getTelephoneNumbers(null); 219 Iterator iter = phones.iterator(); 220 while (iter.hasNext()) { 221 TelephoneNumber phone = (TelephoneNumber)iter.next(); 222 phonesModel.addElement(phone); 223 } 224 225 User primaryContact = org.getPrimaryContact(); 226 String userName = RegistryBrowser.getUserName(primaryContact, registryLevel); 227 primContactText.setText(userName); 228 } 229 } 230 catch (JAXRException e) { 231 RegistryBrowser.displayError(e); 232 } 233 } 234 235 236 protected void validateInput() throws JAXRException { 237 super.validateInput(); 238 239 Organization org = (Organization)model; 240 241 JBListModel phonesModel = (JBListModel)phonesList.getModel(); 242 org.setTelephoneNumbers(phonesModel.getModels()); 243 244 /* 245 try { 246 concept.setValue(valueText.getText()); 247 248 RegistryBrowser.getInstance().getRootPane().updateUI(); 249 } 250 catch (JAXRException e) { 251 RegistryBrowser.displayError(e); 252 } 253 */ 254 } 255 256 public void clear() throws JAXRException { 257 DefaultListModel phonesModel = (DefaultListModel)phonesList.getModel(); 258 phonesModel.clear(); 259 260 DefaultListModel addrsModel = (DefaultListModel)addrsList.getModel(); 261 addrsModel.clear(); 262 primContactText.setText(""); 263 } 264 265 /*** 266 * Sets whether this dialog is read-only or editable. 267 */ 268 public void setEditable(boolean editable) { 269 super.setEditable(editable); 270 271 phonesList.setEditable(editable); 272 addrsList.setEnabled(editable); 273 } 274 275 } 276

This page was automatically generated by Maven