KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.corbaclient.workflowadmin.user;
2
3 import java.awt.*;
4 import java.util.*;
5
6 import javax.swing.*;
7
8 import org.omg.WorkflowModel.*;
9 import org.enhydra.shark.corba.WorkflowService.*;
10 import org.enhydra.shark.corbaclient.*;
11 import org.enhydra.shark.corbaclient.workflowadmin.*;
12 import org.enhydra.shark.corbaclient.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       for (int i=0; i<existingUsersPanel.getTable().getRowCount(); i++) {
116          String JavaDoc uname=(String JavaDoc)existingUsersPanel.getTable().getValueAt(i,0);
117          try {
118             existingUsersPanel.setColumnValueOfSelectedRow(1,uga.getUserFirstName(uname));
119             existingUsersPanel.setColumnValueOfSelectedRow(1,uga.getUserLastName(uname));
120             existingUsersPanel.setColumnValueOfSelectedRow(2,uga.getUserEMailAddress(uname));
121          }catch (Exception JavaDoc ex) {}
122       }
123       // add newly added resources to the table
124
it=toAdd.iterator();
125       while (it.hasNext()) {
126          String JavaDoc username=(String JavaDoc)it.next();
127          Vector v=new Vector();
128          try {
129             v.add(username);
130             v.add(uga.getUserFirstName(username));
131             v.add(uga.getUserLastName(username));
132             v.add(uga.getUserEMailAddress(username));
133             existingUsersPanel.addElement(v);
134          } catch (Exception JavaDoc ex) {
135             System.out.println("Something went wrong during retrival of resource properties");
136             ex.printStackTrace();
137          }
138       }
139    }
140
141 }
142
Popular Tags