KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > rainterface > UsersView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.rainterface;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.ejbca.core.model.ra.UserDataVO;
23
24
25
26
27 /**
28  * A class representing a set of users w
29  * @author philip
30  * @version $Id: UsersView.java,v 1.2 2006/01/26 14:18:20 anatom Exp $
31  */

32 public class UsersView implements java.io.Serializable JavaDoc {
33         
34     /** Creates a new instance of UsersView */
35     public UsersView() {
36       users = new ArrayList JavaDoc();
37       sortby = new SortBy();
38     }
39     
40     public UsersView(UserDataVO importuser, HashMap JavaDoc caidtonamemap){
41       users = new ArrayList JavaDoc();
42       sortby = new SortBy();
43       users.add(new UserView(importuser, caidtonamemap));
44       
45       Collections.sort(users);
46     }
47     
48     public UsersView(Collection JavaDoc importusers, HashMap JavaDoc caidtonamemap){
49       users = new ArrayList JavaDoc();
50       sortby = new SortBy();
51       
52       setUsers(importusers, caidtonamemap);
53     }
54     // Public methods.
55

56     public void sortBy(int sortby, int sortorder) {
57       this.sortby.setSortBy(sortby);
58       this.sortby.setSortOrder(sortorder);
59       
60       Collections.sort(users);
61     }
62     
63     public UserView[] getUsers(int index, int size) {
64       int endindex;
65       UserView[] returnval;
66    
67       if(index > users.size()) index = users.size()-1;
68       if(index < 0) index =0;
69       
70       endindex = index + size;
71       if(endindex > users.size()) endindex = users.size();
72       
73       returnval = new UserView[endindex-index];
74       
75       int end = endindex - index;
76       for(int i = 0; i < end; i++){
77         returnval[i] = (UserView) users.get(index+i);
78       }
79       
80       return returnval;
81     }
82     
83     public void setUsers(UserView[] users) {
84       this.users.clear();
85       if(users !=null && users.length > 0){
86         for(int i=0; i < users.length; i++){
87           users[i].setSortBy(this.sortby);
88           this.users.add(users[i]);
89         }
90       }
91       Collections.sort(this.users);
92     }
93     
94     public void setUsers(UserDataVO[] users, HashMap JavaDoc caidtonamemap) {
95       UserView user;
96       this.users.clear();
97       if(users !=null && users.length > 0){
98         for(int i=0; i< users.length; i++){
99           user = new UserView(users[i], caidtonamemap);
100           user.setSortBy(this.sortby);
101           this.users.add(user);
102         }
103         Collections.sort(this.users);
104       }
105     }
106
107     public void setUsers(Collection JavaDoc importusers, HashMap JavaDoc caidtonamemap) {
108         
109       UserView user;
110       Iterator JavaDoc i;
111       this.users.clear();
112       if(importusers!=null && importusers.size() > 0){
113         i=importusers.iterator();
114         while(i.hasNext()){
115           UserDataVO nextuser = (UserDataVO) i.next();
116           user = new UserView(nextuser, caidtonamemap);
117           user.setSortBy(this.sortby);
118           users.add(user);
119         }
120         Collections.sort(users);
121       }
122     }
123
124     public void addUser(UserView user) {
125        user.setSortBy(this.sortby);
126        users.add(user);
127     }
128     
129     public int size(){
130       return users.size();
131     }
132     
133     public void clear(){
134       this.users.clear();
135     }
136     // Private fields
137
private ArrayList JavaDoc users;
138     private SortBy sortby;
139     
140 }
141
Popular Tags