Revision 023f6f1e

b/.classpath
27 27
	<classpathentry kind="lib" path="lib/gwt-dnd-3.0.1.jar"/>
28 28
	<classpathentry kind="lib" path="ear/lib/ldap.jar"/>
29 29
	<classpathentry kind="lib" path="ear/lib/commons-codec-1.4.jar">
30
	       <attributes>
31
                        <attribute name="javadoc_location" value="http://commons.apache.org/codec/api-release/"/>
32
                </attributes>
30
		<attributes>
31
			<attribute name="javadoc_location" value="http://commons.apache.org/codec/api-release/"/>
32
		</attributes>
33 33
	</classpathentry>
34
	<classpathentry kind="lib" path="lib/gwt-incubator-20100204-r1747.jar"/>
35
	<classpathentry kind="lib" path="lib/gwt-visualization.jar"/>
34 36
	<classpathentry kind="output" path="bin"/>
35 37
</classpath>
b/.hgignore
1 1
syntax: regexp
2 2
^build\.properties$
3 3
^www$
4
^wwwadmin$
4 5
^bin$
5 6
.DS_Store$
6 7
^tomcat
b/GSS-admin.launch
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
3
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4
<listEntry value="/gss"/>
5
</listAttribute>
6
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
7
<listEntry value="4"/>
8
</listAttribute>
9
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
10
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
11
<mapEntry key="GWT_EXTERNAL_BROWSER" value="firefox"/>
12
</mapAttribute>
13
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
14
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;gss&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
15
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.USER_LIBRARY/GWT Dev Library&quot; path=&quot;3&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
16
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/gss/src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
17
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#13;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;gss&quot;/&gt;&#13;&#10;&lt;/runtimeClasspathEntry&gt;&#13;&#10;"/>
18
</listAttribute>
19
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
20
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
21
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.GWTShell"/>
22
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-noserver -out www -whitelist &quot; ^http[:][/][/]127[.]0[.]0[.]1[:]8080&quot; http://127.0.0.1:8080/admin/"/>
23
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gss"/>
24
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx128m"/>
25
</launchConfiguration>
b/build.xml
8 8
	<property name="root.context" value="gss" />
9 9
	<property name="gwt.module" value="gr.ebs.gss.GSS" />
10 10
	<property name="gwt.module.class" value="GSS" />
11
	<property name="gwt.admin.module" value="gr.ebs.gss.admin.TwoAdmin" />
12
	<property name="gwt.admin.module.class" value="TwoAdmin" />
11 13
	<property name="gwt.workers" value="1" />
12 14

  
13 15
	<property environment="env" />
......
63 65
	<property name="test.build.dir" value="${build.dir}" />
64 66
	<property name="test.build.classes.dir" value="${test.build.dir}/" />
65 67
	<property name="gwt.www.dir" value="${basedir}/www" />
68
	<property name="gwt.www.admin.dir" value="${basedir}/wwwadmin" />
66 69
	<property name="dist.war" value="${ant.project.name}.war"/>
70
	<property name="dist.admin.war" value="${ant.project.name}-admin.war"/>
67 71
	<property name="webdav.war" value="webdav.war"/>
68 72
	<property name="dist.ear" value="${ant.project.name}.ear"/>
69 73

  
70 74
	<property name="war.dir" value="${basedir}/war" />
71 75
	<property name="war.web-inf.dir" value="${war.dir}/WEB-INF"/>
72 76
	<property name="war.lib.dir" value="${war.web-inf.dir}/lib"/>
77
	<property name="war.admin.dir" value="${basedir}/waradmin" />
78
	<property name="war.admin.web-inf.dir" value="${war.dir}/WEB-INF"/>
79
	<property name="war.admin.lib.dir" value="${war.web-inf.dir}/lib"/>
73 80
	<property name="webdav.war.dir" value="${basedir}/webdav" />
74 81
	<property name="webdav.war.web-inf.dir" value="${webdav.war.dir}/WEB-INF"/>
75 82
	<property name="webdav.war.lib.dir" value="${webdav.war.web-inf.dir}/lib"/>
......
103 110
		<pathelement location="${junit.path}/junit.jar"/>
104 111
		<pathelement location="${basedir}/lib/gwt-dnd-3.0.1.jar"/>
105 112
		<pathelement location="${basedir}/lib/gwt-gears.jar"/>
106
		
113
		<pathelement location="${basedir}/lib/gwt-incubator-20100204-r1747.jar"/>
114
		<pathelement location="${basedir}/lib/gwt-visualization.jar"/>
107 115
	</path>
108 116

  
109 117
	<target name="install" description="Installs the configuration files of the application server">
......
209 217
		<jar destfile="${build.dir}/${ant.project.name}.jar">
210 218
			<fileset dir="bin">
211 219
				<include name="org/json/**" />
220
				<include name="**/client/AdminService.class" />
212 221
				<include name="**/server/**" />
213 222
				<exclude name="**/domain/**"/>
214 223
				<exclude name="**/ejb/**"/>
215
				<exclude name="**/soap/**"/>
216 224
			</fileset>
225
			<fileset dir="src">
226
				<include name="**/*.xml" />
227
				<include name="**/client/exceptions/**" />
228
				</fileset>
217 229
		</jar>
218 230
	</target>
219 231

  
......
233 245
				<include name="**/exceptions/**" />
234 246
				<include name="**/domain/**" />
235 247
				<include name="**/ejb/**" />
236
				<include name="**/soap/**" />
237 248
				<exclude name="**/*Test.class"/>
238 249
			</zipfileset>
239 250
		</jar>
......
245 256
			<mergemapper to="${build.dir}/www/gr.ebs.gss.GSS.nocache.js"/>
246 257
		</uptodate>
247 258
	</target>
248
	
259

  
249 260
	<target name="gwt-compile" depends="check-gwt-compile" unless="compilation-not-needed" description="Compile client code to JavaScript">
250
	    	<condition property="gwt-dev-lib" value="${gwt.path}/gwt-dev.jar">
251
		    	<available file="${gwt.path}/gwt-dev.jar" />
252
	    	</condition>
261
    	<condition property="gwt-dev-lib" value="${gwt.path}/gwt-dev.jar">
262
	    	<available file="${gwt.path}/gwt-dev.jar" />
263
    	</condition>
264
		
265
		<java classname="com.google.gwt.dev.Compiler" failonerror="true" fork="true">
266
			<!--arg value="-style"/>
267
			<arg value="DETAILED"/-->
268
			<arg value="-localWorkers" />
269
			<arg value="${gwt.workers}" />
270
			<arg value="-war"/>
271
			<arg value="${gwt.www.dir}"/>
272
			<arg value="${gwt.module}"/>
253 273
			
254
			<java classname="com.google.gwt.dev.Compiler" failonerror="true" fork="true">
255
				<!--arg value="-style"/>
256
 				<arg value="DETAILED"/-->
257
				<arg value="-localWorkers" />
258
				<arg value="${gwt.workers}" />
259
				<arg value="-war"/>
260
				<arg value="${gwt.www.dir}"/>
261
				<arg value="${gwt.module}"/>
262
				
263
			    <classpath>
264
			    	<pathelement location="dist/test.jar"/>
265
			        <pathelement path="${gwt-dev-lib}"/>
266
					<path refid="project.class.path" />
