View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/SlotPanel.java,v 1.6 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 to edit/inspect a Service. 15 * 16 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 17 */ 18 public class SlotPanel extends JBPanel { 19 JTextField nameText = null; 20 JTextField typeText = null; 21 JBList valuesList = null; 22 23 protected GridBagConstraints c = null; 24 protected GridBagLayout gbl = null; 25 26 27 /*** 28 * Creates new SlotPanel 29 */ 30 public SlotPanel() { 31 setBorder(BorderFactory.createTitledBorder("Slot Details")); 32 33 gbl = new GridBagLayout(); 34 c = new GridBagConstraints(); 35 setLayout(gbl); 36 37 //The name Text 38 JLabel nameLabel = new JLabel("Name:", SwingConstants.LEFT); 39 c.gridx = 0; 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.WEST; 47 c.insets = new Insets(4, 4, 0, 4); 48 gbl.setConstraints(nameLabel, c); 49 add(nameLabel); 50 51 nameText = new JTextField(); 52 nameText.setEditable(editable); 53 c.gridx = 0; 54 c.gridy = 1; 55 c.gridwidth = 1; 56 c.gridheight = 1; 57 c.weightx = 0.5; 58 c.weighty = 0.0; 59 c.fill = GridBagConstraints.HORIZONTAL; 60 c.anchor = GridBagConstraints.EAST; 61 c.insets = new Insets(4, 4, 4, 4); 62 gbl.setConstraints(nameText, c); 63 add(nameText); 64 65 JLabel typeLabel = new JLabel("Type:", SwingConstants.LEFT); 66 c.gridx = 1; 67 c.gridy = 0; 68 c.gridwidth = 1; 69 c.gridheight = 1; 70 c.weightx = 0.0; 71 c.weighty = 0.0; 72 c.fill = GridBagConstraints.NONE; 73 c.anchor = GridBagConstraints.WEST; 74 c.insets = new Insets(4, 4, 0, 4); 75 gbl.setConstraints(typeLabel, c); 76 add(typeLabel); 77 78 typeText = new JTextField(); 79 typeText.setEditable(editable); 80 c.gridx = 1; 81 c.gridy = 1; 82 c.gridwidth = 1; 83 c.gridheight = 1; 84 c.weightx = 0.5; 85 c.weighty = 0.0; 86 c.fill = GridBagConstraints.HORIZONTAL; 87 c.anchor = GridBagConstraints.WEST; 88 c.insets = new Insets(4, 4, 0, 4); 89 gbl.setConstraints(typeText, c); 90 add(typeText); 91 92 JLabel idLabel = new JLabel("Values:", SwingConstants.LEFT); 93 c.gridx = 0; 94 c.gridy = 2; 95 c.gridwidth = 1; 96 c.gridheight = 1; 97 c.weightx = 0.0; 98 c.weighty = 0.0; 99 c.fill = GridBagConstraints.NONE; 100 c.anchor = GridBagConstraints.WEST; 101 c.insets = new Insets(4, 4, 0, 4); 102 gbl.setConstraints(idLabel, c); 103 add(idLabel); 104 105 valuesList = new JBList("java.lang.StringBuffer"); 106 valuesList.setEditable(editable); 107 valuesList.setModel(new JBListModel()); 108 valuesList.setVisibleRowCount(5); 109 JScrollPane valuesListScrollPane = new JScrollPane(valuesList); 110 c.gridx = 0; 111 c.gridy = 3; 112 c.gridwidth = 2; 113 c.gridheight = 1; 114 c.weightx = 0.5; 115 c.weighty = 0.0; 116 c.fill = GridBagConstraints.HORIZONTAL; 117 c.anchor = GridBagConstraints.WEST; 118 c.insets = new Insets(4, 4, 0, 4); 119 gbl.setConstraints(valuesListScrollPane, c); 120 add(valuesListScrollPane); 121 } 122 123 public void setModel(Object obj) throws JAXRException { 124 if (!(obj instanceof Slot)) { 125 throw new InvalidRequestException("Expecting a Slot. Got a " + obj.getClass().getName()); 126 } 127 super.setModel(obj); 128 129 Slot slot = (Slot)obj; 130 131 try { 132 if (slot != null) { 133 134 String slotName = slot.getName(); 135 if (slotName != null) { 136 nameText.setText(slotName); 137 } 138 139 String slotType = slot.getSlotType(); 140 if (slotType != null) { 141 typeText.setText(slotType); 142 } 143 144 Collection values = slot.getValues(); 145 if (values != null) { 146 JBListModel valuesListModel = (JBListModel)valuesList.getModel(); 147 Iterator iter = values.iterator(); 148 while (iter.hasNext()) { 149 StringBuffer value = new StringBuffer((String)iter.next()); 150 valuesListModel.addElement(value); 151 } 152 } 153 } 154 } 155 catch (JAXRException e) { 156 RegistryBrowser.displayError(e); 157 } 158 } 159 160 public Object getModel() throws JAXRException { 161 super.getModel(); 162 if (model != null) { 163 Slot slot = (Slot)model; 164 165 slot.setName(nameText.getText()); 166 slot.setSlotType(typeText.getText()); 167 168 JBListModel valuesListModel = (JBListModel)valuesList.getModel(); 169 170 ArrayList values = new ArrayList(); 171 Object[] valuesArray = valuesListModel.toArray(); 172 for (int i=0; i<valuesArray.length; i++) { 173 values.add(valuesArray[i].toString());; 174 } 175 slot.setValues(values); 176 177 RegistryBrowser.getInstance().getRootPane().updateUI(); 178 } 179 180 return model; 181 } 182 183 protected void validateInput() throws JAXRException { 184 super.validateInput(); 185 Slot slot = (Slot)model; 186 187 if (nameText.getText().length() > 128) { 188 throw new JAXRException("Error. Slot.name length must be <= 128"); 189 } 190 191 JBListModel valuesListModel = (JBListModel)valuesList.getModel(); 192 193 ArrayList values = new ArrayList(); 194 Object[] valuesArray = valuesListModel.toArray(); 195 for (int i=0; i<valuesArray.length; i++) { 196 String value = valuesArray[i].toString(); 197 if (value.length() > 128) { 198 throw new JAXRException("Error. Slot.value length must be <= 128"); 199 } 200 } 201 } 202 203 public void clear() throws JAXRException { 204 super.clear(); 205 nameText.setText(""); 206 typeText.setText(""); 207 valuesList.setModel(new JBListModel()); 208 } 209 210 /*** 211 * Sets whether this dialog is read-only or editable. 212 */ 213 public void setEditable(boolean editable) { 214 super.setEditable(editable); 215 216 nameText.setEditable(editable); 217 typeText.setEditable(editable); 218 valuesList.setEditable(editable); 219 } 220 221 } 222

This page was automatically generated by Maven