KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > UpdateVariables


1 package org.enhydra.shark.swingclient;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8 import org.enhydra.shark.api.client.wfservice.AdminMisc;
9
10
11 /**
12  * Used to update workflow variables.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

17 public class UpdateVariables extends ActionPanel {
18
19    private String JavaDoc procId;
20    private Map context;
21    private Map readOnlyContext=new LinkedHashMap();
22
23    private JPanel mainPanel;
24
25    private Set ntvdpanels=new HashSet();
26
27    private boolean isCanceled=false;
28
29
30    public UpdateVariables(Window parent,String JavaDoc dialogName,String JavaDoc procId,
31                           Map context,Map readOnlyContext){
32       super();
33       this.procId=procId;
34       this.context=context;
35       if (readOnlyContext!=null) {
36          this.readOnlyContext.putAll(readOnlyContext);
37       }
38       super.init();
39       super.initDialog(parent,dialogName,true,true);
40    }
41
42    protected void createActions () {}
43
44    protected Component createCenterComponent() {
45       JScrollPane jsp=new JScrollPane();
46       JPanel panel = new JPanel();
47       panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
48       panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
49
50       if (context!=null) {
51          int i=0;
52          AdminMisc am=SharkClient.getAdminMiscUtilities();
53          for (Iterator it=context.entrySet().iterator(); it.hasNext(); i++) {
54             Map.Entry me=(Map.Entry)it.next();
55             String JavaDoc varId=(String JavaDoc)me.getKey();
56             Object JavaDoc varVal=me.getValue();
57             try {
58                String JavaDoc varType;
59                if (varVal!=null) {
60                   varType=WorkflowUtilities.getTypeKeyOfAnyObject(varVal);
61                } else {
62                   varType=WorkflowUtilities.getTypeKeyOfAnyObject(am.getVariableJavaClassName(procId,varId));
63                }
64                //System.out.println("Var "+varId+", val="+varVal+", varType="+varType);
65
ActionPanel ntvdPanel;
66                if (!varType.equals(WorkflowUtilities.MAP_KEY)) {
67                   ntvdPanel=
68                      new NTVDPanel(varId,
69                                    varVal,
70                                    am.getVariableName(procId,varId),
71                                    am.getVariableDescription(procId,varId),
72                                    varType,
73                                    readOnlyContext.containsKey((varId)));
74                } else {
75                   ntvdPanel=
76                      new MapPanel(varId,
77                                      (HashMap)varVal,
78                                   am.getVariableName(procId,varId),
79                                   am.getVariableDescription(procId,varId),
80                                   varType,
81                                   readOnlyContext.containsKey((varId)));
82                }
83                panel.add(ntvdPanel);
84                panel.add(Box.createVerticalStrut(5));
85                ntvdpanels.add(ntvdPanel);
86             } catch (Exception JavaDoc ex) {ex.printStackTrace();}
87          }
88       }
89       panel.add(Box.createVerticalGlue());
90       jsp.setViewportView(panel);
91       return jsp;
92    }
93
94    private boolean updateFields () {
95       Iterator nvs=ntvdpanels.iterator();
96       while (nvs.hasNext()) {
97          Object JavaDoc p=nvs.next();
98          if (p instanceof NTVDPanel) {
99             NTVDPanel ntvdp=(NTVDPanel)p;
100             if (!ntvdp.updateField() && !ntvdp.isReadOnly()) {
101                JOptionPane.showMessageDialog(this,
102                                              ResourceManager.getLanguageDependentString("ErrorUncorrectType"),
103                                              ResourceManager.getLanguageDependentString("DialogUpdateProcessVariables"),
104                                              JOptionPane.ERROR_MESSAGE);
105                ntvdp.requestFocus();
106                return false;
107             }
108          } else if (p instanceof MapPanel) {
109             MapPanel mp=(MapPanel)p;
110             if (!mp.updateFields() && !mp.isReadOnly()) {
111                return false;
112             }
113          }
114       }
115       nvs=ntvdpanels.iterator();
116       while (nvs.hasNext()) {
117          Object JavaDoc p=nvs.next();
118          if (p instanceof NTVDPanel) {
119             NTVDPanel ntvdp=(NTVDPanel)p;
120             if (!ntvdp.isReadOnly()) {
121                context.put(ntvdp.getVariableId(),ntvdp.getVariableValue());
122             }
123          } else if (p instanceof MapPanel) {
124             MapPanel mp=(MapPanel)p;
125             if (!mp.isReadOnly()) {
126                context.put(mp.getVariableId(),mp.getVariableValue());
127             }
128          }
129       }
130       return true;
131    }
132
133    protected void applyChanges () {
134       if (updateFields()) {
135          myDialog.dispose();
136       }
137    }
138
139    protected void cancelChanges () {
140       isCanceled=true;
141       myDialog.dispose();
142    }
143
144    public boolean isCanceled () {
145       return isCanceled;
146    }
147
148 }
149
Popular Tags