267
					<pathelement path="${src.dir}" />
268
			    </classpath>
269
			</java>
270
			<mkdir dir="${build.dir}/www"/>
271
			<copy todir="${build.dir}/www">
272
				<fileset dir="${gwt.www.dir}/${gwt.module}" excludes="**/${gwt.module.class}.html">
273
				</fileset>
274
			</copy>
275
			<copy file="${gwt.www.dir}/${gwt.module}/${gwt.module.class}.html" tofile="${build.dir}/www/index.html" />
276
		</target>
274
		    <classpath>
275
		        <pathelement path="${gwt-dev-lib}"/>
276
				<path refid="project.class.path" />
277
				<pathelement path="${src.dir}" />
278
		    </classpath>
279
		</java>
280
		<mkdir dir="${build.dir}/www"/>
281
		<copy todir="${build.dir}/www">
282
			<fileset dir="${gwt.www.dir}/${gwt.module}" excludes="**/${gwt.module.class}.html">
283
			</fileset>
284
		</copy>
285
		<copy file="${gwt.www.dir}/${gwt.module}/${gwt.module.class}.html" tofile="${build.dir}/www/index.html" />
286
	</target>
277 287
	
278 288
	<target name="package-war" depends="gwt-compile, package-code" description="Package up the web part as a war">
279 289
		<jar destfile="${build.dir}/${dist.war}">
280 290
			<zipfileset dir="${war.dir}" >
281
			                                <exclude name="**/classes/**"/>
282
			                                </zipfileset>
283

  
291
			    <exclude name="**/classes/**"/>
292
			</zipfileset>
284 293
			<zipfileset dir="${build.dir}/www" />
285 294
			<zipfileset dir="${build.dir}" prefix="WEB-INF/lib">
286 295
				<include name="${ant.project.name}.jar" />
287 296
			</zipfileset>
297
		</jar>
298
	</target>
299
	
300
	<target name="check-gwt-admin-compile" depends="compile">
301
		<uptodate property="compilation-not-needed">
302
			<srcfiles dir="${src.dir}" excludes="**/server/**"/>
303
			<mergemapper to="${build.dir}/wwwadmin/gr.ebs.gss.admin.TwoAdmin.nocache.js"/>
304
		</uptodate>
305
	</target>
306

  
307
	<target name="gwt-admin-compile" depends="check-gwt-admin-compile" unless="compilation-not-needed" description="Compile client code to JavaScript">
308
    	<condition property="gwt-dev-lib" value="${gwt.path}/gwt-dev.jar">
309
	    	<available file="${gwt.path}/gwt-dev.jar" />
310
    	</condition>
311
		
312
		<java classname="com.google.gwt.dev.Compiler" failonerror="true" fork="true">
313
			<!--arg value="-style"/>
314
			<arg value="DETAILED"/-->
315
			<arg value="-localWorkers" />
316
			<arg value="${gwt.workers}" />
317
			<arg value="-war"/>
318
			<arg value="${gwt.www.admin.dir}"/>
319
			<arg value="${gwt.admin.module}"/>
320
            <jvmarg value="-Xmx128m"/>						
321
		    <classpath>
322
		        <pathelement path="${gwt-dev-lib}"/>
323
				<path refid="project.class.path" />
324
				<pathelement path="${src.dir}" />
325
		    </classpath>
326
		</java>
327
		<mkdir dir="${build.dir}/wwwadmin"/>
328
		<copy todir="${build.dir}/wwwadmin">
329
			<fileset dir="${gwt.www.admin.dir}/${gwt.admin.module}" excludes="**/${gwt.admin.module.class}.html">
330
			</fileset>
331
		</copy>
332
		<copy file="${gwt.www.admin.dir}/${gwt.admin.module}/${gwt.admin.module.class}.html" tofile="${build.dir}/wwwadmin/index.html" />
333
	</target>
334
		
335
	<target name="package-admin-war" depends="gwt-admin-compile, package-code" description="Package up the web part as a war">
336
		<jar destfile="${build.dir}/${dist.admin.war}">
337
			<zipfileset dir="${war.admin.dir}" >
338
				  <exclude name="**/classes/**"/>
339
            </zipfileset>
340
			<zipfileset dir="${build.dir}/wwwadmin" />
341
			<zipfileset dir="${build.dir}" prefix="WEB-INF/lib">
342
				<include name="${ant.project.name}.jar" />
343
			</zipfileset>
288 344
			<zipfileset dir="${gwt.path}" prefix="WEB-INF/lib">
289 345
				<include name="gwt-servlet.jar" />
290 346
			</zipfileset>
......
307 363
		</jar>
308 364
	</target>
309 365
	
310
	<target name="package-ear" depends="package-war, package-webdav-war, package-ejb, package-mbeans" description="Package up the project as an ear">
366
	<target name="package-ear" depends="package-admin-war, package-war, package-webdav-war, package-ejb, package-mbeans" description="Package up the project as an ear">
311 367
		<jar destfile="${build.dir}/${dist.ear}">
312 368
			<zipfileset dir="${ear.dir}" />
313 369
			<zipfileset dir="${build.dir}">
314 370
				<include name="ejbs.jar" />
315 371
				<include name="${dist.war}" />
316 372
				<include name="${webdav.war}" />
373
                <include name="${dist.admin.war}" />
317 374
				<include name="${mbeans.dist.file}"/>
318 375
			</zipfileset>
319 376
		</jar>
......
338 395
	<target name="clean" description="Delete the contents of the bin and www directories">
339 396
		<delete dir="${build.dir}" />
340 397
		<delete dir="${gwt.www.dir}" />
398
		<delete dir="${gwt.www.admin.dir}" />
341 399
	</target>
342 400

  
343 401
	<target name="test" description="Performs unit tests on the project" depends="compile">
b/ear/META-INF/application.xml
9 9
	</module>
10 10
	<module>
11 11
		<web>
12
			<web-uri>gss-admin.war</web-uri>
13
			<context-root>/admin</context-root>
14
		</web>
15
	</module>
16
	<module>
17
		<web>
12 18
			<web-uri>webdav.war</web-uri>
13 19
			<context-root>/webdav</context-root>
14 20
		</web>
b/jboss/conf/gss.properties
3 3
restUrl=http://127.0.0.1:8080/pithos/rest/
4 4
loginUrl=http://127.0.0.1:8080/pithos/login
5 5
externalApiPath=gss/ExternalAPIBean/local
6
adminApiPath=gss/AdminAPIBean/local
6 7
version=1.0.0-beta
7 8
noUsernameMessage=<B>No username found in the Shibboleth attributes!</B><P>Your Identity Provider sent the following attributes:
8 9
fileRepositoryPath=/tmp/gss-root
b/jboss/conf/roles.properties
1
#
2
# user=role1,role2,...
3
#
4
admin=admin
b/jboss/conf/users.properties
1
#
2
# user=password
3
#
4
admin=manager
b/src/gr/ebs/gss/admin/TwoAdmin.gwt.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<module>
3
  <!-- Inherit the core Web Toolkit stuff.                        -->
4
  <inherits name='com.google.gwt.user.User'/>
5
  <inherits name='com.google.gwt.user.datepicker.DatePicker'/>
6
	
7
  <!-- Inherit the default GWT style sheet.  You can change       -->
