Source code: org/mitre/cvw/AuditListFrame.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 javax.swing.*;
10 import java.awt.*;
11 import java.util.*;
12
13 //public class AuditListFrame extends CVWFrame
14 /**
15 * This class displays a static of objects owned by a CVW user.
16 * It also displays a list of objects that the user has permissions to edit.
17 * Because this list is static, the user must close and reopen the window.
18 * Currently this client only allows the current user to view their own objects,
19 * and not objects owned by a different user. This limitation is not in this code
20 * but as a filter on the code received from the CVW server.
21 * @version
22 * @author Deb Ercolini
23 */
24 public class AuditListFrame extends FolderDialog {
25 // class variable declarations
26 AuditList ownObjectsPanel, sharedObjectsPanel;
27 GridBagLayout gridbag = new GridBagLayout();
28
29 AuditListFrame(String userName ) {
30 super("Item Window for " +userName);
31
32 ownObjectsPanel = new AuditList(this, "Items created by " + userName, "");
33 addTab("Created", ownObjectsPanel);
34 sharedObjectsPanel = new AuditList(this, "Items shared with " + userName, null);
35 addTab("Shared", sharedObjectsPanel);
36
37 //folder.setFont(new Font("Helvetica",Font.BOLD, 12));
38
39 pack();
40
41 Point jcvwLoc = CVWCoordinator.getJCVWXY();
42 System.err.println(jcvwLoc);
43 setLocation(jcvwLoc.x - 20, jcvwLoc.y - 20);
44 setHelp("Currently waiting on information from the server.");
45
46 setEditability("0");
47 }
48
49 /**
50 * Process the MCP from the CVW server
51 * <br> MCP receive cvw-user-audit
52 * @param user the user this audit is on
53 * @param quota the number of items left allowed for creation on the CVW server
54 * (this is a what the CVW server sends as quota)
55 * @param oNums the spaced delimeted list of object numbers for objects owned
56 * @param envs the space delimited list of object numbers where those objects are
57 * @param paths the space delimited list of full paths to where those objects are
58 * @param sharedONums the spaced delimeted list of object numbers for objects shared
59 * @param sharedEnvs the space delimited list of object numbers where those objects are
60 * @param sharedPaths the space delimited list of full paths to where those objects are
61 */
62 public void userAudit(CVWObject user, String quota, String oNums, String envs, String paths, String sharedONums, String sharedEnvs, String sharedPaths) {
63
64 StringTokenizer o = new StringTokenizer(oNums, " ");
65 int num = o.countTokens();
66 Vector objs = new Vector(num);
67 Vector location = new Vector(num);
68 Vector fullPaths = new Vector(num);
69
70 paths = CVWServerComm.parseBarDelimitedStringFromServer(paths);
71 processObjects(o, envs, paths, objs, location, fullPaths);
72
73 //process the shared objects in same fashion
74 o = new StringTokenizer(sharedONums, " ");
75 num = o.countTokens();
76 Vector objsShared = new Vector(num);
77 Vector locShared = new Vector(num);
78 Vector fPathsShared = new Vector(num);
79
80 sharedPaths = CVWServerComm.parseBarDelimitedStringFromServer(sharedPaths);
81 processObjects(o, sharedEnvs, sharedPaths, objsShared, locShared, fPathsShared);
82
83 updateObjects(quota, objs, location, fullPaths, objsShared, locShared, fPathsShared);
84 }
85
86 /**
87 * Process the object, location and fullpath strings populating the vectors with
88 * CVWObjects, CVWObjects, and full path Strings respectively
89 * @param o the object numbers to be processed
90 * @param lStr the locations of those objects
91 * @param pStr the full paths of thos objects
92 * @param objs the return vector of CVWObjects
93 * @param locs the return vector of CVWObjects which are locations of those CVWObjects
94 * @param paths the return vector of full path strings of thos CVWObjects
95 * @return <code>true</code> if the objects were processed without error
96 */
97 public boolean processObjects(StringTokenizer o, String lStr, String pStr, Vector objs, Vector locs, Vector paths) {
98 int num;
99 num = o.countTokens();
100 if (num == 0) return true;
101
102 StringTokenizer e = new StringTokenizer(lStr, " ");
103 StringTokenizer p = new StringTokenizer(pStr, "|");
104 CVWObjNum objNum;
105 CVWObject obj;
106 CVWCache cache = CVWCache.getInstance();
107
108 if (num != e.countTokens()) { //shouldnt happen
109 System.err.println(num + " envs tokens diff" + e.countTokens());
110 return false;
111 }
112 if (num != p.countTokens()) { //shouldnt happen
113 System.err.println(num + " paths tokens diff" + p.countTokens());
114 return false;
115 }
116
117 for (int i=0;i<num; i++) {
118 objNum = new CVWObjNum(o.nextToken());
119 obj = (CVWObject)(cache.get(objNum));
120 if (obj == null) {
121 obj = new CVWObject();
122 obj.objNum = objNum;
123 obj.name = null;
124 }
125 objs.addElement(obj);
126 objNum = new CVWObjNum(e.nextToken());
127 obj = (CVWObject)(cache.get(objNum));
128 if (obj == null) {
129 obj = new CVWObject();
130 obj.objNum = objNum;
131 obj.name = new String();
132 }
133 locs.addElement(obj);
134 paths.addElement(p.nextToken());
135 }
136 return true;
137 }
138
139 /**
140 * Updates the lists.
141 * @param quota the max number of items allowed for creation on the CVW server
142 * @param objs a vector of objects owned
143 * @param locObjs a vector of objects where those objects are
144 * @param fullPaths a vector of full paths to where those objects are
145 * @param sharedObjs a vector of objects shared with this user
146 * @param sharedLocObjs a vector of objects where the shared objects are
147 * @param sharedFullPaths a vector of full paths to where those shared objects are
148
149 */
150 public void updateObjects(String quota, Vector objs, Vector locObjs, Vector fullPaths, Vector sharedObjs, Vector sharedLocObjs, Vector sharedFullPaths) {
151
152 setHelp("Currently updating lists");
153 getDocTypes(objs, sharedObjs);
154 ownObjectsPanel.updateAuditList(objs, locObjs, fullPaths, quota);
155 sharedObjectsPanel.updateAuditList(sharedObjs, sharedLocObjs, sharedFullPaths);
156 }
157
158 /**
159 * Retrieves the document types from the Document server for both
160 * owned and shared objects, if any.
161 * @param objs the objects owned by this user
162 * @param sharedObjs the objects shared with this user
163 */
164 public void getDocTypes(Vector objs, Vector sharedObjs) {
165 Vector docIDs = new Vector(objs.size());
166 //docs = new Hashtable();
167 Vector docs = new Vector(objs.size());
168 CVWDocument doc;
169 for (int i=0;i<objs.size();i++) {
170 if (objs.elementAt(i) instanceof CVWDocument) {
171 doc = (CVWDocument)objs.elementAt(i);
172 docs.addElement(doc);
173 docIDs.addElement(doc.docID);
174 }
175 }
176 for (int i=0;i<sharedObjs.size();i++) {
177 if (sharedObjs.elementAt(i) instanceof CVWDocument) {
178 doc = (CVWDocument)sharedObjs.elementAt(i);
179 docs.addElement(doc);
180 docIDs.addElement(doc.docID);
181 }
182 }
183 if (docIDs.size() == 0) return;
184 CVWDocument.getDocTypes(docs, docIDs, false);
185 }
186
187
188 /**
189 * Unselects object from other AuditList panel.
190 * 12/29/97 dage
191 * @param aList the current AuditList
192 */
193 public void currentSelection(AuditList aList) {
194 if (aList.equals(ownObjectsPanel))
195 sharedObjectsPanel.select(-1);
196 if (aList.equals(sharedObjectsPanel))
197 ownObjectsPanel.select(-1);
198 }
199
200 /**
201 * Gets the preferred size of this component.
202 * @return A dimension object indicating this component's preferred size.
203 */
204 public Dimension getPreferredSize() {
205 Dimension screen = JCVWApplic.getScreenDimension();
206 int width, height;
207 width = Math.min(2 * screen.width / 3, 690);
208 height = Math.min(screen.height / 2, 350);
209
210 return new Dimension(width, height);
211 }
212
213 /**
214 * Closes the window, removing it from the window manager.
215 * Overrides FolderDialog#cancel
216 * @see WindowMgr#removeTooWindow
217 */
218 public void cancel() {
219 (WindowMgr.getWindowMgr()).removeToolWindow(this);
220 this.dispose();
221 }
222
223 }