KickJava   Java API By Example, From Geeks To Geeks.

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


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
9 import org.omg.WfBase.*;
10 import org.enhydra.shark.corba.WorkflowService.*;
11 import org.omg.CORBA.*;
12
13 /**
14  * Used to update workflow variables.
15  *
16  * @author Sasa Bojanic
17  * @version 1.0
18  */

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