8
  <!-- the theme of your GWT application by uncommenting          -->
9
  <!-- any one of the following lines.                            -->
10
  <inherits name="com.google.gwt.user.theme.standard.Standard"/>
11
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
12
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->
13
	<inherits name='com.google.gwt.gen2.Gen2' /> 
14
    <inherits name="com.google.gwt.visualization.Visualization"/>
15
	<inherits name='gr.ebs.gss.client.exceptions' />
16
	<inherits name='gr.ebs.gss.server.domain.dto' />
17
   <!-- <set-property name="user.agent" value="gecko,gecko1_8" />-->   
18

  
19
  <!-- Specify the app entry point class.                         -->
20
  <entry-point class='gr.ebs.gss.admin.client.TwoAdmin'/>
21

  
22
  <!-- Specify the paths for translatable code                    -->
23
  <source path='client'/>
24
</module>
b/src/gr/ebs/gss/admin/client/AdminService.java
1
package gr.ebs.gss.admin.client;
2

  
3
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
4
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
5
import gr.ebs.gss.client.exceptions.RpcException;
6
import gr.ebs.gss.server.domain.dto.FileBodyDTO;
7
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
8
import gr.ebs.gss.server.domain.dto.PermissionDTO;
9
import gr.ebs.gss.server.domain.dto.StatsDTO;
10
import gr.ebs.gss.server.domain.dto.SystemStatsDTO;
11
import gr.ebs.gss.server.domain.dto.UserClassDTO;
12
import gr.ebs.gss.server.domain.dto.UserDTO;
13

  
14
import java.util.Date;
15
import java.util.List;
16
import java.util.Set;
17

  
18
import com.google.gwt.user.client.rpc.RemoteService;
19
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
20

  
21
@RemoteServiceRelativePath("admin")
22
public interface AdminService extends RemoteService {
23
	List<UserDTO> getUsers() throws RpcException;
24

  
25
	List<UserDTO> searchUsers(String query) throws RpcException;
26

  
27
	StatsDTO getUserStatistics(Long userId) throws RpcException, ObjectNotFoundException;
28

  
29
	void toggleActiveUser(Long userId) throws RpcException,ObjectNotFoundException;
30

  
31
	void setFilePermissions(String uri, Set<PermissionDTO> permissions)	throws RpcException, ObjectNotFoundException;
32

  
33
	SystemStatsDTO getSystemStatistics() throws RpcException,ObjectNotFoundException;
34

  
35
	public List<UserDTO> getLastLoggedInUsers(Date lastLoginDate) throws RpcException;
36

  
37
	public void logout();
38

  
39
	public List<FileHeaderDTO> searchFiles(String query) throws RpcException, ObjectNotFoundException, InsufficientPermissionsException;
40

  
41
	UserDTO getUser(String username) throws ObjectNotFoundException, RpcException;
42

  
43
	FileHeaderDTO getFile(long fileId) throws ObjectNotFoundException, RpcException;
44

  
45
	public List<FileBodyDTO> getVersions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException,RpcException;
46

  
47
	List<UserDTO> getUsersWaitingActivation() throws RpcException;
48

  
49
	void changeUserClass(Long userId,Long userClassId) throws RpcException,ObjectNotFoundException;
50

  
51
	List<UserClassDTO> getUserClasses() throws RpcException;
52

  
53
	void saveOrUpdateUserClass(UserClassDTO userClass) throws RpcException,ObjectNotFoundException;
54

  
55
	void removeUserClass(UserClassDTO userClass) throws RpcException,ObjectNotFoundException;
56

  
57
	void removeUser(Long userId) throws RpcException,ObjectNotFoundException,InsufficientPermissionsException;
58
}
b/src/gr/ebs/gss/admin/client/AdminServiceAsync.java
1
package gr.ebs.gss.admin.client;
2

  
3
import gr.ebs.gss.server.domain.dto.FileBodyDTO;
4
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
5
import gr.ebs.gss.server.domain.dto.PermissionDTO;
6
import gr.ebs.gss.server.domain.dto.StatsDTO;
7
import gr.ebs.gss.server.domain.dto.SystemStatsDTO;
8
import gr.ebs.gss.server.domain.dto.UserClassDTO;
9
import gr.ebs.gss.server.domain.dto.UserDTO;
10

  
11
import java.util.Date;
12
import java.util.List;
13
import java.util.Set;
14

  
15
import com.google.gwt.user.client.rpc.AsyncCallback;
16

  
17
public interface AdminServiceAsync {
18
	void getUsers(AsyncCallback<List<UserDTO>> callback);
19

  
20
	void getUserStatistics(Long userId, AsyncCallback<StatsDTO> callback);
21

  
22
	void toggleActiveUser(Long userId, AsyncCallback<Void> callback);
23

  
24
	void setFilePermissions(String uri, Set<PermissionDTO> permissions, AsyncCallback<Void> callback);
25

  
26
	void searchUsers(String query, AsyncCallback<List<UserDTO>> callback);
27

  
28
	void  getSystemStatistics(AsyncCallback<SystemStatsDTO> callback);
29

  
30
	void getLastLoggedInUsers(Date lastLoginDate, AsyncCallback<List<UserDTO>> callback);
31

  
32
	void logout(AsyncCallback<Void> callback);
33

  
34
	void searchFiles(String query, AsyncCallback<List<FileHeaderDTO>> callback);
35

  
36
	void getUser(String username, AsyncCallback<UserDTO> callback);
37

  
38
	void getFile(long fileId, AsyncCallback<FileHeaderDTO> callback);
39

  
40
	void getVersions(Long userId, Long fileId, AsyncCallback<List<FileBodyDTO>> callback);
41

  
42
	void getUsersWaitingActivation(AsyncCallback<List<UserDTO>> callback);
43

  
44
	void changeUserClass(Long userId, Long userClassId, AsyncCallback<Void> callback);
45

  
46
	void getUserClasses(AsyncCallback<List<UserClassDTO>> callback);
47

  
48
	void saveOrUpdateUserClass(UserClassDTO userClass, AsyncCallback<Void> callback);
49

  
50
	void removeUserClass(UserClassDTO userClass, AsyncCallback<Void> callback);
51

  
52
	void removeUser(Long userId, AsyncCallback<Void> callback);
53
}
b/src/gr/ebs/gss/admin/client/TwoAdmin.java
1
package gr.ebs.gss.admin.client;
2

  
3
import gr.ebs.gss.admin.client.ui.HeaderPanel;
4
import gr.ebs.gss.admin.client.ui.UserPanel;
5
import gr.ebs.gss.admin.client.ui.VisualizationPanel;
6
import gr.ebs.gss.server.domain.dto.SystemStatsDTO;
7

  
8
import com.google.gwt.core.client.EntryPoint;
9
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.event.dom.client.ClickEvent;
11
import com.google.gwt.event.dom.client.ClickHandler;
12
import com.google.gwt.event.logical.shared.ResizeEvent;
13
import com.google.gwt.event.logical.shared.ResizeHandler;
14
import com.google.gwt.event.logical.shared.SelectionEvent;
15
import com.google.gwt.event.logical.shared.SelectionHandler;
16
import com.google.gwt.uibinder.client.UiBinder;
17
import com.google.gwt.uibinder.client.UiField;
18
import com.google.gwt.user.client.Command;
19
import com.google.gwt.user.client.DeferredCommand;
20
import com.google.gwt.user.client.Window;
21
import com.google.gwt.user.client.rpc.AsyncCallback;
22
import com.google.gwt.user.client.ui.Button;
23
import com.google.gwt.user.client.ui.DialogBox;
24
import com.google.gwt.user.client.ui.DockLayoutPanel;
25
import com.google.gwt.user.client.ui.Label;
26
import com.google.gwt.user.client.ui.RootLayoutPanel;
27
import com.google.gwt.user.client.ui.TabLayoutPanel;
28
import com.google.gwt.user.client.ui.VerticalPanel;
29

  
30
/**
31
 * Entry point classes define <code>onModuleLoad()</code>.
32
 */
