View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/ExtrinsicObjectPanel.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 import java.io.*; 14 import javax.activation.DataHandler; 15 import javax.activation.FileDataSource; 16 17 /*** 18 * Panel to edit/inspect a Service. 19 * 20 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 21 */ 22 public class ExtrinsicObjectPanel extends RegistryEntryPanel { 23 24 JTextField objectTypeText = null; 25 JCheckBox isOpaqueCheckBox = null; 26 JComboBox mimeTypeCombo = null; 27 static JFileChooser chooser = new JFileChooser(); 28 29 //How to initialize this from browser's mimeTypes 30 String[] mimeTypes = { 31 "application/octet-stream", 32 "text/xml", 33 "text/plain" 34 }; 35 36 37 /*** 38 * Creates new ServicePanel 39 */ 40 public ExtrinsicObjectPanel() { 41 super(); 42 43 setBorder(BorderFactory.createTitledBorder("ExtrinsicObject Details")); 44 45 JLabel mimeTypeLabel = new JLabel("Mime Type:", SwingConstants.LEFT); 46 c.gridx = 0; 47 c.gridy = row+0; 48 c.gridwidth = 1; 49 c.gridheight = 1; 50 c.weightx = 0.0; 51 c.weighty = 0.0; 52 c.fill = GridBagConstraints.NONE; 53 c.anchor = GridBagConstraints.WEST; 54 c.insets = new Insets(4, 4, 0, 4); 55 gbl.setConstraints(mimeTypeLabel, c); 56 add(mimeTypeLabel); 57 58 mimeTypeCombo = new JComboBox(new DefaultComboBoxModel(mimeTypes)); 59 mimeTypeCombo.setEditable(true); 60 c.gridx = 0; 61 c.gridy = row+1; 62 c.gridwidth = 1; 63 c.gridheight = 1; 64 c.weightx = 0.5; 65 c.weighty = 0.0; 66 c.fill = GridBagConstraints.HORIZONTAL; 67 c.anchor = GridBagConstraints.WEST; 68 c.insets = new Insets(4, 4, 0, 4); 69 gbl.setConstraints(mimeTypeCombo, c); 70 add(mimeTypeCombo); 71 72 //Concept 73 JLabel conceptLabel = new JLabel("Object Type:", SwingConstants.LEFT); 74 c.gridx = 1; 75 c.gridy = row+0; 76 c.gridwidth = 1; 77 c.gridheight = 1; 78 c.weightx = 0.0; 79 c.weighty = 0.0; 80 c.fill = GridBagConstraints.NONE; 81 c.anchor = GridBagConstraints.WEST; 82 c.insets = new Insets(4, 4, 0, 4); 83 gbl.setConstraints(conceptLabel, c); 84 add(conceptLabel); 85 86 objectTypeText = new JTextField(); 87 objectTypeText.setEditable(false); 88 c.gridx = 1; 89 c.gridy = row+1; 90 c.gridwidth = 1; 91 c.gridheight = 1; 92 c.weightx = 0.5; 93 c.weighty = 0.5; 94 c.fill = GridBagConstraints.HORIZONTAL; 95 c.anchor = GridBagConstraints.WEST; 96 c.insets = new Insets(4, 4, 4, 4); 97 gbl.setConstraints(objectTypeText, c); 98 add(objectTypeText); 99 100 //Select ClassificationScheme or Concept 101 JButton showSchemeButton = new JButton("Select Concept for Object Type..."); 102 showSchemeButton.addActionListener(new ActionListener() { 103 public void actionPerformed(ActionEvent ev) { 104 getSelectedConcept(); 105 } 106 }); 107 c.gridx = 1; 108 c.gridy = row+2; 109 c.gridwidth = 1; 110 c.gridheight = 1; 111 c.weightx = 0.0; 112 c.weighty = 0.0; 113 c.fill = GridBagConstraints.NONE; 114 c.anchor = GridBagConstraints.EAST; 115 c.insets = new Insets(4, 4, 0, 4); 116 gbl.setConstraints(showSchemeButton, c); 117 add(showSchemeButton); 118 119 isOpaqueCheckBox = new JCheckBox("Is Opaque"); 120 isOpaqueCheckBox.setSelected(false); 121 c.gridx = 0; 122 c.gridy = row+2; 123 c.gridwidth = 1; 124 c.gridheight = 1; 125 c.weightx = 0.0; 126 c.weighty = 0.0; 127 c.fill = GridBagConstraints.NONE; 128 c.anchor = GridBagConstraints.WEST; 129 c.insets = new Insets(4, 4, 0, 4); 130 gbl.setConstraints(isOpaqueCheckBox, c); 131 add(isOpaqueCheckBox); 132 133 JPanel buttonPanel = new JPanel(); 134 c.gridx = 1; 135 c.gridy = row+3; 136 c.gridwidth = 1; 137 c.gridheight = 2; 138 c.weightx = 0.0; 139 c.weighty = 0.0; 140 c.fill = GridBagConstraints.NONE; 141 c.anchor = GridBagConstraints.CENTER; 142 c.insets = new Insets(4, 4, 0, 4); 143 gbl.setConstraints(buttonPanel, c); 144 add(buttonPanel); 145 146 //Select ClassificationScheme or Concept 147 JButton chooseRepositoryItemButton = new JButton("Choose Repository Item file..."); 148 chooseRepositoryItemButton.addActionListener(new ActionListener() { 149 public void actionPerformed(ActionEvent ev) { 150 getRepositoryItemFromFile(); 151 } 152 }); 153 buttonPanel.add(chooseRepositoryItemButton, BorderLayout.NORTH); 154 155 //Select ClassificationScheme or Concept 156 JButton removeRepositoryItemButton = new JButton("Remove Repository Item"); 157 removeRepositoryItemButton.addActionListener(new ActionListener() { 158 public void actionPerformed(ActionEvent ev) { 159 removeRepositoryItem(); 160 } 161 }); 162 buttonPanel.add(removeRepositoryItemButton, BorderLayout.SOUTH); 163 164 } 165 166 private void getSelectedConcept() { 167 ConceptsTreeDialog dialog = ConceptsTreeDialog.showSchemes(this, true, true); 168 if (dialog.getStatus() == JBDialog.OK_STATUS) { 169 ArrayList selectedObjects = dialog.getSelectedObjects(); 170 171 int selectionCount = selectedObjects.size(); 172 if (selectionCount == 0) { 173 RegistryBrowser.displayError("Must select a Concept in ClassificationScheme dialog"); 174 } 175 else { 176 if (selectionCount > 1) { 177 RegistryBrowser.displayError("Only one selection allowed in ClassificationScheme dialog. Using last selection"); 178 } 179 180 ExtrinsicObject eo = (ExtrinsicObject)model; 181 Object obj = selectedObjects.get(selectionCount-1); 182 183 try { 184 185 if (obj instanceof Concept) { 186 Concept concept = (Concept)obj; 187 ((com.sun.xml.registry.ebxml.infomodel.ExtrinsicObjectImpl)eo).setObjectType(concept); 188 objectTypeText.setText(concept.getValue()); 189 } 190 else { 191 throw new JAXRException("Must select a Concept only"); 192 } 193 } 194 catch (JAXRException e) { 195 RegistryBrowser.displayError(e); 196 } 197 } 198 } 199 } 200 201 private void getRepositoryItemFromFile() { 202 if (model != null) { 203 ExtrinsicObject eo = (ExtrinsicObject)model; 204 205 try { 206 int returnVal = chooser.showOpenDialog(this); 207 if(returnVal == JFileChooser.APPROVE_OPTION) { 208 File repositoryItemFile = chooser.getSelectedFile(); 209 210 //??Need to encapsulate in a until method and later include in JAXR API 2.0 211 DataHandler repositoryItemDH = new DataHandler(new FileDataSource(repositoryItemFile)); 212 eo.setRepositoryItem(repositoryItemDH); 213 } 214 } 215 catch (JAXRException e) { 216 RegistryBrowser.displayError(e); 217 } 218 } 219 220 } 221 222 private void removeRepositoryItem() { 223 if (model != null) { 224 ExtrinsicObject eo = (ExtrinsicObject)model; 225 226 try { 227 eo.setRepositoryItem(null); 228 } 229 catch (JAXRException e) { 230 RegistryBrowser.displayError(e); 231 } 232 } 233 } 234 235 public void setModel(Object obj) throws JAXRException { 236 if (!(obj instanceof ExtrinsicObject)) { 237 throw new InvalidRequestException("Expecting a ExtrinsicObject. Got a " + obj.getClass().getName()); 238 } 239 super.setModel(obj); 240 ExtrinsicObject eo = (ExtrinsicObject)obj; 241 242 try { 243 if (eo != null) { 244 isOpaqueCheckBox.setSelected(eo.isOpaque()); 245 Concept objectType = eo.getObjectType(); 246 if (objectType != null) { 247 objectTypeText.setText(objectType.getValue()); 248 } 249 String mimeType = eo.getMimeType(); 250 mimeTypeCombo .insertItemAt(mimeType, 0); 251 mimeTypeCombo .setSelectedIndex(0); 252 } 253 } 254 catch (JAXRException e) { 255 RegistryBrowser.displayError(e); 256 } 257 } 258 259 public Object getModel() throws JAXRException { 260 super.getModel(); 261 262 if (model != null) { 263 ExtrinsicObject eo = (ExtrinsicObject)model; 264 265 eo.setOpaque(isOpaqueCheckBox.isSelected()); 266 eo.setMimeType((String)(mimeTypeCombo.getSelectedItem())); 267 268 RegistryBrowser.getInstance().getRootPane().updateUI(); 269 } 270 271 return model; 272 } 273 274 protected void validateInput() throws JAXRException { 275 super.validateInput(); 276 277 ExtrinsicObject eo = (ExtrinsicObject)model; 278 } 279 280 public void clear() throws JAXRException { 281 super.clear(); 282 isOpaqueCheckBox.setSelected(false); 283 } 284 285 } 286

This page was automatically generated by Maven