View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/ExternalIdentifierPanel.java,v 1.12 2003/08/30 23:09:45 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 to edit/inspect a Service. 15 * 16 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 17 */ 18 public class ExternalIdentifierPanel extends RegistryObjectPanel { 19 20 JTextField schemeText = null; 21 JTextField valueText = null; 22 23 /*** 24 * Creates new ExternalIdentifierPanel 25 */ 26 public ExternalIdentifierPanel() { 27 setBorder(BorderFactory.createTitledBorder("ExternalIdentifier Details")); 28 29 //ClassificationScheme 30 JLabel schemeLabel = new JLabel("ClassificationScheme:", SwingConstants.LEFT); 31 c.gridx = 0; 32 c.gridy = row+0; 33 c.gridwidth = 1; 34 c.gridheight = 1; 35 c.weightx = 0.0; 36 c.weighty = 0.0; 37 c.fill = GridBagConstraints.NONE; 38 c.anchor = GridBagConstraints.WEST; 39 c.insets = new Insets(4, 4, 0, 4); 40 gbl.setConstraints(schemeLabel, c); 41 add(schemeLabel); 42 43 schemeText = new JTextField(); 44 schemeText.setEditable(false); 45 c.gridx = 0; 46 c.gridy = row+1; 47 c.gridwidth = 1; 48 c.gridheight = 1; 49 c.weightx = 0.5; 50 c.weighty = 0.0; 51 c.fill = GridBagConstraints.HORIZONTAL; 52 c.anchor = GridBagConstraints.CENTER; 53 c.insets = new Insets(4, 4, 0, 4); 54 gbl.setConstraints(schemeText, c); 55 add(schemeText); 56 57 //Select ClassificationScheme 58 JButton showSchemeButton = new JButton("Select ClassificationScheme..."); 59 showSchemeButton.addActionListener(new ActionListener() { 60 public void actionPerformed(ActionEvent ev) { 61 getSelectedScheme(); 62 } 63 }); 64 c.gridx = 1; 65 c.gridy = row+1; 66 c.gridwidth = 1; 67 c.gridheight = 1; 68 c.weightx = 0.0; 69 c.weighty = 0.0; 70 c.fill = GridBagConstraints.NONE; 71 c.anchor = GridBagConstraints.CENTER; 72 c.insets = new Insets(4, 4, 0, 4); 73 gbl.setConstraints(showSchemeButton, c); 74 add(showSchemeButton); 75 76 //Value 77 JLabel valueLabel = new JLabel("Value:", SwingConstants.LEFT); 78 c.gridx = 0; 79 c.gridy = row+2; 80 c.gridwidth = 1; 81 c.gridheight = 1; 82 c.weightx = 0.0; 83 c.weighty = 0.0; 84 c.fill = GridBagConstraints.NONE; 85 c.anchor = GridBagConstraints.WEST; 86 c.insets = new Insets(4, 4, 0, 4); 87 gbl.setConstraints(valueLabel, c); 88 add(valueLabel); 89 90 valueText = new JTextField(); 91 valueText.setEditable(editable); 92 c.gridx = 0; 93 c.gridy = row+3; 94 c.gridwidth = 2; 95 c.gridheight = 1; 96 c.weightx = 0.5; 97 c.weighty = 0.5; 98 c.fill = GridBagConstraints.HORIZONTAL; 99 c.anchor = GridBagConstraints.WEST; 100 c.insets = new Insets(4, 4, 4, 4); 101 gbl.setConstraints(valueText, c); 102 add(valueText); 103 } 104 105 private void getSelectedScheme() { 106 ConceptsTreeDialog dialog = ConceptsTreeDialog.showSchemes(this, true, true); 107 if (dialog.getStatus() == dialog.OK_STATUS) { 108 109 110 ArrayList selectedObjects = dialog.getSelectedClassificationSchemes(); 111 112 int selectionCount = selectedObjects.size(); 113 if (selectionCount == 0) { 114 RegistryBrowser.displayError("Must select a ClassificationScheme in ClassificationScheme dialog"); 115 } 116 else { 117 if (selectionCount > 1) { 118 RegistryBrowser.displayError("Only one ClassificationScheme selection is allowed in ClassificationScheme dialog. Using last selection"); 119 } 120 121 ExternalIdentifier externalId = (ExternalIdentifier)model; 122 Object obj = selectedObjects.get(selectionCount-1); 123 124 try { 125 126 String conceptNameStr = null; 127 ClassificationScheme scheme = null; 128 if (obj instanceof ClassificationScheme) { 129 scheme = (ClassificationScheme)obj; 130 externalId.setIdentificationScheme(scheme); 131 } 132 133 String schemeName = RegistryBrowser.getName(scheme); 134 if ((schemeName == null) || (schemeName.length() == 0)) { 135 schemeName = scheme.getKey().getId(); 136 } 137 schemeText.setText(schemeName); 138 } 139 catch (JAXRException e) { 140 RegistryBrowser.displayError(e); 141 } 142 } 143 } 144 145 } 146 147 public void setModel(Object obj) throws JAXRException { 148 if (!(obj instanceof ExternalIdentifier)) { 149 throw new InvalidRequestException("Expecting a ExternalIdentifier. Got a " + obj.getClass().getName()); 150 } 151 super.setModel(obj); 152 153 ExternalIdentifier externalId = (ExternalIdentifier)obj; 154 155 try { 156 if (externalId != null) { 157 158 ClassificationScheme scheme = externalId.getIdentificationScheme(); 159 160 if (scheme != null) { 161 String schemeName = RegistryBrowser.getName(scheme); 162 if ((schemeName == null) || (schemeName.length() == 0)) { 163 schemeName = scheme.getKey().getId(); 164 } 165 schemeText.setText(schemeName); 166 } 167 168 valueText.setText(externalId.getValue()); 169 } 170 } 171 catch (JAXRException e) { 172 RegistryBrowser.displayError(e); 173 } 174 } 175 176 public Object getModel() throws JAXRException { 177 super.getModel(); 178 179 if (model != null) { 180 ExternalIdentifier externalId = (ExternalIdentifier)model; 181 182 String value = valueText.getText(); 183 externalId.setValue(value); 184 185 RegistryBrowser.getInstance().getRootPane().updateUI(); 186 } 187 188 return model; 189 } 190 191 protected void validateInput() throws JAXRException { 192 super.validateInput(); 193 194 ExternalIdentifier externalId = (ExternalIdentifier)model; 195 196 String value = valueText.getText(); 197 if ((value == null) || (value.length() == 0)) { 198 throw new JAXRException("Error. ExternalIdentifier.value length must have a value"); 199 } 200 } 201 202 public void clear() throws JAXRException { 203 super.clear(); 204 schemeText.setText(""); 205 valueText.setText(""); 206 } 207 208 /*** 209 * Sets whether this dialog is read-only or editable. 210 */ 211 public void setEditable(boolean editable) { 212 super.setEditable(editable); 213 214 valueText.setEditable(editable); 215 } 216 217 218 219 } 220

This page was automatically generated by Maven