33
public class TwoAdmin implements EntryPoint {
34

  
35
	interface Binder extends UiBinder<DockLayoutPanel, TwoAdmin> {
36
	}
37

  
38
	private final AdminServiceAsync adminService = GWT.create(AdminService.class);
39

  
40
	private static final Binder binder = GWT.create(Binder.class);
41

  
42
	/**
43
	 * The single TwoAdmin instance.
44
	 */
45
	private static TwoAdmin singleton;
46

  
47
	/**
48
	 * Gets the singleton TwoAdmin instance.
49
	 *
50
	 * @return the TwoAdmin object
51
	 */
52
	public static TwoAdmin get() {
53
		if (TwoAdmin.singleton == null)
54
			TwoAdmin.singleton = new TwoAdmin();
55
		return TwoAdmin.singleton;
56
	}
57

  
58
	@UiField(provided = true)
59
	HeaderPanel headerPanel = new HeaderPanel();
60

  
61
	@UiField UserPanel userPanel;
62

  
63
	@UiField
64
	TabLayoutPanel tabPanel;
65

  
66
	@UiField VisualizationPanel chart2;
67

  
68
	final DialogBox loadingBox = new DialogBox();
69

  
70
	@Override
71
	public void onModuleLoad() {
72
		TwoAdmin.singleton=this;
73
		loadingBox.setHTML("Loading data");
74
		//scroll.setAlwaysShowScrollBars(true);
75
		VerticalPanel vPanel = new VerticalPanel();
76
		loadingBox.setSize("50%", "50%");
77
		loadingBox.setWidget(vPanel);
78
		vPanel.add(new Label("Fetching Requested Data"));
79

  
80
		DockLayoutPanel outer = binder.createAndBindUi(this);
81
		tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
82

  
83
			@Override
84
			public void onSelection(SelectionEvent<Integer> event) {
85
				switch (event.getSelectedItem()) {
86
					case 0:
87
						loadStatistics();
88
						break;
89
					default:
90
						break;
91
				}
92

  
93
			}
94
		});
95

  
96

  
97
		// Get rid of scrollbars, and clear out the window's built-in margin,
98
		// because we want to take advantage of the entire client area.
99
		//Window.enableScrolling(true);
100
		//Window.setMargin("0px");
101
		Window.addResizeHandler(new ResizeHandler(){
102

  
103
			@Override
104
			public void onResize(ResizeEvent event) {
105
				int height=event.getHeight();
106
				resize(height);
107

  
108
			}
109

  
110
		});
111
		RootLayoutPanel root = RootLayoutPanel.get();
112
		root.add(outer);
113
		// RootPanel.get().add(outer);
114
		loadStatistics();
115
		tabPanel.selectTab(0);
116

  
117
		resize(Window.getClientHeight());
118
	}
119

  
120
	private void resize(int height){
121

  
122
		int newHeight = height - tabPanel.getAbsoluteTop()-100;
123
		if (newHeight < 1)
124
			newHeight = 1;
125
		tabPanel.setHeight("" + newHeight);
126
		GWT.log("New Height:"+ newHeight);
127
	}
128
	/**
129
	 * Retrieve the adminService.
130
	 *
131
	 * @return the adminService
132
	 */
133
	public AdminServiceAsync getAdminService() {
134
		return adminService;
135
	}
136

  
137
	public void showErrorBox(String message) {
138
		final DialogBox dialogBox = new DialogBox();
139
		dialogBox.setHTML("An error occured");
140
		VerticalPanel vPanel = new VerticalPanel();
141
		dialogBox.setSize("50%", "50%");
142
		ClickHandler cancelHandler = new ClickHandler() {
143

  
144
			@Override
145
			public void onClick(ClickEvent event) {
146
				dialogBox.hide();
147
			}
148
		};
149
		dialogBox.setWidget(vPanel);
150
		vPanel.add(new Label(message));
151
		Button close = new Button("Close");
152
		close.addClickHandler(cancelHandler);
153
		vPanel.add(close);
154
		dialogBox.center();
155
		dialogBox.show();
156
	}
157

  
158

  
159

  
160
	public void showLoadingBox() {
161
		loadingBox.center();
162
		loadingBox.show();
163
	}
164

  
165
	public void hideLoadingBox(){
166
		loadingBox.hide();
167
	}
168

  
169

  
170
	public void loadStatistics(){
171
		DeferredCommand.addCommand(new Command() {
172

  
173
			@Override
174
			public void execute() {
175
				showLoadingBox();
176
				getAdminService().getSystemStatistics(new AsyncCallback<SystemStatsDTO>() {
177

  
178
					@Override
179
					public void onFailure(Throwable caught) {
180
						hideLoadingBox();
181
						// TODO Auto-generated method stub
182

  
183
					}
184

  
185
					@Override
186
					public void onSuccess(SystemStatsDTO result) {
187
						chart2.updateData(result);
188
						hideLoadingBox();
189
					}});
190

  
191
			}
192
		});
193
	}
194

  
195
	public void searchUsers(String query){
196
		tabPanel.selectTab(1);
197
		userPanel.populateTable(query);
198
	}
199
}
b/src/gr/ebs/gss/admin/client/TwoAdmin.ui.xml
1
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
2
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
3
	xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:admin='urn:import:gr.ebs.gss.admin.client'
4
	xmlns:adminui='urn:import:gr.ebs.gss.admin.client.ui'>
5

  
6
	<g:DockLayoutPanel unit='EM'>
7
		<g:north size='5'>
8
			<adminui:HeaderPanel ui:field='headerPanel' />
9
		</g:north>
10

  
11
		<g:center size='100%'>
12
			<g:TabLayoutPanel barUnit='PX' barHeight='25'
13
				height="600" ui:field="tabPanel">
14

  
15
				<g:tab>
16
					<g:header>Statistics</g:header>
17
					<g:ScrollPanel>
18
						<adminui:VisualizationPanel ui:field="chart2"></adminui:VisualizationPanel>
19
					</g:ScrollPanel>
20

  
21

  
22
				</g:tab>
23
				<g:tab>
24
					<g:header>Search Users</g:header>
25
					<g:ScrollPanel>
26
					<adminui:UserPanel ui:field="userPanel">
27
					</adminui:UserPanel>
28
					</g:ScrollPanel>
29

  
30
				</g:tab>
31
				<g:tab>
32
					<g:header>Files Search</g:header>
33
					<g:ScrollPanel>
34
					<adminui:FilesPanel></adminui:FilesPanel>
