KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > user > UserAccountManagement


1 package org.enhydra.shark.swingclient.workflowadmin.user;
2
3 import java.awt.*;
4 import java.util.*;
5
6 import javax.swing.*;
7
8
9 import org.enhydra.shark.api.client.wfservice.*;
10 import org.enhydra.shark.swingclient.*;
11 import org.enhydra.shark.swingclient.workflowadmin.*;
12 import org.enhydra.shark.swingclient.workflowadmin.user.actions.*;
13
14 /**
15  * Implements the user interface and program logic to create the
16  * user account, remove it or change it's properties.
17  *
18  * @author Sasa Bojanic
19  * @version 1.0
20  */

21 public class UserAccountManagement extends ActionPanel {
22
23
24    private SharkAdmin workflowAdmin;
25
26    private TablePanel existingUsersPanel;
27    private ArrayList existingUsers=new ArrayList();
28
29    public UserAccountManagement (SharkAdmin wa) {
30       super();
31       this.workflowAdmin=wa;
32       super.init();
33    }
34
35    protected void createActions () {
36       defaultActions=new Action[] {
37          new CreateUserAccount(this),
38             new RemoveUserAccount(this),
39             new ChangeUserAccountSettings(this),
40             new ChangeUserAccountPassword(this)
41       };
42    }
43
44    protected Component createCenterComponent() {
45       Vector columnNames=new Vector();
46       columnNames.add(ResourceManager.getLanguageDependentString("UsernameKey"));
47       columnNames.add(ResourceManager.getLanguageDependentString("FirstNameKey"));
48       columnNames.add(ResourceManager.getLanguageDependentString("LastNameKey"));
49       columnNames.add(ResourceManager.getLanguageDependentString("EmailAddressKey"));
50
51       existingUsersPanel=new TablePanel(columnNames, true);
52       return existingUsersPanel;
53    }
54
55    public SharkAdmin getWorkflowAdmin () {
56       return workflowAdmin;
57    }
58
59    public TablePanel getExistingUsersPanel () {
60       return existingUsersPanel;
61    }
62
63    public ArrayList getExistingUsers () {
64       return new ArrayList(existingUsers);
65    }
66
67    /*public WfResource getResourceForUsername (String username) {
68     ArrayList copyOfEU=new ArrayList(existingUsers);
69     Iterator it=copyOfEU.iterator();
70     while (it.hasNext()) {
71     WfResource res=(WfResource)it.next();
72     try {
73     if (res.resource_key().equals(username)) {
74     return res;
75     }
76     } catch (Exception ex) {}
77     }
78     return null;
79     }*/

80
81    public void clear () {
82       existingUsers.clear();
83       existingUsersPanel.removeAll();
84    }
85
86    public synchronized void refresh (boolean mandatoryRefreshing) {
87       if (!(mandatoryRefreshing || isShowing())) return;
88       UserGroupAdministration uga=SharkAdmin.getUserGroupAmin();
89
90       ArrayList oldEU=new ArrayList(existingUsers);
91       try {
92          /*existingUsers=new ArrayList(
93           Arrays.asList(uga.getAllGroupnames()));*/

94          existingUsers=new ArrayList(Arrays.asList(uga.getAllUsers()));
95       } catch (Throwable JavaDoc ex) {
96          System.out.println("Something went wrong during retrival of resources from engine");
97       }
98
99       ArrayList toAdd=new ArrayList(existingUsers);
100       toAdd.removeAll(oldEU);
101       ArrayList toRemove=new ArrayList(oldEU);
102       toRemove.removeAll(existingUsers);
103
104       // remove removed resources from table
105
Iterator it=toRemove.iterator();
106       while (it.hasNext()) {
107          try {
108             String JavaDoc username=(String JavaDoc)it.next();
109             existingUsersPanel.removeElement(new Object JavaDoc[]{username});
110          } catch (Exception JavaDoc ex) {
111             System.out.println("Something went wrong during retrival of resource property");
112          }
113       }
114
115       // refresh retained users
116
for (int i=0; i<existingUsersPanel.getTable().getRowCount(); i++) {
117          String JavaDoc uname=(String JavaDoc)existingUsersPanel.getTable().getValueAt(i,0);
118          try {
119             existingUsersPanel.setColumnValueOfSelectedRow(1,uga.getUserFirstName(uname));
120             existingUsersPanel.setColumnValueOfSelectedRow(2,uga.getUserLastName(uname));
121             existingUsersPanel.setColumnValueOfSelectedRow(3,uga.getUserEMailAddress(uname));
122          }catch (Exception JavaDoc ex) {}
123       }
124
125       // add newly added resources to the table
126
it=toAdd.iterator();
127       while (it.hasNext()) {
128          String JavaDoc username=(String JavaDoc)it.next();
129          Vector v=new Vector();
130          try {
131             v.add(username);
132             v.add(uga.getUserFirstName(username));
133             v.add(uga.getUserLastName(username));
134             v.add(uga.getUserEMailAddress(username));
135             existingUsersPanel.addElement(v);
136          } catch (Exception JavaDoc ex) {
137             System.out.println("Something went wrong during retrival of resource properties");
138             ex.printStackTrace();
139          }
140       }
141
142    }
143
144 }
145
Popular Tags