KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > worklist > Reassignment


1 package org.enhydra.shark.swingclient.workflowadmin.worklist;
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.shark.api.client.wfmodel.*;
13 import org.enhydra.shark.swingclient.*;
14 import org.enhydra.shark.swingclient.workflowadmin.*;
15
16
17 /**
18  * Enables the user to map some participant to the actual
19  * user represented by it's account username.
20  *
21  * @author Sasa Bojanic
22  * @version 1.0
23  */

24 public class Reassignment extends ActionPanel {
25
26    private static Dimension listFieldDimension=new Dimension(300,300);
27
28    private JList usernames;
29    private JTextField username=new JTextField();
30
31    private String JavaDoc uname;
32
33    private ArrayList allUsers;
34
35    private WfAssignment assignment;
36
37    public Reassignment (JFrame parent,WfAssignment ass,ArrayList allUsers) {
38       this.assignment=ass;
39       this.allUsers=allUsers;
40       init();
41       initDialog(parent,ResourceManager.getLanguageDependentString("DialogReassignWorkitem"),
42                  true,true);
43    }
44
45    protected void createActions () {}
46
47    protected Component createCenterComponent () {
48       username.setEnabled(false);
49
50       DefaultListModel listModel=new DefaultListModel();
51       // fills list of users
52
Iterator it=allUsers.iterator();
53       while (it.hasNext()) {
54          String JavaDoc uname=(String JavaDoc)it.next();
55          try {
56             //listModel.addElement(res.resource_key()+" - "+res.resource_name());
57
listModel.addElement(uname);
58          } catch (Exception JavaDoc ex) {}
59       }
60       JScrollPane scrollParam=new JScrollPane();
61
62       usernames=new JList(listModel);
63       usernames.addListSelectionListener(new ListSelectionListener() {
64                public void valueChanged(ListSelectionEvent e) {
65                   if (e.getValueIsAdjusting()) {
66                      return;
67                   }
68
69                   JList theList = (JList)e.getSource();
70                   if (theList.isSelectionEmpty()) {
71                      username.setText("");
72                   } else {
73                      String JavaDoc un = (String JavaDoc)theList.getSelectedValue();
74                      username.setText(un);
75                   }
76                }
77             });
78       usernames.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
79       scrollParam.setViewportView(usernames);
80       scrollParam.setPreferredSize(new Dimension(listFieldDimension));
81
82       JPanel up=new JPanel();
83       Border emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
84       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
85       inb=BorderFactory.createTitledBorder(inb,
86                                            ResourceManager.getLanguageDependentString("ReassignToKey"));
87       up.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
88       up.setLayout(new BoxLayout(up,BoxLayout.Y_AXIS));
89       up.add(scrollParam);
90       up.add(username);
91
92       return up;
93    }
94
95
96    protected void applyChanges () {
97       WfResource newAssignee;
98       if (usernames.isSelectionEmpty()) {
99          newAssignee=null;
100          JOptionPane.showMessageDialog(this,
101                                        ResourceManager.getLanguageDependentString("ErrorSelectValidUser"),
102                                        ResourceManager.getLanguageDependentString("DialogReassignWorkitem"),
103                                        JOptionPane.ERROR_MESSAGE);
104          return;
105       } else {
106          try {
107             newAssignee=SharkAdmin.getExecAmin().getResource((String JavaDoc)allUsers.get(usernames.getSelectedIndex()));
108             WfResource oldAssignee=assignment.assignee();
109             assignment.set_assignee(newAssignee);
110          } catch (Exception JavaDoc ex) {
111             try {
112                boolean accepted=assignment.get_accepted_status();
113                if (accepted) {
114                   JOptionPane.showMessageDialog(this,
115                                                 ResourceManager.getLanguageDependentString("ErrorCannotReassignAcceptedWorkitem"),
116                                                 SharkAdmin.getAppTitle(),
117                                                 JOptionPane.ERROR_MESSAGE);
118                }
119             } catch (Exception JavaDoc ex2) {
120             }
121             ex.printStackTrace();
122          }
123          myDialog.dispose();
124       }
125    }
126
127    protected void cancelChanges () {
128       myDialog.dispose();
129    }
130
131 }
132
133
Popular Tags