Source code: org/mitre/cvw/AllUserListPanel.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import java.util.*;
12
13 /**
14 * Displays the list of all users
15 * @version 1.0 8/20/98
16 * @author Deb Ercolini
17 */
18 public class AllUserListPanel extends OnlineUserListPanel implements ObjectValues, Observer {
19
20 /**
21 * Constructor
22 */
23 public AllUserListPanel() {
24 super();
25 }
26 /**
27 * Sets up the widths and titles of the data columns.
28 */
29 public void init() {
30 int[] tmp = {100, 60, 100, 120};
31 //int[] tmp = {100, 75, 100, 100, 90};
32 widths = tmp;
33 //colTitles = "Name|User|Email|Location|Idle";
34 colTitles = new String[4];
35 colTitles[0] = "Name";
36 colTitles[1] = "User";
37 colTitles[2] = "Location";
38 colTitles[3] = "Idle";
39 super.init();
40 }
41
42 /* 2/16/99 dage - NOTE
43 * the email address is no longer displayed in the window
44 * so that code has been commented out. The CVW server was sending a
45 * space delimeted list of email addresses, the problem with that is that
46 * the admin is the first user and has no email address but the space is
47 * trimmed when the mcp is received. A quick solution is to not have admin
48 * email be blank or change the delimiter on the CVW server.
49 */
50 /**
51 * CVW Server has sent the list of all users in the system.
52 * <br> MCP receive cvw-system-allusers
53 *
54 * @param objstr a space delimited list of object numbers
55 * @param nameStr a space delimited list of user names
56 * @param roomstr a bar delimited list of room names
57 * @param emailstr a space delimited list of email addresses
58 * @param timestr a bar delimited list of time stamps
59 * @param fNameStr a bar delimited list of user full names
60 * @param busy a space delimited list of busy status,
61 either 0 or 1 or --- meaning disconnected
62 */
63 public void updateAllUsers(String objstr, String nameStr, String roomstr, String emailstr, String timestr, String fNameStr, String busy, String server) {
64
65 CVWObjNum tempObj;
66
67 StringTokenizer u = new StringTokenizer(objstr, " ");
68 StringTokenizer r = new StringTokenizer(roomstr, "|");
69 //emailstr = emailstr.replace(' ', '|');
70 //emailstr = CVWServerComm.parseBarDelimitedStringFromServer(emailstr);
71 //StringTokenizer e = new StringTokenizer(emailstr, "|");
72 StringTokenizer t = new StringTokenizer(timestr, "|");
73 StringTokenizer n = new StringTokenizer(nameStr, " ");
74 StringTokenizer b = new StringTokenizer(busy, " ");
75 String fString = CVWServerComm.parseBarDelimitedStringFromServer(fNameStr);
76 if (fString.length() == 0) fString = " ";
77 StringTokenizer f = new StringTokenizer(fString, "|");
78 int num_lines = u.countTokens();
79 CVWUser[] users = new CVWUser[num_lines];
80 String[] rooms = new String[num_lines];
81 int[] times = new int[num_lines];
82 String[] messages = new String[num_lines];
83 String[] busyVal = new String[num_lines];
84 String[] fNames = new String[num_lines];
85 CVWCache cache = CVWCache.getInstance();
86 CVWUser tmpUser;
87 for (int i=0;i<num_lines; i++) {
88 String objectString = u.nextToken();
89 tempObj = (server == null) ? new CVWObjNum(objectString) : new CVWObjNum(objectString + "@" + server);
90 try {
91 tmpUser = (CVWUser)cache.get(tempObj);
92 } catch (ClassCastException cce) { // don't know why this is happening. Assume cache retrieval was null (???)
93 tmpUser = null;
94 }
95 if (tmpUser == null) {
96 users[i] = (server == null) ? new CVWUser() : new CVWUser(CVWServerList.getCVWServerList().getServer(server));
97 users[i].objNum = tempObj;
98 users[i].setCached(false);
99 }
100 else
101 users[i] = tmpUser;
102 users[i].name = n.nextToken();
103 //users[i].setEmail(e.nextToken());
104 users[i].setRawDetailName(f.nextToken());
105
106 rooms[i] = r.nextToken();
107 times[i] = (new Integer(t.nextToken())).intValue();
108 busyVal[i] = b.nextToken();
109 }
110 updateUserList(users,rooms,times,messages,busyVal);
111 }
112
113 public void updateAllUsers(String objstr, String nameStr, String roomstr, String emailstr, String timestr, String fNameStr, String busy) {
114 updateAllUsers(objstr, nameStr, roomstr, emailstr, timestr, fNameStr, busy, null);
115 }
116
117 /**
118 * Returns an array of strings for the object sent in. The array format
119 * was determined by the MultiList widget.
120 *
121 * @param anObj the object for which the data is desired
122 * @return the array of strings
123 */
124 public String[] getStringArray(OnlineUserObject anObj) {
125 String room = anObj.getRoom();
126 String time;
127 if (anObj.isDisconnected()) {
128 room = "Disconnected";
129 int i = anObj.getIdleTime();
130 //System.err.println(i);
131 String str;
132 if (i == 999999999 || i == -1)
133 time = "---";
134 else {
135 str = Integer.toString(i);
136 Date now = new Date();
137 long n = now.getTime();
138 long l = DateUtils.convertDateFromServer(str);
139 long sub = n - l;
140 if (sub < 0)
141 sub = n;
142 Date d = new Date(sub);
143 time = DateUtils.formatDateTime(d);
144 }
145 }
146 else
147 time = anObj.getIdleTimeStr() + anObj.getBusyStr();
148 String[] strlist= {anObj.getDetailName(), anObj.getName(),
149 //anObj.getEmail(),
150 room, time};
151 return strlist;
152 }
153
154 }