KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > application > ApplicationMapping


1 package org.enhydra.shark.swingclient.workflowadmin.application;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import javax.swing.event.*;
10
11
12 import org.enhydra.jawe.xml.elements.*;
13 import org.enhydra.shark.Administration;
14 import org.enhydra.shark.swingclient.*;
15 import org.enhydra.shark.swingclient.workflowadmin.*;
16 import org.enhydra.shark.api.client.wfbase.BaseException;
17 //import org.enhydra.shark.api.client.wfservice.MappingAdministration;
18
import org.enhydra.shark.api.client.wfservice.ApplicationMap;
19
20 /**
21  * The dialog that enables the application to map some application definition to
22  * the actual application represented by its tool agent.
23  *
24  * @author Sasa Bojanic
25  * @version 1.0
26  */

27 public class ApplicationMapping extends ActionPanel {
28
29    //private static String[] appModes={"SYNCHRONOUS","ASYNCHRONOUS","FILE","TEXT"};
30

31    private static Dimension listFieldDimension=new Dimension(400,300);
32    private static Dimension textFieldDimension=new Dimension(300,20);
33
34
35    private JList applications;
36    private JList toolAgents;
37    private JTextField pkgId=new JTextField();
38    private JTextField procDefId=new JTextField();
39    private JTextField applicationId=new JTextField();
40    private JTextField applicationName=new JTextField();
41
42    private JTextArea taDesc=new JTextArea();
43    private JTextField username=new JTextField();
44    private JTextField password=new JPasswordField();
45    private JTextField appName=new JTextField();
46    private JTextField appMode=new JTextField();
47
48    private Collection allApplications;
49    private Map allToolAgents;
50
51    private ApplicationMappingManagement pmm;
52    public ApplicationMapping(ApplicationMappingManagement pmm,
53       Collection allApplications,Map allToolAgents) {
54       this.pmm=pmm;
55       this.allApplications=allApplications;
56       this.allToolAgents=allToolAgents;
57       init();
58
59       initDialog(pmm.getWindow(),ResourceManager.
60          getLanguageDependentString("DialogCreateApplicationDefinitionToToolAgentMapping"),true,true);
61
62       dialogOKButton.setText(ResourceManager.getLanguageDependentString("ApplyKey"));
63       dialogCancelButton.setText(ResourceManager.getLanguageDependentString("CloseKey"));
64    }
65
66    protected void createActions () {}
67
68    protected Component createCenterComponent (){
69       pkgId.setEditable(false);
70       procDefId.setEditable(false);
71       applicationId.setEditable(false);
72       applicationName.setEditable(false);
73       taDesc.setEditable(false);
74
75       JScrollPane scrollParam=new JScrollPane();
76       applications=new JList(allApplications.toArray());
77       applications.addListSelectionListener(new ListSelectionListener() {
78          public void valueChanged(ListSelectionEvent e) {
79             if (e.getValueIsAdjusting()) {
80                return;
81             }
82
83             JList theList = (JList)e.getSource();
84             if (theList.isSelectionEmpty()) {
85                pkgId.setText("");
86                procDefId.setText("");
87                applicationId.setText("");
88             } else {
89                Application app = (Application)theList.getSelectedValue();
90                pkgId.setText(app.getPackage().get("Id").toString());
91                if (app.getCollection().getOwner() instanceof WorkflowProcess) {
92                  procDefId.setText(((WorkflowProcess)app.getCollection().getOwner()).getID());
93                } else {
94                   procDefId.setText("");
95                }
96                applicationId.setText(app.getID());
97                applicationName.setText(app.get("Name").toString());
98             }
99          }
100       });
101
102       applications.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
103       scrollParam.setViewportView(applications);
104       scrollParam.setMinimumSize(new Dimension(listFieldDimension));
105       scrollParam.setMaximumSize(new Dimension(listFieldDimension));
106       scrollParam.setPreferredSize(new Dimension(listFieldDimension));
107
108       JPanel ap=new JPanel();
109       Border emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
110       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
111       inb=BorderFactory.createTitledBorder(inb,
112          ResourceManager.getLanguageDependentString("SelectApplicationKey"));
113       ap.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
114       ap.setLayout(new BoxLayout(ap,BoxLayout.Y_AXIS));
115       ap.add(scrollParam);
116
117       ap.add(Box.createVerticalGlue());
118
119       JPanel ap1=new JPanel();
120       ap1.setLayout(new BoxLayout(ap1,BoxLayout.X_AXIS));
121       ap1.add(Box.createHorizontalGlue());
122       ap1.add(new JLabel(ResourceManager.getLanguageDependentString("PackageIdKey")+": "));
123       pkgId.setMinimumSize(new Dimension(textFieldDimension));
124       pkgId.setMaximumSize(new Dimension(textFieldDimension));
125       pkgId.setPreferredSize(new Dimension(textFieldDimension));
126       ap1.add(pkgId);
127       ap.add(ap1);
128
129       ap1=new JPanel();
130       ap1.setLayout(new BoxLayout(ap1,BoxLayout.X_AXIS));
131       ap1.add(Box.createHorizontalGlue());
132       ap1.add(new JLabel(ResourceManager.getLanguageDependentString("ProcessDefinitionIdKey")+": "));
133       procDefId.setMinimumSize(new Dimension(textFieldDimension));
134       procDefId.setMaximumSize(new Dimension(textFieldDimension));
135       procDefId.setPreferredSize(new Dimension(textFieldDimension));
136       ap1.add(procDefId);
137       ap.add(ap1);
138
139       ap1=new JPanel();
140       ap1.setLayout(new BoxLayout(ap1,BoxLayout.X_AXIS));
141       ap1.add(Box.createHorizontalGlue());
142       ap1.add(new JLabel(ResourceManager.getLanguageDependentString("ApplicationIdKey")+": "));
143       applicationId.setMinimumSize(new Dimension(textFieldDimension));
144       applicationId.setMaximumSize(new Dimension(textFieldDimension));
145       applicationId.setPreferredSize(new Dimension(textFieldDimension));
146       ap1.add(applicationId);
147       ap.add(ap1);
148
149       ap1=new JPanel();
150       ap1.setLayout(new BoxLayout(ap1,BoxLayout.X_AXIS));
151       ap1.add(Box.createHorizontalGlue());
152       ap1.add(new JLabel(ResourceManager.getLanguageDependentString("ApplicationNameKey")+": "));
153       applicationName.setMinimumSize(new Dimension(textFieldDimension));
154       applicationName.setMaximumSize(new Dimension(textFieldDimension));
155       applicationName.setPreferredSize(new Dimension(textFieldDimension));
156       ap1.add(applicationName);
157       ap.add(ap1);
158
159       scrollParam=new JScrollPane();
160       toolAgents=new JList(new Vector(allToolAgents.keySet()));
161       toolAgents.addListSelectionListener(new ListSelectionListener() {
162          public void valueChanged(ListSelectionEvent e) {
163             if (e.getValueIsAdjusting()) {
164                return;
165             }
166             username.setText("");
167             password.setText("");
168             appName.setText("");
169             appMode.setText("");
170             taDesc.setText((String JavaDoc)allToolAgents.get(toolAgents.getSelectedValue().toString()));
171             taDesc.getCaret().setDot(0);
172          }
173       });
174       toolAgents.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
175       scrollParam.setViewportView(toolAgents);
176       scrollParam.setMinimumSize(new Dimension(listFieldDimension));
177       scrollParam.setMaximumSize(new Dimension(listFieldDimension));
178       scrollParam.setPreferredSize(new Dimension(listFieldDimension));
179
180
181       JPanel pd=new JPanel();
182       pd.setLayout(new BoxLayout(pd,BoxLayout.Y_AXIS));
183       //pd.add(Box.createVerticalGlue());
184
JLabel jl=new JLabel(ResourceManager.getLanguageDependentString("DescriptionKey")+": ");
185       jl.setAlignmentX(Component.LEFT_ALIGNMENT);
186       jl.setAlignmentY(Component.TOP_ALIGNMENT);
187       jl.setHorizontalAlignment(SwingConstants.RIGHT);
188       pd.add(jl);
189
190       JScrollPane jsp=new JScrollPane();
191
192       taDesc.setTabSize(4);
193       taDesc.setLineWrap(false);
194       taDesc.setWrapStyleWord(false);
195
196       jsp.setViewportView(taDesc);
197       jsp.setMinimumSize(new Dimension(listFieldDimension.width,75));
198       jsp.setMaximumSize(new Dimension(listFieldDimension.width,75));
199       jsp.setPreferredSize(new Dimension(listFieldDimension.width,75));
200       pd.add(jsp);
201
202       JPanel pp=new JPanel();
203       emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
204       inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
205       inb=BorderFactory.createTitledBorder(inb,
206          ResourceManager.getLanguageDependentString("SelectToolAgentKey"));
207       pp.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
208       pp.setLayout(new BoxLayout(pp,BoxLayout.Y_AXIS));
209       pp.add(scrollParam);
210       pp.add(Box.createVerticalStrut(5));
211       pp.add(pd);
212       pp.add(Box.createVerticalStrut(5));
213
214       JPanel pp1=new JPanel();
215       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
216       pp1.add(Box.createHorizontalGlue());
217       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("UsernameKey")+": "));
218       username.setMinimumSize(new Dimension(textFieldDimension));
219       username.setMaximumSize(new Dimension(textFieldDimension));
220       username.setPreferredSize(new Dimension(textFieldDimension));
221       pp1.add(username);
222       pp.add(pp1);
223
224       pp1=new JPanel();
225       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
226       pp1.add(Box.createHorizontalGlue());
227       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("PasswordKey")+": "));
228       password.setMinimumSize(new Dimension(textFieldDimension));
229       password.setMaximumSize(new Dimension(textFieldDimension));
230       password.setPreferredSize(new Dimension(textFieldDimension));
231       pp1.add(password);
232       pp.add(pp1);
233
234       pp1=new JPanel();
235       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
236       pp1.add(Box.createHorizontalGlue());
237       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("ApplicationNameKey")+": "));
238       appName.setMinimumSize(new Dimension(textFieldDimension));
239       appName.setMaximumSize(new Dimension(textFieldDimension));
240       appName.setPreferredSize(new Dimension(textFieldDimension));
241       pp1.add(appName);
242       pp.add(pp1);
243
244       pp1=new JPanel();
245       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
246       pp1.add(Box.createHorizontalGlue());
247       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("ApplicationModeKey")+": "));
248       appMode.setMinimumSize(new Dimension(textFieldDimension));
249       appMode.setMaximumSize(new Dimension(textFieldDimension));
250       appMode.setPreferredSize(new Dimension(textFieldDimension));
251       pp1.add(appMode);
252       pp.add(pp1);
253
254       JPanel mp=new JPanel();
255       mp.setBorder(BorderFactory.createEtchedBorder());
256       mp.setLayout(new BoxLayout(mp,BoxLayout.X_AXIS));
257
258       mp.add(ap);
259       mp.add(pp);
260
261       return mp;
262    }
263
264    protected void applyChanges () {
265       String JavaDoc packageId;
266       String JavaDoc processDefinitionId;
267       String JavaDoc participantId;
268       String JavaDoc applicationId;
269       String JavaDoc pname=null;
270
271       if (applications.isSelectionEmpty() || toolAgents.isSelectionEmpty()) return;
272
273       Application selApp=(Application)applications.getSelectedValue();
274       packageId=selApp.getPackage().get("Id").toString();
275       if (selApp.getCollection().getOwner() instanceof WorkflowProcess) {
276          processDefinitionId=((WorkflowProcess)selApp.getCollection().getOwner()).getID();
277       } else {
278          processDefinitionId="";
279       }
280       applicationId=((Application)applications.getSelectedValue()).get("Id").toString();
281
282       try {
283          pname=(String JavaDoc)toolAgents.getSelectedValue();
284       } catch (Exception JavaDoc ex){
285          return;
286       }
287
288      ApplicationMap am = null;
289      am = SharkAdmin.getApplicationMappingsAdmin().createApplicationMap();
290      am.setPackageId(packageId);
291      am.setProcessDefinitionId(processDefinitionId);
292      am.setApplicationDefinitionId(applicationId);
293      am.setToolAgentClassName(pname);
294      am.setUsername(username.getText());
295      am.setPassword(password.getText());
296      am.setApplicationName(appName.getText());
297
298       String JavaDoc aM=appMode.getText().trim();
299       if (am!=null && aM.length()>0) {
300          try {
301             am.setApplicationMode(new Integer JavaDoc(Integer.parseInt(aM)));
302          } catch (Exception JavaDoc ex) {}
303       }
304       try {
305          SharkAdmin.getApplicationMappingsAdmin().addApplicationMapping(am);
306       } catch (Exception JavaDoc ex) {
307          ex.printStackTrace();
308          JOptionPane.showMessageDialog(pmm.getWindow(),
309                ResourceManager.getLanguageDependentString("MessageMappingAlreadyExistsOrCannotBeAddedAtTheMoment"),
310                ResourceManager.getLanguageDependentString("WorkflowAdminTitle"),
311                JOptionPane.INFORMATION_MESSAGE);
312          return;
313       }
314       pmm.refresh(true);
315    }
316
317    protected void cancelChanges () {
318       myDialog.dispose();
319    }
320
321 }
322
323
Popular Tags