35
					</g:ScrollPanel>
36

  
37
				</g:tab>
38
				<g:tab>
39
					<g:header>User Classes</g:header>
40
					<g:ScrollPanel>
41
					<adminui:UserClassListPanel></adminui:UserClassListPanel>
42
					</g:ScrollPanel>
43

  
44
				</g:tab>
45

  
46

  
47
			</g:TabLayoutPanel>
48

  
49
		</g:center>
50
	</g:DockLayoutPanel>
51

  
52

  
53

  
54
</ui:UiBinder> 
b/src/gr/ebs/gss/admin/client/ui/ConfirmationDialog.java
1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.admin.client.ui;
20

  
21
import com.google.gwt.dom.client.NativeEvent;
22
import com.google.gwt.event.dom.client.ClickEvent;
23
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.event.dom.client.KeyCodes;
25
import com.google.gwt.user.client.Event.NativePreviewEvent;
26
import com.google.gwt.user.client.ui.Button;
27
import com.google.gwt.user.client.ui.DialogBox;
28
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
30
import com.google.gwt.user.client.ui.HorizontalPanel;
31
import com.google.gwt.user.client.ui.VerticalPanel;
32

  
33

  
34
/**
35
 * A dialog for requesting confirmation from the user.
36
 *
37
 * @author kman
38
 */
