View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/ClassificationPanel.java,v 1.9 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 ClassificationPanel extends RegistryObjectPanel { 19 20 JTextField schemeText = null; 21 JTextField conceptText = null; 22 JTextField valueText = null; 23 24 /*** 25 * Creates new ServicePanel 26 */ 27 public ClassificationPanel() { 28 super(); 29 30 setBorder(BorderFactory.createTitledBorder("Classification Details")); 31 32 //ClassificationScheme 33 JLabel schemeLabel = new JLabel("ClassificationScheme:", SwingConstants.LEFT); 34 c.gridx = 0; 35 c.gridy = row+0; 36 c.gridwidth = 1; 37 c.gridheight = 1; 38 c.weightx = 0.0; 39 c.weighty = 0.0; 40 c.fill = GridBagConstraints.NONE; 41 c.anchor = GridBagConstraints.WEST; 42 c.insets = new Insets(4, 4, 0, 4); 43 gbl.setConstraints(schemeLabel, c); 44 add(schemeLabel); 45 46 schemeText = new JTextField(); 47 schemeText.setEditable(false); 48 c.gridx = 0; 49 c.gridy = row+1; 50 c.gridwidth = 1; 51 c.gridheight = 1; 52 c.weightx = 0.5; 53 c.weighty = 0.0; 54 c.fill = GridBagConstraints.HORIZONTAL; 55 c.anchor = GridBagConstraints.CENTER; 56 c.insets = new Insets(4, 4, 0, 4); 57 gbl.setConstraints(schemeText, c); 58 add(schemeText); 59 60 //Select ClassificationScheme or Concept 61 JButton showSchemeButton = new JButton("Select ClassificationScheme or Concept..."); 62 showSchemeButton.addActionListener(new ActionListener() { 63 public void actionPerformed(ActionEvent ev) { 64 getSelectedSchemeOrConcept(); 65 } 66 }); 67 c.gridx = 1; 68 c.gridy = row+1; 69 c.gridwidth = 1; 70 c.gridheight = 1; 71 c.weightx = 0.0; 72 c.weighty = 0.0; 73 c.fill = GridBagConstraints.NONE; 74 c.anchor = GridBagConstraints.CENTER; 75 c.insets = new Insets(4, 4, 0, 4); 76 gbl.setConstraints(showSchemeButton, c); 77 add(showSchemeButton); 78 79 //Concept 80 JLabel conceptLabel = new JLabel("Concept:", SwingConstants.LEFT); 81 c.gridx = 0; 82 c.gridy = row+2; 83 c.gridwidth = 1; 84 c.gridheight = 1; 85 c.weightx = 0.0; 86 c.weighty = 0.0; 87 c.fill = GridBagConstraints.NONE; 88 c.anchor = GridBagConstraints.WEST; 89 c.insets = new Insets(4, 4, 0, 4); 90 gbl.setConstraints(conceptLabel, c); 91 add(conceptLabel); 92 93 conceptText = new JTextField(); 94 conceptText.setEditable(false); 95 c.gridx = 0; 96 c.gridy = row+3; 97 c.gridwidth = 1; 98 c.gridheight = 1; 99 c.weightx = 0.5; 100 c.weighty = 0.5; 101 c.fill = GridBagConstraints.HORIZONTAL; 102 c.anchor = GridBagConstraints.WEST; 103 c.insets = new Insets(4, 4, 4, 4); 104 gbl.setConstraints(conceptText, c); 105 add(conceptText); 106 107 //Value 108 JLabel valueLabel = new JLabel("Value:", SwingConstants.LEFT); 109 c.gridx = 1; 110 c.gridy = row+2; 111 c.gridwidth = 1; 112 c.gridheight = 1; 113 c.weightx = 0.0; 114 c.weighty = 0.0; 115 c.fill = GridBagConstraints.NONE; 116 c.anchor = GridBagConstraints.WEST; 117 c.insets = new Insets(4, 4, 0, 4); 118 gbl.setConstraints(valueLabel, c); 119 add(valueLabel); 120 121 valueText = new JTextField(); 122 valueText.setEditable(false); 123 c.gridx = 1; 124 c.gridy = row+3; 125 c.gridwidth = 1; 126 c.gridheight = 1; 127 c.weightx = 0.5; 128 c.weighty = 0.5; 129 c.fill = GridBagConstraints.HORIZONTAL; 130 c.anchor = GridBagConstraints.WEST; 131 c.insets = new Insets(4, 4, 4, 4); 132 gbl.setConstraints(valueText, c); 133 add(valueText); 134 135 } 136 137 private void getSelectedSchemeOrConcept() { 138 ConceptsTreeDialog dialog = ConceptsTreeDialog.showSchemes(this, true, true); 139 if (dialog.getStatus() == dialog.OK_STATUS) { 140 141 142 ArrayList selectedObjects = dialog.getSelectedObjects(); 143 144 int selectionCount = selectedObjects.size(); 145 if (selectionCount == 0) { 146 RegistryBrowser.displayError("Must select a ClassificationScheme or Concept in ClassificationScheme dialog"); 147 } 148 else { 149 if (selectionCount > 1) { 150 RegistryBrowser.displayError("Only one selection allowed in ClassificationScheme dialog. Using last selection"); 151 } 152 153 Classification classification = (Classification)model; 154 Object obj = selectedObjects.get(selectionCount-1); 155 156 try { 157 158 ClassificationScheme scheme = null; 159 if (obj instanceof Concept) { 160 Concept concept = (Concept)obj; 161 classification.setConcept(concept); 162 163 valueText.setEditable(false); 164 165 conceptText.setText(concept.getKey().getId()); 166 valueText.setText(concept.getValue()); 167 168 scheme = concept.getClassificationScheme(); 169 } 170 else if (obj instanceof ClassificationScheme) { 171 scheme = (ClassificationScheme)obj; 172 classification.setClassificationScheme(scheme); 173 174 valueText.setEditable(true); 175 } 176 177 String schemeName = RegistryBrowser.getName(scheme); 178 if ((schemeName != null) && (schemeName.length() > 0)) { 179 schemeText.setText(schemeName); 180 } 181 else { 182 schemeText.setText(scheme.getKey().getId()); 183 } 184 } 185 catch (JAXRException e) { 186 RegistryBrowser.displayError(e); 187 } 188 } 189 } 190 191 } 192 193 public void setModel(Object obj) throws JAXRException { 194 if (!(obj instanceof Classification)) { 195 throw new InvalidRequestException("Expecting a Classification. Got a " + obj.getClass().getName()); 196 } 197 super.setModel(obj); 198 199 Classification classification = (Classification)obj; 200 201 try { 202 if (classification != null) { 203 204 ClassificationScheme scheme = classification.getClassificationScheme(); 205 Concept concept = classification.getConcept(); 206 207 if (concept != null) { 208 if (scheme == null) { 209 scheme =concept.getClassificationScheme(); 210 } 211 conceptText.setText(concept.getKey().getId()); 212 valueText.setText(concept.getValue()); 213 } 214 else { 215 conceptText.setText(""); 216 valueText.setText(classification.getValue()); 217 } 218 if (scheme != null) { 219 schemeText.setText(RegistryBrowser.getName(scheme)); 220 } 221 } 222 } 223 catch (JAXRException e) { 224 RegistryBrowser.displayError(e); 225 } 226 } 227 228 public Object getModel() throws JAXRException { 229 super.getModel(); 230 231 if (model != null) { 232 Classification classification = (Classification)model; 233 234 235 236 String value = valueText.getText(); 237 if ((value != null) && (value.length() > 0)) { 238 classification.setValue(value); 239 } 240 241 RegistryBrowser.getInstance().getRootPane().updateUI(); 242 } 243 244 return model; 245 } 246 247 protected void validateInput() throws JAXRException { 248 super.validateInput(); 249 250 Classification classification = (Classification)model; 251 String value = valueText.getText(); 252 if ((value == null) || (value.length() == 0)) { 253 Concept concept = classification.getConcept(); 254 if (concept == null) { 255 throw new JAXRException("Error. An Classification must have a ClassificationScheme or Concept specified. If ClassificationScheme is specified instead of Concept then a Value must also be provided."); 256 } 257 } 258 } 259 260 public void clear() throws JAXRException { 261 super.clear(); 262 schemeText.setText(""); 263 conceptText.setText(""); 264 valueText.setText(""); 265 } 266 267 } 268

This page was automatically generated by Maven