1 package org.enhydra.shark.corbaclient; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 6 7 import javax.swing.*; 8 import org.omg.WfBase.NameValue; 9 10 11 17 public class MapPanel extends ActionPanel { 18 19 private static Dimension labelFieldDimension=new Dimension(250,20); 20 private static Dimension textFieldDimension=new Dimension(250,20); 21 private static Dimension buttonFieldDimension=new Dimension(50,25); 22 23 private NameValue nameValue; 24 private String varId; 25 private String varName; 26 private HashMap val; 27 28 private JLabel name=new JLabel(); 29 private JLabel type=new JLabel(); 30 private JTextField value; 31 private JComboBox choices; 32 private JTextField vDay; 33 private JTextField vMonth; 34 private JTextField vYear; 35 private JButton description; 36 37 private String typeKey; 38 private String desc; 39 private boolean isReadOnly; 40 41 private JPanel mainPanel; 42 private Set ntvdpanels=new HashSet(); 43 44 public MapPanel(NameValue nv,String nm,String d,String typeKey,boolean isReadOnly) { 45 super(); 46 this.nameValue=nv; 47 this.varId=nv.the_name; 48 this.val=(HashMap)nv.the_value.extract_Value(); 49 this.varName=nm; 50 this.desc=d; 51 this.typeKey=typeKey; 52 this.isReadOnly=isReadOnly; 53 super.init(); 54 } 55 56 protected void createActions () {} 57 58 protected Component createCenterComponent() { 59 JScrollPane jsp=new JScrollPane(); 60 JPanel panel = new JPanel(); 61 panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 62 panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); 63 64 JPanel p=new JPanel(); 65 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 66 p.add(Box.createHorizontalStrut(5)); 67 if (varName!=null && varName.trim().length()>0) { 68 name.setText(varName); 69 } else { 70 name.setText(varId); 71 } 72 name.setMinimumSize(new Dimension(labelFieldDimension)); 73 name.setPreferredSize(new Dimension(labelFieldDimension)); 74 name.setMaximumSize(new Dimension(labelFieldDimension)); 75 p.add(name); 76 p.add(Box.createHorizontalStrut(5)); 77 78 type.setText(ResourceManager.getLanguageDependentString(typeKey)); 79 type.setMinimumSize(new Dimension(labelFieldDimension)); 80 type.setPreferredSize(new Dimension(labelFieldDimension)); 81 type.setMaximumSize(new Dimension(labelFieldDimension)); 82 p.add(type); 83 p.add(Box.createHorizontalStrut(5)); 84 85 description=(JButton)BarFactory. 86 createButton("VariableDescription",null,false); 87 description.setMinimumSize(new Dimension(buttonFieldDimension)); 88 description.setPreferredSize(new Dimension(buttonFieldDimension)); 89 description.setMaximumSize(new Dimension(buttonFieldDimension)); 90 description.addActionListener(new ActionListener () { 91 public void actionPerformed (ActionEvent ae) { 92 String dk=ResourceManager.getLanguageDependentString("DescriptionKey"); 93 ItemView iv=new ItemView(getWindow(), 94 dk+" - "+((varName==null || varName.trim().length()==0)?varId:varName),dk,desc); 95 iv.showDialog(); 96 } 97 }); 98 description.setEnabled(true); 99 p.add(description); 100 p.add(Box.createHorizontalGlue()); 101 102 panel.add(p); 103 if (val!=null) { 104 int i=0; 105 for (Iterator it=val.entrySet().iterator(); it.hasNext(); i++) { 106 Map.Entry me=(Map.Entry)it.next(); 107 String varId=(String )me.getKey(); 108 Object varVal=me.getValue(); 109 try { 110 String varType; 111 if (varVal!=null) { 112 varType=MapPanel.getTypeKeyOfAnyObject(varVal); 113 } else { 114 varType=WorkflowUtilities.UNKNOWN_KEY; 115 } 116 ActionPanel ntvdPanel; 117 if (!varType.equals(WorkflowUtilities.MAP_KEY)) { 119 ntvdPanel= 120 new MapsNTVDPanel(varId, 121 varVal, 122 varId, 123 "", 124 varType, 125 isReadOnly); 126 } else { 127 NameValue nv=new NameValue(); 128 nv.the_name=varId; 129 nv.the_value=SharkClient.getORB().create_any(); 130 nv.the_value.insert_Value((HashMap)varVal); 131 ntvdPanel= 132 new MapPanel(nv, 133 varId, 134 "", 135 varType, 136 isReadOnly); 137 } 138 panel.add(ntvdPanel); 139 panel.add(Box.createVerticalStrut(5)); 140 ntvdpanels.add(ntvdPanel); 141 } catch (Exception ex) {ex.printStackTrace();} 142 } 143 } 144 panel.add(Box.createVerticalGlue()); 145 146 jsp.setViewportView(panel); 147 return jsp; 148 } 149 150 public void requestFocus() { 151 super.requestFocus(); 152 if (value!=null) { 153 value.requestFocus(); 154 } else if (choices!=null) { 155 choices.requestFocus(); 156 } 157 } 158 159 public boolean updateFields () { 160 Iterator nvs=ntvdpanels.iterator(); 161 while (nvs.hasNext()) { 162 Object p=nvs.next(); 163 if (p instanceof MapsNTVDPanel) { 164 MapsNTVDPanel ntvdp=(MapsNTVDPanel)p; 165 if (!ntvdp.updateField() && !ntvdp.isReadOnly()) { 166 JOptionPane.showMessageDialog(this, 167 ResourceManager.getLanguageDependentString("ErrorUncorrectType"), 168 ResourceManager.getLanguageDependentString("DialogUpdateProcessVariables"), 169 JOptionPane.ERROR_MESSAGE); 170 ntvdp.requestFocus(); 171 return false; 172 } 173 } else if (p instanceof MapPanel) { 174 MapPanel mp=(MapPanel)p; 175 if (!mp.updateFields() && !mp.isReadOnly()) { 176 return false; 177 } 178 } 179 } 180 nvs=ntvdpanels.iterator(); 181 while (nvs.hasNext()) { 182 Object p=nvs.next(); 183 if (p instanceof MapsNTVDPanel) { 184 MapsNTVDPanel ntvdp=(MapsNTVDPanel)p; 185 if (!ntvdp.isReadOnly()) { 186 val.put(ntvdp.getVariableId(),ntvdp.getVariableValue()); 187 } 188 } else if (p instanceof MapPanel) { 189 MapPanel mp=(MapPanel)p; 190 if (!mp.isReadOnly()) { 191 val.put(mp.getVariableId(),mp.getVariableValue()); 192 } 193 } 194 } 195 nameValue.the_value.insert_Value(val); 196 return true; 197 } 198 199 public String getTypeKey () { 200 return typeKey; 201 } 202 203 public boolean isReadOnly () { 204 return isReadOnly; 205 } 206 207 public String getVariableId () { 208 return varId; 209 } 210 211 public Object getVariableValue () { 212 return val; 213 } 214 215 public static String getTypeKeyOfAnyObject (Object theValueHolder) { 216 try { 217 if (theValueHolder instanceof Boolean ) { 219 return WorkflowUtilities.BOOLEAN_KEY; 220 } else if (theValueHolder instanceof String ) { 221 return WorkflowUtilities.STRING_KEY; 222 } else if (theValueHolder instanceof Date) { 223 return WorkflowUtilities.DATE_KEY; 224 } else if (theValueHolder instanceof Long ) { 225 return WorkflowUtilities.INTEGER_KEY; 226 } else if (theValueHolder instanceof Double ) { 227 return WorkflowUtilities.DOUBLE_KEY; 228 } else if (theValueHolder instanceof HashMap) { 229 return WorkflowUtilities.MAP_KEY; 230 } else { 235 return WorkflowUtilities.UNKNOWN_KEY; 236 } 237 } catch (Exception bo) { 238 return WorkflowUtilities.UNKNOWN_KEY; 239 } 240 } 241 242 243 } 244 | Popular Tags |