39
public abstract class ConfirmationDialog extends DialogBox {
40

  
41
	/**
42
	 * The widget's constructor.
43
	 *
44
	 * @param message the message to display
45
	 * @param buttonLabel the label of the confirmation button
46
	 */
47
	public ConfirmationDialog(String message, String buttonLabel) {
48
		// Set the dialog's caption.
49
		setText("Confirmation");
50
		setAnimationEnabled(true);
51
		// Create a VerticalPanel to contain the label and the buttons.
52
		VerticalPanel outer = new VerticalPanel();
53
		HorizontalPanel buttons = new HorizontalPanel();
54

  
55
		HTML text = new HTML("<table><tr><td rowspan='2'>" +
56
					//AbstractImagePrototype.create(MessagePanel.images.warn()).getHTML() +
57

  
58
					"</td><td>" + message + "</td></tr></table>");
59
		text.setStyleName("gss-warnMessage");
60
		outer.add(text);
61

  
62
		// Create the 'Update' button, along with a listener that hides the dialog
63
		// when the button is clicked and renames the file.
64
		Button ok = new Button(buttonLabel, new ClickHandler() {
65

  
66
			@Override
67
			public void onClick(ClickEvent event) {
68
				confirm();
69
				hide();
70
			}
71
		});
72
		buttons.add(ok);
73
		buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
74
		// Create the 'Cancel' button, along with a listener that hides the
75
		// dialog when the button is clicked.
76
		Button cancel = new Button("Cancel", new ClickHandler() {
77

  
78
			@Override
79
			public void onClick(ClickEvent event) {
80
				hide();
81
				cancel();
82
			}
83
		});
84
		buttons.add(cancel);
85
		buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
86
		buttons.setSpacing(8);
87
		buttons.setStyleName("gss-warnMessage");
88
		outer.setStyleName("gss-warnMessage");
89
		outer.add(buttons);
90
		outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
91
		outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
92
		setWidget(outer);
93
	}
94

  
95
	@Override
96
	protected void onPreviewNativeEvent(NativePreviewEvent preview) {
97
		super.onPreviewNativeEvent(preview);
98
		NativeEvent evt = preview.getNativeEvent();
99
		if (evt.getType().equals("keydown"))
100
			// Use the popup's key preview hooks to close the dialog when either
101
			// enter or escape is pressed.
102
			switch (evt.getKeyCode()) {
103
				case KeyCodes.KEY_ENTER:
104
					hide();
105
					confirm();
106
					break;
107
				case KeyCodes.KEY_ESCAPE:
108
					hide();
109
					cancel();
110
					break;
111
			}
112
	}
113

  
114
	public abstract void confirm();
115

  
116
	public abstract void cancel();
117
}
b/src/gr/ebs/gss/admin/client/ui/FilesPanel.java
1
package gr.ebs.gss.admin.client.ui;
2

  
3
import gr.ebs.gss.admin.client.TwoAdmin;
4
import gr.ebs.gss.server.domain.dto.FileBodyDTO;
5
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
6
import gr.ebs.gss.server.domain.dto.PermissionDTO;
7

  
8
import java.util.ArrayList;
9
import java.util.HashSet;
10
import java.util.List;
11

  
12
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.event.dom.client.ClickEvent;
14
import com.google.gwt.event.dom.client.ClickHandler;
15
import com.google.gwt.event.dom.client.KeyPressEvent;
16
import com.google.gwt.event.dom.client.KeyPressHandler;
17
import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
18
import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
19
import com.google.gwt.uibinder.client.UiBinder;
20
import com.google.gwt.uibinder.client.UiField;
21
import com.google.gwt.uibinder.client.UiHandler;
22
import com.google.gwt.user.client.Command;
23
import com.google.gwt.user.client.DeferredCommand;
24
import com.google.gwt.user.client.rpc.AsyncCallback;
25
import com.google.gwt.user.client.ui.Button;
26
import com.google.gwt.user.client.ui.Composite;
27
import com.google.gwt.user.client.ui.Grid;
28
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.TextBox;
30
import com.google.gwt.user.client.ui.Widget;
31

  
32
public class FilesPanel extends Composite {
33

  
34
	private static UserPanelUiBinder uiBinder = GWT
35
			.create(UserPanelUiBinder.class);
36

  
37
	interface UserPanelUiBinder extends UiBinder<Widget, FilesPanel> {
38
	}
39

  
40

  
41

  
42
	@UiField TextBox searchBox;
43
	@UiField Button searchButton;
44
	@UiField(provided=true) final FilesTable filesTable = new FilesTable();
45
	@UiField(provided=true) Grid g =new Grid(9,6);
46
	@UiField(provided=true) PermissionsList permissionsGrid = new PermissionsList(new HashSet<PermissionDTO>(),"",true);
47
	@UiField(provided=true) VersionsList versionsList = new VersionsList(new ArrayList<FileBodyDTO>());
48
	private Object lastQuery;
49

  
50
	public FilesPanel() {
51
		g.setCellPadding(5);
52
		g.setCellSpacing(5);
53

  
54
		initWidget(uiBinder.createAndBindUi(this));
55
		searchBox.addKeyPressHandler(new KeyPressHandler() {
56

  
57
			@Override
58
			public void onKeyPress(KeyPressEvent event) {
59
				char keyCode = event.getCharCode();
60
				if (keyCode == '\r')
61
					handleClick(null);
62
			}
63
		});
64
		filesTable.addRowSelectionHandler(new RowSelectionHandler() {
65

  
66
			@Override
67
			public void onRowSelection(RowSelectionEvent event) {
68
				final FileHeaderDTO user = filesTable.getSelectedRowObject(event);
69

  
70
				TwoAdmin.get().showLoadingBox();
71
				if(user!=null)
72
					DeferredCommand.addCommand(new Command() {
73

  
74
						@Override
75
						public void execute() {
76
							TwoAdmin.get().showLoadingBox();
77
							TwoAdmin.get().getAdminService().getFile(user.getId(), new AsyncCallback<FileHeaderDTO>() {
78

  
79
								@Override
80
								public void onSuccess(final FileHeaderDTO result) {
81
									TwoAdmin.get().getAdminService().getVersions(result.getOwner().getId(), result.getId(), new AsyncCallback<List<FileBodyDTO>>() {
82

  
83
										@Override
84
										public void onFailure(Throwable caught) {
85
											GWT.log("Error requesting  file details", caught);
86
											TwoAdmin.get().hideLoadingBox();
87
											TwoAdmin.get().showErrorBox("Error requesting file details");
88

  
89
										}
90

  
91
										@Override
92
										public void onSuccess(List<FileBodyDTO> versions) {
93
											clearFileDetails();
94
											displayFileDetails(result, versions);
95
											TwoAdmin.get().hideLoadingBox();
96

  
97

  
98
										}
99

  
100
									});
101

  
102
								}
103

  
104
								@Override
105
								public void onFailure(Throwable caught) {
106
									GWT.log("Error requesting user statistics file", caught);
107
									TwoAdmin.get().hideLoadingBox();
108
									TwoAdmin.get().showErrorBox("Error requesting user statistics");
109

  
110
								}
111
							});
112

  
113
						}
114
					});
115

  
116
			}
117
		});
118

  
119

  
120
		clearFileDetails();
121

  
122
	}
123

  
124
	@UiHandler("searchButton")
125
	void handleClick(@SuppressWarnings("unused") ClickEvent e){
126
		final String toSearch = searchBox.getText();
127
		if(toSearch == null || "".equals(toSearch.trim())){
128
			TwoAdmin.get().showErrorBox("You must enter a query");
129
			return;
130
		}
131
		lastQuery = toSearch;
132
		populateTable(toSearch);
133
	}
134

  
135

  
136

  
137
	public void populateTable(String query){
138
		TwoAdmin.get().showLoadingBox();
139
		TwoAdmin.get().getAdminService().searchFiles(query,new AsyncCallback<List<FileHeaderDTO>>() {
140

  
141
			@Override
142
			public void onFailure(Throwable caught) {
143
				TwoAdmin.get().hideLoadingBox();
144
				GWT.log("Error fetching files", caught);
145
				TwoAdmin.get().showErrorBox("Unable to Find any Files");
146
			}
147

  
148
			@Override
149
			public void onSuccess(List<FileHeaderDTO> result) {
150
				filesTable.showUsers(result);
151
				clearFileDetails();
152
				TwoAdmin.get().hideLoadingBox();
153

  
154
			}
155

  
156
		});
157
	}
158

  
159

  
160

  
161

  
162
	public void displayFileDetails(final FileHeaderDTO file, List<FileBodyDTO> versions){
163
		clearFileDetails();
164
		versionsList.updateTable(versions);
165
		g.setHTML(0, 0, "<span>"  + "Name:");
166
		g.setHTML(0, 1, file.getName()+"</span>");
167
		g.setHTML(1, 0, "<span>"  + "URI:");
168
		g.setHTML(1, 1, file.getURI()+"</span>");
169
		g.setHTML(2, 0, "<span>"  + "Owner:");
170
		HTML userLabel =new HTML("<a href='#'>"+file.getOwner().getUsername()+"</a></span>");
171
		g.setWidget(2, 1, userLabel );
172

  
173
		userLabel.addClickHandler(new ClickHandler() {
174

  
175
			@Override
176
			public void onClick(ClickEvent event) {
177
				TwoAdmin.get().searchUsers("username:"+file.getOwner().getUsername());
178

  
179
			}
180
		});
181
		g.setHTML(3, 0, "<span>"  + "Size:");
182
		g.setHTML(3, 1, file.getFileSizeAsString()+"</span>");
183
		g.setHTML(4, 0, "<span>"  + "Content Type:");
184
		g.setHTML(4, 1, file.getMimeType()+"</span>");
185

  
186
		g.setHTML(5, 0, "<span>"  + "Creation Date:");
187
		g.setHTML(5, 1, file.getAuditInfo().getCreationDate()+"</span>");
188

  
189
		g.setHTML(6, 0, "<span>"  + "Modification Date:");
190
		g.setHTML(6, 1, file.getAuditInfo().getModificationDate()+"</span>");
191
		if(file.isVersioned())
192
			g.setHTML(7, 0, "<span>"  + "File is Versioned:</span>");
193
		else
194
			g.setHTML(7, 0, "<span>"  + "File is NOT Versioned:</span>");
195
		if(file.isReadForAll()){
196
			g.setHTML(8, 0, "<span>"  + "Read For All:");
197
			g.setHTML(8, 1, file.getURI()+"</span>");
198
		}
199
		permissionsGrid.update(file.getPermissions(), file.getURI());
200
	}
201

  
202
	public void clearFileDetails(){
203
		g.setHTML(0, 0, "<span>"  + "Name:");
204
		g.setHTML(0, 1, ""+"</span>");
205
		g.setHTML(1, 0, "<span>"  + "URI:");
206
		g.setHTML(1, 1, ""+"</span>");
207
		g.setHTML(2, 0, "<span>"  + "Owner:");
208
		g.setHTML(2, 1, ""+"</span>");
209
		g.setHTML(3, 0, "<span>"  + "Size:");
210
		g.setHTML(3, 1, ""+"</span>");
211
		g.setHTML(4, 0, "<span>"  + "Content Type:");
212
		g.setHTML(4, 1, ""+"</span>");
213
		g.setHTML(5, 0, "<span>"  + "Creation Date:");
214
		g.setHTML(5, 1, "</span>");
215

  
216
		g.setHTML(6, 0, "<span>"  + "Modification Date:");
217
		g.setHTML(6, 1, "</span>");
218
		g.setHTML(7, 0, "<span>"  + "File is Versioned:</span>");
219
		g.setHTML(8, 0, "<span>"  + "Read For All:");
220
		g.setHTML(8, 1, "</span>");
221
		permissionsGrid.clear();
222
		versionsList.updateTable(new ArrayList<FileBodyDTO>());
223

  
224

  
225
	}
226

  
227

  
228
	/**
229
	 * Retrieve the lastQuery.
230
	 *
231
	 * @return the lastQuery
232
	 */
233
	public Object getLastQuery() {
234
		return lastQuery;
235
	}
236
}
b/src/gr/ebs/gss/admin/client/ui/FilesPanel.ui.xml
1
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
2
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
3
	xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:adminui='urn:import:gr.ebs.gss.admin.client.ui' 
4
	 xmlns:dp="urn:import:com.google.gwt.user.datepicker.client"
5
	>
6
	<ui:style>
7
		
8
	</ui:style>
9
	
10
	<g:VerticalPanel addStyleNames="Gmnuri3D" width="100%">
11
		<g:HTMLPanel>
12
			<div>
13
				<h3>Files Search</h3>
14
			</div>
15
		</g:HTMLPanel>
16
		<g:HorizontalPanel spacing="3">
17
			<g:cell horizontalAlignment="ALIGN_CENTER" verticalAlignment="ALIGN_MIDDLE">
18
				<g:HTML>Search Files:</g:HTML>
19
			</g:cell>
20
			<g:cell horizontalAlignment="ALIGN_CENTER" verticalAlignment="ALIGN_MIDDLE">
