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

This page was automatically generated by Maven