21
				<g:TextBox ui:field="searchBox"  visibleLength="50"></g:TextBox>
22
			</g:cell>
23
			<g:cell horizontalAlignment="ALIGN_CENTER" verticalAlignment="ALIGN_MIDDLE">
24
				<g:Button ui:field="searchButton">Search</g:Button>
25
			</g:cell>
26
			
27
		</g:HorizontalPanel>
28

  
29
		<adminui:FilesTable ui:field="filesTable">
30
		</adminui:FilesTable>
31

  
32
		<g:VerticalPanel width="100%" addStyleNames="Gmnuri3D">
33
			<g:HTMLPanel>
34
				<div>
35
					<h3>File Details</h3>
36
				</div>
37
			</g:HTMLPanel>
38
			<g:HorizontalPanel>
39

  
40
				<g:Grid ui:field="g" width="400px"></g:Grid>
41
				<adminui:PermissionsList ui:field="permissionsGrid"
42
					width="300px"></adminui:PermissionsList>
43
					<adminui:VersionsList ui:field="versionsList"></adminui:VersionsList>
44
			</g:HorizontalPanel>
45
			
46
		</g:VerticalPanel>
47
	</g:VerticalPanel>
48

  
49
</ui:UiBinder> 
b/src/gr/ebs/gss/admin/client/ui/FilesTable.java
1
/*
2
 * Copyright 2010 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.admin.client.ui;
20

  
21
import gr.ebs.gss.admin.client.ui.FilesTable.FileSorter.FileComparator;
22
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
23

  
24
import java.util.ArrayList;
25
import java.util.Collections;
26
import java.util.Comparator;
27
import java.util.Date;
28
import java.util.HashMap;
29
import java.util.Iterator;
30
import java.util.LinkedHashMap;
31
import java.util.LinkedList;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.Set;
35

  
36
import com.google.gwt.core.client.GWT;
37
import com.google.gwt.gen2.table.client.AbstractColumnDefinition;
38
import com.google.gwt.gen2.table.client.AbstractScrollTable.ScrollPolicy;
39
import com.google.gwt.gen2.table.client.AbstractScrollTable.SortPolicy;
40
import com.google.gwt.gen2.table.client.CachedTableModel;
41
import com.google.gwt.gen2.table.client.CellRenderer;
42
import com.google.gwt.gen2.table.client.ColumnDefinition;
43
import com.google.gwt.gen2.table.client.DefaultRowRenderer;
44
import com.google.gwt.gen2.table.client.DefaultTableDefinition;
45
import com.google.gwt.gen2.table.client.FixedWidthGridBulkRenderer;
46
import com.google.gwt.gen2.table.client.MutableTableModel;
47
import com.google.gwt.gen2.table.client.PagingOptions;
48
import com.google.gwt.gen2.table.client.PagingScrollTable;
49
import com.google.gwt.gen2.table.client.ScrollTable;
50
import com.google.gwt.gen2.table.client.SelectionGrid.SelectionPolicy;
51
import com.google.gwt.gen2.table.client.TableDefinition;
52
import com.google.gwt.gen2.table.client.TableDefinition.AbstractCellView;
53
import com.google.gwt.gen2.table.client.TableModel;
54
import com.google.gwt.gen2.table.client.TableModelHelper.Request;
55
import com.google.gwt.gen2.table.client.TableModelHelper.Response;
56
import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
57
import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
58
import com.google.gwt.gen2.table.event.client.TableEvent.Row;
59
import com.google.gwt.i18n.client.DateTimeFormat;
60
import com.google.gwt.user.client.ui.CheckBox;
61
import com.google.gwt.user.client.ui.Composite;
62
import com.google.gwt.user.client.ui.FlexTable;
63
import com.google.gwt.user.client.ui.HTML;
64
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
65
import com.google.gwt.user.client.ui.Label;
66
import com.google.gwt.user.client.ui.VerticalPanel;
67

  
68

  
69
/**
70
 * @author kman
71
 *
72
 */
73
public class FilesTable extends Composite {
74
	private CachedTableModel<FileHeaderDTO> cachedTableModel = null;
75
	private DefaultTableDefinition<FileHeaderDTO> tableDefinition = null;
76
	private PagingScrollTable<FileHeaderDTO> pagingScrollTable = null;
77
	private Label countLabel = new Label("There are no files to display.");
78
	private DataSourceTableModel tableModel = null;
79

  
80
	private VerticalPanel vPanel = new VerticalPanel();
81
	private FlexTable flexTable = new FlexTable();
82

  
83
	/**
84
	 * Constructor
85
	 */
86
	public FilesTable() {
87
		super();
88
		pagingScrollTable = createScrollTable();
89
		pagingScrollTable.setHeight("200px");
90
		pagingScrollTable.setScrollPolicy(ScrollPolicy.DISABLED);
91
		PagingOptions pagingOptions = new PagingOptions(pagingScrollTable);
92

  
93
		flexTable.setWidget(0, 0, pagingScrollTable);
94
		flexTable.getFlexCellFormatter().setColSpan(0, 0, 2);
95
		flexTable.setWidget(1, 0, pagingOptions);
96

  
97
		countLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
98
		vPanel.add(countLabel);
99
		vPanel.add(flexTable);
100

  
101
		vPanel.setWidth("100%");
102
		flexTable.setWidth("100%");
103

  
104
		super.initWidget(vPanel);
105
		showUsers(new ArrayList<FileHeaderDTO>());
106
		pagingScrollTable.setFooterGenerated(true);
107
	}
108

  
109
	public void showUsers(List<FileHeaderDTO> newList) {
110
		countLabel.setText("There are "+ newList.size() + " files.");
111
		tableModel.setData(newList);
112
		tableModel.setRowCount(newList.size());
113
		cachedTableModel.clearCache();
114
		cachedTableModel.setRowCount(newList.size());
115

  
116
		pagingScrollTable.gotoPage(0, true);
117
		if(newList.size()<2)
118
			flexTable.setWidget(1, 0, new HTML());
119
		else{
120
			PagingOptions pagingOptions = new PagingOptions(pagingScrollTable);
121
			flexTable.setWidget(1, 0, pagingOptions);
122
		}
123
	}
124

  
125
	public FileHeaderDTO getUserOnRow(int rowIdx){
126
		String id = pagingScrollTable.getDataTable().getHTML(rowIdx, 0);
127
		final FileHeaderDTO m = tableModel.getUserById(Long.parseLong(id));
128
		return m;
129
	}
130

  
131

  
132
	public FileHeaderDTO getSelectedRowObject(RowSelectionEvent event){
133
		Set<Row> set = event.getSelectedRows();
134
		if(set.size() == 1) {
135
			int rowIdx = set.iterator().next().getRowIndex();
136
			String id = pagingScrollTable.getDataTable().getHTML(rowIdx, 0);
137
			FileHeaderDTO m = tableModel.getUserById(Long.parseLong(id));
138
			return m;
139
		}
140
		return null;
141
	}
142

  
143
	public FileHeaderDTO getUser(Long id){
144

  
145
		return tableModel.getUserById(id);
146
	}
147

  
148

  
149

  
150
	/**
151
	 * Initializes the scroll table
152
	 * @return
153
	 */
154
	private PagingScrollTable<FileHeaderDTO> createScrollTable() {
155
		// create our own table model
156
		tableModel = new DataSourceTableModel();
157
		// add it to cached table model
158
		cachedTableModel = createCachedTableModel(tableModel);
159

  
160
		// create the table definition
161
		TableDefinition<FileHeaderDTO> tableDef = createTableDefinition();
162

  
163
		// create the paging scroll table
164
		pagingScrollTable = new PagingScrollTable<FileHeaderDTO>(cachedTableModel, tableDef);
165
		pagingScrollTable.setPageSize(10);
166
		pagingScrollTable.setEmptyTableWidget(new HTML("There is no data to display"));
167
		pagingScrollTable.getDataTable().setSelectionPolicy(SelectionPolicy.ONE_ROW);
168

  
169
		FixedWidthGridBulkRenderer<FileHeaderDTO> bulkRenderer = new FixedWidthGridBulkRenderer<FileHeaderDTO>(pagingScrollTable.getDataTable(), pagingScrollTable);
170
		pagingScrollTable.setBulkRenderer(bulkRenderer);
171

  
172

  
173
		pagingScrollTable.setCellPadding(3);
174
		pagingScrollTable.setCellSpacing(0);
175
		pagingScrollTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);
176

  
177
		pagingScrollTable.setSortPolicy(SortPolicy.SINGLE_CELL);
178

  
179
		return pagingScrollTable;
180
	}
181

  
182
	public void addRowSelectionHandler(RowSelectionHandler handler){
183
		pagingScrollTable.getDataTable().addRowSelectionHandler(handler);
184
	}
185

  
186
	/**
187
	 * Create the {@link CachedTableModel}
188
	 * @param aTableModel
189
	 * @return
190
	 */
191
	private CachedTableModel<FileHeaderDTO> createCachedTableModel(DataSourceTableModel aTableModel) {
192
		CachedTableModel<FileHeaderDTO> tm = new CachedTableModel<FileHeaderDTO>(aTableModel);
193
		tm.setPreCachedRowCount(20);
194
		tm.setPostCachedRowCount(20);
195
		tm.setRowCount(20);
196
		return tm;
197
	}
198

  
199
	private DefaultTableDefinition<FileHeaderDTO> createTableDefinition() {
200
		tableDefinition = new DefaultTableDefinition<FileHeaderDTO>();
201

  
202
		final String[] rowColors = new String[] { "#FFFFDD", "EEEEEE" };
203
		tableDefinition.setRowRenderer(new DefaultRowRenderer<FileHeaderDTO>(rowColors));
204

  
205
		// id
206
		{
207
			IdColumnDefinition columnDef = new IdColumnDefinition();
208
			columnDef.setColumnSortable(true);
209
			columnDef.setColumnTruncatable(false);
210
			columnDef.setPreferredColumnWidth(35);
211
			columnDef.setHeader(0, new HTML("Id"));
212
			columnDef.setHeaderCount(1);
213
			columnDef.setHeaderTruncatable(false);
214
			tableDefinition.addColumnDefinition(columnDef);
215
		}
216
		{
217
			NameColumnDefinition columnDef = new NameColumnDefinition();
218
			columnDef.setColumnSortable(true);
219
			columnDef.setColumnTruncatable(true);
220
			columnDef.setHeader(0, new HTML("File Name"));
221
			columnDef.setHeaderCount(1);
222
			columnDef.setHeaderTruncatable(false);
223
			tableDefinition.addColumnDefinition(columnDef);
224
		}
225
		{
226
			UriColumnDefinition columnDef = new UriColumnDefinition();
227
			columnDef.setColumnSortable(true);
228
			columnDef.setColumnTruncatable(true);
229
			columnDef.setHeader(0, new HTML("URI"));
230
			columnDef.setHeaderCount(1);
231
			columnDef.setHeaderTruncatable(false);
232
			tableDefinition.addColumnDefinition(columnDef);
233
		}
234
		// username
235
		{
236
			UserColumnDefinition columnDef = new UserColumnDefinition();
237
			columnDef.setColumnSortable(true);
238
			columnDef.setColumnTruncatable(true);
239
			columnDef.setHeader(0, new HTML("Username"));
240
			columnDef.setHeaderCount(1);
241
			columnDef.setHeaderTruncatable(false);
242
			tableDefinition.addColumnDefinition(columnDef);
243
		}
244
		{
245
			FilesizeDefinition columnDef = new FilesizeDefinition();
246
			columnDef.setColumnSortable(true);
247
			columnDef.setColumnTruncatable(true);
248
			columnDef.setHeader(0, new HTML("File Size"));
249
			columnDef.setHeaderCount(1);
250
			columnDef.setHeaderTruncatable(false);
251
			tableDefinition.addColumnDefinition(columnDef);
252
		}
253
		{
254
			DeletedColumnDefinition columnDef = new DeletedColumnDefinition();
255
			columnDef.setColumnSortable(true);
256
			columnDef.setColumnTruncatable(true);
257
			columnDef.setHeader(0, new HTML("Deleted"));
258
			columnDef.setHeaderCount(1);
259
			columnDef.setHeaderTruncatable(false);
260
			columnDef.setCellRenderer(new CellRenderer<FileHeaderDTO, Boolean>() {
261

  
262
				@Override
263
				public void renderRowValue(FileHeaderDTO rowValue, ColumnDefinition<FileHeaderDTO, Boolean> aColumnDef, AbstractCellView<FileHeaderDTO> view) {
264
					CheckBox check = new CheckBox();
265
					check.setValue(aColumnDef.getCellValue(rowValue));
266
					check.setEnabled(false);
267
					view.setWidget(check);
268

  
269
				}
270
			});
271
			tableDefinition.addColumnDefinition(columnDef);
272
		}
273

  
274

  
275
		{
276
			CreationColumnDefinition columnDef = new CreationColumnDefinition();
277
			columnDef.setColumnSortable(true);
278
			columnDef.setColumnTruncatable(true);
279
			columnDef.setHeader(0, new HTML("Creation Date"));
280
			columnDef.setHeaderCount(1);
281
			columnDef.setHeaderTruncatable(false);
282
			tableDefinition.addColumnDefinition(columnDef);
283
		}
284

  
285
		{
286
			LastModifiedColumnDefinition columnDef = new LastModifiedColumnDefinition();
287
			columnDef.setColumnSortable(true);
288
			columnDef.setColumnTruncatable(true);
289
			columnDef.setHeader(0, new HTML("Modification Date"));
290
			columnDef.setHeaderCount(1);
291
			columnDef.setHeaderTruncatable(false);
292
			tableDefinition.addColumnDefinition(columnDef);
293
		}
294

  
295

  
296

  
297
		return tableDefinition;
298
	}
299

  
300

  
301
	private class DataSourceTableModel extends MutableTableModel<FileHeaderDTO> {
302
		private Map<Long, FileHeaderDTO> map;
303
		private FileSorter sorter = new FileSorter();
304
		public void setData(List<FileHeaderDTO> list) {
305
			// toss the list, index by id in a map.
306
			map = new HashMap<Long, FileHeaderDTO>(list.size());
307
			for(FileHeaderDTO m : list)
308
				map.put(m.getId(), m);
309
		}
310

  
311
		public FileHeaderDTO getUserById(long id) {
312
			return map.get(id);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff