Alessandro Pieve 2016-09-27 12:50:15 +00:00
commit a690458420
453 changed files with 21110 additions and 0 deletions

BIN
._.DS_Store Normal file

Binary file not shown.

55
.classpath Normal file
View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/auth-portlet-manager-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/auth-portlet-manager-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/pieve/gwt-2.7.0/gwt-user.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/pieve/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/pieve/gwt-2.7.0/gwt-codeserver.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/pieve/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/pieve/gwt-2.7.0/gwt-dev.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/pieve/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/pieve/gwt-2.7.0/validation-api-1.0.0.GA.jar" sourcepath="/home/pieve/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/pieve/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="output" path="target/auth-portlet-manager-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

53
.project Normal file
View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>auth-portlet-manager</name>
<comment>auth-portlet-manager. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

12
.settings/.jsdtscope Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="WebContent"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=
googleCloudSqlEnabled=false
localDevMySqlEnabled=true

View File

@ -0,0 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/home/pieve/workspace/auth-portlet-manager/src/main/webapp
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
entryPointModules=

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="auth-portlet-manager">
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<property name="context-root" value="auth-portlet-manager"/>
<property name="java-output-path" value="/auth-portlet-manager/target/auth-portlet-manager-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

View File

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@ -0,0 +1 @@
Window

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

1
distro/LICENSE Normal file
View File

@ -0,0 +1 @@
${gcube.license}

68
distro/README Normal file
View File

@ -0,0 +1,68 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
Maintainers
-----------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
https://gcube.wiki.gcube-system.org/gcube/Accounting_Manager
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
https://gcube.wiki.gcube-system.org/gcube/Accounting_Manager
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

5
distro/changelog.xml Normal file
View File

@ -0,0 +1,5 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.admin.authportletmanager.1-0-0" date="2015-10-15">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

32
distro/descriptor.xml Normal file
View File

@ -0,0 +1,32 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

29
distro/profile.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Service</Type>
<Profile>
<Description>${project.description}</Description>
<Class>PortletsAdmin</Class>
<Name>${project.name}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.name}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>webapplication</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

356
pom.xml Normal file
View File

@ -0,0 +1,356 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.admin</groupId>
<artifactId>auth-portlet-manager</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>auth-portlet-manager</name>
<description>auth-portlet-manager</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/auth-portlet-manager</url>
</scm>
<developers>
<developer>
<name>Alessandro Pieve</name>
<email>alessandro.pieve@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- GWT configuration -->
<gwtVersion>2.7.0</gwtVersion>
<gwtLogVersion></gwtLogVersion>
<KEYS>${env.KEYS}</KEYS>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>localRun</id>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<!-- GWT -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
<!-- <version>2.3.2.0</version> -->
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>callout-tour</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<exclusions>
<exclusion>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Portlet -->
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- PORTAL -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<!-- <version>[1.0.2-SNAPSHOT,2.0.0-SNAPSHOT)</version> -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
</dependency>
<!-- GCube Widgets -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[0.2.0-SNAPSHOT,1.0.0-SNAPSHOT)</version>
</dependency>
<!-- LOGGING <dependency> <groupId>com.allen-sauer.gwt.log</groupId> <artifactId>gwt-log</artifactId>
<version>${gwtLogVersion}</version> </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<!-- <version>2.0.0-SNAPSHOT</version> -->
</dependency>
<!-- JUnit TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<!-- Authorization Client -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope> compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope> compile</scope>
</dependency>
<!-- End Authorization Client -->
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xmx1024M -Xss1024k -Dgwt.compiler.localWorkers=1</extraJvmArgs>
<superDevMode>false</superDevMode>
</configuration>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>AuthPortletManager.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.admin.authportletmanager.authman</module>
<!-- <compileSourcesArtifacts> <artifact>com.github.highcharts4gwt:highcharts</artifact>
</compileSourcesArtifacts> -->
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<!--<goals> <goal>exploded</goal> </goals> -->
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
<warName>${project.build.finalName}</warName>
<!-- Include static jar into WEB-INF/lib -->
<!-- <webResources> <resource> <directory>lib</directory> <includes>
<include>*.jar</include> </includes> <targetPath>WEB-INF/lib</targetPath>
</resource> </webResources> -->
</configuration>
</plugin>
<!-- Maven Surefire Plugin for Test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

BIN
src/._.DS_Store Normal file

Binary file not shown.

BIN
src/main/._.DS_Store Normal file

Binary file not shown.

BIN
src/main/java/._.DS_Store Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='authman'>
<inherits name='com.google.gwt.user.User' />
<inherits name="com.google.gwt.http.HTTP" />
<inherits name="com.google.gwt.resources.Resources" />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<inherits name='org.gcube.portlets.widgets.widgettour.WidgetTour' />
<!-- Specify the app entry point class. -->
<entry-point
class='org.gcube.portlets.admin.authportletmanager.client.AuthManager' />
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
</module>

View File

@ -0,0 +1,59 @@
package org.gcube.portlets.admin.authportletmanager.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class AuthManager implements EntryPoint {
@SuppressWarnings("unused")
private AuthManagerController rootPanel;
/**
* {@inheritDoc}
*/
public void onModuleLoad() {
GWT.log("AuthManager - Start Portlet");
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loadScope();
}
});
}
private void loadScope() {
ClientScopeHelper.getService().setScope(Location.getHref(),
new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
GWT.log("AuthManager - Scope Location set!");
if (result) {
loadController();
} else {
GWT.log("AuthManager - Attention ClientScopeHelper has returned a false value!");
}
}
@Override
public void onFailure(Throwable caught) {
GWT.log("AuthManager - Error setting scope: "
+ caught.getLocalizedMessage());
caught.printStackTrace();
}
});
}
protected void loadController() {
rootPanel = new AuthManagerController();
}
}

View File

@ -0,0 +1,766 @@
package org.gcube.portlets.admin.authportletmanager.client;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.admin.authportletmanager.client.event.AddPoliciesEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.AddQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.ListPolicyEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.ListQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.RemovePoliciesEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.RemoveQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.UpdatePolicyEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.UpdateQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.DialogError;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.DialogLoader;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyAddDialog;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyDataGrid;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyDataProvider;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyDeleteDialog;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyFilter;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuotaFilter;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteAddDialog;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteDataGrid;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteDataProvider;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteDeleteDialog;
import org.gcube.portlets.admin.authportletmanager.client.resource.AuthResources;
import org.gcube.portlets.admin.authportletmanager.client.rpc.AuthManagerServiceAsync;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.github.gwtbootstrap.client.ui.Container;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class AuthManagerController {
public static SimpleEventBus eventBus;
private static final String JSP_TAG_ID = "AuthPortletManager";
/** The MainPanell pg mng. */
private Container mainPanelLayout;
/*Start Component for Tab Policy */
/** The SearchPolicy pg mng. */
private PolicyFilter policyfilter =new PolicyFilter();
/** The policyDataGrid pg mng. */
private PolicyDataGrid policydatagrid =new PolicyDataGrid();
/*Start Component for Tab Quota */
/** The SearchQuota pg mng. */
private QuotaFilter quotafilter =new QuotaFilter();
/** The quoteDataGrid pg mng. */
private QuoteDataGrid quotedatagrid =new QuoteDataGrid();
/** Dialog Box for Loading*/
private DialogLoader dialogLoader = new DialogLoader();
/** Dialog Box for Error*/
private DialogError dialogError = new DialogError();
private Integer countLoader=0;
// public String result_test;
public AuthManagerController() {
eventBus = new SimpleEventBus();
init();
}
private void init() {
loadMainPanel();
loadEnviromentPolicy();
//loadEnviromentQuote();
bindToEvents();
}
@SuppressWarnings("unused")
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
}
/**
* @return the eventBus
*/
public EventBus getEventBus() {
return eventBus;
}
private void loadMainPanel(){
GWT.log("AuthManager - LoadMainPanel");
GWT.log("AuthManager -Init Start with -DEBUG_MODE:"+ConstantsSharing.DEBUG_MODE+" DEBUG_TOKEN:"+ConstantsSharing.DEBUG_TOKEN+" MOCKUP:"+ConstantsSharing.MOCK_UP);
AuthResources.INSTANCE.authCSS().ensureInjected();
mainPanelLayout = new Container();
mainPanelLayout.setId("mainPanelLayout_AuthPortlet");
mainPanelLayout.setWidth("98%");
//Panel Policy
DockPanel dockPolicy = new DockPanel();
dockPolicy.setStyleName("Management-Panel");
dockPolicy.setWidth("100%");
dockPolicy.add(policyfilter, DockPanel.NORTH);
dockPolicy.add(policydatagrid, DockPanel.SOUTH);
Tab tab_policy =new Tab();
tab_policy.add(dockPolicy);
tab_policy.setHeading("POLICY");
//Panel Quota
DockPanel dockQuota = new DockPanel();
dockQuota.setStyleName("Management-Panel-Quota");
dockQuota.setWidth("100%");
dockQuota.add(quotafilter, DockPanel.NORTH);
dockQuota.add(quotedatagrid, DockPanel.SOUTH);
/*
Tab tab_quota =new Tab();
tab_quota.add(dockQuota);
tab_quota.setHeading("QUOTA");
*/
TabPanel tabPanel = new TabPanel();
tabPanel.add(tab_policy);
//tabPanel.add(tab_quota);
tab_policy.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("AuthManager - Tab Policy");
loadEnviromentPolicy();
}
});
/*
tab_quota.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("AuthManager - Tab Quota");
loadEnviromentQuote();
}
});
*/
//select first tab
tabPanel.selectTab(0);
mainPanelLayout.add(tabPanel);
bind(mainPanelLayout);
}
protected void bind(Widget mainWidget) {
try {
RootPanel root = RootPanel.get(JSP_TAG_ID);
//Log.info("Root Panel: " + root);
GWT.log("AuthManager - Root Panel: " + root, null);
if (root == null) {
GWT.log("AuthManager - Div with id " + JSP_TAG_ID + " not found, starting in dev mode");
RootPanel.get().add(mainWidget);
} else {
GWT.log("AuthManager - Div with id " + JSP_TAG_ID + " found, starting in portal mode");
root.add(mainWidget);
}
} catch (Exception e) {
e.printStackTrace();
GWT.log("AuthManager - Error in attach viewport:" + e.getLocalizedMessage(), null);
}
}
private void loadEnviromentPolicy() {
countLoader=0;
dialogLoader.startLoader();
loadPolicy(4);
loadCaller(4);
loadServicePolicy(4);
loadAccessPolicy(4);
}
private void loadEnviromentQuote() {
countLoader=0;
dialogLoader.startLoader();
loadCaller(2);
loadQuote(2);
}
private void loadPolicy(final int numberLoad){
//reset provider
PolicyDataProvider.get().resetPolicyProvider();
AuthManagerServiceAsync.INSTANCE
.loadListPolicy(new AsyncCallback<ArrayList<PolicyAuth>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Failed to load a list policy:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(ArrayList<PolicyAuth> result) {
PolicyDataProvider.get().loadPolicyProvider(result);
GWT.log("AuthManager - Load Policy complete");
checkLoader(numberLoad,0);
}
});
}
/**
* Load a caller from AsyncCallBack from server
*/
private void loadCaller(final int numberLoad){
AuthManagerServiceAsync.INSTANCE
.loadListCaller(new AsyncCallback<ArrayList<Caller>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Failed to load a caller:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(ArrayList<Caller> callerList) {
Entities.getInstance();
Entities.setCallers(callerList);
GWT.log("AuthManager - Load Caller complete");
checkLoader(numberLoad,0);
}
});
}
public void loadServicePolicy(final int numberLoad){
AuthManagerServiceAsync.INSTANCE
.loadListService(new AsyncCallback<Map<String, List<String>>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Failed to load a service:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(Map<String, List<String>> result) {
Entities.setServicesMap(result);
GWT.log("AuthManager - Load Service complete");
checkLoader(numberLoad,0);
}
});
}
/***
* Load a list access
*/
public void loadAccessPolicy(final int numberLoad){
AuthManagerServiceAsync.INSTANCE
.loadListAccess(new AsyncCallback <ArrayList<String>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Failes to load an Access:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(ArrayList<String> result) {
Entities.setAccess(result);
GWT.log("AuthManager - Load Access complete");
checkLoader(numberLoad,0);
}
});
}
public void loadQuote(final int numberLoad){
//reset provider
QuoteDataProvider.get().resetQuoteProvider();
AuthManagerServiceAsync.INSTANCE
.loadListQuota(new AsyncCallback<ArrayList<Quote>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Failed to load a list quote:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(ArrayList<Quote> result) {
QuoteDataProvider.get().loadQuoteProvider(result);
GWT.log("AuthManager - Load Quote complete");
checkLoader(numberLoad,1);
}
});
}
/**
* Checkloader for stop dialogbox with loader when finished
*
* @param
* @return
* @see
*/
private void checkLoader(Integer operation,Integer typeGuide){
countLoader++;
if (countLoader.equals(operation)){
GWT.log("AuthManager - Load Complete ");
dialogLoader.stopLoader();
}
}
private void sessionExpiredShowDelayed() {
Timer timeoutTimer = new Timer() {
public void run() {
sessionExpiredShow();
}
};
int TIMEOUT = 3; // 3 second timeout
timeoutTimer.schedule(TIMEOUT * 1000); // timeout is in milliseconds
}
/*
private void checkLocale() {
String[] locales = LocaleInfo.getAvailableLocaleNames();
for (String locale : locales) {
//Log.debug("Locale avaible:" + locale);
}
String currentLocaleCookie = Cookies.getCookie(LocaleInfo
.getLocaleCookieName());
//Log.debug(Constants.AM_LANG_COOKIE + ":" + currentLocaleCookie);
LocaleInfo currentLocaleInfo = LocaleInfo.getCurrentLocale();
//Log.debug("Current Locale:" + currentLocaleInfo.getLocaleName());
}
*/
protected void changeLanguage(String localeName) {
Date now = new Date();
long nowLong = now.getTime();
nowLong = nowLong + (1000 * 60 * 60 * 24 * 21);
now.setTime(nowLong);
String cookieLang = Cookies.getCookie(ConstantsSharing.AM_LANG_COOKIE);
if (cookieLang != null) {
Cookies.removeCookie(ConstantsSharing.AM_LANG_COOKIE);
}
Cookies.setCookie(ConstantsSharing.AM_LANG_COOKIE, localeName, now);
com.google.gwt.user.client.Window.Location.reload();
}
//
public void restoreUISession() {
//checkLocale();
//showDefault();
}
// Bind Controller to events on bus
private void bindToEvents() {
//event bus for add multiple policy
eventBus.addHandler(AddPoliciesEvent.TYPE,
new AddPoliciesEvent.AddPoliciesEventHandler() {
@Override
public void onAdd(AddPoliciesEvent event) {
addPolicies(event);
}
});
//event bus for update policy
eventBus.addHandler(UpdatePolicyEvent.TYPE,
new UpdatePolicyEvent.UpdatePolicyEventHandler() {
@Override
public void onAdd(UpdatePolicyEvent event) {
updatePolicy(event);
}
});
//event bus for refresh list policy
eventBus.addHandler(ListPolicyEvent.TYPE,
new ListPolicyEvent.ListPolicyEventHandler(){
@Override
public void onAdd(ListPolicyEvent event) {
loadEnviromentPolicy();
}
});
//event bus for delete multiple policy
eventBus.addHandler(RemovePoliciesEvent.TYPE,
new RemovePoliciesEvent.RemovePoliciesEventHandler(){
@Override
public void onAdd(RemovePoliciesEvent event) {
removePolicies(event);
}
});
/***
* SECTION QUOTE
*/
//event bus for add multiple quote
eventBus.addHandler(AddQuoteEvent.TYPE,
new AddQuoteEvent.AddQuoteEventHandler() {
@Override
public void onAdd(AddQuoteEvent event) {
addQuote(event);
}
});
//event bus for update quote
eventBus.addHandler(UpdateQuoteEvent.TYPE,
new UpdateQuoteEvent.UpdateQuoteEventHandler() {
@Override
public void onAdd(UpdateQuoteEvent event) {
updateQuote(event);
}
});
//event bus for refresh quote
eventBus.addHandler(ListQuoteEvent.TYPE,
new ListQuoteEvent.ListQuoteEventHandler(){
@Override
public void onAdd(ListQuoteEvent event) {
loadEnviromentQuote();
}
});
//event bus for delete multiple quote
eventBus.addHandler(RemoveQuoteEvent.TYPE,
new RemoveQuoteEvent.RemoveQuoteEventHandler(){
@Override
public void onAdd(RemoveQuoteEvent event) {
removeQuote(event);
}
});
}
protected void addPolicies(AddPoliciesEvent event) {
final List<PolicyAuth> policies = event.getPolicies();
final PolicyAddDialog policyAddDialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.
addPolicies(policies,new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Error add policy failed:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
public void onSuccess(Void result) {
policyAddDialog.StopAppLoadingView();
dialogLoader.stopLoader();
loadPolicy(4);
}
});
}
protected void addQuote(AddQuoteEvent event) {
final List<Quote> quote = event.getQuote();
GWT.log("AuthManager - Demo");
final QuoteAddDialog quotaAddDialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.
addQuote(quote,new AsyncCallback<List<Quote>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Error add policy failed:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(List<Quote> quote) {
for (Quote quota: quote){
GWT.log("AuthManager - Inserted a new quota:"+quota.getCallerAsString()+
" identifier:"+quota.getIdQuote()+
" Time Interval:"+quota.getTimeInterval()+
" Type:"+quota.getManager()+
" Data Insert:"+quota.getDataInsert()
);
//update list for a new caller
QuoteDataProvider.get().addQuoteProvider(quota);
}
quotaAddDialog.StopAppLoadingView();
dialogLoader.stopLoader();
};
});
}
protected void updatePolicy(UpdatePolicyEvent event) {
final PolicyAuth policies = event.getPolicies();
final PolicyAddDialog policyUpdateDialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.updatePolicy(policies,new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("Error update policy failed:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
GWT.log("AuthManager - Update complete");
/*
PolicyDataProvider.get().removePolicyProvider(policy.getIdpolicy());
PolicyDataProvider.get().addPolicyProvider(policy);
*/
policyUpdateDialog.StopAppLoadingView();
dialogLoader.stopLoader();
loadPolicy(4);
};
});
}
protected void updateQuote(UpdateQuoteEvent event) {
final Quote quote = event.getQuote();
final QuoteAddDialog quoteUpdateDialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.updateQuote(quote,new AsyncCallback<Quote>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("Error update quote failed:"+caught.getLocalizedMessage());
caught.printStackTrace();
}
}
@Override
public void onSuccess(Quote quote) {
// TODO Auto-generated method stub
GWT.log("AuthManager - Update complete");
QuoteDataProvider.get().removeQuoteProvider(quote.getIdQuote());
//GWT.log("quote update"+quote.getDataUpdate().toString());
QuoteDataProvider.get().addQuoteProvider(quote);
quoteUpdateDialog.StopAppLoadingView();
dialogLoader.stopLoader();
};
});
}
protected void removePolicies(RemovePoliciesEvent event) {
// TODO Auto-generated method stub
final List<Long> identifier = event.getIdentifier();
final PolicyDeleteDialog dialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.deletePolicies(identifier,new AsyncCallback<List<Long>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Error delete policy failed:"+caught.getLocalizedMessage());
//dialog.StopAppLoadingView();
caught.printStackTrace();
}
}
@Override
public void onSuccess(List<Long> listRemovePolicies) {
for (Long identifier:listRemovePolicies){
PolicyDataProvider.get().removePolicyProvider(identifier);
GWT.log("AuthManager - Delete complete:"+identifier);
}
dialog.StopAppLoadingView();
dialogLoader.stopLoader();
}
});
}
protected void removeQuote(RemoveQuoteEvent event) {
// TODO Auto-generated method stub
final List<Long> identifier = event.getIdentifier();
final QuoteDeleteDialog dialog =event.getDialog();
dialogLoader.startLoader();
AuthManagerServiceAsync.INSTANCE.deleteQuote(identifier,new AsyncCallback<List<Long>>() {
@Override
public void onFailure(Throwable caught) {
if (caught instanceof ExpiredSessionServiceException) {
GWT.log("AuthManager - Alert Expired Session");
sessionExpiredShowDelayed();
} else {
dialogLoader.stopLoader();
dialogError.showError(caught.getLocalizedMessage());
GWT.log("AuthManager - Error delete quote failed:"+caught.getLocalizedMessage());
//dialog.StopAppLoadingView();
caught.printStackTrace();
}
}
@Override
public void onSuccess(List<Long> listRemoveQuote) {
for (Long identifier:listRemoveQuote){
QuoteDataProvider.get().removeQuoteProvider(identifier);
GWT.log("AuthManager - Delete quote complete:"+identifier);
}
dialog.StopAppLoadingView();
dialogLoader.stopLoader();
}
});
}
@SuppressWarnings("unused")
private void asyncCodeLoadingFailed(Throwable reason) {
//Log.error("Async code loading failed", reason);
/*
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
*/
}
}

View File

@ -0,0 +1,95 @@
package org.gcube.portlets.admin.authportletmanager.client;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class Entities {
private static Entities istanza;
private static ArrayList<Caller> callers;
private static Map<String, List<String>> servicesMap;
private static ArrayList<String> access;
private Entities(){
}
public static Entities getInstance()
{
if (istanza == null)
{
istanza = new Entities();
}
return istanza;
}
/**
* getCallers
* @return
*/
public static ArrayList<Caller> getCallers(){
//order by type caller
Collections.sort(callers,new Comparator<Caller>() {
public int compare(Caller o1, Caller o2) {
int c;
c =o1.getTypecaller().compareTo(o2.getTypecaller());
if (c == 0)
c = o1.getCallerName().compareTo(o2.getCallerName());
return c;
}
});
return callers;
}
/**
* callerList
* @param callersList
*/
public static void setCallers(ArrayList<Caller> callersList) {
callers = callersList;
}
public static Caller getCallerByName(String callerName){
for (Caller caller: callers){
if (caller.getCallerName().equals(callerName)){
return caller;
}
}
return null;
}
public static Map<String, List<String>> getServicesMap() {
return servicesMap;
}
public static void setServicesMap(Map<String, List<String>> servicesMapList) {
servicesMap = servicesMapList;
}
public static ArrayList<String> getAccess() {
return access;
}
public static void setAccess(ArrayList<String> access) {
Entities.access = access;
}
}

View File

@ -0,0 +1,75 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyAddDialog;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class AddPoliciesEvent extends
GwtEvent<AddPoliciesEvent.AddPoliciesEventHandler> {
public static Type<AddPoliciesEventHandler> TYPE = new Type<AddPoliciesEventHandler>();
public static Type<AddPoliciesEventHandler> getType() {
return TYPE;
}
private List<PolicyAuth> policies;
private PolicyAddDialog dialog;
public interface AddPoliciesEventHandler extends EventHandler {
void onAdd(AddPoliciesEvent event);
}
public interface HasAddPoliciesEventHandler extends HasHandlers {
public HandlerRegistration addAddPoliciesEventHandler(
AddPoliciesEventHandler handler);
}
public AddPoliciesEvent(List<PolicyAuth> policies,PolicyAddDialog dialog){
super();
this.policies=policies;
this.dialog=dialog;
}
@Override
protected void dispatch(AddPoliciesEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<AddPoliciesEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
AddPoliciesEvent event) {
source.fireEvent(event);
}
public List<PolicyAuth> getPolicies() {
return policies;
}
public PolicyAddDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "AddPoliciesEvent [policies=" + policies + ", dialog=" + dialog
+ "]";
}
}

View File

@ -0,0 +1,110 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyAddDialog;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class AddPolicyEventOld extends
GwtEvent<AddPolicyEventOld.AddPolicyEventHandler> {
public static Type<AddPolicyEventHandler> TYPE = new Type<AddPolicyEventHandler>();
public static Type<AddPolicyEventHandler> getType() {
return TYPE;
}
private String caller;
private String typeCaller;
private String serviceClass;
private String serviceName;
private String serviceId;
private String access;
private PolicyAddDialog dialog;
public interface AddPolicyEventHandler extends EventHandler {
void onAdd(AddPolicyEventOld event);
}
public interface HasAddPolicyEventHandler extends HasHandlers {
public HandlerRegistration addAddPolicyEventHandler(
AddPolicyEventHandler handler);
}
public AddPolicyEventOld
(String caller,String typeCaller,String serviceClass,String serviceName,String serviceId,String access,PolicyAddDialog dialog) {
super();
this.caller = caller;
this.typeCaller=typeCaller;
this.serviceClass = serviceClass;
this.serviceName=serviceName;
this.serviceId=serviceId;
this.access = access;
this.dialog=dialog;
}
@Override
protected void dispatch(AddPolicyEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<AddPolicyEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
AddPolicyEventOld event) {
source.fireEvent(event);
}
public String getCaller() {
return caller;
}
public String getTypeCaller() {
return typeCaller;
}
public String getServiceClass() {
return serviceClass;
}
public String getServiceName() {
return serviceName;
}
public String getServiceId() {
return serviceId;
}
public String getAccess() {
return access;
}
public PolicyAddDialog getModal() {
return dialog;
}
@Override
public String toString() {
return "AddPolicyEvent [caller=" + caller + ", typeCaller="
+ typeCaller + ", serviceClass=" + serviceClass
+ ", serviceName=" + serviceName + ", serviceId=" + serviceId
+ ", access=" + access + ", dialog=" + dialog + "]";
}
}

View File

@ -0,0 +1,75 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteAddDialog;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class AddQuoteEvent extends
GwtEvent<AddQuoteEvent.AddQuoteEventHandler> {
public static Type<AddQuoteEventHandler> TYPE = new Type<AddQuoteEventHandler>();
public static Type<AddQuoteEventHandler> getType() {
return TYPE;
}
private List<Quote> quote;
private QuoteAddDialog dialog;
public interface AddQuoteEventHandler extends EventHandler {
void onAdd(AddQuoteEvent event);
}
public interface HasAddQuoteEventHandler extends HasHandlers {
public HandlerRegistration addAddPoliciesEventHandler(
AddQuoteEventHandler handler);
}
public AddQuoteEvent(List<Quote> quote,QuoteAddDialog dialog){
super();
this.quote=quote;
this.dialog=dialog;
}
@Override
protected void dispatch(AddQuoteEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<AddQuoteEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
AddQuoteEvent event) {
source.fireEvent(event);
}
public List<Quote> getQuote() {
return quote;
}
public QuoteAddDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "AddQuoteEvent [quote=" + quote + ", dialog=" + dialog
+ "]";
}
}

View File

@ -0,0 +1,56 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class ListPolicyEvent extends GwtEvent<ListPolicyEvent.ListPolicyEventHandler> {
public static Type<ListPolicyEventHandler> TYPE = new Type<ListPolicyEventHandler>();
public static Type<ListPolicyEventHandler> getType() {
return TYPE;
}
@Override
public Type<ListPolicyEventHandler> getAssociatedType() {
return TYPE;
}
public interface ListPolicyEventHandler extends EventHandler {
void onAdd(ListPolicyEvent event);
}
public interface HasListPolicyEventHandler extends HasHandlers {
public HandlerRegistration addListPolicyEventHandler(
ListPolicyEventHandler handler);
}
public static void fire(HasHandlers source,
ListPolicyEvent event) {
source.fireEvent(event);
}
public ListPolicyEvent() {
super();
}
@Override
protected void dispatch(ListPolicyEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
}

View File

@ -0,0 +1,57 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class ListQuoteEvent extends GwtEvent<ListQuoteEvent.ListQuoteEventHandler> {
public static Type<ListQuoteEventHandler> TYPE = new Type<ListQuoteEventHandler>();
public static Type<ListQuoteEventHandler> getType() {
return TYPE;
}
@Override
public Type<ListQuoteEventHandler> getAssociatedType() {
return TYPE;
}
public interface ListQuoteEventHandler extends EventHandler {
void onAdd(ListQuoteEvent event);
}
public interface HasListQuoteEventHandler extends HasHandlers {
public HandlerRegistration addListQuoteEventHandler(
ListQuoteEventHandler handler);
}
public static void fire(HasHandlers source,
ListQuoteEvent event) {
source.fireEvent(event);
}
public ListQuoteEvent() {
super();
}
@Override
protected void dispatch(ListQuoteEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
}

View File

@ -0,0 +1,76 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyDeleteDialog;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class RemovePoliciesEvent extends
GwtEvent<RemovePoliciesEvent.RemovePoliciesEventHandler> {
public static Type<RemovePoliciesEventHandler> TYPE = new Type<RemovePoliciesEventHandler>();
public static Type<RemovePoliciesEventHandler> getType() {
return TYPE;
}
private List<Long> identifier;
private PolicyDeleteDialog dialog;
public interface RemovePoliciesEventHandler extends EventHandler {
void onAdd(RemovePoliciesEvent event);
}
public interface HasRemovePoliciesEventHandler extends HasHandlers {
public HandlerRegistration addRemovePoliciesEventHandler(
RemovePoliciesEventHandler handler);
}
public RemovePoliciesEvent(List<Long> identifier, PolicyDeleteDialog modal) {
super();
this.identifier = identifier;
this.dialog=modal;
}
@Override
protected void dispatch(RemovePoliciesEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<RemovePoliciesEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
RemovePoliciesEvent event) {
source.fireEvent(event);
}
public List<Long> getIdentifier() {
return identifier;
}
public PolicyDeleteDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "RemovePoliciesEvent [identifier=" + identifier + ", dialog="
+ dialog + "]";
}
}

View File

@ -0,0 +1,90 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyDeleteDialog;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class RemovePolicyEventOLDKO extends
GwtEvent<RemovePolicyEventOLDKO.RemovePolicyEventHandler> {
public static Type<RemovePolicyEventHandler> TYPE = new Type<RemovePolicyEventHandler>();
public static Type<RemovePolicyEventHandler> getType() {
return TYPE;
}
private Long identifier;
private PolicyDeleteDialog dialog;
public interface RemovePolicyEventHandler extends EventHandler {
void onAdd(RemovePolicyEventOLDKO event);
}
public interface HasRemovePolicyEventHandler extends HasHandlers {
public HandlerRegistration addRemovePolicyEventHandler(
RemovePolicyEventHandler handler);
}
public RemovePolicyEventOLDKO(Long identifier, PolicyDeleteDialog modal) {
super();
this.identifier = identifier;
this.dialog=modal;
}
@Override
protected void dispatch(RemovePolicyEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<RemovePolicyEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
RemovePolicyEventOLDKO event) {
source.fireEvent(event);
}
public Long getIdentifier() {
return identifier;
}
public PolicyDeleteDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "RemovePolicyEvent [identifier=" + identifier + ", dialog=" + dialog + "]";
}
}

View File

@ -0,0 +1,76 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteDeleteDialog;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class RemoveQuoteEvent extends
GwtEvent<RemoveQuoteEvent.RemoveQuoteEventHandler> {
public static Type<RemoveQuoteEventHandler> TYPE = new Type<RemoveQuoteEventHandler>();
public static Type<RemoveQuoteEventHandler> getType() {
return TYPE;
}
private List<Long> identifier;
private QuoteDeleteDialog dialog;
public interface RemoveQuoteEventHandler extends EventHandler {
void onAdd(RemoveQuoteEvent event);
}
public interface HasRemoveQuoteEventHandler extends HasHandlers {
public HandlerRegistration addRemoveQuoteEventHandler(
RemoveQuoteEventHandler handler);
}
public RemoveQuoteEvent(List<Long> identifier,QuoteDeleteDialog modal) {
super();
this.identifier = identifier;
this.dialog=modal;
}
@Override
protected void dispatch(RemoveQuoteEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<RemoveQuoteEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
RemoveQuoteEvent event) {
source.fireEvent(event);
}
public List<Long> getIdentifier() {
return identifier;
}
public QuoteDeleteDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "RemoveQuoteEvent [identifier=" + identifier + ", dialog="
+ dialog + "]";
}
}

View File

@ -0,0 +1,77 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.PolicyAddDialog;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class UpdatePolicyEvent extends GwtEvent<UpdatePolicyEvent.UpdatePolicyEventHandler> {
public static Type<UpdatePolicyEventHandler> TYPE = new Type<UpdatePolicyEventHandler>();
public static Type<UpdatePolicyEventHandler> getType() {
return TYPE;
}
private PolicyAuth policies;
private PolicyAddDialog dialog;
public interface UpdatePolicyEventHandler extends EventHandler {
void onAdd(UpdatePolicyEvent event);
}
public interface HasUpdatePolicyEventHandler extends HasHandlers {
public HandlerRegistration addUpdatePolicyEventHandler(
UpdatePolicyEventHandler handler);
}
public UpdatePolicyEvent(PolicyAuth policies,PolicyAddDialog dialog){
super();
this.policies=policies;
this.dialog=dialog;
}
@Override
protected void dispatch(UpdatePolicyEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<UpdatePolicyEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
UpdatePolicyEvent event) {
source.fireEvent(event);
}
public PolicyAuth getPolicies() {
return policies;
}
public PolicyAddDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "UpdatePolicyEvent [policies=" + policies + ", dialog=" + dialog
+ "]";
}
}

View File

@ -0,0 +1,76 @@
package org.gcube.portlets.admin.authportletmanager.client.event;
import org.gcube.portlets.admin.authportletmanager.client.pagelayout.QuoteAddDialog;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
public class UpdateQuoteEvent extends GwtEvent<UpdateQuoteEvent.UpdateQuoteEventHandler> {
public static Type<UpdateQuoteEventHandler> TYPE = new Type<UpdateQuoteEventHandler>();
public static Type<UpdateQuoteEventHandler> getType() {
return TYPE;
}
private Quote quote;
private QuoteAddDialog dialog;
public interface UpdateQuoteEventHandler extends EventHandler {
void onAdd(UpdateQuoteEvent event);
}
public interface HasUpdateQuoteEventHandler extends HasHandlers {
public HandlerRegistration addUpdateQuoteEventHandler(
UpdateQuoteEventHandler handler);
}
public UpdateQuoteEvent(Quote quote,QuoteAddDialog dialog){
super();
this.quote=quote;
this.dialog=dialog;
}
@Override
protected void dispatch(UpdateQuoteEventHandler handler) {
// TODO Auto-generated method stub
handler.onAdd(this);
}
@Override
public Type<UpdateQuoteEventHandler> getAssociatedType() {
return TYPE;
}
public static void fire(HasHandlers source,
UpdateQuoteEvent event) {
source.fireEvent(event);
}
public Quote getQuote() {
return quote;
}
public QuoteAddDialog getDialog() {
return dialog;
}
@Override
public String toString() {
return "UpdateQuoteEvent [quote=" + quote + ", dialog=" + dialog
+ "]";
}
}

View File

@ -0,0 +1,42 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
/**
*
* @author SISTEMAS
*/
public class CheckCellHead extends AbstractCell<Boolean> {
private Boolean isSelected = false;
private static final SafeHtml INPUT_CHECKED =
SafeHtmlUtils.fromSafeConstant("<input type=\"checkbox\" tabindex=\"-1\"checked/>");
private static final SafeHtml INPUT_UNCHECKED =
SafeHtmlUtils.fromSafeConstant("<input type=\"checkbox\"tabindex=\"-1\"/>");
public CheckCellHead() {
super("click");
}
@Override
public void render(Context context, Boolean value, SafeHtmlBuilder sb) {
if (isSelected) {
sb.append(INPUT_CHECKED);
} else {
sb.append(INPUT_UNCHECKED);
}
}
public Boolean isIsSelected() {
return isSelected;
}
public void setIsSelected(Boolean isSelected) {
this.isSelected = isSelected;
}
}

View File

@ -0,0 +1,275 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import org.gcube.portlets.admin.authportletmanager.client.Entities;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for add multiple caller for one policy or quota
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class DialogAddMultipleCallerService extends WindowBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, DialogAddMultipleCallerService> {
}
@UiField
Button b_exit_dialog_caller;
@UiField
Button b_add_caller;
@UiField
ListBox l_service_class_policy;
@UiField
ListBox l_service_name_policy;
@UiField
ListBox l_service_id_policy;
public ListBox rightList= new ListBox(true);
@UiField
VerticalPanel leftPanel;
@UiField
VerticalPanel rightPanel;
@UiField
VerticalPanel buttonPanel;
@UiField
Button toRightButton;
@UiField
Button allToLeftButton;
@UiField
Button toLeftButton;
public PolicyAddDialog dialogPolicy;
public QuoteAddDialog dialogQuota;
public int typeMaster =0;
public DialogAddMultipleCallerService(List<Caller> callerSelected,PolicyAddDialog policyAddDialog) {
this.setWidget(binder.createAndBindUi(this));
//this.setAutoHideEnabled(true);
this.setGlassEnabled(true);
this.setWidth("450px");
this.setText("Add/Remove Service");
this.setAnimationEnabled(isVisible());
this.center();
rightList.setVisibleItemCount(10);
rightList.setSize(12);
rightList.setStyleName("width_select");
rightPanel.add(rightList);
//set padding between cells to make the component look better
this.getElement().setAttribute("cellpadding", "1");
leftPanel.getElement().setAttribute("cellpadding", "1");
buttonPanel.getElement().setAttribute("cellpadding", "2");
rightPanel.getElement().setAttribute("cellpadding", "1");
l_service_class_policy.addChangeHandler(new ChangeHandler() {
@SuppressWarnings("rawtypes")
public void onChange(ChangeEvent event) {
//String newValue = l_service_class_policy.getSelectedValue();
int index = l_service_class_policy.getSelectedIndex();
String newValue =l_service_class_policy.getValue(index);
l_service_name_policy.clear();
if (newValue.equals(ConstantsSharing.Star)){
l_service_name_policy.setEnabled(false);
l_service_name_policy.addItem(ConstantsSharing.Star);
l_service_id_policy.setEnabled(false);
}
else{
l_service_name_policy.setEnabled(true);
l_service_id_policy.setEnabled(true);
//order by service name
@SuppressWarnings("unchecked")
List<String> sortedServiceName=new ArrayList(Entities.getServicesMap().get(newValue));
Collections.sort(sortedServiceName);
for (String serviceName :sortedServiceName )
{
l_service_name_policy.addItem(serviceName);
}
}
}
});
initList(callerSelected,policyAddDialog);
loadListService();
}
/**
* Click close dialog
* @param e
*/
@UiHandler("b_exit_dialog_caller")
void onClickDialogExitCaller(ClickEvent e) {
this.hide();
this.clear();
}
/**
* Click for add a multiple caller service
* @param e
*/
@UiHandler("b_add_caller")
void onClickDialogAddCaller(ClickEvent e) {
//resume list
List <Caller> selectedCallerService =new ArrayList<Caller>();
for(int itemIndex=0; itemIndex<rightList.getItemCount(); itemIndex++) {
String item = rightList.getItemText(itemIndex);
//String valueItem = rightList.getValue(itemIndex);
Caller caller=new Caller(TypeCaller.service, item);
selectedCallerService.add(caller);
}
dialogPolicy.setListCallerService(selectedCallerService);
this.hide();
this.clear();
}
@UiHandler("toLeftButton")
public void toLeftButtonClicked(ClickEvent event) {
String value=rightList.getValue();
if (value == null) {
Window.alert("Select an item first!");
return;
}
if (rightList.getItemCount() >= 1) { // !>= 1! is preferred instead of !== 1! to handle multiple selections
toLeftButton.setEnabled(true);
}
SortedMap<String, String> toTempList=new TreeMap<String,String>();
for(int itemIndex=0; itemIndex<rightList.getItemCount(); itemIndex++) {
if (rightList.isItemSelected(itemIndex)){
//String item = rightList.getItemText(itemIndex);
//String valueItem = rightList.getValue(itemIndex);
}
else{
String item = rightList.getItemText(itemIndex);
String valueItem=rightList.getValue(itemIndex);
toTempList.put(item,valueItem);
}
}
// order by type checklist from
rightList.clear();
@SuppressWarnings("unchecked")
Map<String, String> mapFrom = sortByValues(toTempList);
for (Entry<String, String> entry : mapFrom.entrySet())
{
//rightList.insertItem(item, index);
rightList.addItem(entry.getKey(),entry.getValue());
GWT.log("Key"+entry.getKey()+"Value"+entry.getValue());
}
}
@UiHandler("allToLeftButton")
public void allToLeftButtonClicked(ClickEvent event) {
rightList.clear();
}
@UiHandler("toRightButton")
public void toRightButtonClicked(ClickEvent event) {
//select the selected value and insert into list
int indexC = l_service_class_policy.getSelectedIndex();
String serviceClass =l_service_class_policy.getValue(indexC);
int indexN = l_service_name_policy.getSelectedIndex();
String serviceName =l_service_name_policy.getValue(indexN);
int indexI = l_service_id_policy.getSelectedIndex();
String serviceId =l_service_id_policy.getValue(indexI);
String serviceSelected=serviceClass+":"+serviceName+":"+serviceId;
SortedMap<String, String> toTempList=new TreeMap<String,String>();
for(int itemIndex=0; itemIndex<rightList.getItemCount(); itemIndex++) {
String item = rightList.getItemText(itemIndex);
String valueItem=rightList.getValue(itemIndex);
toTempList.put(item,valueItem);
}
if (!toTempList.containsKey(serviceSelected)){
rightList.addItem(serviceSelected,TypeCaller.service.toString());
}
}
/**
* Load a service into select service class
*/
protected void loadListService(){
l_service_class_policy.addItem(ConstantsSharing.Star);
l_service_name_policy.setEnabled(false);
l_service_name_policy.addItem(ConstantsSharing.Star);
l_service_id_policy.setEnabled(false);
//order by serviceClass
@SuppressWarnings({ "unchecked", "rawtypes" })
List<String> sortedServiceClass=new ArrayList(Entities.getServicesMap().keySet());
Collections.sort(sortedServiceClass);
for (String serviceClass :sortedServiceClass )
{
l_service_class_policy.addItem(serviceClass);
}
l_service_id_policy.addItem(ConstantsSharing.Star);
}
protected void initList(List<Caller> callerSelected,PolicyAddDialog dialog) {
//configure master for policy
typeMaster=1;
this.dialogPolicy=dialog;
for (Caller caller :callerSelected){
if (caller.getTypecaller().equals(TypeCaller.service))
rightList.addItem(caller.getCallerName(), caller.getTypecaller().toString());
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static HashMap sortByValues(SortedMap<String, String> tempList) {
List list = new LinkedList(tempList.entrySet());
// Defined Custom Comparator here
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
return ((Comparable) ((Map.Entry) (o1)).getValue())
.compareTo(((Map.Entry) (o2)).getValue());
}
});
HashMap sortedHashMap = new LinkedHashMap();
for (Iterator it = list.iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
sortedHashMap.put(entry.getKey(), entry.getValue());
}
return sortedHashMap;
}
}

View File

@ -0,0 +1,105 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:i="urn:import:com.github.gwtbootstrap.client.ui.incubator"
xmlns:bi="urn:import:org.gcube.portlets.admin.authportletmanager.client.widget">
<ui:style>
.panel {
background-color: #d9e2e8;
padding: 10px;
border-left: 2px solid #888;
border-right: 2px solid #888;
border-bottom: 2px solid #888;
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 1px solid #ccc;
padding: 10px;
}
.panel_center {
margin-left: 10px;
margin-right: 10px;
}
.panel_right {
margin-top: 20px;
height: 200px;
}
.r_loader_space {
margin-top: 10px;
text-align: center;
height: 30px;
width: auto;
}
.footer_dialog {
text-align: right;
margin-top: 20px;
}
.button_dialog {
margin-left: 10px;
}
.row_element {
margin-top: 10px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}">
<g:HorizontalPanel>
<g:cell verticalAlignment="ALIGN_MIDDLE">
<g:VerticalPanel ui:field="leftPanel">
<b:Label ui:field="leftPanelLabel" />
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Class</b:ControlLabel>
<b:ListBox ui:field="l_service_class_policy">
</b:ListBox>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Name</b:ControlLabel>
<b:ListBox ui:field="l_service_name_policy">
</b:ListBox>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Id</b:ControlLabel>
<b:ListBox ui:field="l_service_id_policy">
</b:ListBox>
</b:Row>
</g:VerticalPanel>
</g:cell>
<g:cell verticalAlignment="ALIGN_MIDDLE">
<g:VerticalPanel ui:field="buttonPanel"
styleName="{style.panel_center}">
<b:Button ui:field="toRightButton" name="toRight" text=">" />
<b:Button ui:field="allToLeftButton" name="toRight"
text="&lt;&lt;" />
<b:Button ui:field="toLeftButton" name="toLeft" text="&lt;" />
</g:VerticalPanel>
</g:cell>
<g:cell verticalAlignment="ALIGN_MIDDLE">
<g:VerticalPanel ui:field="rightPanel" styleName="{style.panel_right}">
<b:Label ui:field="rightPanelLabel" />
</g:VerticalPanel>
</g:cell>
</g:HorizontalPanel>
</g:FlowPanel>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="12" addStyleNames='{style.footer_dialog}'>
<b:Button ui:field="b_add_caller" type="PRIMARY"
addStyleNames='{style.button_dialog}'>Add</b:Button>
<b:Button ui:field="b_exit_dialog_caller" type="DANGER"
addStyleNames='{style.button_dialog}'>Close</b:Button>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,168 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.Entities;
import org.gcube.portlets.admin.authportletmanager.client.widget.PickList;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for add multiple caller for one policy or quota
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class DialogAddMultipleCallerUserRole extends WindowBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, DialogAddMultipleCallerUserRole> {
}
@UiField
Button b_exit_dialog_caller;
@UiField
Button b_add_caller;
@UiField
PickList pickList;
@UiField
ListBox l_select_type_caller;
public PolicyAddDialog dialogPolicy;
public QuoteAddDialog dialogQuota;
public int typeMaster =0;
public DialogAddMultipleCallerUserRole() {
this.setWidget(binder.createAndBindUi(this));
this.setGlassEnabled(true);
this.setWidth("450px");
this.setText("Add/Remove User or Role");
this.setAnimationEnabled(isVisible());
this.center();
//load Handler for service class
l_select_type_caller.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int indexC = l_select_type_caller.getSelectedIndex();
String typeCaller =l_select_type_caller.getValue(indexC);
GWT.log("AuthManager - Add filter select:"+typeCaller);
if (typeCaller.equals("All")){
pickList.clearLeftList();
ArrayList<Caller> listCaller=new ArrayList<Caller>();
for (Caller caller :Entities.getCallers()){
if (!caller.getTypecaller().equals(TypeCaller.service))
listCaller.add(caller);
}
pickList.setLeftListElements(listCaller);
}
else{
List <Caller> filterCaller=new ArrayList<Caller>();
for (Caller caller:Entities.getCallers()){
if (caller.getTypecaller().toString().toLowerCase().equals(typeCaller.toLowerCase()))
filterCaller.add(caller);
}
pickList.clearLeftList();
pickList.setLeftListElements(filterCaller);
}
}
});
}
/**
* Click close dialog
* @param e
*/
@UiHandler("b_exit_dialog_caller")
void onClickDialogExitCaller(ClickEvent e) {
this.hide();
this.clear();
}
/**
* Click for add a multiple caller
* @param e
*/
@UiHandler("b_add_caller")
void onClickDialogAddCaller(ClickEvent e) {
//resume list
if (typeMaster==1)
dialogPolicy.setListCallerUserRole(pickList.getRightListElements());
if (typeMaster==2)
dialogQuota.setListCaller(pickList.getRightListElements());
this.hide();
this.clear();
}
/**
* Init for load a multiple caller with default caller selected
* @param callerSelected
* @param dialog
*/
public void initList(List<Caller> callerSelected, PolicyAddDialog dialog) {
this.dialogPolicy=dialog;
//configure master for policy
typeMaster=1;
ArrayList<Caller> filterList=new ArrayList<Caller>();
for (Caller caller :Entities.getCallers()){
if (!caller.getTypecaller().equals(TypeCaller.service)){
if (!callerSelected.contains(caller))
filterList.add(caller);
}
}
pickList.setLeftListElements(filterList);
ArrayList<Caller> filterListSelected=new ArrayList<Caller>();
for (Caller caller :callerSelected){
if (!caller.getTypecaller().equals(TypeCaller.service))
filterListSelected.add(caller);
}
pickList.setRightListElements(filterListSelected);
}
/**
* Init for load a multiple caller with default caller selected
* @param callerSelected
* @param dialog
*/
public void initList(List<Caller> callerSelected, QuoteAddDialog dialog) {
this.dialogQuota=dialog;
//configure master for quota
typeMaster=2;
ArrayList<Caller> filterList=new ArrayList<Caller>();
for (Caller caller :Entities.getCallers()){
if (!caller.getTypecaller().equals(TypeCaller.service)){
if (!callerSelected.contains(caller))
filterList.add(caller);
}
}
pickList.setLeftListElements(filterList);
ArrayList<Caller> filterListSelected=new ArrayList<Caller>();
for (Caller caller :callerSelected){
if (!caller.getTypecaller().equals(TypeCaller.service))
filterListSelected.add(caller);
}
pickList.setRightListElements(callerSelected);
}
}

View File

@ -0,0 +1,75 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:i="urn:import:com.github.gwtbootstrap.client.ui.incubator"
xmlns:bi="urn:import:org.gcube.portlets.admin.authportletmanager.client.widget">
<ui:style>
.panel {
background-color: #d9e2e8;
padding: 10px;
border-left: 2px solid #888;
border-right: 2px solid #888;
border-bottom: 2px solid #888;
/*
border-radius: 4px;
border: 2px solid #888;
width: 80%;
margin-left: 10%;
*/
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 1px solid #ccc;
padding: 10px;
}
.r_loader_space {
margin-top: 10px;
text-align: center;
height: 30px;
width: auto;
}
.footer_dialog {
text-align: right;
margin-top: 20px;
}
.button_dialog {
margin-left: 10px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}">
<b:ControlLabel>Type Caller</b:ControlLabel>
<b:ListBox ui:field="l_select_type_caller">
<g:item>All</g:item>
<g:item>Role</g:item>
<g:item>User</g:item>
</b:ListBox>
</g:FlowPanel>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}">
<bi:PickList ui:field="pickList">
</bi:PickList>
</g:FlowPanel>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="12" addStyleNames='{style.footer_dialog}'>
<b:Button ui:field="b_add_caller" type="PRIMARY"
addStyleNames='{style.button_dialog}'>Add</b:Button>
<b:Button ui:field="b_exit_dialog_caller" type="DANGER"
addStyleNames='{style.button_dialog}'>Close</b:Button>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,75 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Dialog Box for show an error or warning
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class DialogError extends WindowBox{
public DialogError() {
//super(false, true);
super(true, false);
}
public void showError(String textError){
/*
this.setWidth(ConstantsSharing.WIDTH_DIALOG_LOADER + "px");
this.setHeight(ConstantsSharing.HEIGHT_DIALOG_LOADER + "px");
this.setPopupPosition(((Window.getClientWidth() - ConstantsSharing.WIDTH_DIALOG_LOADER) / 2),
((Window.getClientHeight()-ConstantsSharing.HEIGHT_DIALOG_LOADER)/2) );
this.setGlassEnabled(true);
this.setAnimationEnabled(true);
*/
this.setStyleName("modal_error");
this.setWidth("800px");
this.setAnimationEnabled(true);
this.setGlassEnabled(true);
this.center();
Icon icon=new Icon();
icon.setIcon(IconType.EXCLAMATION_SIGN);
icon.addStyleName("icon_error");
Label labelError =new Label();
labelError.setText("Error");
labelError.setStyleName("label_error");
Label labelTextError =new Label();
labelTextError.setText(textError);
labelTextError.setStyleName("label_text_error");
Button buttonErrorExit= new Button();
buttonErrorExit.setType(ButtonType.DANGER);
buttonErrorExit.setText("Exit");
buttonErrorExit.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// handle the click event
hide();
clear();
}
});
VerticalPanel dialogContents = new VerticalPanel();
dialogContents.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
dialogContents.setWidth("100%");
dialogContents.addStyleName("content_error");
dialogContents.add(icon);
dialogContents.add(labelTextError);
dialogContents.add(buttonErrorExit);
this.add(dialogContents);
this.show();
}
}

View File

@ -0,0 +1,63 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.ProgressBar;
import com.github.gwtbootstrap.client.ui.base.ProgressBarBase.Style;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Dialog Box for show a loader status
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class DialogLoader extends DialogBox{
private ProgressBar progressLoader =new ProgressBar();
public DialogLoader() {
super(false, true);
}
public void startLoader(){
this.setWidth(ConstantsSharing.WIDTH_DIALOG_LOADER + "px");
this.setHeight(ConstantsSharing.HEIGHT_DIALOG_LOADER + "px");
this.setPopupPosition(((Window.getClientWidth() - ConstantsSharing.WIDTH_DIALOG_LOADER) / 2),
((Window.getClientHeight()-ConstantsSharing.HEIGHT_DIALOG_LOADER)/2) );
this.setAnimationEnabled(true);
this.setGlassEnabled(true);
this.setAnimationEnabled(true);
this.setStyleName("modal_loader");
Label labelLoader =new Label();
labelLoader.setText("Loading...");
labelLoader.setStyleName("label_loader");
progressLoader.setActive(true);
progressLoader.setPercent(100);
progressLoader.setType(Style.ANIMATED);
VerticalPanel dialogContents = new VerticalPanel();
dialogContents.setWidth("100%");
dialogContents.addStyleName("content_loader");
dialogContents.add(labelLoader);
dialogContents.add(progressLoader);
this.add(dialogContents);
this.show();
}
public void stopLoader(){
this.hide();
this.clear();
}
}

View File

@ -0,0 +1,23 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class HeaderLayout extends Composite {
private static HeaderLayoutUiBinder uiBinder = GWT
.create(HeaderLayoutUiBinder.class);
interface HeaderLayoutUiBinder extends UiBinder<Widget, HeaderLayout> {
}
public HeaderLayout() {
initWidget(uiBinder.createAndBindUi(this));
}
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<b:Row>
<b:Column size="12">
<b:PageHeader subtext=" policy for user and roles">Management</b:PageHeader>
</b:Column>
</b:Row>
</ui:UiBinder>

View File

@ -0,0 +1,557 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.Entities;
import org.gcube.portlets.admin.authportletmanager.client.event.AddPoliciesEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.UpdatePolicyEvent;
import org.gcube.portlets.admin.authportletmanager.client.resource.AuthResources;
import org.gcube.portlets.admin.authportletmanager.client.widget.InputListWidget;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import org.gcube.portlets.admin.authportletmanager.shared.Access;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import org.gcube.portlets.admin.authportletmanager.shared.Service;
import org.gcube.portlets.widgets.widgettour.client.extendedclasses.GCubeTour;
import com.ait.toolkit.hopscotch.client.Placement;
import com.ait.toolkit.hopscotch.client.TourStep;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ButtonGroup;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Row;
import com.github.gwtbootstrap.client.ui.base.AlertBase;
import com.github.gwtbootstrap.client.ui.event.ClosedEvent;
import com.github.gwtbootstrap.client.ui.event.ClosedHandler;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for add a policy
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class PolicyAddDialog extends WindowBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, PolicyAddDialog> {
}
private Boolean error_display=false;
private ArrayList<PolicyAuth>listModifyPolicy;
private Boolean modifyPolicy=false;
private ArrayList<PolicyAuth>listAddPolicy;
public InputListWidget ListWidget;
@UiField
FlowPanel text_caller_policy;
@UiField
ListBox l_service_class_policy;
@UiField
ListBox l_service_name_policy;
@UiField
ListBox l_service_id_policy;
@UiField
ListBox l_access_policy;
@UiField
ButtonGroup b_caller_checkbox;
@UiField
Button b_caller_all_user;
@UiField
Button b_caller_all_role;
@UiField
Button b_caller_except;
@UiField
Button b_add_multiple_user_role;
@UiField
Button b_add_multiple_service;
@UiField
Button b_exit_dialog_policy;
@UiField
Button b_save_policy;
@UiField
Row r_loader_space;
@UiField
FlowPanel idAddCallerPolicy;
@UiField
FlowPanel idAddServicePolicy;
@UiField
FlowPanel idAddAccessPolicy;
public PolicyAddDialog() {
super(true, false);
this.setWidget(binder.createAndBindUi(this));
//this.setGlassEnabled(true);
this.setWidth("800px");
this.setAnimationEnabled(true);
this.setGlassEnabled(true);
this.center();
this.setText("Add/Update Policy");
idAddCallerPolicy.getElement().setId("idAddCallerPolicy");
idAddServicePolicy.getElement().setId("idAddServicePolicy");
idAddAccessPolicy.getElement().setId("idAddAccessPolicy");
//istance a new list policy for modify
listModifyPolicy=new ArrayList<PolicyAuth>();
//Initialize a suggest for caller
text_caller_policy.setStyleName("auto_suggest");
ListWidget=new InputListWidget();
text_caller_policy.add(ListWidget);
//disable except
b_caller_except.setEnabled(false);
//load Handler for service class
l_service_class_policy.addChangeHandler(new ChangeHandler() {
@SuppressWarnings("rawtypes")
public void onChange(ChangeEvent event) {
int indexC = l_service_class_policy.getSelectedIndex();
String newValue =l_service_class_policy.getValue(indexC);
l_service_name_policy.clear();
if (newValue.equals(ConstantsSharing.Star)){
l_service_name_policy.setEnabled(false);
l_service_name_policy.addItem(ConstantsSharing.StarLabel,ConstantsSharing.Star);
l_service_id_policy.setEnabled(false);
}
else{
l_service_name_policy.setEnabled(true);
l_service_id_policy.setEnabled(true);
//order by service name
@SuppressWarnings("unchecked")
List<String> sortedServiceName=new ArrayList(Entities.getServicesMap().get(newValue));
Collections.sort(sortedServiceName);
//filter distinct service
List<String> distinctServiceName = new ArrayList<String>();
for (String serviceName :sortedServiceName )
{
if (!distinctServiceName.contains(serviceName)){
l_service_name_policy.addItem(serviceName);
distinctServiceName.add(serviceName);
}
}
}
}
});
loadListService();
loadListAccessPolicy();
r_loader_space.clear();
GCubeTour tourAddDialogPolicy = new GCubeTour("tour-auth add dialog", "auth-portlet-manager", 1, "Would you like to see again this tour next time ?", "Tour Policy use");
tourAddDialogPolicy.setShowPrevButton(true);
if (!this.modifyPolicy){
TourStep firstStep = new TourStep(Placement.RIGHT, "idAddCallerPolicy");
firstStep.setContent("Here you can add a single or multiple caller that denies an access on a selected service:"
+ "<br>If insert an user digit @,<br>If insert a role digit #, <br>If you want insert a service digit $.");
firstStep.setTitle("Add Caller");
firstStep.centerXOffset();
firstStep.centerArrowOffset();
tourAddDialogPolicy.addStep(firstStep);
}
TourStep secondStep = new TourStep(Placement.TOP, "idAddServicePolicy");
secondStep.setTitle("Select Service");
secondStep.setContent("Specify a service class and service name ");
secondStep.centerXOffset();
secondStep.centerArrowOffset();
TourStep thirdStep = new TourStep(Placement.TOP, "idAddAccessPolicy");
thirdStep.setTitle("Select Access");
thirdStep.setContent("Specify an acces type");
thirdStep.centerXOffset();
thirdStep.centerArrowOffset();
tourAddDialogPolicy.addStep(secondStep);
tourAddDialogPolicy.addStep(thirdStep);
tourAddDialogPolicy.startTour();
}
/**
* Click all user
* @param e ClickEvent
*/
@UiHandler("b_caller_all_user")
void onClickAddAllUser(ClickEvent e) {
if (!b_caller_all_user.isToggled()){
//selected checkbox all user
b_caller_all_user.setFocus(false);
b_caller_all_role.setFocus(false);
b_caller_all_role.setActive(false);
b_add_multiple_user_role.setEnabled(false);
b_add_multiple_service.setEnabled(false);
b_caller_except.setEnabled(true);
b_caller_except.setActive(false);
//Caller allCallerUser= new Caller("user","ALL");
Caller allCallerUser= new Caller(TypeCaller.user,"ALL");
ListWidget.clearList();
ListWidget.addCaller(allCallerUser);
}
else{
//not selected checkbox all user
b_caller_all_role.setEnabled(true);
b_add_multiple_user_role.setEnabled(true);
b_add_multiple_service.setEnabled(true);
b_caller_except.setEnabled(false);
ListWidget.clearList();
}
}
/**
* Click all role
* @param e ClickEvent
*/
@UiHandler("b_caller_all_role")
void onClickAddAllRole(ClickEvent e) {
if (!b_caller_all_role.isToggled()){
//selected checkbox all role
b_caller_all_role.setFocus(false);
b_caller_all_user.setFocus(false);
b_caller_all_user.setActive(false);
b_add_multiple_user_role.setEnabled(false);
b_add_multiple_service.setEnabled(false);
b_caller_except.setEnabled(true);
b_caller_except.setActive(false);
Caller allCallerRole= new Caller(TypeCaller.role,"ALL");
ListWidget.clearList();
ListWidget.addCaller(allCallerRole);
}
else{
//not selected checkbox all role
b_caller_all_user.setEnabled(true);
b_add_multiple_user_role.setEnabled(true);
b_add_multiple_service.setEnabled(true);
b_caller_except.setEnabled(false);
ListWidget.clearList();
}
}
/**
* Click except
* @param e ClickEvent
*/
@UiHandler("b_caller_except")
void onClickExcept(ClickEvent e) {
//selected except
if (!b_caller_except.isToggled())
ListWidget.enabledList();
else{
ListWidget.clearList();
if (!b_caller_all_role.isToggled()){
Caller allCallerUser= new Caller(TypeCaller.user,"ALL");
ListWidget.addCaller(allCallerUser);
}
else if (!b_caller_all_user.isToggled()){
Caller allCallerRole= new Caller(TypeCaller.role,"ALL");
ListWidget.addCaller(allCallerRole);
}
}
}
/**
* Click open dialog for multiple caller user or role
* @param e
*/
@UiHandler("b_add_multiple_user_role")
void onClickAddCaller(ClickEvent e) {
DialogAddMultipleCallerUserRole popup = new DialogAddMultipleCallerUserRole();
popup.initList(ListWidget.callerSelected,this);
popup.show();
}
/**
* Click open dialog for multiple caller service
* @param e
*/
@UiHandler("b_add_multiple_service")
void onClickAddCallerService(ClickEvent e) {
DialogAddMultipleCallerService popup = new DialogAddMultipleCallerService(ListWidget.callerSelected,this);
//popup.initList();
popup.show();
}
/**
* Click close dialog
* @param e
*/
@UiHandler("b_exit_dialog_policy")
void onClickExitDialogPolicy(ClickEvent e) {
this.hide();
this.clear();
}
/**
* Click add policy
* @param e
*/
@UiHandler("b_save_policy")
void onClickSavePolicy(ClickEvent e) {
//verify if a modify any
if (this.modifyPolicy){
//verifico se ho cambiato qualcosa
for (PolicyAuth verifyPolicy:listModifyPolicy){
String serviceClass =l_service_class_policy.getValue(l_service_class_policy.getSelectedIndex());
String serviceName =l_service_name_policy.getValue(l_service_name_policy.getSelectedIndex());
String serviceId =l_service_id_policy.getValue(l_service_id_policy.getSelectedIndex());
Service service=new Service(serviceClass,serviceName,serviceId);
Access access =Access.valueOf(l_access_policy.getValue(l_access_policy.getSelectedIndex()));
if ((verifyPolicy.getService().equals(service) )&& (verifyPolicy.getAccess().equals(access))){
if (!error_display)
ErrorText("Not changed");
error_display=true;
return ;
}
}
}
if (ListWidget.callerSelected.isEmpty()){
if (!error_display)
ErrorText("Insert Caller");
error_display=true;
}
else{
error_display=false;
String serviceClass =l_service_class_policy.getValue(l_service_class_policy.getSelectedIndex());
String serviceName =l_service_name_policy.getValue(l_service_name_policy.getSelectedIndex());
String serviceId =l_service_id_policy.getValue(l_service_id_policy.getSelectedIndex());
Service service=new Service(serviceClass,serviceName,serviceId);
//Access access = Access.valueOf(l_access_policy.getSelectedValue());
int indexA = l_access_policy.getSelectedIndex();
Access access =Access.valueOf(l_access_policy.getValue(indexA));
if (listModifyPolicy.isEmpty()){
//policy to be added
//verify if a insert simple or exception
if (b_caller_except.isToggled()){
GWT.log("AuthManager - Insert new policy with execption and service:"+service.getServiceClass());
PolicyAuth policy= new PolicyAuth();
List<Caller> callerList=new ArrayList<Caller>();
//order a list caller
if (ListWidget.callerSelected.size() > 0) {
Collections.sort(ListWidget.callerSelected, new Comparator<Caller>() {
@Override
public int compare(final Caller o1, final Caller o2) {
return o1.getCallerName().compareTo(o2.getCallerName());
}
} );
}
for (Caller caller:ListWidget.callerSelected){
GWT.log("add"+caller.getCallerName());
callerList.add(caller);
}
policy.setCaller(callerList);
policy.setService(service);
policy.setAccess(access);
policy.setExcludesCaller(true);
listAddPolicy=new ArrayList<PolicyAuth>();
listAddPolicy.add(policy);
AuthManagerController.eventBus.fireEvent(new AddPoliciesEvent(listAddPolicy, this));
}
else{
listAddPolicy=new ArrayList<PolicyAuth>();
for (Caller caller:ListWidget.callerSelected){
GWT.log("AuthManager - Insert new policy:"+caller.getCallerName()+" with type:"+caller.getTypecaller().toString()+"and service:"+service.getServiceClass()+" and access:"+access.toString());
PolicyAuth policy= new PolicyAuth();
List<Caller> callerList=new ArrayList<Caller>();
callerList.add(caller);
policy.setCaller(callerList);
policy.setService(service);
policy.setAccess(access);
listAddPolicy.add(policy);
}
AuthManagerController.eventBus.fireEvent(new AddPoliciesEvent(listAddPolicy, this));
}
}
else{
for (PolicyAuth modifyPolicy:listModifyPolicy){
Long idPolicy=modifyPolicy.getIdpolicy();
GWT.log("AuthManager - Update policy:"+idPolicy);
modifyPolicy.setService(service);
modifyPolicy.setAccess(access);
AuthManagerController.eventBus.fireEvent(new UpdatePolicyEvent(modifyPolicy,this));
}
}
}
}
/**
* Array list for policy modified
* @param listPolicy
*/
public void setModifyPolicy(ArrayList<PolicyAuth> listPolicy) {
String serviceClass = null;
String serviceName = null;
String serviceId = null;
Access access = null;
this.listModifyPolicy = listPolicy;
this.modifyPolicy=true;
for (PolicyAuth result :listPolicy){
List<Caller> callerList= result.getCaller();
Service service = result.getService();
serviceClass=service.getServiceClass();
serviceName=service.getServiceName();
serviceId=service.getServiceId();
access=result.getAccess();
if (result.getExcludesCaller()){
TypeCaller typeCaller=result.getCallerType();
callerList.add(new Caller(typeCaller,"ALL"));
}
ListWidget.addListCaller(callerList, false);
GWT.log("AuthManager - Modify existing Policy identifier:"+result.getIdpolicy()+" from caller:"+result.getCallerAsString()+ "with access:"+access);
}
//DISABLE ADD ANOTHER CALLER
b_caller_all_user.setEnabled(false);
b_caller_all_role.setEnabled(false);
b_add_multiple_user_role.setEnabled(false);
b_add_multiple_service.setEnabled(false);
//RETRIVE A SERVICE SELECT
l_service_name_policy.addItem("ALL");
GWT.log("access:"+serviceClass);
if (!serviceClass.equals("ALL")){
List<String> distinctServiceName = new ArrayList<String>();
for (String serviceNameList : Entities.getServicesMap().get(serviceClass)){
if (!distinctServiceName.contains(serviceNameList)){
l_service_name_policy.addItem(serviceNameList);
distinctServiceName.add(serviceNameList);
}
}
//selected the values of policy
l_service_class_policy.setSelectedValue(serviceClass);
l_service_name_policy.setSelectedValue(serviceName);
l_service_id_policy.setSelectedValue(serviceId);
}
l_access_policy.setSelectedValue(access.toString());
}
/**
* Retrieve information from dialog multiple caller
* @param listCaller
*/
public void setListCallerUserRole(List<Caller> listCaller){
List<Caller> selectedCaller= new ArrayList<Caller>();
for (Caller caller: ListWidget.callerSelected){
if (caller.getTypecaller().equals(TypeCaller.service)){
selectedCaller.add(caller);
}
}
selectedCaller.addAll(listCaller);
ListWidget.replaceListCaller(selectedCaller);
}
/**
*
* @param listCaller
*/
public void setListCallerService(List<Caller> listCaller) {
List<Caller> selectedCaller= new ArrayList<Caller>();
for (Caller caller: ListWidget.callerSelected){
if ((caller.getTypecaller().equals(TypeCaller.user))||(caller.getTypecaller().equals(TypeCaller.role))){
selectedCaller.add(caller);
}
}
selectedCaller.addAll(listCaller);
ListWidget.replaceListCaller(selectedCaller);
}
/**
* Load a service into select service class
*/
public void loadListService(){
l_service_class_policy.addItem(ConstantsSharing.StarLabel,ConstantsSharing.Star);
l_service_name_policy.setEnabled(false);
l_service_name_policy.addItem(ConstantsSharing.StarLabel,ConstantsSharing.Star);
l_service_id_policy.setEnabled(false);
//order by serviceClass
@SuppressWarnings({ "unchecked", "rawtypes" })
List<String> sortedServiceClass=new ArrayList(Entities.getServicesMap().keySet());
Collections.sort(sortedServiceClass);
for (String serviceClass :sortedServiceClass )
{
l_service_class_policy.addItem(serviceClass);
}
l_service_id_policy.addItem(ConstantsSharing.StarLabel,ConstantsSharing.Star);
}
/**
* Load a list access into select access
*/
public void loadListAccessPolicy(){
l_access_policy.ensureDebugId("l_access_policy");
l_access_policy.setHeight("30px");
l_access_policy.setVisibleItemCount(1);
//order by Access
/*
@SuppressWarnings({ "rawtypes", "unchecked" })
List<String> sortedAccess=new ArrayList(Entities.getAccess());
Collections.sort(sortedAccess);
*/
for( Access access : Access.values() ) {
l_access_policy.addItem(access.toString());
}
}
/**
* Alert for msg error
* @param stringMsg
*/
public void ErrorText(String stringMsg) {
Alert msg = new Alert();
msg.setAnimation(true);
msg.setText(stringMsg);
msg.addClosedHandler(new ClosedHandler<AlertBase>() {
@Override
public void onClosed(ClosedEvent<AlertBase> event) {
error_display=false;
}
});
r_loader_space.add(msg);
}
/**
* Start Animation loading
*/
public void AppLoadingView() {
b_exit_dialog_policy.setEnabled(false);
b_save_policy.setEnabled(false);
Image imgLoading = new Image(AuthResources.INSTANCE.loaderIcon());
r_loader_space.clear();
r_loader_space.add(imgLoading);
}
/**
* Stop animation loading
*/
public void StopAppLoadingView() {
b_exit_dialog_policy.setEnabled(true);
b_save_policy.setEnabled(true);
clear();
hide();
}
}

View File

@ -0,0 +1,110 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.panel {
background-color: #d9e2e8;
padding: 10px;
border-left: 2px solid #888;
border-right: 2px solid #888;
border-bottom: 2px solid #888;
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 2px solid #ccc;
padding: 10px;
}
.r_loader_space {
/*margin-top:10px;*/
text-align: center;
height: 30px;
margin-bottom: 10px;
margin-right: 20px;
}
.row_element {
margin-top: 10px;
}
.footer_dialog {
padding-right: 20px;
text-align: right;
}
.button_dialog {
margin-left: 10px;
}
.margin_left{
margin-left: 10px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddCallerPolicy">
<b:FluidRow styleName="{style.row_element}">
<b:ControlLabel>Caller</b:ControlLabel>
</b:FluidRow>
<b:Row styleName="{style.row_element}">
<b:ButtonGroup toggle="checkbox" ui:field="b_caller_checkbox">
<b:Button ui:field="b_caller_all_user">All Users</b:Button>
</b:ButtonGroup>
<b:ButtonGroup toggle="checkbox">
<b:Button ui:field="b_caller_all_role">All Role</b:Button>
</b:ButtonGroup>
<b:ButtonGroup toggle="checkbox">
<b:Button ui:field="b_caller_except">Except</b:Button>
</b:ButtonGroup>
</b:Row>
<b:Row styleName="{style.row_element}">
<g:FlowPanel ui:field="text_caller_policy">
</g:FlowPanel>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:Tooltip text='Add Caller User or Role'>
<b:Button addStyleNames="btn btn_add" ui:field="b_add_multiple_user_role">Add
User/Role</b:Button>
</b:Tooltip>
<b:Tooltip text='Add Caller Service'>
<b:Button addStyleNames="btn btn_add margin_left" ui:field="b_add_multiple_service">Add
Service</b:Button>
</b:Tooltip>
</b:Row>
</g:FlowPanel>
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddServicePolicy">
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Class</b:ControlLabel>
<b:ListBox ui:field="l_service_class_policy">
</b:ListBox>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Name</b:ControlLabel>
<b:ListBox ui:field="l_service_name_policy">
</b:ListBox>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Service Id</b:ControlLabel>
<b:ListBox ui:field="l_service_id_policy">
</b:ListBox>
</b:Row>
</g:FlowPanel>
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddAccessPolicy">
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Access</b:ControlLabel>
<b:ListBox ui:field="l_access_policy">
</b:ListBox>
</b:Row>
</g:FlowPanel>
</b:Column>
<b:Column size="12">
<b:Row ui:field="r_loader_space" addStyleNames='{style.r_loader_space}'>
</b:Row>
</b:Column>
<b:Column size="6" offset="6" addStyleNames='{style.footer_dialog}'>
<b:Button ui:field="b_save_policy" type="PRIMARY"
addStyleNames='{style.button_dialog}'>Save</b:Button>
<b:Button ui:field="b_exit_dialog_policy" type="DANGER"
addStyleNames='{style.button_dialog}'>Close</b:Button>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,331 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.widget.ActionCellClass;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import com.github.gwtbootstrap.client.ui.Label;
import com.google.gwt.cell.client.ActionCell.Delegate;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.CheckboxCell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionModel;
/**
* Table for list policy (data grid)
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class PolicyDataGrid extends Composite {
private static PolicyDataGridUiBinder uiBinder = GWT
.create(PolicyDataGridUiBinder.class);
interface PolicyDataGridUiBinder extends UiBinder<Widget, PolicyDataGrid> {
}
/**
* The main DataGrid.
*/
@UiField(provided = true)
DataGrid<PolicyAuth> dataGrid;
@UiField(provided = true)
SimplePager pager;
public PolicyDataGrid() {
onInitialize();
initWidget(uiBinder.createAndBindUi(this));
}
private Column<PolicyAuth, String> callerColumn;
private Column<PolicyAuth, String> callerType;
private Column<PolicyAuth, String> serviceClassColumn;
private Column<PolicyAuth, String> accessColumn;
private Column<PolicyAuth, Date> dataInsertColumn;
private Column<PolicyAuth, Date> dataUpdateColumn;
public static SelectionModel<PolicyAuth> selectionModel;
public static ArrayList<PolicyAuth>selectedPolicy= new ArrayList<PolicyAuth>();
public void onInitialize() {
dataGrid = new DataGrid<PolicyAuth>();
dataGrid.setWidth("100%");
dataGrid.setHeight("400px");
dataGrid.setAutoHeaderRefreshDisabled(true);
dataGrid.setAutoHeaderRefreshDisabled(true);
dataGrid.addStyleName("table_policy");
dataGrid.getElement().setId("idGridPolicy");
//Set the message to display when the table is empty.
dataGrid.setEmptyTableWidget(new Label("No Policy Entry"));
dataGrid.setSkipRowHoverStyleUpdate(false);
// Create a Pager to control the table.
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
pager.setDisplay(dataGrid);
// Attach a column sort handler to the ListDataProvider to sort the list.
ListHandler<PolicyAuth> sortHandler =
new ListHandler<PolicyAuth>(PolicyDataProvider.get().getDataProvider().getList());
dataGrid.addColumnSortHandler(sortHandler);
//Add a selection model so we can select cells.
selectionModel = new MultiSelectionModel<PolicyAuth>();
dataGrid.setSelectionModel(selectionModel, DefaultSelectionEventManager
.<PolicyAuth> createCheckboxManager());
//Init Table Columns
initTableColumns(selectionModel, sortHandler);
PolicyDataProvider.get().addDataDisplay(dataGrid);
dataGrid.setVisible(true);
}
/**
* Init the columns to the table.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void initTableColumns(final SelectionModel<PolicyAuth> selectionModel,
ListHandler<PolicyAuth> sortHandler) {
// Checkbox column. This table will uses a checkbox column for selection.
Column<PolicyAuth, Boolean> checkColumn =
new Column<PolicyAuth, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(PolicyAuth object) {
// Get the value from the selection model.
if (selectionModel.isSelected(object)){
//if already exist no add
if (!selectedPolicy.contains(object))
selectedPolicy.add(object);
}
else
selectedPolicy.remove(object);
return selectionModel.isSelected(object);
}
};
dataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
dataGrid.setColumnWidth(checkColumn, 5, Unit.PCT);
// CallerColumn column this is caller for the service
callerColumn = new Column<PolicyAuth, String>(new TextCell()) {
@Override
public String getValue(PolicyAuth object) {
boolean excludeCaller =object.getExcludesCaller();
String caller=object.getCallerAsString();
if (excludeCaller)
caller="All execpt: "+caller;
return caller;
}
/** for override style on clik */
@Override
public String getCellStyleNames(Context context, PolicyAuth object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
else
return null;
}
};
callerColumn.setSortable(true);
sortHandler.setComparator(callerColumn, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
return o1.getCallerAsString().compareTo(o2.getCallerAsString());
}
});
dataGrid.setColumnWidth(callerColumn, 20, Unit.PCT);
dataGrid.addColumn(callerColumn, new ResizableHeader("Caller", dataGrid, callerColumn));
// CallerType column this is caller for the service
callerType = new Column<PolicyAuth, String>(new TextCell()) {
@Override
public String getValue(PolicyAuth object) {
String caller=object.getCallerTypeAsDataGrid().toUpperCase();
return caller;
}
/** for override style on clik */
@Override
public String getCellStyleNames(Context context, PolicyAuth object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
else
return null;
}
};
callerType.setSortable(true);
sortHandler.setComparator(callerType, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
return o1.getCallerTypeAsString().compareTo(o2.getCallerTypeAsString());
}
});
dataGrid.setColumnWidth(callerType, 20, Unit.PCT);
dataGrid.addColumn(callerType, new ResizableHeader("Type", dataGrid, callerType));
// Service Class this a service class column for the caller.
serviceClassColumn = new Column<PolicyAuth, String>(new TextCell()) {
@Override
public String getValue(PolicyAuth object) {
String service=object.getServiceAsString();
return service;
}
};
serviceClassColumn.setSortable(true);
sortHandler.setComparator(serviceClassColumn, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
return o1.getServiceAsString().compareTo(o2.getServiceAsString());
}
});
dataGrid.setColumnWidth(serviceClassColumn, 30, Unit.PCT);
dataGrid.addColumn(serviceClassColumn, new ResizableHeader("Service", dataGrid, serviceClassColumn));
// accessColumn.
accessColumn = new Column<PolicyAuth, String>(new TextCell()) {
@Override
public String getValue(PolicyAuth object) {
return object.getAccessString();
}
};
accessColumn.setSortable(true);
sortHandler.setComparator(accessColumn, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
return o1.getAccess().compareTo(o2.getAccess());
}
});
dataGrid.setColumnWidth(accessColumn, 10, Unit.PCT);
dataGrid.addColumn(accessColumn, new ResizableHeader("Access", dataGrid, accessColumn));
dataInsertColumn = new Column<PolicyAuth, Date>(new DateCell(DateTimeFormat.getFormat("EEE, d MMM yyyy HH:mm:ss"))) {
@Override
public Date getValue(PolicyAuth object) {
return object.getDataInsert();
}
};
dataInsertColumn.setSortable(true);
sortHandler.setComparator(dataInsertColumn, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
if (o1 == o2) {
return 0;
}
if (o1.getDataInsert() != null) {
Date date1 =o1.getDataInsert();
Date date2 =o2.getDataInsert();
return (o2.getDataInsert() != null) ? date1.compareTo(date2) : 1;
}
return -1;
}
});
dataGrid.setColumnWidth(dataInsertColumn, 10, Unit.PCT);
dataGrid.addColumn(dataInsertColumn, new ResizableHeader("Insert", dataGrid, dataInsertColumn));
dataUpdateColumn = new Column<PolicyAuth, Date>(new DateCell(DateTimeFormat.getFormat("EEE, d MMM yyyy HH:mm:ss "))) {
@Override
public Date getValue(PolicyAuth object) {
return object.getDataUpdate();
}
};
dataUpdateColumn.setSortable(true);
sortHandler.setComparator(dataUpdateColumn, new Comparator<PolicyAuth>() {
@Override
public int compare(PolicyAuth o1, PolicyAuth o2) {
if (o1 == o2) {
return 0;
}
if (o1.getDataUpdate() != null) {
Date date1 =o1.getDataUpdate();
Date date2 =o2.getDataUpdate();
return (o2.getDataUpdate() != null) ? date1.compareTo(date2) : 1;
}
return -1;
} });
dataGrid.setColumnWidth(dataUpdateColumn, 10, Unit.PCT);
dataGrid.addColumn(dataUpdateColumn, new ResizableHeader("Last Update", dataGrid, dataUpdateColumn));
//add Columns Actions whit button Edit
List<HasCell<PolicyAuth, ?>> cells = new LinkedList<HasCell<PolicyAuth, ?>>();
cells.add(new ActionHasCell("Edit", new Delegate<PolicyAuth>() {
@Override
public void execute(PolicyAuth policy) {
// EDIT CODE
PolicyAddDialog dialogedit = new PolicyAddDialog();
ArrayList<PolicyAuth> listModifiedPolicy= new ArrayList<PolicyAuth>();
listModifiedPolicy.add(policy);
dialogedit.setModifyPolicy(listModifiedPolicy);
dialogedit.show();
}
}));
cells.add(new ActionHasCell("Delete", new Delegate<PolicyAuth>() {
@Override
public void execute(PolicyAuth policy) {
// DELETE CODE
ArrayList<PolicyAuth> listDeletePolicy =new ArrayList<PolicyAuth>();
listDeletePolicy.add(policy);
PolicyDeleteDialog confirmDeleteDialog = new PolicyDeleteDialog(listDeletePolicy);
confirmDeleteDialog.show();
}
}));
CompositeCell<PolicyAuth> cell = new CompositeCell<PolicyAuth>(cells);
Column<PolicyAuth, PolicyAuth> actionColumn =new Column<PolicyAuth, PolicyAuth>(cell) {
@Override
public PolicyAuth getValue(PolicyAuth object) {
return object;
}
};
dataGrid.setColumnWidth(actionColumn, 15, Unit.PCT);
dataGrid.addColumn(actionColumn, "Actions");
}
private class ActionHasCell implements HasCell<PolicyAuth, PolicyAuth> {
private ActionCellClass<PolicyAuth> cell;
public ActionHasCell(String text, Delegate<PolicyAuth> delegate) {
cell = new ActionCellClass<PolicyAuth>(text, delegate);
}
@Override
public Cell<PolicyAuth> getCell() {
return cell;
}
@Override
public FieldUpdater<PolicyAuth, PolicyAuth> getFieldUpdater() {
return null;
}
@Override
public PolicyAuth getValue(PolicyAuth object) {
return object;
}
}
}

View File

@ -0,0 +1,34 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:c="urn:import:com.google.gwt.user.cellview.client">
<ui:style>
.cellTable {
border-bottom: 1px solid #ccc;
text-align: left;
margin-bottom: 4px;
}
</ui:style>
<g:HTMLPanel>
<table cellspacing='0' cellpadding='0' style='width:100%;'>
<tr>
<td valign='top'>
<c:DataGrid addStyleNames='{style.cellTable}' pageSize='30'
ui:field='dataGrid' />
</td>
</tr>
<tr>
<td align='center'>
<c:SimplePager ui:field='pager' />
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,250 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.ListDataProvider;
/**
* The data source for contact information used in the sample.
*/
public class PolicyDataProvider {
/**
* The singleton instance of the database.
*/
private static PolicyDataProvider instance;
/**
* Get the singleton instance of the contact database.
*
* @return the singleton instance
*/
public static PolicyDataProvider get() {
if (instance == null) {
instance = new PolicyDataProvider();
}
return instance;
}
/**
* The provider that holds the list of contacts in the database.
*/
private ListDataProvider<PolicyAuth> dataProvider = new ListDataProvider<PolicyAuth>();
/**
* The list string used for search
*/
private List<String> initialSearch= new ArrayList<String>();;
/**
* The list policy used for datagrid
*/
private List<PolicyAuth> initialPolicies;
/**
* Construct a new PolicyDataProvider
*/
private PolicyDataProvider() {
}
/**
* Add a display to the database. The current range of interest of the display
* will be populated with data.
*
* @param display a {@Link HasData}.
*/
public void addDataDisplay(HasData<PolicyAuth> display) {
dataProvider.addDataDisplay(display);
}
public ListDataProvider<PolicyAuth> getDataProvider() {
return dataProvider;
}
/**
* Load list policy provider
* @param listResultPolicy
*/
public void loadPolicyProvider(List<PolicyAuth> listResultPolicy) {
initialPolicies = listResultPolicy;
//load list policy from servlet
List<PolicyAuth> policies = dataProvider.getList();
policies.removeAll(policies);
for (PolicyAuth policy : listResultPolicy){
policies.add(policy);
}
}
/***
* Reset a provider
*/
public void resetPolicyProvider(){
List<PolicyAuth> policies = dataProvider.getList();
policies.clear();
}
/**
* Refresh all displays.
*/
public void refreshDisplays() {
dataProvider.refresh();
}
/**
* Method for remove policy from provider
* @param idpolicy
*/
public void removePolicyProvider(Long idpolicy) {
// TODO Auto-generated method stub
List<PolicyAuth> policies = dataProvider.getList();
for (int i=0; i<policies.size(); i++ )
if (policies.get(i).getIdpolicy()==(idpolicy)){
policies.remove(i);
initialPolicies.remove(i);
break;
}
}
/**
* Method for add a policy into provider
* @param policy
*/
public void addPolicyProvider(PolicyAuth policy) {
// TODO Auto-generated method stub
List<PolicyAuth> policies = dataProvider.getList();
policies.add(policy);
initialPolicies.add(policy);
dataProvider.setList(policies);
}
/**
* Used for research a string filter
* @return
*/
public List<String> getInitialSearch() {
return initialSearch;
}
/**
* Refresh list from a list search
*/
public void refreshlistFromSearch(String typeSearch){
List<PolicyAuth> policies = new ArrayList<PolicyAuth>();
Collections.copy(policies, initialPolicies);
List<PolicyAuth> toRemove = new ArrayList<PolicyAuth>(policies.size());
for (int index=0; index<policies.size(); index++ ){
for(String stringSearch: initialSearch) {
String ricerca=null;
if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagCaller)){
stringSearch=stringSearch.substring(1);
ricerca=policies.get(index).getCallerAsString();
}
else if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagService)){
ricerca=policies.get(index).getServiceAsString();
stringSearch=stringSearch.substring(1);
}
else if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagAccess)){
stringSearch=stringSearch.substring(1);
ricerca=policies.get(index).getAccessString();
}
else
ricerca=policies.get(index).getCallerAsString();
if (typeSearch.equals("contains")){
if(!ricerca.toLowerCase().contains(stringSearch.toLowerCase())){
toRemove.add(policies.get(index));
}
}
else{
if(!ricerca.toLowerCase().startsWith(stringSearch.toLowerCase())){
toRemove.add(policies.get(index));
}
}
}
}
policies.removeAll(toRemove);
dataProvider.setList(policies);
}
/**
* Used for add a List string filter
* @param initialSearch
*/
public void setInitialSearch(List<String> initialSearch) {
this.initialSearch = initialSearch;
}
/**
* Used for add a string search
* @param search
*/
public void setAddStringSearch(String search){
this.initialSearch.add(search);
}
/**
* Used for remove string search
* @param filter
*/
public void removeStringSearch(String filter) {
// TODO Auto-generated method stub
this.initialSearch.remove(filter);
}
/**
* Used for remove all string search
*/
public void removeAllStringSearch() {
// TODO Auto-generated method stub
this.initialSearch.clear();
}
/**
* Used for insert a filter button
* @param typefilter
*/
public void setFilterList(String typefilter) {
// TODO Auto-generated method stub
List<PolicyAuth> policiesFilter = new ArrayList<PolicyAuth>();
if (typefilter.isEmpty()){
Collections.copy(policiesFilter, initialPolicies);
}
else{
for (int index=0; index<initialPolicies.size(); index++ ){
GWT.log("initialPolicies:"+initialPolicies.get(index).getCallerTypeAsString().trim()+" typefilter:"+typefilter);
if (initialPolicies.get(index).getCallerTypeAsString().trim().equalsIgnoreCase(typefilter))
policiesFilter.add(initialPolicies.get(index));
}
}
dataProvider.setList(policiesFilter);
}
}

View File

@ -0,0 +1,128 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.event.RemovePoliciesEvent;
import org.gcube.portlets.admin.authportletmanager.client.resource.AuthResources;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.Row;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for confirm delete policy
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class PolicyDeleteDialog extends WindowBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, PolicyDeleteDialog> {
}
private ArrayList<PolicyAuth> deletePolicy;
//private Boolean error=false;
@UiField
Row r_loader_space;
@UiField
Button b_confirm_delete;
@UiField
Button b_confirm_exit;
public PolicyDeleteDialog(ArrayList<PolicyAuth> listDeletePolicy) {
super(true, false);
this.setWidget(binder.createAndBindUi(this));
//this.setAutoHideEnabled(true);
this.setGlassEnabled(true);
this.setWidth("400px");
this.setHeight("200px");
this.setAnimationEnabled(isVisible());
//this.center();
this.setText("Delete Policy");
this.setStyleName("modal_delete");
this.setPopupPosition(((Window.getClientWidth() - 400) / 2),
((Window.getClientHeight()-200)/2) );
this.deletePolicy=listDeletePolicy;
for (PolicyAuth policy:listDeletePolicy){
String caller=policy.getCallerAsString();
Label textpolicy =new Label();
textpolicy.setText(caller);
textpolicy.addStyleName("text_label_delete_policy");
r_loader_space.add(textpolicy);
}
}
/***
* Handler on click for delete policy
* @param event
*/
@UiHandler("b_confirm_delete")
void onClickConfirmDeletePolicy(ClickEvent event) {
List<Long> listIdentifier=new ArrayList<Long>();
for (PolicyAuth policy:deletePolicy){
GWT.log("AuthManager - Delete: "+policy.getIdpolicy());
listIdentifier.add(policy.getIdpolicy());
}
AuthManagerController.eventBus.fireEvent(new RemovePoliciesEvent(listIdentifier,this));
}
/***
* Handler on click for close dialog
* @param event
*/
@UiHandler("b_confirm_exit")
void onClickConfirmExitPolicy(ClickEvent event) {
this.setAnimationEnabled(true);
this.hide();
this.clear();
}
/**
* Method for loader animation
*/
public void AppLoadingView()
{
Image imgLoading = new Image(AuthResources.INSTANCE.loaderIcon());
b_confirm_delete.setEnabled(false);
b_confirm_exit.setEnabled(false);
r_loader_space.clear();
r_loader_space.add(imgLoading);
}
public void StopAppLoadingView(){
b_confirm_delete.setEnabled(true);
b_confirm_exit.setEnabled(true);
deletePolicy.clear();
this.hide();
this.clear();
}
}

View File

@ -0,0 +1,63 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.panel {
background-color: #d9e2e8;
padding: 10px;
border-left: 2px solid #888;
border-right: 2px solid #888;
border-bottom: 2px solid #888;
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 1px solid #ccc;
padding: 11px;
}
.r_loader_space {
margin-top: 10px;
text-align: center;
margin-bottom: 20px;
width: 100%;
margin-left: 0px;
}
.footer_dialog {
text-align: right;
}
.button_dialog {
margin-left: 10px;
}
.label_summary {
text-align: center;
width: 100%;
margin-left: 5px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}">
<b:FluidRow>
<!-- <b:Heading size="5"> -->
<b:ControlLabel>Confirm Delete ?</b:ControlLabel>
<!-- </b:Heading> -->
</b:FluidRow>
<b:Row ui:field="r_loader_space" addStyleNames='{style.r_loader_space}'>
</b:Row>
<b:FluidRow addStyleNames='{style.footer_dialog}'>
<b:Button type="PRIMARY" dismiss="MODAL" ui:field="b_confirm_exit"
addStyleNames='{style.button_dialog}'>NO</b:Button>
<b:Button type="DANGER" ui:field="b_confirm_delete"
addStyleNames='{style.button_dialog}'>YES</b:Button>
</b:FluidRow>
</g:FlowPanel>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,322 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.event.ListPolicyEvent;
import org.gcube.portlets.admin.authportletmanager.client.widget.BulletList;
import org.gcube.portlets.admin.authportletmanager.client.widget.ListItem;
import org.gcube.portlets.admin.authportletmanager.client.widget.Paragraph;
import org.gcube.portlets.admin.authportletmanager.client.widget.Span;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import org.gcube.portlets.widgets.widgettour.client.extendedclasses.GCubeTour;
import com.ait.toolkit.hopscotch.client.Placement;
import com.ait.toolkit.hopscotch.client.TourStep;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ButtonGroup;
import com.github.gwtbootstrap.client.ui.InputAddOn;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Header Filter for search, add and delete policy
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class PolicyFilter extends Composite {
private static PolicyFilterUiBinder uiBinder = GWT
.create(PolicyFilterUiBinder.class);
interface PolicyFilterUiBinder extends UiBinder<Widget, PolicyFilter> {
}
@UiField
TextBox t_search;
@UiField
InputAddOn i_search;
@UiField
Button b_search;
@UiField
Button b_refresh;
@UiField
Button b_add_policy;
@UiField
Button b_delete_policy;
@UiField
Button b_group_none;
@UiField
Button b_group_user;
@UiField
Button b_group_role;
@UiField
Button b_group_service;
@UiField
Button b_search_start;
@UiField
Button b_search_contains;
@UiField
ButtonGroup b_search_type;
@UiField
FlowPanel string_search;
private String typeSearch="start";
private BulletList list;
/**
*
*/
public PolicyFilter() {
initWidget(uiBinder.createAndBindUi(this));
initFilter();
// guideTour();
}
public void guideTour(){
GCubeTour tour = new GCubeTour("Tour-auth", "auth-portlet-manager", 1, "Would you like to see again this tour next time ?", "Tour Auth Manager");
GWT.log("AuthManager - Start Gcube Tour ");
tour.setShowPrevButton(true);
TourStep firstStep = new TourStep(Placement.TOP, "idGridPolicy");
firstStep.setContent("See your rule policYY");
firstStep.setTitle("List policy active");
firstStep.centerXOffset();
firstStep.centerArrowOffset();
TourStep secondStep = new TourStep(Placement.TOP, "idAddPolicy");
secondStep.setContent("Use this for add a new policy ");
secondStep.setTitle("Add Policy");
secondStep.centerXOffset();
secondStep.centerArrowOffset();
TourStep thirdStep = new TourStep(Placement.TOP, "idSearchPolicy");
thirdStep.setContent("Use this for search an existing policy "
+ " <br>Use @ for search caller, <br>Use $ for search service, "
+ "<br>Use * for search access type.");
thirdStep.setTitle("Search Policy");
thirdStep.centerXOffset();
thirdStep.centerArrowOffset();
TourStep fourthStep = new TourStep(Placement.TOP, "idGroupPolicy");
fourthStep.setContent("Use this for filter group policy ");
fourthStep.setTitle("Filter Policy");
fourthStep.centerXOffset();
fourthStep.centerArrowOffset();
//tour.addStep(firstStep);
tour.addStep(secondStep);
tour.addStep(thirdStep);
tour.addStep(fourthStep);
tour.startTour();
}
/**
* Init filter
*/
public void initFilter(){
list = new BulletList();
list.setStyleName("input-list-caller");
list.clear();
}
@UiHandler("t_search")
public void onKeyDown(KeyDownEvent event) {
if(event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
searchPolicy();
}
}
@UiHandler("b_search")
void onClickSearch(ClickEvent e) {
searchPolicy();
}
@UiHandler("b_search_start")
void onClickSearchTypeStart(ClickEvent e) {
typeSearch="start";
searchPolicy();
}
@UiHandler("b_search_contains")
void onClickSearchTypeContains(ClickEvent e) {
typeSearch="contains";
searchPolicy();
}
@UiHandler("b_group_none")
void onClickFilterNone(ClickEvent e) {
filterPolicy("");
}
@UiHandler("b_group_user")
void onClickFilterUser(ClickEvent e) {
filterPolicy(TypeCaller.user.toString());
}
@UiHandler("b_group_role")
void onClickFilterRole(ClickEvent e) {
filterPolicy(TypeCaller.role.toString());
}
@UiHandler("b_group_service")
void onClickFilterService(ClickEvent e) {
filterPolicy(TypeCaller.service.toString());
}
@UiHandler("b_add_policy")
void onClickAddPolicy(ClickEvent e) {
GWT.log("AuthManager - Open Dialog Insert/Modify Policy");
PolicyAddDialog popup = new PolicyAddDialog();
popup.setAnimationEnabled(true);
popup.show();
}
@UiHandler("b_delete_policy")
void onClickRemovePolicy(ClickEvent e) {
GWT.log("AuthManager - Remove Policy");
if (!PolicyDataGrid.selectedPolicy.isEmpty()){
PolicyDeleteDialog confirmDeleteDialog = new PolicyDeleteDialog(PolicyDataGrid.selectedPolicy);
confirmDeleteDialog.show();
}
}
/**
*clear filter and reload all policy
* @param e
*/
@UiHandler("b_refresh")
void onClickRefresh(ClickEvent e) {
GWT.log("AuthManager - Refresh List Policy");
list.clear();
b_group_none.setFocus(true);
b_group_none.setActive(true);
b_group_user.setFocus(false);
b_group_user.setActive(false);
b_group_role.setFocus(false);
b_group_role.setActive(false);
b_group_service.setFocus(false);
b_group_service.setActive(false);
AuthManagerController.eventBus.fireEvent(new ListPolicyEvent());
}
public void searchPolicy(){
final String search = t_search.getText();
if (!search.isEmpty()){
GWT.log("AuthManager - Filter Search:"+search);
//build a list item
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(search);
displayItem.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
displayItem.addStyleName("token-input-selected-token-facebook");
}
});
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeStringSearch(displayItem, list,search);
}
});
//add a new filter into list
displayItem.add(p);
displayItem.add(span);
//add a filter into new list search
PolicyDataProvider.get().setAddStringSearch(search);
if (b_search_contains.isToggled())
typeSearch="contains";
else
typeSearch="start";
//refresh a provider for data grid
PolicyDataProvider.get().refreshlistFromSearch(typeSearch);
list.add(displayItem);
string_search.add(list);
//init textbox search
t_search.setText(null);
}
else{
PolicyDataProvider.get().refreshlistFromSearch(typeSearch);
}
}
/**
* Filter list policy for radio button and reset box search
* @param typefilter
*/
private void filterPolicy(String typefilter) {
// TODO Auto-generated method stub
//use filter
PolicyDataProvider.get().setFilterList(typefilter);
//reset box search
PolicyDataProvider.get().removeAllStringSearch();
list.clear();
}
/**
* Remove a string filter from list and provider
*
* @param displayItem
* @param list
* @param search
*/
public void removeStringSearch(ListItem displayItem, BulletList list,String search){
list.remove(displayItem);
PolicyDataProvider.get().removeStringSearch(search);
PolicyDataProvider.get().refreshlistFromSearch(typeSearch);
}
}

View File

@ -0,0 +1,123 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.txt_search {
border-radius: 0px !important;
margin-bottom: 0px !important;
}
.btn_search {
border-radius: 0px 8px 8px 0 !important;
-webkit-border-radius: 0px 8px 8px 0 !important;;
-moz-border-radius: 0px 8px 8px 0 !important;
margin-right: 30px !important;
}
.btn_search_start {
-webkit-border-radius: 0px;
border-radius: 0px !important;
}
.btn_search_start:before {
color: #333333;
content: "\f036";
display: inline-block;
font-family: "fontawesome";
}
.btn_search_contains {
-webkit-border-radius: 0px;
border-radius: 0px !important;
}
.btn_search_contains:before {
color: #333333;
content: "\f039";
display: inline-block;
font-family: "fontawesome";
}
.filter_bar {
height: 30px;
padding: 2px;
background-color: #fff;
border-radius: 4px;
}
.label_wizard_policy {
margin-left: 10 px;
font-size: 15 px;
font-weight: 600;
}
</ui:style>
<g:HTMLPanel>
<b:WellForm type="SEARCH" ui:field="form_search">
<b:ControlGroup>
<b:Controls>
<b:Tooltip text='Delete Policy'>
<b:Button type="DANGER" addStyleNames="btn btn_delete"
ui:field="b_delete_policy" />
</b:Tooltip>
<b:Tooltip text='' b:id="idAddPolicy">
<b:Button type="SUCCESS" addStyleNames="btn btn_add"
ui:field="b_add_policy" />
</b:Tooltip>
<b:InputAddOn prependIcon="SEARCH" ui:field="i_search"
b:id="idSearchPolicy">
<b:Popover trigger="FOCUS" placement="TOP"
text="use @ for search caller,
or $ for service, or * for access"
heading="Tag for search">
<b:TextBox addStyleNames="{style.txt_search}"
placeholder="click for search" b:id="t_search" ui:field="t_search" />
</b:Popover>
<b:ButtonGroup toggle="radio" ui:field="b_search_type">
<b:Tooltip text='Search Starts With'>
<b:Button addStyleNames="btn {style.btn_search_start}"
ui:field="b_search_start" active="true" />
</b:Tooltip>
<b:Tooltip text='Search Container'>
<b:Button addStyleNames="btn {style.btn_search_contains}"
ui:field="b_search_contains" />
</b:Tooltip>
</b:ButtonGroup>
<b:Button addStyleNames='{style.btn_search}' ui:field="b_search">Search</b:Button>
</b:InputAddOn>
<b:ButtonGroup toggle="radio" b:id="idGroupPolicy">
<b:Tooltip text='Select All Caller'>
<b:Button addStyleNames="btn btn_group_none" ui:field="b_group_none"
active="true" />
</b:Tooltip>
<b:Tooltip text='Caller Group by User'>
<b:Button addStyleNames="btn btn_group_user" ui:field="b_group_user" />
</b:Tooltip>
<b:Tooltip text='Caller Group by Role'>
<b:Button addStyleNames="btn btn_group_role" ui:field="b_group_role" />
</b:Tooltip>
<b:Tooltip text='Caller Group by Service'>
<b:Button addStyleNames="btn btn_group_service"
ui:field="b_group_service" />
</b:Tooltip>
</b:ButtonGroup>
<b:Tooltip text='Refresh List Policy'>
<b:Button addStyleNames="btn btn_refresh" ui:field="b_refresh" />
</b:Tooltip>
<span styleName="{style.label_wizard_policy}">
Create policy to deny access to Services
in the current context
</span>
</b:Controls>
</b:ControlGroup>
<g:FlowPanel addStyleNames="{style.filter_bar}" ui:field="string_search">
</g:FlowPanel>
</b:WellForm>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,298 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.event.ListQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.widget.BulletList;
import org.gcube.portlets.admin.authportletmanager.client.widget.ListItem;
import org.gcube.portlets.admin.authportletmanager.client.widget.Paragraph;
import org.gcube.portlets.admin.authportletmanager.client.widget.Span;
import org.gcube.portlets.widgets.widgettour.client.extendedclasses.GCubeTour;
import com.ait.toolkit.hopscotch.client.Placement;
import com.ait.toolkit.hopscotch.client.TourStep;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ButtonGroup;
import com.github.gwtbootstrap.client.ui.InputAddOn;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Header Filter for search, add and delete quote
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class QuotaFilter extends Composite {
private static QuotaFilterUiBinder uiBinder = GWT
.create(QuotaFilterUiBinder.class);
interface QuotaFilterUiBinder extends UiBinder<Widget, QuotaFilter> {
}
@UiField
TextBox t_search;
@UiField
InputAddOn i_search;
@UiField
Button b_search;
@UiField
Button b_refresh;
@UiField
Button b_add_quota;
@UiField
Button b_delete_quota;
@UiField
Button b_group_none;
@UiField
Button b_group_user;
@UiField
Button b_group_role;
@UiField
Button b_search_start;
@UiField
Button b_search_contains;
@UiField
ButtonGroup b_search_type;
@UiField
FlowPanel string_search;
private String typeSearch="start";
private BulletList list;
/**
*
*/
public QuotaFilter() {
initWidget(uiBinder.createAndBindUi(this));
initFilter();
guideTour();
}
public void guideTour(){
GCubeTour tour = new GCubeTour("Tour-auth", "auth-portlet-manager", 2, "Would you like to see again this tour next time ?", "Tour Auth Manager");
GWT.log("AuthManager - Start Gcube Tour ");
tour.setShowPrevButton(true);
/*
TourStep firstStep = new TourStep(Placement.TOP, "idGridQuote");
firstStep.setContent("See your quote");
firstStep.setTitle("List quote manager active");
firstStep.centerXOffset();
firstStep.centerArrowOffset();
*/
TourStep secondStep = new TourStep(Placement.TOP, "idAddQuote");
secondStep.setContent("Use this for add a new quote manager ");
secondStep.setTitle("Add Quote");
secondStep.centerXOffset();
secondStep.centerArrowOffset();
TourStep thirdStep = new TourStep(Placement.TOP, "idSearchQuote");
thirdStep.setContent("Use this for search an existing quote manager ");
thirdStep.setTitle("Search Quote");
thirdStep.centerXOffset();
thirdStep.centerArrowOffset();
TourStep fourthStep = new TourStep(Placement.TOP, "idGroupQuote");
fourthStep.setContent("Use this for filter group quote manager ");
fourthStep.setTitle("Filter Quote");
fourthStep.centerXOffset();
fourthStep.centerArrowOffset();
// tour.addStep(firstStep);
tour.addStep(secondStep);
tour.addStep(thirdStep);
tour.addStep(fourthStep);
tour.startTour();
GWT.log("AuthManager - Quota Tour Complete ");
}
/**
* Init filter
*/
public void initFilter(){
list = new BulletList();
list.setStyleName("input-list-caller");
list.clear();
}
@UiHandler("t_search")
public void onKeyDown(KeyDownEvent event) {
if(event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
searchQuote();
}
}
@UiHandler("b_search")
void onClickSearch(ClickEvent e) {
searchQuote();
}
@UiHandler("b_search_start")
void onClickSearchTypeStart(ClickEvent e) {
typeSearch="start";
searchQuote();
}
@UiHandler("b_search_contains")
void onClickSearchTypeContains(ClickEvent e) {
typeSearch="contains";
searchQuote();
}
@UiHandler("b_group_none")
void onClickFilterNone(ClickEvent e) {
filterQuote("");
}
@UiHandler("b_group_user")
void onClickFilterUser(ClickEvent e) {
filterQuote("User");
}
@UiHandler("b_group_role")
void onClickFilterRole(ClickEvent e) {
filterQuote("role");
}
@UiHandler("b_add_quota")
void onClickAddQuote(ClickEvent e) {
GWT.log("AuthManager - Add New Quota");
QuoteAddDialog popupQuote = new QuoteAddDialog();
popupQuote.setAnimationEnabled(true);
popupQuote.show();
}
@UiHandler("b_delete_quota")
void onClickRemoveQuote(ClickEvent e) {
GWT.log("AuthManager - Remove Quote");
if (!QuoteDataGrid.selectedQuote.isEmpty()){
QuoteDeleteDialog confirmDeleteDialog = new QuoteDeleteDialog(QuoteDataGrid.selectedQuote);
confirmDeleteDialog.show();
}
}
/**
*clear filter and reload all quote
* @param e
*/
@UiHandler("b_refresh")
void onClickRefresh(ClickEvent e) {
GWT.log("AuthManager - Refresh List Quote");
list.clear();
AuthManagerController.eventBus.fireEvent(new ListQuoteEvent());
}
public void searchQuote(){
final String search = t_search.getText();
if (!search.isEmpty()){
GWT.log("Search text:"+search);
//build a list item
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(search);
displayItem.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
displayItem.addStyleName("token-input-selected-token-facebook");
}
});
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeStringSearch(displayItem, list,search);
}
});
//add a new filter into list
displayItem.add(p);
displayItem.add(span);
//add a filter into new list search
QuoteDataProvider.get().setAddStringSearch(search);
if (b_search_contains.isToggled())
typeSearch="contains";
else
typeSearch="start";
//refresh a provider for data grid
QuoteDataProvider.get().refreshlistFromSearch(typeSearch);
list.add(displayItem);
string_search.add(list);
//init textbox search
t_search.setText(null);
}
else{
QuoteDataProvider.get().refreshlistFromSearch(typeSearch);
}
}
/**
* Filter list quote for radio button and reset box search
* @param typefilter
*/
private void filterQuote(String typefilter) {
// TODO Auto-generated method stub
//use filter
QuoteDataProvider.get().setFilterList(typefilter);
//reset box search
QuoteDataProvider.get().removeAllStringSearch();
list.clear();
}
/**
* Remove a string filter from list and provider
*
* @param displayItem
* @param list
* @param search
*/
public void removeStringSearch(ListItem displayItem, BulletList list,String search){
list.remove(displayItem);
QuoteDataProvider.get().removeStringSearch(search);
QuoteDataProvider.get().refreshlistFromSearch(typeSearch);
}
}

View File

@ -0,0 +1,125 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.txt_search {
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px !important;
margin-bottom: 0 !important;
}
.btn_search {
border-radius: 0px 8px 8px 0 !important;
-webkit-border-radius: 0px 8px 8px 0 !important;;
-moz-border-radius: 0px 8px 8px 0 !important;
margin-right: 30px !important;
}
.btn_search_start {
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px !important;
}
.btn_search_start:before {
color: #333333;
content: "\f036";
display: inline-block;
font-family: "fontawesome";
}
.btn_search_contains {
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px !important;
}
.btn_search_contains:before {
color: #333333;
content: "\f039";
display: inline-block;
font-family: "fontawesome";
}
.filter_bar {
height: 30px;
padding: 2px;
background-color: #fff;
border-radius: 4px;
}
</ui:style>
<g:HTMLPanel>
<b:WellForm type="SEARCH" ui:field="form_search">
<b:ControlGroup>
<b:Controls>
<b:Tooltip text='Delete Quote'>
<b:Button type="DANGER" addStyleNames="btn btn_delete"
ui:field="b_delete_quota" />
</b:Tooltip>
<b:Tooltip text='' b:id="idAddQuote">
<b:Button type="SUCCESS" addStyleNames="btn btn_add"
ui:field="b_add_quota" />
</b:Tooltip>
<b:InputAddOn prependIcon="SEARCH" ui:field="i_search" b:id="idSearchQuote">
<b:Popover trigger="FOCUS" placement="TOP"
text="use @ for search caller
$ for time
* for type"
heading="Tag for search">
<b:TextBox addStyleNames="{style.txt_search}"
placeholder="click for search" b:id="t_search" ui:field="t_search" />
</b:Popover>
<b:ButtonGroup toggle="radio" ui:field="b_search_type">
<b:Tooltip text='Search Starts With'>
<b:Button addStyleNames="btn {style.btn_search_start}"
ui:field="b_search_start" active="true" />
</b:Tooltip>
<b:Tooltip text='Search Container'>
<b:Button addStyleNames="btn {style.btn_search_contains}"
ui:field="b_search_contains" />
</b:Tooltip>
</b:ButtonGroup>
<b:Button addStyleNames='{style.btn_search}' ui:field="b_search">Search</b:Button>
</b:InputAddOn>
<b:ButtonGroup toggle="radio" b:id="idGroupQuote">
<b:Tooltip text='Select All Caller'>
<b:Button addStyleNames="btn btn_group_none" ui:field="b_group_none"
active="true" />
</b:Tooltip>
<b:Tooltip text='Select User Caller'>
<b:Button addStyleNames="btn btn_group_user" ui:field="b_group_user" />
</b:Tooltip>
<b:Tooltip text='Select Role Caller'>
<b:Button addStyleNames="btn btn_group_role" ui:field="b_group_role" />
</b:Tooltip>
</b:ButtonGroup>
<b:Tooltip text='Refresh List Quota'>
<b:Button addStyleNames="btn btn_refresh" ui:field="b_refresh" />
</b:Tooltip>
</b:Controls>
</b:ControlGroup>
<g:FlowPanel addStyleNames="{style.filter_bar}" ui:field="string_search">
</g:FlowPanel>
</b:WellForm>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,438 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.event.AddQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.event.UpdateQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.resource.AuthResources;
import org.gcube.portlets.admin.authportletmanager.client.widget.InputListWidget;
import org.gcube.portlets.admin.authportletmanager.client.widget.WindowBox;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import org.gcube.portlets.admin.authportletmanager.shared.Quote.ManagerType;
import org.gcube.portlets.admin.authportletmanager.shared.Quote.TimeInterval;
import org.gcube.portlets.widgets.widgettour.client.extendedclasses.GCubeTour;
import com.ait.toolkit.hopscotch.client.Placement;
import com.ait.toolkit.hopscotch.client.TourStep;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ButtonGroup;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Row;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.base.AlertBase;
import com.github.gwtbootstrap.client.ui.event.ClosedEvent;
import com.github.gwtbootstrap.client.ui.event.ClosedHandler;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for add a policy
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class QuoteAddDialog extends WindowBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, QuoteAddDialog> {
}
private Boolean error_display=false;
private ArrayList<Quote>listModifyQuote;
private ArrayList<Quote>listAddQuote;
public InputListWidget ListWidget;
@UiField
FlowPanel text_caller_quota;
@UiField
ListBox l_time_interval_quota;
@UiField
ListBox l_type_quota;
@UiField
ButtonGroup b_caller_checkbox;
@UiField
Button b_caller_all_user;
@UiField
Button b_caller_all_role;
@UiField
Button b_caller_except;
@UiField
Button b_add_multiple_caller;
@UiField
Button b_exit_dialog_quota;
@UiField
Button b_save_quota;
@UiField
TextBox t_value_quota;
@UiField
Row r_loader_space;
@UiField
FlowPanel idAddCallerQuote;
@UiField
FlowPanel idAddTimeQuote;
@UiField
FlowPanel idAddTypeQuote;
@UiField
FlowPanel idAddValueQuote;
public QuoteAddDialog() {
super(true, false);
this.setWidget(binder.createAndBindUi(this));
//this.setGlassEnabled(true);
this.setWidth("800px");
this.setAnimationEnabled(true);
this.setGlassEnabled(true);
this.center();
this.setText("Add/Update Quota");
idAddCallerQuote.getElement().setId("idAddCallerQuote");
idAddTimeQuote.getElement().setId("idAddTimeQuote");
idAddTypeQuote.getElement().setId("idAddTypeQuote");
idAddValueQuote.getElement().setId("idAddValueQuote");
//istance a new list policy for modify
listModifyQuote=new ArrayList<Quote>();
//Initialize a suggest for caller
text_caller_quota.setStyleName("auto_suggest");
ListWidget=new InputListWidget();
text_caller_quota.add(ListWidget);
//disable except
b_caller_except.setEnabled(false);
for (TimeInterval time : TimeInterval.values()) {
l_time_interval_quota.addItem(time.toString());
}
for (ManagerType managerType : ManagerType.values()) {
l_type_quota.addItem(managerType.toString());
}
r_loader_space.clear();
GCubeTour tourAddDialogQuote = new GCubeTour("tour-auth add dialog", "auth-portlet-manager", 2, "Would you like to see again this tour next time ?", "Tour Quote Manager use");
tourAddDialogQuote.setShowPrevButton(true);
TourStep firstStep = new TourStep(Placement.TOP, "idAddCallerQuote");
firstStep.setContent("Add a single or multiple caller that you define a quote manager"
+ "If insert an user digit @ before,if insert a role digit # and $ if you want insert a service");
firstStep.setTitle("Add Caller");
firstStep.centerXOffset();
firstStep.centerArrowOffset();
TourStep secondStep = new TourStep(Placement.TOP, "idAddTimeQuote");
secondStep.setContent("Select an interval time for quote ");
secondStep.setTitle("Specify a Time ");
secondStep.centerXOffset();
secondStep.centerArrowOffset();
TourStep thirdStep = new TourStep(Placement.TOP, "idAddTypeQuote");
thirdStep.setContent("Select a type for quote ");
thirdStep.setTitle("Specify a Type");
thirdStep.centerXOffset();
thirdStep.centerArrowOffset();
TourStep fourthStep = new TourStep(Placement.TOP, "idAddValueQuote");
fourthStep.setContent("Select a value for quote ");
fourthStep.setTitle("Specify a Quota");
fourthStep.centerXOffset();
fourthStep.centerArrowOffset();
tourAddDialogQuote.addStep(firstStep);
tourAddDialogQuote.addStep(secondStep);
tourAddDialogQuote.addStep(thirdStep);
tourAddDialogQuote.addStep(fourthStep);
tourAddDialogQuote.startTour();
}
/**
* Click all user
* @param e ClickEvent
*/
@UiHandler("b_caller_all_user")
void onClickAddAllUser(ClickEvent e) {
if (!b_caller_all_user.isToggled()){
//selected checkbox all user
b_caller_all_user.setFocus(false);
b_caller_all_role.setFocus(false);
b_caller_all_role.setActive(false);
b_add_multiple_caller.setEnabled(false);
b_caller_except.setEnabled(true);
b_caller_except.setActive(false);
Caller allCallerUser= new Caller(TypeCaller.user,"ALL");
ListWidget.addCaller(allCallerUser);
}
else{
//not selected checkbox all user
b_caller_all_role.setEnabled(true);
b_add_multiple_caller.setEnabled(true);
b_caller_except.setEnabled(false);
ListWidget.clearList();
}
}
/**
* Click all role
* @param e ClickEvent
*/
@UiHandler("b_caller_all_role")
void onClickAddAllRole(ClickEvent e) {
if (!b_caller_all_role.isToggled()){
//selected checkbox all role
b_caller_all_role.setFocus(false);
b_caller_all_user.setFocus(false);
b_caller_all_user.setActive(false);
b_add_multiple_caller.setEnabled(false);
b_caller_except.setEnabled(true);
b_caller_except.setActive(false);
Caller allCallerRole= new Caller(TypeCaller.role,"ALL");
ListWidget.addCaller(allCallerRole);
}
else{
//not selected checkbox all role
b_caller_all_user.setEnabled(true);
b_add_multiple_caller.setEnabled(true);
b_caller_except.setEnabled(false);
ListWidget.clearList();
}
}
/**
* Click except
* @param e ClickEvent
*/
@UiHandler("b_caller_except")
void onClickExcept(ClickEvent e) {
//selected except
if (!b_caller_except.isToggled())
ListWidget.enabledList();
else{
ListWidget.clearList();
if (!b_caller_all_role.isToggled()){
Caller allCallerUser= new Caller(TypeCaller.user,"ALL");
ListWidget.addCaller(allCallerUser);
}
else if (!b_caller_all_user.isToggled()){
Caller allCallerRole= new Caller(TypeCaller.role,"ALL");
ListWidget.addCaller(allCallerRole);
}
}
}
/**
* Click open dialog for multiple caller
* @param e
*/
@UiHandler("b_add_multiple_caller")
void onClickAddCaller(ClickEvent e) {
DialogAddMultipleCallerUserRole popup = new DialogAddMultipleCallerUserRole();
popup.initList(ListWidget.callerSelected,this);
popup.show();
}
/**
* Click close dialog
* @param e
*/
@UiHandler("b_exit_dialog_quota")
void onClickExitDialogQuote(ClickEvent e) {
this.hide();
this.clear();
}
/**
* Click add policy
* @param e
*/
@UiHandler("b_save_quota")
void onClickSaveQuote(ClickEvent e) {
if (ListWidget.callerSelected.isEmpty()){
if (!error_display)
ErrorText("Insert Caller");
error_display=true;
}
else{
error_display=false;
//TimeInterval timeIntervalQuota=TimeInterval.valueOf(l_time_interval_quota.getSelectedValue());
int indexI = l_time_interval_quota.getSelectedIndex();
TimeInterval timeIntervalQuota =TimeInterval.valueOf(l_time_interval_quota.getValue(indexI));
//ManagerType typeQuota=ManagerType.valueOf(l_type_quota.getSelectedValue());
int indexQ = l_type_quota.getSelectedIndex();
ManagerType typeQuota =ManagerType.valueOf(l_type_quota.getValue(indexQ));
Double valueQuota=Double.parseDouble(t_value_quota.getText());
if (listModifyQuote.isEmpty()){
//quota to be added
//verify if a insert simple or exception
if (b_caller_except.isToggled()){
GWT.log("AuthManager - Insert new quota with execption and type:"+typeQuota);
Quote quote= new Quote();
List<Caller> callerList=new ArrayList<Caller>();
//order a list caller
if (ListWidget.callerSelected.size() > 0) {
Collections.sort(ListWidget.callerSelected, new Comparator<Caller>() {
@Override
public int compare(final Caller o1, final Caller o2) {
return o1.getCallerName().compareTo(o2.getCallerName());
}
} );
}
for (Caller caller:ListWidget.callerSelected){
// GWT.log("add"+caller.getCallerName());
callerList.add(caller);
}
quote.setCaller(callerList);
quote.setManager(typeQuota);
quote.setTimeInterval(timeIntervalQuota);
quote.setQuota(valueQuota);
listAddQuote=new ArrayList<Quote>();
listAddQuote.add(quote);
AuthManagerController.eventBus.fireEvent(new AddQuoteEvent(listAddQuote, this));
}
else{
listAddQuote=new ArrayList<Quote>();
for (Caller caller:ListWidget.callerSelected){
GWT.log("AuthManager - Insert new quote "+caller.getCallerName()+" and type:"+typeQuota);
Quote quote= new Quote();
List<Caller> callerList=new ArrayList<Caller>();
callerList.add(caller);
quote.setCaller(callerList);
quote.setManager(typeQuota);
quote.setTimeInterval(timeIntervalQuota);
quote.setQuota(valueQuota);
listAddQuote.add(quote);
}
AuthManagerController.eventBus.fireEvent(new AddQuoteEvent(listAddQuote, this));
}
}
else{
for (Quote modifyQuote:listModifyQuote){
Long idQuote=modifyQuote.getIdQuote();
GWT.log("AuthManager - Update quote:"+idQuote);
modifyQuote.setManager(typeQuota);
modifyQuote.setTimeInterval(timeIntervalQuota);
modifyQuote.setQuota(valueQuota);
AuthManagerController.eventBus.fireEvent(new UpdateQuoteEvent(modifyQuote,this));
}
}
}
}
/**
* Array list for policy modified
* @param listPolicy
*/
public void setModifyQuote(ArrayList<Quote> listQuote) {
String timeInterval = null;
String managerType = null;
String quota = null;
this.listModifyQuote = listQuote;
for (Quote result :listQuote){
List<Caller> callerList= result.getCaller();
timeInterval = result.getTimeInterval().toString();
managerType=result.getManager().toString();
//String target=result.getTarget();
quota =result.getQuota().toString();
ListWidget.addListCaller(callerList,false);
GWT.log("AuthManager - Modify existing Quote identifier:"+result.getIdQuote()+" from caller:"+result.getCallerAsString());
}
//DISABLE ADD ANOTHER CALLER
b_caller_all_user.setEnabled(false);
b_caller_all_role.setEnabled(false);
b_add_multiple_caller.setEnabled(false);
/*
for (TimeInterval time : TimeInterval.values()) {
l_time_interval_quota.addItem(time.toString());
}
*/
l_time_interval_quota.setSelectedValue(timeInterval);
/*
for (ManagerType manager : ManagerType.values()) {
l_type_quota.addItem(manager.toString());
}
*/
l_type_quota.setSelectedValue(managerType);
t_value_quota.setText(quota);
}
/**
* Retrieve information from dialog multiple caller
* @param listCaller
*/
public void setListCaller(List<Caller> listCaller){
ListWidget.addListCaller(listCaller,true);
}
/**
* Alert for msg error
* @param stringMsg
*/
public void ErrorText(String stringMsg) {
Alert msg = new Alert();
msg.setAnimation(true);
msg.setText(stringMsg);
msg.addClosedHandler(new ClosedHandler<AlertBase>() {
@Override
public void onClosed(ClosedEvent<AlertBase> event) {
// TODO Auto-generated method stub
error_display=false;
}
});
r_loader_space.add(msg);
}
/**
* Start Animation loading
*/
public void AppLoadingView() {
b_exit_dialog_quota.setEnabled(false);
b_save_quota.setEnabled(false);
Image imgLoading = new Image(AuthResources.INSTANCE.loaderIcon());
r_loader_space.clear();
r_loader_space.add(imgLoading);
}
/**
* Stop animation loading
*/
public void StopAppLoadingView() {
// TODO Auto-generated method stub
b_exit_dialog_quota.setEnabled(true);
b_save_quota.setEnabled(true);
clear();
hide();
}
}

View File

@ -0,0 +1,123 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.panel {
background-color: #d9e2e8;
padding: 10px;
border-left: 2px solid #888;
border-right: 2px solid #888;
border-bottom: 2px solid #888;
/*
border-radius: 4px;
border: 2px solid #888;
width: 80%;
margin-left: 10%;
*/
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 1px solid #ccc;
padding: 10px;
}
.r_loader_space {
/*margin-top:10px;*/
text-align: center;
height: 30px;
margin-bottom: 10px;
margin-right: 20px;
}
.row_element {
margin-top: 10px;
}
.footer_dialog {
padding-right: 20px;
text-align: right;
}
.button_dialog {
margin-left: 10px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddCallerQuote">
<!-- CALLER -->
<b:FluidRow styleName="{style.row_element}">
<b:ControlLabel>Caller</b:ControlLabel>
</b:FluidRow>
<b:Row styleName="{style.row_element}">
<b:ButtonGroup toggle="checkbox" ui:field="b_caller_checkbox">
<b:Button ui:field="b_caller_all_user">All Users</b:Button>
</b:ButtonGroup>
<b:ButtonGroup toggle="checkbox">
<b:Button ui:field="b_caller_all_role">All Role</b:Button>
</b:ButtonGroup>
<b:ButtonGroup toggle="checkbox">
<b:Button ui:field="b_caller_except">Except</b:Button>
</b:ButtonGroup>
</b:Row>
<b:Row styleName="{style.row_element}">
<g:FlowPanel ui:field="text_caller_quota">
</g:FlowPanel>
</b:Row>
<b:Row styleName="{style.row_element}">
<b:Tooltip text='Add Caller'>
<b:Button addStyleNames="btn btn_add" ui:field="b_add_multiple_caller">Add
Caller</b:Button>
</b:Tooltip>
</b:Row>
</g:FlowPanel>
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddTimeQuote">
<!-- TIME INTERVAL -->
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Time</b:ControlLabel>
<b:ListBox ui:field="l_time_interval_quota">
</b:ListBox>
</b:Row>
</g:FlowPanel>
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddTypeQuote">
<!-- TYPE INTERVAL -->
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Type</b:ControlLabel>
<b:ListBox ui:field="l_type_quota">
</b:ListBox>
</b:Row>
</g:FlowPanel>
<g:FlowPanel styleName="{style.panel_text}" ui:field="idAddValueQuote">
<!-- VALUE QUOTA -->
<b:Row styleName="{style.row_element}">
<b:ControlLabel>Quota</b:ControlLabel>
<b:TextBox ui:field="t_value_quota"></b:TextBox>
</b:Row>
</g:FlowPanel>
</b:Column>
<b:Column size="12">
<b:Row ui:field="r_loader_space" addStyleNames='{style.r_loader_space}'>
</b:Row>
</b:Column>
<b:Column size="6" offset="6" addStyleNames='{style.footer_dialog}'>
<b:Button ui:field="b_save_quota" type="PRIMARY"
addStyleNames='{style.button_dialog}'>Save</b:Button>
<b:Button ui:field="b_exit_dialog_quota" type="DANGER"
addStyleNames='{style.button_dialog}'>Close</b:Button>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,406 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.widget.ActionCellClass;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.github.gwtbootstrap.client.ui.Label;
import com.google.gwt.cell.client.ActionCell.Delegate;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.CheckboxCell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.cell.client.NumberCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionModel;
/**
* Table for list quote (data grid)
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class QuoteDataGrid extends Composite {
private static QuoteDataGridUiBinder uiBinder = GWT
.create(QuoteDataGridUiBinder.class);
interface QuoteDataGridUiBinder extends UiBinder<Widget, QuoteDataGrid> {
}
/**
* The main DataGrid.
*/
@UiField(provided = true)
DataGrid<Quote> dataGrid;
@UiField(provided = true)
SimplePager pager;
public QuoteDataGrid() {
onInitialize();
initWidget(uiBinder.createAndBindUi(this));
}
private Column<Quote, String> callerColumn;
//private Column<Quote, String> targetColumn;
private Column<Quote, String> managerColumn;
private Column<Quote, String> timeIntervalColumn;
private Column<Quote, Number> quoteColumn;
private Column<Quote, Date> dataInsertColumn;
private Column<Quote, Date> dataUpdateColumn;
public static SelectionModel<Quote> selectionModel;
public static ArrayList<Quote>selectedQuote= new ArrayList<Quote>();
public void onInitialize() {
//resources = GWT.create(Resources.class);
//resources.styles().ensureInjected();
dataGrid = new DataGrid<Quote>();
dataGrid.setWidth("100%");
dataGrid.setHeight("400px");
dataGrid.setAutoHeaderRefreshDisabled(true);
dataGrid.setAutoHeaderRefreshDisabled(true);
dataGrid.addStyleName("table_quote");
dataGrid.getElement().setId("idGridQuote");
//Set the message to display when the table is empty.
dataGrid.setEmptyTableWidget(new Label("No Quote Entry"));
dataGrid.setSkipRowHoverStyleUpdate(false);
/*
// dataGrid.setHeaderBuilder(new CustomHeaderBuilder());
// dataGrid.setFooterBuilder(new CustomFooterBuilder());
*/
// Create a Pager to control the table.
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
pager.setDisplay(dataGrid);
// Attach a column sort handler to the ListDataProvider to sort the list.
ListHandler<Quote> sortHandler =
new ListHandler<Quote>(QuoteDataProvider.get().getDataProvider().getList());
dataGrid.addColumnSortHandler(sortHandler);
//Add a selection model so we can select cells.
selectionModel = new MultiSelectionModel<Quote>();
dataGrid.setSelectionModel(selectionModel, DefaultSelectionEventManager
.<Quote> createCheckboxManager());
//Init Table Columns
initTableColumns(selectionModel, sortHandler);
QuoteDataProvider.get().addDataDisplay(dataGrid);
dataGrid.setVisible(true);
}
/**
* Init the columns to the table.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initTableColumns(final SelectionModel<Quote> selectionModel,
ListHandler<Quote> sortHandler) {
// Checkbox column. This table will uses a checkbox column for selection.
Column<Quote, Boolean> checkColumn =
new Column<Quote, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(Quote object) {
// Get the value from the selection model.
if (selectionModel.isSelected(object)){
//if already exist no add
if (!selectedQuote.contains(object))
selectedQuote.add(object);
}
else
selectedQuote.remove(object);
return selectionModel.isSelected(object);
}
};
dataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
dataGrid.setColumnWidth(checkColumn, 5, Unit.PCT);
// CallerColumn column this is caller for the service
callerColumn = new Column<Quote, String>(new TextCell()) {
@Override
public String getValue(Quote object) {
String caller=object.getCallerAsString();
return caller;
}
/** for override style on clik */
@Override
public String getCellStyleNames(Context context, Quote object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
else
return null;
}
};
callerColumn.setSortable(true);
sortHandler.setComparator(callerColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
return o1.getCallerAsString().compareTo(o2.getCallerAsString());
}
});
dataGrid.setColumnWidth(callerColumn, 20, Unit.PCT);
dataGrid.addColumn(callerColumn, new ResizableHeader("Caller", dataGrid, callerColumn));
//timeIntervalColumn
timeIntervalColumn = new Column<Quote, String>(new TextCell()) {
@Override
public String getValue(Quote object) {
String target=object.getTimeInterval().toString();
return target;
}
/** for override style on clik */
@Override
public String getCellStyleNames(Context context, Quote object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
else
return null;
}
};
timeIntervalColumn.setSortable(true);
sortHandler.setComparator(timeIntervalColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
return o1.getTimeInterval().compareTo(o2.getTimeInterval());
}
});
dataGrid.setColumnWidth(timeIntervalColumn, 20, Unit.PCT);
dataGrid.addColumn(timeIntervalColumn, new ResizableHeader("Time", dataGrid, timeIntervalColumn));
//managerColumn
managerColumn = new Column<Quote, String>(new TextCell()) {
@Override
public String getValue(Quote object) {
String target=object.getManager().toString();
return target;
}
/** for override style on clik */
@Override
public String getCellStyleNames(Context context, Quote object) {
if (selectionModel.isSelected(object)) {
return "boldStyle";
}
else
return null;
}
};
managerColumn.setSortable(true);
sortHandler.setComparator(managerColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
return o1.getManager().compareTo(o2.getManager());
}
});
dataGrid.setColumnWidth(managerColumn, 20, Unit.PCT);
dataGrid.addColumn(managerColumn, new ResizableHeader("Type", dataGrid, managerColumn));
//quoteColumn
quoteColumn = new Column<Quote, Number>(new NumberCell()) {
@Override
public Double getValue(Quote object) {
Double target=object.getQuota();
return target;
}
};
quoteColumn.setSortable(true);
sortHandler.setComparator(quoteColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
return o1.getQuota().compareTo(o2.getQuota());
}
});
dataGrid.setColumnWidth(quoteColumn, 20, Unit.PCT);
dataGrid.addColumn(quoteColumn, new ResizableHeader("Quota", dataGrid, quoteColumn));
dataInsertColumn = new Column<Quote, Date>(new DateCell(DateTimeFormat.getFormat("EEE, d MMM yyyy HH:mm:ss"))) {
@Override
public Date getValue(Quote object) {
return object.getDataInsert();
}
};
dataInsertColumn.setSortable(true);
sortHandler.setComparator(dataInsertColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
if (o1 == o2) {
return 0;
}
if (o1.getDataInsert() != null) {
Date date1 =o1.getDataInsert();
Date date2 =o2.getDataInsert();
return (o2.getDataInsert() != null) ? date1.compareTo(date2) : 1;
}
return -1;
}
});
dataGrid.setColumnWidth(dataInsertColumn, 10, Unit.PCT);
dataGrid.addColumn(dataInsertColumn, new ResizableHeader("Insert", dataGrid, dataInsertColumn));
// dataUpdate.
dataUpdateColumn = new Column<Quote, Date>(new DateCell(DateTimeFormat.getFormat("EEE, d MMM yyyy HH:mm:ss "))) {
@Override
public Date getValue(Quote object) {
return object.getDataUpdate();
}
};
dataUpdateColumn.setSortable(true);
sortHandler.setComparator(dataUpdateColumn, new Comparator<Quote>() {
@Override
public int compare(Quote o1, Quote o2) {
if (o1 == o2) {
return 0;
}
if (o1.getDataUpdate() != null) {
Date date1 =o1.getDataUpdate();
Date date2 =o2.getDataUpdate();
return (o2.getDataUpdate() != null) ? date1.compareTo(date2) : 1;
}
return -1;
} });
dataGrid.setColumnWidth(dataUpdateColumn, 10, Unit.PCT);
dataGrid.addColumn(dataUpdateColumn, new ResizableHeader("Last Update", dataGrid, dataUpdateColumn));
//add Columns Actions whit button Edit
List<HasCell<Quote, ?>> cells = new LinkedList<HasCell<Quote, ?>>();
cells.add(new ActionHasCell("Edit", new Delegate<Quote>() {
@Override
public void execute(Quote quote) {
// EDIT CODE
QuoteAddDialog dialogedit = new QuoteAddDialog();
ArrayList<Quote> listModifiedQuote= new ArrayList<Quote>();
listModifiedQuote.add(quote);
dialogedit.setModifyQuote(listModifiedQuote);
dialogedit.show();
}
}));
cells.add(new ActionHasCell("Delete", new Delegate<Quote>() {
@Override
public void execute(Quote quote) {
// DELETE CODE
ArrayList<Quote> listDeleteQuotes =new ArrayList<Quote>();
listDeleteQuotes.add(quote);
QuoteDeleteDialog confirmDeleteDialog= new QuoteDeleteDialog(listDeleteQuotes);
confirmDeleteDialog.show();
}
}));
CompositeCell<Quote> cell = new CompositeCell<Quote>(cells);
Column<Quote, Quote> actionColumn =new Column<Quote, Quote>(cell) {
@Override
public Quote getValue(Quote object) {
return object;
}
};
dataGrid.setColumnWidth(actionColumn, 15, Unit.PCT);
dataGrid.addColumn(actionColumn, "Actions");
}
private class ActionHasCell implements HasCell<Quote, Quote> {
private ActionCellClass<Quote> cell;
public ActionHasCell(String text, Delegate<Quote> delegate) {
cell = new ActionCellClass<Quote>(text, delegate);
}
@Override
public Cell<Quote> getCell() {
return cell;
}
@Override
public FieldUpdater<Quote, Quote> getFieldUpdater() {
return null;
}
@Override
public Quote getValue(Quote object) {
return object;
}
}
}

View File

@ -0,0 +1,34 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:c="urn:import:com.google.gwt.user.cellview.client">
<ui:style>
.cellTable {
border-bottom: 1px solid #ccc;
text-align: left;
margin-bottom: 4px;
}
</ui:style>
<g:HTMLPanel>
<table cellspacing='0' cellpadding='0' style='width:100%;'>
<tr>
<td valign='top'>
<c:DataGrid addStyleNames='{style.cellTable}' pageSize='30'
ui:field='dataGrid' />
</td>
</tr>
<tr>
<td align='center'>
<c:SimplePager ui:field='pager' />
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,261 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.ListDataProvider;
/**
* The data source for contact information used in the sample.
*/
public class QuoteDataProvider {
/**
* The singleton instance of the database.
*/
private static QuoteDataProvider instance;
/**
* Get the singleton instance of the contact database.
*
* @return the singleton instance
*/
public static QuoteDataProvider get() {
if (instance == null) {
instance = new QuoteDataProvider();
}
return instance;
}
/**
* The provider that holds the list of contacts in the database.
*/
private ListDataProvider<Quote> dataProvider = new ListDataProvider<Quote>();
/**
* The list string used for search
*/
private List<String> initialSearch= new ArrayList<String>();;
/**
* The list quote used for datagrid
*/
private List<Quote> initialQuote;
/**
* Construct a new QuoteDataProvider
*/
private QuoteDataProvider() {
}
/**
* Add a display to the database. The current range of interest of the display
* will be populated with data.
*
* @param display a {@Link HasData}.
*/
public void addDataDisplay(HasData<Quote> display) {
dataProvider.addDataDisplay(display);
}
public ListDataProvider<Quote> getDataProvider() {
return dataProvider;
}
/**
* Load list quote provider
* @param listResultQuote
*/
public void loadQuoteProvider(List<Quote> listResultQuote) {
initialQuote = listResultQuote;
//load list quote from servlet
List<Quote> quote = dataProvider.getList();
quote.removeAll(quote);
for (Quote quota : listResultQuote){
quote.add(quota);
}
}
/***
* Reset a provider
*/
public void resetQuoteProvider(){
List<Quote> quote = dataProvider.getList();
quote.clear();
}
/**
* Refresh all displays.
*/
public void refreshDisplays() {
dataProvider.refresh();
}
/**
* Method for remove quote from provider
* @param idquote
*/
public void removeQuoteProvider(Long idquote) {
// TODO Auto-generated method stub
List<Quote> quote = dataProvider.getList();
for (int i=0; i<quote.size(); i++ ){
if (quote.get(i).getIdQuote().equals(idquote)){
quote.remove(i);
initialQuote.remove(i);
break;
}
}
}
/**
* Method for add a quote into provider
* @param quota
*/
public void addQuoteProvider(Quote quota) {
// TODO Auto-generated method stub
List<Quote> quote = dataProvider.getList();
quote.add(quota);
initialQuote.add(quota);
dataProvider.setList(quote);
}
/**
* Used for research a string filter
* @return
*/
public List<String> getInitialSearch() {
return initialSearch;
}
/**
* Refresh list from a list search
*/
public void refreshlistFromSearch(String typeSearch){
List<Quote> quote = new ArrayList<Quote>();
Collections.copy(quote, initialQuote);
List<Quote> toRemove = new ArrayList<Quote>(quote.size());
for (int index=0; index<quote.size(); index++ ){
for(String stringSearch: initialSearch) {
String ricerca=null;
if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagCaller)){
stringSearch=stringSearch.substring(1);
ricerca=quote.get(index).getCallerAsString();
}
else if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagTime)){
ricerca=quote.get(index).getTimeInterval().toString();
stringSearch=stringSearch.substring(1);
}
else if (stringSearch.substring(0, 1).equals(ConstantsSharing.TagType)){
stringSearch=stringSearch.substring(1);
ricerca=quote.get(index).getManager().toString();
}
else
ricerca=quote.get(index).getCallerAsString();
if (typeSearch.equals("contains")){
if(!ricerca.toLowerCase().contains(stringSearch.toLowerCase())){
toRemove.add(quote.get(index));
}
}
else{
if(!ricerca.toLowerCase().startsWith(stringSearch.toLowerCase())){
toRemove.add(quote.get(index));
}
}
}
}
quote.removeAll(toRemove);
dataProvider.setList(quote);
}
/**
* Used for add a List string filter
* @param initialSearch
*/
public void setInitialSearch(List<String> initialSearch) {
this.initialSearch = initialSearch;
}
/**
* Used for add a string search
* @param search
*/
public void setAddStringSearch(String search){
this.initialSearch.add(search);
}
/**
* Used for remove string search
* @param filter
*/
public void removeStringSearch(String filter) {
// TODO Auto-generated method stub
this.initialSearch.remove(filter);
}
/**
* Used for remove all string search
*/
public void removeAllStringSearch() {
// TODO Auto-generated method stub
this.initialSearch.clear();
}
/**
* Used for insert a filter button
* @param typefilter
*/
public void setFilterList(String typefilter) {
// TODO Auto-generated method stub
List<Quote> quoteFilter = new ArrayList<Quote>();
if (typefilter.isEmpty()){
Collections.copy(quoteFilter, initialQuote);
}
else{
for (int index=0; index<initialQuote.size(); index++ ){
if (initialQuote.get(index).getCallerTypeAsString().trim().equalsIgnoreCase(typefilter))
quoteFilter.add(initialQuote.get(index));
}
}
dataProvider.setList(quoteFilter);
}
}

View File

@ -0,0 +1,124 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.AuthManagerController;
import org.gcube.portlets.admin.authportletmanager.client.event.RemoveQuoteEvent;
import org.gcube.portlets.admin.authportletmanager.client.resource.AuthResources;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.Row;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;
/**
* Dialog Box for confirm delete quote
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class QuoteDeleteDialog extends DialogBox {
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, QuoteDeleteDialog> {
}
private ArrayList<Quote> deleteQuote;
//private Boolean error=false;
@UiField
Row r_loader_space;
@UiField
Button b_confirm_delete;
@UiField
Button b_confirm_exit;
public QuoteDeleteDialog(ArrayList<Quote> listDeleteQuote) {
this.setWidget(binder.createAndBindUi(this));
//this.setAutoHideEnabled(true);
this.setGlassEnabled(true);
this.setWidth("400px");
this.setHeight("200px");
this.setAnimationEnabled(isVisible());
//this.center();
this.setStyleName("modal_delete");
this.setPopupPosition(((Window.getClientWidth() - 400) / 2),
((Window.getClientHeight()-200)/2) );
this.deleteQuote=listDeleteQuote;
for (Quote quote:listDeleteQuote){
String caller=quote.getCallerAsString();
Label textquote =new Label();
textquote.setText("Caller:"+caller);
r_loader_space.add(textquote);
}
}
/***
* Handler on click for delete quote
* @param event
*/
@UiHandler("b_confirm_delete")
void onClickConfirmDeleteQuote(ClickEvent event) {
List<Long> listIdentifier=new ArrayList<Long>();
for (Quote quote:deleteQuote){
GWT.log("AuthManager - Delete Quote: "+quote.getIdQuote());
listIdentifier.add(quote.getIdQuote());
}
AuthManagerController.eventBus.fireEvent(new RemoveQuoteEvent(listIdentifier,this));
}
/***
* Handler on click for close dialog
* @param event
*/
@UiHandler("b_confirm_exit")
void onClickConfirmExitQuote(ClickEvent event) {
this.setAnimationEnabled(true);
this.hide();
this.clear();
}
/**
* Method for loader animation
*/
public void AppLoadingView()
{
Image imgLoading = new Image(AuthResources.INSTANCE.loaderIcon());
b_confirm_delete.setEnabled(false);
b_confirm_exit.setEnabled(false);
r_loader_space.clear();
r_loader_space.add(imgLoading);
}
public void StopAppLoadingView(){
b_confirm_delete.setEnabled(true);
b_confirm_exit.setEnabled(true);
deleteQuote.clear();
this.hide();
this.clear();
}
}

View File

@ -0,0 +1,67 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.panel {
background-color: #d9e2e8;
border-radius: 4px;
border: 2px solid #888;
/*padding: 10px;*/
width: 80%;
margin-left: 10%;
}
.panel_text {
background-color: #F3F7FB;
border-radius: 4px;
border: 1px solid #ccc;
padding: 10px;
}
.r_loader_space {
margin-top: 10px;
text-align: center;
/*height:30px;*/
margin-bottom: 20px;
width: 100%;
margin-left: 0px;
}
.footer_dialog {
text-align: right;
}
.button_dialog {
margin-left: 10px;
}
.label_summary {
text-align: center;
width: 100%;
margin-left: 5px;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}">
<b:FluidRow>
<b:Column size="12">
<g:FlowPanel styleName="{style.panel_text}">
<b:FluidRow>
<b:Heading size="2">
Confirm Delete ?
</b:Heading>
</b:FluidRow>
<b:Row ui:field="r_loader_space" addStyleNames='{style.r_loader_space}'>
</b:Row>
<b:FluidRow addStyleNames='{style.footer_dialog}'>
<b:Button type="PRIMARY" dismiss="MODAL" ui:field="b_confirm_exit"
addStyleNames='{style.button_dialog}'>NO</b:Button>
<b:Button type="DANGER" ui:field="b_confirm_delete"
addStyleNames='{style.button_dialog}'>YES</b:Button>
</b:FluidRow>
</g:FlowPanel>
</b:Column>
</b:FluidRow>
</g:FlowPanel>
</ui:UiBinder>

View File

@ -0,0 +1,170 @@
package org.gcube.portlets.admin.authportletmanager.client.pagelayout;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.cellview.client.AbstractCellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
/**
* ResizableHeader for DataGrid
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class ResizableHeader<T> extends Header<String> {
private Column<T, ?> column = null;
private AbstractCellTable<T> cellTable;
private String title = "";
private static final int width = 20;
public ResizableHeader(String title, AbstractCellTable<T> cellTable, Column<T, ?> column) {
super(new HeaderCell());
this.title = title;
this.cellTable = cellTable;
this.column = column;
}
@Override
public String getValue() {
return title;
}
@Override
public void onBrowserEvent(Context context, Element target, NativeEvent event) {
String eventType = event.getType();
if (eventType.equals("mousemove")) {
new ColumnResizeHelper<T>(cellTable, column, target);
} else {
return;
}
}
private void setCursor(Element element, Cursor cursor) {
element.getStyle().setCursor(cursor);
}
class ColumnResizeHelper<E> implements NativePreviewHandler {
private HandlerRegistration handler;
private AbstractCellTable<E> table;
private Column<E, ?> col;
private Element el;
private boolean mousedown;
private Element measuringElement;
public ColumnResizeHelper(AbstractCellTable<E> table, Column<E, ?> col, Element el) {
this.el = el;
this.table = table;
this.col = col;
handler = Event.addNativePreviewHandler(this);
}
@SuppressWarnings("unchecked")
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
NativeEvent nativeEvent = event.getNativeEvent();
nativeEvent.preventDefault();
nativeEvent.stopPropagation();
String eventType = nativeEvent.getType();
int clientX = nativeEvent.getClientX();
if (eventType.equals("mousemove") && mousedown) {
int absoluteLeft = el.getAbsoluteLeft();
int newWidth = clientX - absoluteLeft;
newWidth = newWidth < width ? width : newWidth;
table.setColumnWidth(col, newWidth + "px");
return;
}
if (eventType.equals("mousemove") || eventType.equals("mousedown")) {
Element eventTargetEl = nativeEvent.getEventTarget().cast();
int absoluteLeft = eventTargetEl.getAbsoluteLeft();
int offsetWidth = eventTargetEl.getOffsetWidth();
if (clientX > absoluteLeft + offsetWidth - width) {
if (eventType.equals("mousedown")) {
mousedown = true;
} else {
setCursor(el, Cursor.COL_RESIZE);
}
} else {
removeHandler();
return;
}
} else if (eventType.equals("mouseup")) {
mousedown = false;
} else if (eventType.equals("mouseout") && !mousedown) {
removeHandler();
return;
}
if (eventType.equals("dblclick")) {
// Get column
nativeEvent.preventDefault();
nativeEvent.stopPropagation();
double max = 0;
startMeasuring();
for (E t : table.getVisibleItems()) {
Object value = col.getValue(t);
SafeHtmlBuilder sb = new SafeHtmlBuilder();
Cell<Object> cell = (Cell<Object>) col.getCell();
cell.render(null, value, sb);
max = Math.max(measureText(sb.toSafeHtml().asString()), max);
}
finishMeasuring();
table.setColumnWidth(col, (max + width) + "px");
removeHandler();
}
}
private void removeHandler() {
handler.removeHandler();
setCursor(el, Cursor.DEFAULT);
}
private void startMeasuring() {
Document document = Document.get();
measuringElement = document.createElement("div");
measuringElement.getStyle().setPosition(Position.ABSOLUTE);
measuringElement.getStyle().setLeft(-1000, Unit.PX);
measuringElement.getStyle().setTop(-1000, Unit.PX);
document.getBody().appendChild(measuringElement);
}
private double measureText(String text) {
measuringElement.setInnerHTML(text);
return measuringElement.getOffsetWidth();
}
private void finishMeasuring() {
Document.get().getBody().removeChild(measuringElement);
}
}
static class HeaderCell extends AbstractCell<String> {
public HeaderCell() {
super("click", "mousedown", "mousemove", "dblclick");
}
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
sb.append(SafeHtmlUtils.fromString(value));
}
}
};

View File

@ -0,0 +1,96 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.form_search {
margin-bottom: 0px;
min-height: 20px;
padding: 19px;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
border-bottom: 0px;
border-radius: 0px;
}
.select{
padding-top: 20px;
padding-bottom: 20px;
height: 229px !important;
border-radius: 0px;
width: 291px;
border: 0px;
background: whitesmoke;
overflow-y: auto;
}
</ui:style>
<g:HTMLPanel>
<b:WellForm type="SEARCH" ui:field="form_search" addStyleNames="{style.form_search}">
<g:Button addStyleNames="btn" ui:field="b_search_all_users">All Users</g:Button>
<g:Button addStyleNames="btn" ui:field="b_search_all_roles">All Roles</g:Button>
<b:ControlGroup>
<b:Controls>
<b:InputAddOn prependIcon="SEARCH">
<b:TextBox placeholder="User, Roles" />
</b:InputAddOn>
</b:Controls>
</b:ControlGroup>
<!-- <b:Button ui:field="ricerca">Ricerca</b:Button> -->
<!-- <b:SubmitButton addStyleNames="btn" >Ricerca</b:SubmitButton> -->
</b:WellForm>
<g:ListBox ui:field="list_panel" addStyleNames="{style.select}">
</g:ListBox>
<!--
<div id="scroll_panel">
<g:ScrollPanel width="100%" height="227px" >
<g:HTMLPanel>
<div class="result_container">
<ul>
<li>Alessandro Pieve</li>
<li>Mario Rossi</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
<li>Alessandro Pieve</li>
</ul>
</div>
</g:HTMLPanel>
</g:ScrollPanel>
</div>
-->
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,21 @@
@CHARSET "UTF-8";
.ribbon {
line-height: 13px;
font-size: 11px;
}
#mainPanelLayout_AuthPortlet {
background-color: #d9e2e8;
border-radius: 4px;
}
.tab-content {
overflow: hidden;
border-right: 1px solid;
border-left: 1px solid #888;
/* padding-top: 10px; */
padding: 10px 5px 5px 5px;
border-bottom: 1px solid #888;
border-radius: 4px;
}

View File

@ -0,0 +1,21 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.client.resource;
import com.google.gwt.resources.client.CssResource;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public interface AuthCSS extends CssResource {
@ClassName("ribbon")
public String getRibbon();
@ClassName("tab-content")
public String getTabContent();
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.client.resource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public interface AuthResources extends ClientBundle {
public static final AuthResources INSTANCE = GWT
.create(AuthResources.class);
@Source("Auth.css")
AuthCSS authCSS();
@Source("accounting-manager_128.png")
ImageResource accountingManager128();
@Source("loaderHorizontal.gif")
ImageResource loaderIcon();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@ -0,0 +1,74 @@
package org.gcube.portlets.admin.authportletmanager.client.rpc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.ServiceException;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro
* .pieve@isti.cnr.it</a>
*
*/
@RemoteServiceRelativePath("authm")
public interface AuthManagerService extends RemoteService {
/**
* Get informations on the current user
*
* @return
* @throws AccountingManagerServiceException
*/
// Service for load Policy
public ArrayList<PolicyAuth> loadListPolicy() throws ServiceException;
// Service for load Caller
public ArrayList<Caller> loadListCaller() throws ServiceException;
//Service for load Service
public Map<String, List<String>> loadListService()throws ServiceException;
//Service for load Access
public ArrayList<String> loadListAccess() throws ServiceException;
// Service for delete multiple policy
List<Long> deletePolicies(List<Long>identifier) throws ServiceException;
public void addPolicies(List<PolicyAuth>identifier) throws ServiceException;
//Service for update policy
public void updatePolicy(PolicyAuth policies) throws ServiceException;
/*
* SECTION QUOTA
*/
//Service for load list quota
public ArrayList<Quote> loadListQuota() throws ServiceException;
// Service for delete multiple policy
public List<Long> deleteQuote(List<Long>identifier) throws ServiceException;
//Service for add multiple quote
public List<Quote> addQuote(List<Quote> quote) throws ServiceException;
//Service for update quote
public Quote updateQuote(Quote quote) throws ServiceException;
}

View File

@ -0,0 +1,72 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.client.rpc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public interface AuthManagerServiceAsync {
public static AuthManagerServiceAsync INSTANCE = (AuthManagerServiceAsync) GWT
.create(AuthManagerService.class);
//load init value
void loadListPolicy(AsyncCallback<ArrayList<PolicyAuth>> callback);
void loadListCaller(AsyncCallback<ArrayList<Caller>> callback);
void loadListService(AsyncCallback<Map<String, List<String>>> asyncCallback);
void loadListAccess(AsyncCallback<ArrayList<String>> callback);
/*
void deletePolicy(Long identifier,
AsyncCallback<Long> callback);
*/
/*
void addPolicy(String caller, String typeCaller, String serviceClass,
String serviceName, String serviceId, String access,
AsyncCallback<Long> callback);
*/
void updatePolicy(PolicyAuth policies, AsyncCallback<Void> callback);
void addPolicies(List<PolicyAuth> identifier,AsyncCallback<Void> asyncCallback);
void deletePolicies(List<Long> identifier,AsyncCallback<List<Long>> callback);
/*
* SECTION QUOTA
*/
void loadListQuota(AsyncCallback<ArrayList<Quote>> asyncCallback);
void deleteQuote(List<Long> identifier, AsyncCallback<List<Long>> callback);
void addQuote(List<Quote> quote, AsyncCallback<List<Quote>> callback);
void updateQuote(Quote quote, AsyncCallback<Quote> asyncCallback);
}

View File

@ -0,0 +1,81 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import static com.google.gwt.dom.client.BrowserEvents.CLICK;
import static com.google.gwt.dom.client.BrowserEvents.KEYDOWN;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ActionCell.Delegate;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
public class ActionCellClass<C> extends AbstractCell<C> {
private final SafeHtml html;
private final Delegate<C> delegate;
/**
* Construct a new {@link ActionCellClass}.
*
* @param message the message to display on the button
* @param delegate the delegate that will handle events
*/
public ActionCellClass(SafeHtml message, Delegate<C> delegate) {
super(CLICK, KEYDOWN);
this.delegate = delegate;
String cssClass="";
if (message.asString().toLowerCase().equals("delete"))
cssClass="btn-danger";
this.html = new SafeHtmlBuilder().appendHtmlConstant(
"<button class=\"btn btn_"+message.asString().toLowerCase()+" "+cssClass+" \" type=\"button\" tabindex=\"-1\">").appendHtmlConstant(
"</button>").toSafeHtml();
}
/**
* Construct a new {@link ActionCellClass} with a text String that does not contain
* HTML markup.
*
* @param text the text to display on the button
* @param delegate the delegate that will handle events
*/
public ActionCellClass(String text, Delegate<C> delegate) {
this(SafeHtmlUtils.fromString(text), delegate);
}
@Override
public void onBrowserEvent(Context context, Element parent, C value,
NativeEvent event, ValueUpdater<C> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if (CLICK.equals(event.getType())) {
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return;
}
if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) {
// Ignore clicks that occur outside of the main element.
onEnterKeyDown(context, parent, value, event, valueUpdater);
}
}
}
@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
sb.append(html);
}
@Override
protected void onEnterKeyDown(Context context, Element parent, C value,
NativeEvent event, ValueUpdater<C> valueUpdater) {
delegate.execute(value);
}
}

View File

@ -0,0 +1,23 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
public class BulletList extends ComplexPanel {
@SuppressWarnings("deprecation")
public BulletList() {
setElement(DOM.createElement("UL"));
}
@SuppressWarnings("deprecation")
public void add(Widget w) {
super.add(w, getElement());
}
@SuppressWarnings("deprecation")
public void insert(Widget w, int beforeIndex) {
super.insert(w, getElement(), beforeIndex, true);
}
}

View File

@ -0,0 +1,380 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.client.Entities;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
public class InputListWidget extends Composite {
List<String> itemsSelected = new ArrayList<String>();
public List<Caller> callerSelected = new ArrayList<Caller>();
public final BulletList list;
/*
* Disable list for entry caller
*/
public void disableList(){
list.clear();
}
/*
* Clear list for caller and insert a input box
*/
public void clearList(){
list.clear();
callerSelected.clear();
enabledList();
}
public InputListWidget() {
FlowPanel panel = new FlowPanel();
initWidget(panel);
//final BulletList list = new BulletList();
list = new BulletList();
list.setStyleName("input-list-caller");
final ListItem item = new ListItem();
item.setStyleName("token-input-input-token-facebook");
final TextBox itemBox = new TextBox();
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final SuggestBox box = new SuggestBox(getSuggestions(), itemBox);
box.setLimit(200);
box.getElement().setId("suggestion_box");
item.add(box);
list.add(item);
// this needs to be on the itemBox rather than box, or backspace will get executed twice
itemBox.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
GWT.log("key enter");
// only allow manual entries with @ signs (assumed email addresses)
//if (itemBox.getValue().contains("@"))
// deselectItem(itemBox, list);
}
// handle backspace
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
if ("".equals(itemBox.getValue().trim())) {
ListItem li = (ListItem) list.getWidget(list.getWidgetCount() - 2);
Paragraph p = (Paragraph) li.getWidget(0);
if (itemsSelected.contains(p.getText())) {
itemsSelected.remove(p.getText());
GWT.log("Removing selected item '" + p.getText() + "'", null);
GWT.log("Remaining: " + itemsSelected, null);
}
list.remove(li);
itemBox.setFocus(true);
}
}
}
});
//box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
box.addSelectionHandler(new SelectionHandler<MultiWordSuggestOracle.Suggestion>() {
public void onSelection(SelectionEvent selectionEvent) {
GWT.log("addSelectionHandler on Selection");
addItem(itemBox);
}
});
panel.add(list);
panel.getElement().setAttribute("onclick", "document.getElementById('suggestion_box').focus()");
box.setFocus(true);
}
/**
* addCaller
* add a caller to list
* @param caller
* @param list
*/
public void addCaller(Caller caller){
GWT.log("aggiunto caller"+caller.getCallerName());
String prefix=null;
switch (caller.getTypecaller()) {
case user:
prefix=ConstantsSharing.TagCaller;
break;
case role:
prefix=ConstantsSharing.TagRole;
break;
case service:
prefix=ConstantsSharing.TagService;
break;
default:
prefix ="";
break;
}
if (!callerSelected.contains(caller))
callerSelected.add(caller);
//reset error
//r_loader_space.clear();
final TextBox itemBox=new TextBox();
itemBox.setValue(prefix+caller.getCallerName());
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(itemBox.getValue());
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, list);
}
});
displayItem.add(p);
// displayItem.add(span);
list.clear();
list.insert(displayItem, 0);
}
/**
*
* @param listCaller list caller for add
* @param list Caller used
* @param append Boolean used for add an input text
*/
public void addListCaller(List<Caller> listCaller, boolean append){
if(!append){
list.clear();
}
for (Caller caller:listCaller){
String prefix=null;
switch (caller.getTypecaller()) {
case user:
prefix=ConstantsSharing.TagCaller;
break;
case role:
prefix=ConstantsSharing.TagRole;
break;
case service:
prefix=ConstantsSharing.TagService;
break;
default:
prefix ="";
break;
}
//reset error
final TextBox itemBox=new TextBox();
itemBox.setValue(prefix+caller.getCallerName());
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(itemBox.getValue());
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, list);
}
});
if (!callerSelected.contains(caller)){
callerSelected.add(caller);
displayItem.add(p);
if(append)
displayItem.add(span);
list.insert(displayItem, 0);
}
}
}
/*
* Replace a list of caller selected
*/
public void replaceListCaller(List<Caller> listCaller){
//remove all caller
clearList();
for (Caller caller:listCaller){
String prefix=null;
switch (caller.getTypecaller()) {
case user:
prefix=ConstantsSharing.TagCaller;
break;
case role:
prefix=ConstantsSharing.TagRole;
break;
case service:
prefix=ConstantsSharing.TagService;
break;
default:
prefix ="";
break;
}
final TextBox itemBox=new TextBox();
itemBox.setValue(prefix+caller.getCallerName());
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(itemBox.getValue());
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, list);
}
});
callerSelected.add(caller);
displayItem.add(p);
displayItem.add(span);
list.insert(displayItem, 0);
}
}
private void addItem(final TextBox itemBox) {
if (itemBox.getValue() != null && !"".equals(itemBox.getValue().trim())) {
String callerName= itemBox.getValue().substring(1);
if (!callerSelected.contains(Entities.getCallerByName(callerName))){
final ListItem displayItem = new ListItem();
displayItem.setStyleName("token-input-token-facebook");
Paragraph p = new Paragraph(itemBox.getValue());
displayItem.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
displayItem.addStyleName("token-input-selected-token-facebook");
}
});
Span span = new Span("x");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, list);
}
});
displayItem.add(p);
displayItem.add(span);
// hold the original value of the item selected and add at arraylist
itemsSelected.add(itemBox.getValue());
//String callerName= itemBox.getValue().substring(1);
GWT.log("AuthManager - Insert Caller: " + callerName, null);
callerSelected.add(Entities.getCallerByName(callerName));
list.insert(displayItem, list.getWidgetCount() - 1);
}
itemBox.setValue("");
itemBox.setFocus(true);
}
}
/**
*
* @param displayItem
* @param list
*/
private void removeListItem(ListItem displayItem, BulletList list) {
GWT.log("Removing: " + displayItem.getWidget(0).getElement().getInnerHTML(), null);
itemsSelected.remove(displayItem.getWidget(0).getElement().getInnerHTML());
String callerName=displayItem.getWidget(0).getElement().getInnerHTML().substring(1);
callerSelected.remove(Entities.getCallerByName(callerName));
list.remove(displayItem);
}
/**
*
* Enabling list caller and add an input box for input
*/
public void enabledList() {
// TODO Auto-generated method stub
list.setStyleName("input-list-caller");
final ListItem item = new ListItem();
item.setStyleName("token-input-input-token-facebook");
final TextBox itemBox = new TextBox();
itemBox.getElement().setAttribute("style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final SuggestBox box = new SuggestBox(getSuggestions(), itemBox);
box.getElement().setId("suggestion_box");
item.add(box);
list.add(item);
// this needs to be on the itemBox rather than box, or backspace will get executed twice
itemBox.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
// only allow manual entries with @ signs (assumed email addresses)
//if (itemBox.getValue().contains("@"))
// deselectItem(itemBox, list);
}
// handle backspace
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
if ("".equals(itemBox.getValue().trim())) {
ListItem li = (ListItem) list.getWidget(list.getWidgetCount() - 2);
Paragraph p = (Paragraph) li.getWidget(0);
if (itemsSelected.contains(p.getText())) {
itemsSelected.remove(p.getText());
GWT.log("Removing selected item '" + p.getText() + "'", null);
GWT.log("Remaining: " + itemsSelected, null);
}
list.remove(li);
itemBox.setFocus(true);
}
}
}
});
box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
public void onSelection(SelectionEvent selectionEvent) {
addItem(itemBox);
}
});
}
//
private MultiWordSuggestOracle getSuggestions() {
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(".:");
String prefix=null;
for (Caller suggestion:Entities.getCallers()){
switch (suggestion.getTypecaller()) {
case user:
prefix=ConstantsSharing.TagCaller;
break;
case role:
prefix=ConstantsSharing.TagRole;
break;
case service:
prefix=ConstantsSharing.TagService;
break;
default:
prefix ="";
break;
}
oracle.add(prefix+suggestion.getCallerName());
}
return oracle;
}
}

View File

@ -0,0 +1,69 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasBlurHandlers;
import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;
public class ListItem extends ComplexPanel implements HasText, HasHTML, HasClickHandlers, HasKeyDownHandlers, HasBlurHandlers {
HandlerRegistration clickHandler;
public ListItem() {
setElement(DOM.createElement("LI"));
}
public void add(Widget w) {
super.add(w, getElement());
}
public void insert(Widget w, int beforeIndex) {
super.insert(w, getElement(), beforeIndex, true);
}
@SuppressWarnings("deprecation")
public String getText() {
return DOM.getInnerText(getElement());
}
@SuppressWarnings("deprecation")
public void setText(String text) {
DOM.setInnerText(getElement(), (text == null) ? "" : text);
}
@SuppressWarnings("deprecation")
public void setId(String id) {
DOM.setElementAttribute(getElement(), "id", id);
}
@SuppressWarnings("deprecation")
public String getHTML() {
return DOM.getInnerHTML(getElement());
}
public void setHTML(String html) {
DOM.setInnerHTML(getElement(), (html == null) ? "" : html);
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
return addDomHandler(handler, ClickEvent.getType());
}
public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
return addDomHandler(handler, KeyDownEvent.getType());
}
public HandlerRegistration addBlurHandler(BlurHandler handler) {
return addDomHandler(handler, BlurEvent.getType());
}
}

View File

@ -0,0 +1,76 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.TextBoxBase;
public class MultipleTextBox extends TextBoxBase {
/**
* Creates an empty multiple text box.
*/
public MultipleTextBox() {
this(Document.get().createTextInputElement(), "gwt-TextBox");
}
/**
* This constructor may be used by subclasses to explicitly use an existing
* element. This element must be an <input> element whose type is
* 'text'.
*
* @param element the element to be used
*/
protected MultipleTextBox(Element element) {
super(element);
assert InputElement.as(element).getType().equalsIgnoreCase("text");
}
MultipleTextBox(Element element, String styleName) {
super(element);
if (styleName != null) {
setStyleName(styleName);
}
}
@Override
public String getText() {
String wholeString = super.getText();
String lastString = wholeString;
if (wholeString != null && !wholeString.trim().equals("")) {
int lastComma = wholeString.trim().lastIndexOf(",");
if (lastComma > 0) {
lastString = wholeString.trim().substring(lastComma + 1);
}
}
return lastString;
}
@Override
public void setText(String text) {
String wholeString = super.getText();
if (text != null && text.equals("")) {
super.setText(text);
} else {
// Clean last text, to replace with new value, for example, if new
// text is v.zaprudnevd@gmail.com:
// "manuel@we-r-you.com, v" need to be replaced with:
// "manuel@we-r-you.com, v.zaprudnevd@gmail.com, "
if (wholeString != null) {
int lastComma = wholeString.trim().lastIndexOf(",");
if (lastComma > 0) {
wholeString = wholeString.trim().substring(0, lastComma);
} else {
wholeString = "";
}
if (!wholeString.trim().endsWith(",")
&& !wholeString.trim().equals("")) {
wholeString = wholeString + ", ";
}
wholeString = wholeString + text + ", ";
super.setText(wholeString);
}
}
}
}

View File

@ -0,0 +1,29 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;
/**
* This widget is to create <p> elements in a page.
*/
public class Paragraph extends Widget implements HasText {
public Paragraph() {
setElement(DOM.createElement("p"));
}
public Paragraph(String text) {
this();
setText(text);
}
public String getText() {
return getElement().getInnerText();
}
public void setText(String text) {
getElement().setInnerText(text);
}
}

View File

@ -0,0 +1,355 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
*
* Usage Example:<br/>
* <ul><li>
* Put following code into your ui.xml file:<br/>
* <code>
*<bi:PickList ui:field="pickList" >
* </code><br/><br/>
*
* </li><li>
* Populate your picklist using {@link NameValuePairImpl}:<br/>
* <code>
* List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();<br/>
* nameValuePairs.add(new NameValuePairImpl("item 1", "item_1"));<br/>
* nameValuePairs.add(new NameValuePairImpl("item 2", "item_2"));<br/>
* nameValuePairs.add(new NameValuePairImpl("item 3", "item_3"));<br/>
* pickList.setLeftListElements(nameValuePairs);
* pickList.setRightListElements(nameValuePairs);
* </code><br/>
* </li></ul>
*
* Screenshot:
* <br/>
* <img src="http://gamenism.com/gwt/picklist.png"/>
* <br/>
*
* User: Halil Karakose
* Date: 10/18/13
* Time: 3:53 PM
*
* @see NameValuePairImpl
*/
public class PickList extends Composite {
private static PickListUiBinder ourUiBinder = GWT.create(PickListUiBinder.class);
public ListBox leftList= new ListBox(true);
public ListBox rightList= new ListBox(true);
@UiField
VerticalPanel leftPanel;
@UiField
VerticalPanel rightPanel;
@UiField
VerticalPanel buttonPanel;
@UiField
Button toRightButton;
@UiField
Button toLeftButton;
@UiField
Button allToRightButton;
@UiField
Button allToLeftButton;
@UiField
Label rightPanelLabel;
@UiField
Label leftPanelLabel;
public PickList() {
initWidget(ourUiBinder.createAndBindUi(this));
leftList.setVisibleItemCount(10);
leftList.setSize(12);
leftList.setStyleName("width_select");
leftPanel.add(leftList);
rightList.setVisibleItemCount(10);
rightList.setSize(12);
rightList.setStyleName("width_select");
rightPanel.add(rightList);
//set padding between cells to make the component look better
this.getElement().setAttribute("cellpadding", "1");
leftPanel.getElement().setAttribute("cellpadding", "1");
buttonPanel.getElement().setAttribute("cellpadding", "2");
rightPanel.getElement().setAttribute("cellpadding", "1");
setLeftListElements(new ArrayList<Caller>());
setRightListElements(new ArrayList<Caller>());
}
public void clearLeftList() {
clear(leftList);
}
public void clearRightList() {
clear(rightList);
}
private void clear(ListBox listBox) {
listBox.clear();
}
public void addElementToLeftList(Caller element) {
addElement(leftList, element);
}
public void addElementToRightList(Caller element) {
addElement(rightList, element);
}
private void addElement(ListBox listBox, Caller element) {
listBox.addItem(element.getCallerName(), element.getTypecaller().toString());
}
public List<Caller> getLeftListElements() {
return getListBoxElements(leftList);
}
public void setLeftListElements(List<Caller> elements) {
ArrayList<Caller> callerFilter = new ArrayList<Caller>();
List<Caller> callerSelected=new ArrayList<Caller>();
callerSelected=getRightListElements();
//verify a list elements not present in right list
for (Caller element : elements) {
boolean trovato=false;
for (Caller elementRight : callerSelected) {
if (elementRight.equals(element)){
trovato=true;
break;
}
}
if (!trovato)
callerFilter.add(element);
}
populate(callerFilter, leftList);
}
public List<Caller> getRightListElements() {
return getListBoxElements(rightList);
}
public void setRightListElements(List<Caller> elements) {
populate(elements, rightList);
}
public String getSelectedLabelText() {
return rightPanelLabel.getText();
}
public void setSelectedLabelText(String selectedLabelText) {
rightPanelLabel.setText(selectedLabelText);
}
public String getCandidateLabelText() {
return leftPanelLabel.getText();
}
public void setCandidateLabelText(String selectedLabelText) {
leftPanelLabel.setText(selectedLabelText);
}
private List<Caller> getListBoxElements(ListBox listBox) {
ArrayList<Caller> callerPairs = new ArrayList<Caller>();
for (int i = 0; i < listBox.getItemCount(); i++) {
TypeCaller typecaller =TypeCaller.valueOf(listBox.getValue(i));
Caller nameValuePair = new Caller(typecaller,listBox.getItemText(i) );
callerPairs.add(nameValuePair);
}
return callerPairs;
}
/**
* Popolate a leftlist element and sorted by Caller Type
* @param leftListElements
* @param listBox
*/
private void populate(List<Caller> leftListElements, ListBox listBox) {
SortedMap<String, String> fromTempList=new TreeMap<String,String>();
for (Caller element : leftListElements) {
fromTempList.put(element.getCallerName(), element.getTypecaller().toString());
}
// order by type checklist from
listBox.clear();
@SuppressWarnings("unchecked")
Map<String, String> mapFrom = sortByValues(fromTempList);
for (Entry<String, String> entry : mapFrom.entrySet())
listBox.addItem(entry.getKey(),entry.getValue());
}
@UiHandler("toRightButton")
public void toRightButtonClicked(ClickEvent event) {
moveItem(leftList, rightList, event);
if (leftList.getItemCount() == 0) {
toRightButton.setEnabled(false);
allToRightButton.setEnabled(false);
}
if (rightList.getItemCount() >= 1) { // !>= 1! is preferred instead of !== 1! to handle multiple selections
toLeftButton.setEnabled(true);
allToLeftButton.setEnabled(true);
}
}
@UiHandler("allToRightButton")
public void allToRightButtonClicked(ClickEvent event) {
moveAllItem(leftList, rightList, event);
allToRightButton.setEnabled(false);
toRightButton.setEnabled(false);
if (rightList.getItemCount() >= 1) { // !>= 1! is preferred instead of !== 1! to handle multiple selections
allToLeftButton.setEnabled(true);
toLeftButton.setEnabled(true);
}
}
@UiHandler("toLeftButton")
public void toLeftButtonClicked(ClickEvent event) {
moveItem(rightList, leftList, event);
if (rightList.getItemCount() == 0) {
toLeftButton.setEnabled(false);
allToLeftButton.setEnabled(false);
}
if (leftList.getItemCount() >= 1) { // !>= 1! is preferred instead of !== 1! to handle multiple selections
toRightButton.setEnabled(true);
allToRightButton.setEnabled(true);
}
}
@UiHandler("allToLeftButton")
public void allToLeftButtonClicked(ClickEvent event) {
moveAllItem(rightList,leftList , event);
allToLeftButton.setEnabled(false);
toLeftButton.setEnabled(false);
if (leftList.getItemCount() >= 1) { // !>= 1! is preferred instead of !== 1! to handle multiple selections
allToRightButton.setEnabled(true);
toRightButton.setEnabled(true);
}
}
private void moveItem(ListBox from, ListBox to, ClickEvent event) {
String value=from.getValue();
if (value == null) {
Window.alert("Select an item first!");
return;
}
SortedMap<String, String> fromTempList=new TreeMap<String,String>();
SortedMap<String, String> toTempList=new TreeMap<String,String>();
for(int itemIndex=0; itemIndex<from.getItemCount(); itemIndex++) {
if (from.isItemSelected(itemIndex)){
String item = from.getItemText(itemIndex);
String valueItem = from.getValue(itemIndex);
toTempList.put(item,valueItem);
}
else{
String item = from.getItemText(itemIndex);
String valueItem=from.getValue(itemIndex);
fromTempList.put(item,valueItem);
}
}
// order by type checklist from
from.clear();
@SuppressWarnings("unchecked")
Map<String, String> mapFrom = sortByValues(fromTempList);
for (Entry<String, String> entry : mapFrom.entrySet())
from.addItem(entry.getKey(),entry.getValue());
//order by type checklist to
for(int itemIndex=0; itemIndex<to.getItemCount(); itemIndex++)
toTempList.put(to.getItemText(itemIndex),to.getValue(itemIndex));
to.clear();
@SuppressWarnings("unchecked")
Map<String, String> mapTo = sortByValues(toTempList);
for (Entry<String, String> entry : mapTo.entrySet())
to.addItem(entry.getKey(),entry.getValue());
}
private void moveAllItem(ListBox from, ListBox to, ClickEvent event) {
SortedMap<String, String> toTempList=new TreeMap<String,String>();
for(int itemIndex=0; itemIndex<from.getItemCount(); itemIndex++)
toTempList.put(from.getItemText(itemIndex),from.getValue(itemIndex));
for(int itemIndex=0; itemIndex<to.getItemCount(); itemIndex++)
toTempList.put(to.getItemText(itemIndex),to.getValue(itemIndex));
to.clear();
@SuppressWarnings("unchecked")
Map<String, String> mapTo = sortByValues(toTempList);
for (Entry<String, String> entry : mapTo.entrySet())
to.addItem(entry.getKey(),entry.getValue());
from.clear();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static HashMap sortByValues(SortedMap<String, String> tempList) {
List list = new LinkedList(tempList.entrySet());
// Defined Custom Comparator here
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
return ((Comparable) ((Map.Entry) (o1)).getValue())
.compareTo(((Map.Entry) (o2)).getValue());
}
});
HashMap sortedHashMap = new LinkedHashMap();
for (Iterator it = list.iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
sortedHashMap.put(entry.getKey(), entry.getValue());
}
return sortedHashMap;
}
interface PickListUiBinder extends UiBinder<HorizontalPanel, PickList> {
}
}

View File

@ -0,0 +1,30 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b='urn:import:com.github.gwtbootstrap.client.ui'>
<ui:style>
.width_select {
width: 200px !important;
}
</ui:style>
<g:HorizontalPanel>
<g:VerticalPanel ui:field="leftPanel">
<b:Label ui:field="leftPanelLabel" />
</g:VerticalPanel>
<g:cell verticalAlignment="ALIGN_MIDDLE">
<g:VerticalPanel ui:field="buttonPanel">
<b:Button ui:field="allToRightButton" name="toRight" text=">>" />
<b:Button ui:field="toRightButton" name="toRight" text=">" />
<b:Button ui:field="toLeftButton" name="toLeft" text="&lt;" />
<b:Button ui:field="allToLeftButton" name="toRight" text="&lt;&lt;" />
</g:VerticalPanel>
</g:cell>
<g:VerticalPanel ui:field="rightPanel">
<b:Label ui:field="rightPanelLabel" />
</g:VerticalPanel>
</g:HorizontalPanel>
</ui:UiBinder>

View File

@ -0,0 +1,20 @@
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasText;
/**
* This widget is to create <span> elements in a page.
*/
public class Span extends HTML implements HasText {
public Span() {
super(DOM.createElement("span"));
}
public Span(String text) {
this();
setText(text);
}
}

View File

@ -0,0 +1,762 @@
/*
* Copyright 2010 Traction Software, Inc.
* Copyright 2010 clazzes.org Project
*
* Based on TractionDialogBox by Traction Software, Inc. Renamed to WindowBox and
* added resize support by clazzes.org
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.gcube.portlets.admin.authportletmanager.client.widget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.logical.shared.HasOpenHandlers;
import com.google.gwt.event.logical.shared.OpenEvent;
import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Extension of the standard GWT DialogBox to provide a more "window"-like functionality. By default, the WindowBox
* has two control-buttons in the top right corner of the header, which allow the box to be reduced to it's header
* ("minimize") or the whole box to be hidden ("close"). The visiblity of these controls can be toggled seperately
* with {@link #setMinimizeIconVisible(boolean)} and {@link #setCloseIconVisible(boolean)} respectively.
* <br><br>
* The WindowBox relies on the css settings of {@link DialogBox} for styling of the border and header. It also uses
* the following classes to style the additional elements:
*
* <pre>
* .gwt-extras-WindowBox
* the box itself
* .gwt-extras-WindowBox .gwt-extras-dialog-container
* the div holding the contents of the box
* .gwt-extras-WindowBox .gwt-extras-dialog-controls
* the div holding the window-controls - PLEASE NOTE: on the DOM-tree, this div is located inside the center-center
* cell of the windowBox table, not in the top-center (where the header-text is). Therefore the css has a negative
* top-value to position the controls on the header
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-close
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-close:hover
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-minimize
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-minimize:hover
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-maximize
* .gwt-extras-WindowBox .gwt-extras-dialog-controls a.gwt-extras-dialog-maximize:hover
* the controls in the header. A background image sprite is used to create the mouseover- and clicking-effects.
* When the window is minimized, the style-name of the corresponding control changes to "gwt-extras-dialog-maximize"
* and vice-versa
* </pre>
*/
public class WindowBox extends DialogBox
implements HasOpenHandlers<WindowBox> {
private static final int MIN_WIDTH = 600;
private static final int MIN_HEIGHT = 300;
private FlowPanel container;
//private FlowPanel content;
private FlowPanel controls;
private Anchor close;
private Anchor minimize;
private int dragX;
private int dragY;
private int minWidth = MIN_WIDTH;
private int minHeight = MIN_HEIGHT;
private int dragMode;
private boolean resizable;
private boolean minimized;
/**
* Static helper method to change the cursor for a given element when resizing is enabled.
*
* @param dm The code describing the position of the element in question
* @param element The {@link com.google.gwt.dom.client.Element} to set the cursor on
*/
protected static void updateCursor(int dm, com.google.gwt.dom.client.Element element) {
Cursor cursor;
switch (dm) {
case 0:
cursor = Cursor.NW_RESIZE;
break;
case 1:
cursor = Cursor.N_RESIZE;
break;
case 2:
cursor = Cursor.NE_RESIZE;
break;
case 3:
cursor = Cursor.W_RESIZE;
break;
case 5:
cursor = Cursor.E_RESIZE;
break;
case 6:
cursor = Cursor.SW_RESIZE;
break;
case 7:
cursor = Cursor.S_RESIZE;
break;
case 8:
cursor = Cursor.SE_RESIZE;
break;
default:
cursor = Cursor.AUTO;
break;
}
element.getStyle().setCursor(cursor);
}
/**
* Creates a DialogBoxEx which is permanent (no auto-hide), non-modal, has a "minimize"- and "close"-button
* in the top-right corner and is not resizeable. The dialog box should not be shown until a child widget has been
* added using {@link #add(com.google.gwt.user.client.ui.IsWidget)}.
* <br><br>
* This is the equivalent for calling <code>DialogBoxEx(false, false, true, false)</code>.
*
* @see WindowBox#DialogBoxEx(boolean, boolean, boolean, boolean)
*/
public WindowBox() {
this(false, false, true, true, false);
}
/**
* Creates a DialogBoxEx which is permanent, non-modal, has a "minimize"- and "close"-button and is optionally resizeable.
* The dialog box should not be shown until a child widget has been added using
* {@link #setWidget(Widget)}.
*
* @see WindowBox#DialogBoxEx(boolean, boolean, boolean, boolean)
*
* @param resizeable <code>true</code> to allow resizing by dragging the borders
*/
public WindowBox(boolean resizeable) {
this(false, false, true, true, resizeable);
}
/**
* Creates a DialogBoxEx which is permanent and nonmodal, optionally resizeable and/or has a "minimize"- and
* "close"-button. The dialog box should not be shown until a child widget has been added using
* {@link #setWidget(Widget)}.
*
* @see WindowBox#DialogBoxEx(boolean, boolean, boolean, boolean)
*
* @param resizeable <code>true</code> to allow resizing by dragging the borders
* @param showCloseIcon <code>true</code> to show "close"-icon in the top right corner of the header
*/
public WindowBox(boolean showCloseIcon, boolean resizeable) {
this(false, false, true, showCloseIcon, resizeable);
}
/**
* Creates a DialogBoxEx which is permanent and nonmodal, optionally resizeable and/or has a "minimize"- and
* "close"-button. The dialog box should not be shown until a child widget has been added using
* {@link #setWidget(Widget)}.
*
* @see WindowBox#DialogBoxEx(boolean, boolean, boolean, boolean)
*
* @param showMinimizeIcon <code>true</code> to show "minimize"-icon int the top right corner of the header
* @param resizeable <code>true</code> to allow resizing by dragging the borders
* @param showCloseIcon <code>true</code> to show "close"-icon in the top right corner of the header
*/
public WindowBox(boolean showMinimizeIcon, boolean showCloseIcon, boolean resizeable) {
this(false, false, showMinimizeIcon, showCloseIcon, resizeable);
}
/**
* Creates a DialogBoxEx which is permanent, optionally modal, resizeable and/or has a "minimize"- and
* "close"-button. The dialog box should not be shown until a child widget has been added using
* {@link #setWidget(Widget)}.
*
* @param modal <code>true</code> if keyboard and mouse events for widgets not contained by the dialog
* should be ignored
* @param showMinimizeIcon <code>true</code> to show "minimize"-icon int the top right corner of the header
* @param resizeable <code>true</code> to allow resizing by dragging the borders
* @param showCloseIcon <code>true</code> to show "close"-icon in the top right corner of the header
*/
public WindowBox(boolean modal, boolean showMinimizeIcon, boolean showCloseIcon, boolean resizeable) {
this(false, modal, showMinimizeIcon, showCloseIcon, resizeable);
}
/**
* Creates an empty DialogBoxEx with all configuration options.
* The dialog box should not be shown until a child widget has been added using
* {@link #setWidget(Widget)}.
*
* @see DialogBox#DialogBox()
* @see DialogBox#DialogBox(boolean)
* @see DialogBox#DialogBox(boolean, boolean)
* @see DialogBox#DialogBox(boolean, boolean, boolean)
*
* @param autoHide <code>true</code> if the dialog should be automatically hidden when the user clicks outside of it
* @param modal <code>true</code> if keyboard and mouse events for widgets not contained by the dialog
* should be ignored
* @param showMinimizeIcon <code>true</code> to show "minimize"-icon int the top right corner of the header
* @param showCloseIcon <code>true</code> to show "close"-icon in the top right corner of the header
* @param resizeable <code>true</code> to allow resizing by dragging the borders
*/
public WindowBox(boolean autoHide, boolean modal, boolean showMinimizeIcon, boolean showCloseIcon, boolean resizeable) {
super(autoHide, modal);
this.setStyleName("gwt-extras-WindowBox", true);
this.container = new FlowPanel();
this.container.addStyleName("gwt-extras-dialog-container");
//this.content = new FlowPanel();
this.close = new Anchor();
this.close.setStyleName("gwt-extras-dialog-close");
this.close.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
onCloseClick(event);
}
});
setCloseIconVisible(showCloseIcon);
this.minimize = new Anchor();
this.minimize.setStyleName("gwt-extras-dialog-minimize");
this.minimize.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
onMinimizeClick(event);
}
});
setMinimizeIconVisible(showMinimizeIcon);
Grid ctrlGrid = new Grid(1, 2);
ctrlGrid.setWidget(0, 0, this.minimize);
ctrlGrid.setWidget(0, 1, this.close);
this.controls = new FlowPanel();
this.controls.setStyleName("gwt-extras-dialog-controls");
this.controls.add(ctrlGrid);
this.dragMode = -1;
this.resizable = resizeable;
}
/**
* Sets the cursor to indicate resizability for a specified "drag-mode" (i.e. how the box is being resized)
* on the dialog box. The position is described by an integer, as follows:
*
* <pre>
* 0-- --1-- --2
* | |
*
* | |
* 3 -1 5
* | |
*
* | |
* 6-- --7-- --8
* </pre>
*
* passing <code>-1</code> resets the cursor to the default.
* @param dragMode
*/
protected void updateCursor(int dragMode) {
if (this.resizable) {
updateCursor(dragMode,this.getElement());
com.google.gwt.dom.client.Element top = this.getCellElement(0,1);
updateCursor(dragMode,top);
top = Element.as(top.getFirstChild());
if (top != null)
updateCursor(dragMode,top);
}
}
/**
* Returns whether the dialog box is mouse-resizeable
*
* @return <code>true</code> if the user can resize the dialog with the mouse
*/
public boolean isResizable() {
return this.resizable;
}
/**
* Set the dialog box to be resizeable by the user
*
* @param resizable <code>true</code> if the user can resize the dialog with the mouse
*/
public void setResizable(boolean resizable) {
this.resizable = resizable;
}
/*
* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#onBrowserEvent(com.google.gwt.user.client.Event)
*/
@Override
public void onBrowserEvent(Event event) {
// If we're not yet dragging, only trigger mouse events if the event occurs
// in the caption wrapper
if (this.resizable) {
switch (event.getTypeInt()) {
case Event.ONMOUSEDOWN:
case Event.ONMOUSEUP:
case Event.ONMOUSEMOVE:
case Event.ONMOUSEOVER:
case Event.ONMOUSEOUT:
if (this.dragMode >= 0 || calcDragMode(event.getClientX(),event.getClientY()) >= 0) {
// paste'n'copy from Widget.onBrowserEvent
switch (DOM.eventGetType(event)) {
case Event.ONMOUSEOVER:
// Only fire the mouse over event if it's coming from outside this
// widget.
case Event.ONMOUSEOUT:
// Only fire the mouse out event if it's leaving this
// widget.
Element related = event.getRelatedEventTarget().cast();
if (related != null && getElement().isOrHasChild(related)) {
return;
}
break;
}
DomEvent.fireNativeEvent(event, this, this.getElement());
return;
}
if (this.dragMode<0)
this.updateCursor(this.dragMode);
}
}
super.onBrowserEvent(event);
}
/**
*
* @param resize
* @param clientX
* @return
*/
private int getRelX(com.google.gwt.dom.client.Element resize, int clientX) {
return clientX - resize.getAbsoluteLeft() +
resize.getScrollLeft() +
resize.getOwnerDocument().getScrollLeft();
}
/**
*
* @param resize
* @param clientY
* @return
*/
private int getRelY(com.google.gwt.dom.client.Element resize, int clientY) {
return clientY - resize.getAbsoluteTop() +
resize.getScrollTop() +
resize.getOwnerDocument().getScrollTop();
}
/**
* Calculates the position of the mouse relative to the dialog box, and returns the corresponding "drag-mode"
* integer, which describes which area of the box is being resized.
*
* @param clientX The x-coordinate of the mouse in screen pixels
* @param clientY The y-coordinate of the mouse in screen pixels
* @return A value in range [-1..8] describing the position of the mouse (see {@link #updateCursor(int)} for more
* information)
*/
protected int calcDragMode(int clientX, int clientY) {
com.google.gwt.dom.client.Element resize = this.getCellElement(2,2).getParentElement();
int xr = this.getRelX(resize, clientX);
int yr = this.getRelY(resize, clientY);
int w = resize.getClientWidth();
int h = resize.getClientHeight();
if ((xr >= 0 && xr < w && yr >= -5 && yr < h)
|| (yr >= 0 && yr < h && xr >= -5 && xr < w))
return 8;
resize = this.getCellElement(2,0).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if ((xr >= 0 && xr < w && yr >= -5 && yr < h)
|| (yr >= 0 && yr < h && xr >= 0 && xr < w+5))
return 6;
resize = this.getCellElement(0,2).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if ((xr >= 0 && xr < w && yr >= 0 && yr < h+5)
|| (yr >= 0 && yr < h && xr >= -5 && xr < w))
return 2;
resize = this.getCellElement(0,0).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if ((xr >= 0 && xr < w && yr >= 0 && yr < h+5)
|| (yr >= 0 && yr < h && xr >= 0 && xr < w+5))
return 0;
resize = this.getCellElement(0,1).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if (yr >= 0 && yr < h)
return 1;
resize = this.getCellElement(1,0).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if (xr >= 0 && xr < w)
return 3;
resize = this.getCellElement(2,1).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if (yr >= 0 && yr < h)
return 7;
resize = this.getCellElement(1,2).getParentElement();
xr = this.getRelX(resize, clientX);
yr = this.getRelY(resize, clientY);
if (xr >= 0 && xr < w)
return 5;
return -1;
}
/**
* Convenience method to set the height, width and position of the given widget
*
* @param panel
* @param dx
* @param dy
*/
protected void dragResizeWidget(PopupPanel panel, int dx, int dy) {
int x = this.getPopupLeft();
int y = this.getPopupTop();
Widget widget = panel.getWidget();
// left + right
if ((this.dragMode % 3) != 1) {
int w = widget.getOffsetWidth();
// left edge -> move left
if ((this.dragMode % 3) == 0) {
x += dx;
w -= dx;
} else {
w += dx;
}
w = w < this.minWidth ? this.minWidth : w;
widget.setWidth(w + "px");
}
// up + down
if ((this.dragMode / 3) != 1) {
int h = widget.getOffsetHeight();
// up = dy is negative
if ((this.dragMode / 3) == 0) {
y += dy;
h -= dy;
} else {
h += dy;
}
h = h < this.minHeight ? this.minHeight : h;
widget.setHeight(h + "px");
}
if (this.dragMode / 3 == 0 || this.dragMode % 3 == 0)
panel.setPopupPosition(x, y);
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#beginDragging(com.google.gwt.event.dom.client.MouseDownEvent)
*/
@Override
protected void beginDragging(MouseDownEvent event) {
int dm = -1;
if (this.resizable && !this.minimized)
dm = this.calcDragMode(event.getClientX(),event.getClientY());
if (this.resizable && dm >= 0) {
this.dragMode = dm;
DOM.setCapture(getElement());
this.dragX = event.getClientX();
this.dragY = event.getClientY();
updateCursor(dm,RootPanel.get().getElement());
} else {
super.beginDragging(event);
}
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#continueDragging(com.google.gwt.event.dom.client.MouseMoveEvent)
*/
@Override
protected void continueDragging(MouseMoveEvent event) {
if (this.dragMode >= 0 && this.resizable) {
this.updateCursor(this.dragMode);
int dx = event.getClientX() - this.dragX;
int dy = event.getClientY() - this.dragY;
this.dragX = event.getClientX();
this.dragY = event.getClientY();
dragResizeWidget(this, dx, dy);
} else {
// this updates the cursor when dragging is NOT activated
if (!this.minimized) {
int dm = calcDragMode(event.getClientX(),event.getClientY());
this.updateCursor(dm);
}
super.continueDragging(event);
}
}
/*
* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
*/
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
if (this.resizable) {
// We need to preventDefault() on mouseDown events (outside of the
// DialogBox content) to keep text from being selected when it
// is dragged.
NativeEvent nativeEvent = event.getNativeEvent();
if (!event.isCanceled()
&& (event.getTypeInt() == Event.ONMOUSEDOWN)
&& calcDragMode(nativeEvent.getClientX(),nativeEvent.getClientY()) >= 0) {
nativeEvent.preventDefault();
}
}
super.onPreviewNativeEvent(event);
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#endDragging(com.google.gwt.event.dom.client.MouseUpEvent)
*/
@Override
protected void endDragging(MouseUpEvent event) {
if (this.dragMode >= 0 && this.resizable) {
DOM.releaseCapture(getElement());
this.dragX = event.getClientX() - this.dragX;
this.dragY = event.getClientY() - this.dragY;
this.dragMode = -1;
this.updateCursor(this.dragMode);
RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
}
else {
super.endDragging(event);
}
}
/*
* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DecoratedPopupPanel#setWidget(com.google.gwt.user.client.ui.Widget)
*/
@Override
public void setWidget(Widget widget) {
if (this.container.getWidgetCount() == 0) {
// setup
this.container.add(this.controls);
//this.container.add(this.content);
super.setWidget(this.container);
} else {
// remove the old one
this.container.remove(1);
}
this.container.add(widget);
// add the new widget
// this.content.add(widget);
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DecoratedPopupPanel#getWidget()
*/
@Override
public Widget getWidget() {
if (this.container.getWidgetCount() > 1)
return this.container.getWidget(1);
else
return null;
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DecoratedPopupPanel#remove(com.google.gwt.user.client.ui.Widget)
*/
@Override
public boolean remove(Widget w) {
return this.container.remove(w);
}
/**
* Set whether the "close"-button should appear in the top right corner of the header
*
* @param visible <code>true</code> if a "close"-button should be shown
*/
public void setCloseIconVisible(boolean visible) {
this.close.setVisible(visible);
}
/**
* Set whether the "minimize"-button should appear in the top right corner of the header
*
* @param visible <code>true</code> if a "minimize"-button should be shown
*/
public void setMinimizeIconVisible(boolean visible) {
this.minimize.setVisible(visible);
}
/**
* Returns the FlowPanel that contains the controls. More controls can be
* added directly to this.
*/
public FlowPanel getControlPanel() {
return this.controls;
}
/**
* Called when the close icon is clicked. The default implementation hides the dialog box.
*
* @param event The {@link ClickEvent} to handle
*/
protected void onCloseClick(ClickEvent event) {
hide();
}
/**
* Called when the minimize icon is clicked. The default implementation hides the container of the dialog box.
*
* @param event The {@link ClickEvent} to handle
*/
protected void onMinimizeClick(ClickEvent event) {
Widget widget = getWidget();
if (widget == null)
return;
boolean visible = widget.isVisible();
int offsetWidth = widget.getOffsetWidth();
widget.setVisible(!visible);
this.minimized = visible;
if (visible) {
this.container.setWidth(offsetWidth + "px");
this.minimize.setStyleName("gwt-extras-dialog-maximize");
} else {
this.container.setWidth(null);
this.minimize.setStyleName("gwt-extras-dialog-minimize");
}
}
/*
* (non-Javadoc)
* @see com.google.gwt.event.logical.shared.HasOpenHandlers#addOpenHandler(com.google.gwt.event.logical.shared.OpenHandler)
*/
@Override
public HandlerRegistration addOpenHandler(OpenHandler<WindowBox> handler) {
return addHandler(handler, OpenEvent.getType());
}
/*
* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#show()
*/
@Override
public void show() {
boolean fireOpen = !isShowing();
super.show();
if (fireOpen) {
OpenEvent.fire(this, this);
}
}
/**
* Sets the minimum width to which this widget can be resized by the user, if resizing is enabled. If the value
* is invalid, it is reset to {@link #MIN_WIDTH}
*
* @param minWidth A positive int value
*/
public void setMinWidth(int minWidth) {
if (minWidth < 1)
minWidth = MIN_WIDTH;
this.minWidth = minWidth;
}
/**
* Sets the minimum height to which this widget can be resized by the user, if resizing is enabled. If the value
* is invalid, it is reset to {@link #MIN_WIDTH}
*
* @param minHeight A positive int value
*/
public void setMinHeight(int minHeight) {
if (minHeight < 1)
minHeight = MIN_HEIGHT;
this.minHeight = minHeight;
}
}

View File

@ -0,0 +1,605 @@
package org.gcube.portlets.admin.authportletmanager.server;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.authorization.library.policies.Action;
import org.gcube.common.authorization.library.policies.Policy;
import org.gcube.common.authorization.library.policies.PolicyType;
import org.gcube.common.authorization.library.policies.Roles;
import org.gcube.common.authorization.library.policies.Service2ServicePolicy;
import org.gcube.common.authorization.library.policies.ServiceAccess;
import org.gcube.common.authorization.library.policies.Services;
import org.gcube.common.authorization.library.policies.User2ServicePolicy;
import org.gcube.common.authorization.library.policies.Users;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.portlets.admin.authportletmanager.client.rpc.AuthManagerService;
import org.gcube.portlets.admin.authportletmanager.shared.Access;
import org.gcube.portlets.admin.authportletmanager.shared.Caller;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.PolicyAuth;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
import org.gcube.portlets.admin.authportletmanager.shared.Service;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.ServiceException;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.TypeCallerException;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* AuthServiceImpl
*
* Support service request
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
@SuppressWarnings({ "serial", "deprecation" })
public class AuthServiceImpl extends RemoteServiceServlet
implements AuthManagerService {
private static Logger logger = LoggerFactory
.getLogger(AuthServiceImpl.class);
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException {
super.init();
System.out.println("Fix JAXP: jdk.xml.entityExpansionLimit=0");
System.setProperty("jdk.xml.entityExpansionLimit", "0");
System.out.println("initializing AccountingManager");
}
/**
* Load all list policy
*/
@Override
public ArrayList<PolicyAuth> loadListPolicy() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ArrayList<PolicyAuth> policyList =new ArrayList<PolicyAuth>();
ASLSession aslSession = SessionUtil.getASLSession(session);
String scope=aslSession.getScope();
String token =aslSession.getSecurityToken();
if (ConstantsSharing.DEBUG_MODE) {
token=ConstantsSharing.DEBUG_TOKEN;
scope="/gcube/devNext";
logger.debug("load list policy in scope:"+scope);
}
SecurityTokenProvider.instance.set(token);
List<Policy> policies = authorizationService().getPolicies(scope);
if (policies!=null){
logger.info("Load List Policy Find:"+policies.size());
if (policies.size()>0){
for (Policy policy : policies){
logger.debug("retrieve a policy service object"+policy);
ArrayList<Caller> callers =new ArrayList<Caller>();
boolean excludeCallers=false;
if (policy.getPolicyType()==PolicyType.USER){
//retrive caller type user or role
List<String> callerExcludes=((User2ServicePolicy) policy).getEntity().getExcludes();
TypeCaller typecaller=TypeCaller.valueOf(((User2ServicePolicy) policy).getEntity().getType().toString().toLowerCase());
logger.debug("callerExcludes:"+callerExcludes +" and size:"+callerExcludes.size());
if (callerExcludes.size()>0){
//condition with all excepiton
for (String callerExclude: callerExcludes){
callers.add(new Caller(typecaller,callerExclude));
}
excludeCallers=true;
}
else{
String callerIdentifier=((User2ServicePolicy) policy).getEntity().getIdentifier();
if (callerIdentifier==null)
callerIdentifier=ConstantsSharing.Star;
callers.add(new Caller(typecaller,callerIdentifier));
}
}
else{
//retrive caller type service
logger.debug("retrieve a policy service"+policy.toString());
String callerIdentifier=((Service2ServicePolicy) policy).getClient().getService().getName().toString()+
":"+((Service2ServicePolicy) policy).getClient().getService().getServiceClass()+
":"+((Service2ServicePolicy) policy).getClient().getService().getServiceId().toString();
TypeCaller typecaller=TypeCaller.valueOf("service");
callers.add(new Caller(typecaller,callerIdentifier));
}
Long idpolicy=policy.getId();
String serviceClass="ALL";
String serviceName="ALL";
String serviceId="ALL";
if (!policy.getServiceAccess().toString().equals("*")){
serviceClass=policy.getServiceAccess().getServiceClass();
serviceName=policy.getServiceAccess().getName();
serviceId=policy.getServiceAccess().getServiceId();
}
Service service =new Service(serviceClass,serviceName,serviceId);
Calendar creationTime = policy.getCreationTime();
Date dataInsert = creationTime.getTime();
Calendar lastUpdateTime = policy.getLastUpdateTime();
Date dataUpdate = lastUpdateTime.getTime();
Access access= Access.valueOf(policy.getMode().toString());
PolicyAuth policyAuth =new PolicyAuth(idpolicy,callers,excludeCallers,service,access,dataInsert,dataUpdate);
logger.debug("traduce into a policy auth:"+policyAuth.toString());
policyList.add(policyAuth);
}
}
}
return policyList;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("loadListPolicy error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Load all caller
*/
@Override
public ArrayList<Caller> loadListCaller() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
@SuppressWarnings("unused")
ASLSession aslSession = SessionUtil.getASLSession(session);
ArrayList<Caller> callers =new ArrayList<Caller>();
String token =aslSession.getSecurityToken();
if (ConstantsSharing.DEBUG_MODE) {
token=ConstantsSharing.DEBUG_TOKEN;
}
SecurityTokenProvider.instance.set(token);
if (ConstantsSharing.MOCK_UP) {
logger.trace("List Caller on debug mode");
callers.add(new Caller(TypeCaller.role,"administrator"));
callers.add(new Caller(TypeCaller.user,"lucio.lelii"));
callers.add(new Caller(TypeCaller.role,"agent"));
callers.add(new Caller(TypeCaller.user,"luca.frosini"));
callers.add(new Caller(TypeCaller.user,"giancarlo.panichi"));
callers.add(new Caller(TypeCaller.role,"user"));
callers.add(new Caller(TypeCaller.service,"InformationSystem:IC:all"));
callers.add(new Caller(TypeCaller.service,"InformationSystem:IRegisrty:all"));
}
else{
RoleManager roleManager = new LiferayRoleManager();
UserManager userManager = new LiferayUserManager();
String scope=SessionUtil.getASLSession(session).getScope();
GroupManager groupManager= new LiferayGroupManager();
Long groupId= groupManager.getGroupIdFromInfrastructureScope(scope);
for (GCubeUser user :userManager.listUsersByGroup(groupId)){
callers.add(new Caller(TypeCaller.user,user.getUsername()));
}
//List All roles
for (GCubeRole role :roleManager.listAllGroupRoles()){
callers.add(new Caller(TypeCaller.role,role.getRoleName()));
}
//List Service
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.setResult("<Service><ServiceClass>{$resource/Profile/ServiceClass/text()}</ServiceClass>" +
"<ServiceName>{$resource/Profile/ServiceName/text()}</ServiceName></Service>");
DiscoveryClient<ServiceResult> client = clientFor(ServiceResult.class);
List<ServiceResult> resources = client.submit(query);
for (ServiceResult result: resources){
callers.add(new Caller(TypeCaller.service,result.getServiceClass()+":"+result.getServiceName()));
}
}
return callers;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("loadListCaller error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(),e);
}
}
/**
* Load all service
*/
@Override
public Map<String, List<String>> loadListService() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
@SuppressWarnings("unused")
ASLSession aslSession = SessionUtil.getASLSession(session);
Map<String, List<String>> services =new HashMap<String, List<String>>();
if (ConstantsSharing.DEBUG_MODE) {
String token=ConstantsSharing.DEBUG_TOKEN;
SecurityTokenProvider.instance.set(token);
}
if (ConstantsSharing.MOCK_UP) {
services.put("InformationSystem", Arrays.asList("IC", "ISRegistry"));
services.put("DataAccess", Arrays.asList("SpeciesProductsDiscovery","dAAaCCESS@"));
services.put("DataAnalysis", Arrays.asList("StatisticalManager"));
}
else{
//Get List service
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.setResult("<Service><ServiceClass>{$resource/Profile/ServiceClass/text()}</ServiceClass>" +
"<ServiceName>{$resource/Profile/ServiceName/text()}</ServiceName></Service>");
DiscoveryClient<ServiceResult> client = clientFor(ServiceResult.class);
List<ServiceResult> resources = client.submit(query);
for (ServiceResult result: resources){
if (!services.containsKey(result.getServiceClass()))
services.put(result.getServiceClass(),new ArrayList<String>());
services.get(result.getServiceClass()).add(result.getServiceName());
}
}
return services;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("loadListService error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Load all access
*/
@Override
public ArrayList<String> loadListAccess() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
@SuppressWarnings("unused")
ASLSession aslSession = SessionUtil.getASLSession(session);
if (ConstantsSharing.DEBUG_MODE) {
String token=ConstantsSharing.DEBUG_TOKEN;
SecurityTokenProvider.instance.set(token);
}
ArrayList<String> access =new ArrayList<String>();
for( Access accessValue : Access.values() )
access.add(access.toString());
return access;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("loadListAccess error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Insert a new List Policy
* @return
* @throws Throwable
*/
@Override
public void addPolicies(List<PolicyAuth> policiesAuth) throws ServiceException {
try {
//Long identifier;
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
List<Policy> policies = new ArrayList<Policy>();
String token =aslSession.getSecurityToken();
if (ConstantsSharing.DEBUG_MODE) {
token=ConstantsSharing.DEBUG_TOKEN;
}
SecurityTokenProvider.instance.set(token);
String scope=SessionUtil.getASLSession(session).getScope();
for (PolicyAuth policy: policiesAuth){
ServiceAccess service=new ServiceAccess(policy.getService().getServiceName(), policy.getService().getServiceClass(), policy.getService().getServiceId());
Action access =Action.valueOf(policy.getAccessString());
logger.debug("policy translate:"+policy.getCallerTypeAsString());
if (policy.getCallerTypeAsString().equalsIgnoreCase(TypeCaller.user.toString())){
logger.debug("add policy with user");
policies.add(new User2ServicePolicy(scope, service, Users.one(policy.getCallerAsString()), access ));
}
else if (policy.getCallerTypeAsString().equalsIgnoreCase(TypeCaller.role.toString())){
logger.debug("add policy with role");
policies.add(new User2ServicePolicy(scope, service, Roles.one(policy.getCallerAsString()), access ));
}
else if (policy.getCallerTypeAsString().equalsIgnoreCase(TypeCaller.service.toString())){
logger.debug("add policy with service");
String[] policyService=policy.getCallerAsString().split(":");
String serviceName=policyService[0].trim();
String serviceClass=policyService[1].trim();
String serviceId="All";
if (policyService.length==3)
serviceId=policy.getCallerAsString().split(":")[2];
ServiceAccess serviceCaller =new ServiceAccess(serviceName, serviceClass, serviceId);
policies.add(new Service2ServicePolicy(scope,service,Services.specialized(serviceCaller),access));
}
else{
String[] allExecpt=policy.getCallerTypeAsString().trim().split(" ");
if (allExecpt.length>0){
if (allExecpt[0].equalsIgnoreCase(TypeCaller.user.toString())){
logger.debug("add policy with user execpt");
policies.add(new User2ServicePolicy(scope, service, Users.allExcept(policy.getCallerExecptAsString()), access ));
}
else if (allExecpt[0].equalsIgnoreCase(TypeCaller.role.toString())){
logger.debug("add policy with role execpt");
policies.add(new User2ServicePolicy(scope, service, Roles.allExcept(policy.getCallerExecptAsString()), access ));
}
else{
logger.error("ERROR caller type not recognized"+allExecpt[0]);
throw new TypeCallerException("Caller type not found");
}
}
else{
logger.error("ERROR caller type not recognized"+policy.getCallerTypeAsString());
throw new TypeCallerException("Caller type not found");
}
}
}
logger.info("INSERT CALLER:"+policies.toString());
authorizationService().addPolicies(policies);
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Exception e) {
logger.error("addPolicies error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Update an existing policy
*/
@Override
public void updatePolicy(PolicyAuth policy) throws ServiceException{
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token =aslSession.getSecurityToken();
if (ConstantsSharing.DEBUG_MODE) {
token=ConstantsSharing.DEBUG_TOKEN;
}
SecurityTokenProvider.instance.set(token);
//remove old policy
authorizationService().removePolicies(policy.getIdpolicy());
//add a new policy
List<Policy> policies = new ArrayList<Policy>();
String scope=SessionUtil.getASLSession(session).getScope();
ServiceAccess service=new ServiceAccess(policy.getService().getServiceName(), policy.getService().getServiceClass(), policy.getService().getServiceId());
logger.info("updatePolicy -policy.getCallerAsString()"+policy.getCallerAsString());
Action access =Action.valueOf(policy.getAccessString());
policies.add(new User2ServicePolicy(scope, service, Users.one(policy.getCallerAsString()), access ));
authorizationService().addPolicies(policies);
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("updatePolicy error: " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage());
}
}
@Override
public List<Long> deletePolicies(List<Long> identifiers)throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
ArrayList<PolicyAuth> policy =new ArrayList<PolicyAuth>();
String token =aslSession.getSecurityToken();
if (ConstantsSharing.DEBUG_MODE) {
token=ConstantsSharing.DEBUG_TOKEN;
}
SecurityTokenProvider.instance.set(token);
for (Long identifier:identifiers){
logger.info("Remove policy idpolicy "+identifier);
authorizationService().removePolicies(identifier);
}
return identifiers;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("deletePolicies error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Load all list quota
*/
@Override
public ArrayList<Quote> loadListQuota() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getASLSession(session);
ArrayList<Quote> quote =new ArrayList<Quote>();
if (ConstantsSharing.MOCK_UP) {
logger.info("loadListQuota");
for (Quote quoteList : TableUtils.SERVICESQUOTE.values()){
quote.add(quoteList);
}
}
else{
logger.info("loadListQuota ");
for (Quote quoteList : TableUtils.SERVICESQUOTE.values()){
quote.add(quoteList);
}
}
return quote;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("loadListQuota error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
@Override
public List<Long> deleteQuote(List<Long> identifiers)throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
if (ConstantsSharing.MOCK_UP) {
for (Long identifier:identifiers){
logger.info("Remove quote idquote "+identifier);
TableUtils.SERVICESQUOTE.remove(identifier);
}
}
else{
for (Long identifier:identifiers){
logger.info("Remove quote idquote "+identifier);
TableUtils.SERVICESQUOTE.remove(identifier);
}
}
return identifiers;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("deleteQuote error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
@Override
public List<Quote> addQuote(List<Quote> quote) throws ServiceException {
try {
Long identifier;
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
if (ConstantsSharing.MOCK_UP) {
for (Quote quota: quote){
identifier =(long)(Math.random()*1000000000);
logger.info("Insert new quota for "+quota.getCallerAsString()+ "return with:"+identifier);
quota.setIdQuote(identifier);
Calendar calendarStart = Calendar.getInstance();
Date dateStart = calendarStart.getTime();
quota.setDataInsert(dateStart);
TableUtils.SERVICESQUOTE.put(identifier, quota);
}
}
else{
for (Quote quota: quote){
identifier =(long)(Math.random()*1000000000);
logger.info("Insert new quota for "+quota.getCallerAsString()+ "return with:"+identifier);
quota.setIdQuote(identifier);
Calendar calendarStart = Calendar.getInstance();
Date dateStart = calendarStart.getTime();
quota.setDataInsert(dateStart);
TableUtils.SERVICESQUOTE.put(identifier, quota);
}
}
return quote;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("addQuote error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
/**
* Update an existing quote
*/
@Override
public Quote updateQuote(Quote quote) throws ServiceException{
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
if (ConstantsSharing.MOCK_UP) {
//TableUtils.SERVICES.
TableUtils.SERVICESQUOTE.remove(quote.getIdQuote());
Calendar calendarStart = Calendar.getInstance();
Date dateUpdate = calendarStart.getTime();
quote.setDataUpdate(dateUpdate);
TableUtils.SERVICESQUOTE.put(quote.getIdQuote(), quote);
logger.info("Update quote identifier:"+quote.getIdQuote());
}
else{
TableUtils.SERVICESQUOTE.remove(quote.getIdQuote());
Calendar calendarStart = Calendar.getInstance();
Date dateUpdate = calendarStart.getTime();
quote.setDataUpdate(dateUpdate);
TableUtils.SERVICESQUOTE.put(quote.getIdQuote(), quote);
logger.info("Update quote identifier:"+quote.getIdQuote());
}
return quote;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("updateQuote error: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
}
}

View File

@ -0,0 +1,5 @@
package org.gcube.portlets.admin.authportletmanager.server;
public class ExpiredSessionServiceException extends Exception {
}

View File

@ -0,0 +1,26 @@
package org.gcube.portlets.admin.authportletmanager.server;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="Service")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class ServiceResult {
@XmlElement(name="ServiceClass")
private String serviceClass;
@XmlElement(name="ServiceName")
private String serviceName;
public String getServiceClass() {
return serviceClass;
}
public String getServiceName() {
return serviceName;
}
}

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.server;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.admin.authportletmanager.shared.ConstantsSharing;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.ExpiredSessionServiceException;
import org.gcube.portlets.admin.authportletmanager.shared.exceptions.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class SessionUtil {
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession)
throws ServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession aslSession;
if (username == null) {
if (ConstantsSharing.DEBUG_MODE) {
logger.info("no user found in session, use test user");
username = ConstantsSharing.DEFAULT_USER;
String scope = ConstantsSharing.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username);
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("no user found in session!");
throw new ExpiredSessionServiceException("Session Expired!");
}
} else {
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ aslSession.getScope());
return aslSession;
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.admin.authportletmanager.server;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.admin.authportletmanager.shared.Quote;
public class TableUtils {
public static List<Quote> quoteList = Arrays.asList(
// new Quote(100000l,"user.name","devNext",ManagerType.STORAGE,TimeInterval.WEEKLY,500.00)
);
public static Map<Long, Quote> SERVICESQUOTE = new HashMap<Long, Quote>();
static {
for (Quote quote: quoteList)
SERVICESQUOTE.put(quote.getIdQuote(), quote);
}
}

View File

@ -0,0 +1,50 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.server.portlet;
import java.io.IOException;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class AccountingManagerPortlet extends GenericPortlet {
protected Logger logger = LoggerFactory.getLogger(AccountingManagerPortlet.class);
/**
* JSP folder name
*/
public static final String JSP_FOLDER = "/WEB-INF/jsp/";
/**
*
*/
public static final String VIEW_JSP = JSP_FOLDER + "AccountingManagerPortlet_view.jsp";
/**
* @param request .
* @param response .
* @throws IOException .
* @throws PortletException .
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
ScopeHelper.setContext(request);
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
rd.include(request,response);
}
}

View File

@ -0,0 +1,56 @@
/**
*
*/
package org.gcube.portlets.admin.authportletmanager.server.portlet;
import java.io.IOException;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class AuthManagerPortlet extends GenericPortlet {
protected Logger logger = LoggerFactory.getLogger(AuthManagerPortlet.class);
/**
* JSP folder name
*/
public static final String JSP_FOLDER = "/WEB-INF/jsp/";
/**
*
*/
public static final String VIEW_JSP = JSP_FOLDER + "AuthPortletManager_view.jsp";
/**
* @param request .
* @param response .
* @throws IOException .
* @throws PortletException .
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
logger.trace("AuthPortletManager loading from JSP: "+VIEW_JSP);
logger.trace("setting context using ScopeHelper");
ScopeHelper.setContext(request);
logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
rd.include(request,response);
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.portlets.admin.authportletmanager.shared;
public enum Access {
ALL,
ACCESS,
DELETE,
EXECUTE,
WRITE;
}

View File

@ -0,0 +1,119 @@
package org.gcube.portlets.admin.authportletmanager.shared;
import java.io.Serializable;
/**
* Caller class for
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class Caller implements Serializable, Comparable<Caller> {
/**
*
*/
private static final long serialVersionUID = -8450499385104913365L;
//private String typeCaller;
public enum TypeCaller {
user,
role,
service;
}
private String callerName;
private TypeCaller typeCaller;
public Caller() {
super();
}
public Caller(TypeCaller typeCaller, String callerName) {
super();
this.typeCaller = typeCaller;
this.callerName=callerName;
}
public TypeCaller getTypecaller() {
return typeCaller;
}
public void setTypecaller(TypeCaller typeCaller) {
this.typeCaller = typeCaller;
}
public String getCallerName() {
return callerName;
}
public void setCallerName(String callerName) {
this.callerName = callerName;
}
@Override
public int compareTo(Caller o) {
// TODO Auto-generated method stub
return -this.getCallerName().compareTo(o.getCallerName());
}
public int compare(Caller o1, Caller o2) {
// TODO Auto-generated method stub
return -o1.getCallerName().compareTo(o2.getCallerName());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((callerName == null) ? 0 : callerName.hashCode());
result = prime * result
+ ((typeCaller == null) ? 0 : typeCaller.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Caller other = (Caller) obj;
if (callerName == null) {
if (other.callerName != null)
return false;
} else if (!callerName.equals(other.callerName))
return false;
if (typeCaller == null) {
if (other.typeCaller != null)
return false;
} else if (!typeCaller.equals(other.typeCaller))
return false;
return true;
}
}

View File

@ -0,0 +1,32 @@
package org.gcube.portlets.admin.authportletmanager.shared;
/**
*
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class Constants {
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
public static final String AM_LANG_COOKIE = "AMLangCookie";
public static final String AM_LANG = "AMLang";
public final static String DEFAULT_USER = "alessandro.pieve";
public static final boolean DEBUG_MODE = true;
public static final boolean TEST_ENABLE = false;
public static final String DEFAULT_ROLE = "OrganizationMember";
public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
}

View File

@ -0,0 +1,44 @@
package org.gcube.portlets.admin.authportletmanager.shared;
/**
* CostantsSharing usage for project
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class ConstantsSharing {
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
public static final String AM_LANG_COOKIE = "AMLangCookie";
public static final String AM_LANG = "AMLang";
public final static String DEFAULT_USER = "alessandro.pieve";
public static final boolean DEBUG_MODE = false;
public static final String DEBUG_TOKEN = "afdaa1c6-493b-405e-801d-b219e056f564|98187548";
public static final boolean MOCK_UP = false;
public static final String DEFAULT_ROLE = "OrganizationMember";
public final static String DEFAULT_SCOPE = "/gcube/devNext";
/***
* For client
*/
public static final String LOADINGSTYLE = "x-mask-loading";
public static final String SERVER_ERROR = "Sorry, an error has occurred on the server when";
public static final String TRY_AGAIN = "Try again";
public static int WIDTH_DIALOG_LOADER = 200;
public static int HEIGHT_DIALOG_LOADER = 80;
public static String Star="ALL";
public static String StarIcon="*";
public static String StarLabel="ALL SERVICE";
public static String TagCaller="@";
public static String TagRole="#";
public static String TagService="$";
public static String TagAccess="*";
public static String TagTime="$";
public static String TagType="*";
}

View File

@ -0,0 +1,269 @@
package org.gcube.portlets.admin.authportletmanager.shared;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.gcube.portlets.admin.authportletmanager.shared.Caller.TypeCaller;
/**
* PolicyAuth usage for project
* @author "Alessandro Pieve " <a
* href="mailto:alessandro.pieve@isti.cnr.it">alessandro.pieve@isti.cnr.it</a>
*
*/
public class PolicyAuth implements Serializable {
private static final long serialVersionUID = 5453609273197782507L;
private Long idPolicy;
private List<Caller> caller;
private Boolean excludesCaller;
private Service service;
//private String access;
// private Action access;
private Access access;
private Date dataInsert;
private Date dataUpdate;
public PolicyAuth() {
super();
}
public PolicyAuth(List<Caller> caller, Service service, Access access) {
super();
this.caller=caller;
this.service = service;
this.access = access;
}
public PolicyAuth(Long idPolicy, List<Caller> caller,Service service,Access access) {
super();
this.idPolicy = idPolicy;
this.caller=caller;
this.service = service;
this.access = access;
}
public PolicyAuth(Long idPolicy, List<Caller> caller,Service service,Access access, Date dataInsert, Date dataUpdate) {
super();
this.idPolicy = idPolicy;
this.caller=caller;
this.service = service;
this.access = access;
this.dataInsert=dataInsert;
this.dataUpdate=dataUpdate;
}
public PolicyAuth(Long idPolicy, List<Caller> caller,Service service,Access access, Date dataInsert) {
super();
this.idPolicy = idPolicy;
this.caller=caller;
this.service = service;
this.access = access;
this.dataInsert=dataInsert;
}
public PolicyAuth(Long idPolicy,List<Caller> caller,Boolean excludeCallers,Service service,Access access, Date dataInsert, Date dataUpdate) {
super();
this.idPolicy = idPolicy;
this.caller=caller;
this.excludesCaller=excludeCallers;
this.service = service;
this.access = access;
this.dataInsert=dataInsert;
this.dataUpdate=dataUpdate;
}
public long getIdpolicy() {
return idPolicy;
}
public void setIdpolicy(Long idPolicy) {
this.idPolicy = idPolicy;
}
public List<Caller> getCaller() {
return caller;
}
public void setCaller(List<Caller> caller) {
this.caller = caller;
}
public void setService(Service service) {
this.service = service;
}
public Access getAccess() {
return access;
}
public String getAccessString() {
return access.toString();
}
public void setAccess(Access access) {
this.access = access;
}
public Service getService() {
return service;
}
/*
* Get full name
*/
public String getServiceAsString(){
return service.getServiceClass()+":"+service.getServiceName()+":"+service.getServiceId();
}
/*
* Get full name caller
*/
public String getCallerAsString(){
String callerNameString = new String();
for (Caller caller:this.caller){
callerNameString=caller.getCallerName()+" "+ callerNameString;
}
return callerNameString;
}
/*
* Get full type caller
*/
public String getCallerTypeAsString(){
String callerTypeString = "";
for (Caller caller:this.caller){
if (this.caller.size()==1){
callerTypeString=caller.getTypecaller().toString();
}
else{
callerTypeString=callerTypeString+" "+caller.getTypecaller().toString();
}
}
return callerTypeString;
}
/**
*
* @return
*/
public TypeCaller getCallerType(){
TypeCaller callerTypeString =null;
for (Caller caller:this.caller){
callerTypeString=caller.getTypecaller();
}
return callerTypeString;
}
/*
* Get full type caller
*/
public String getCallerTypeAsDataGrid(){
String callerTypeString = "";
for (Caller caller:this.caller){
callerTypeString=caller.getTypecaller().toString();
}
return callerTypeString;
}
/**
*
* @return
*/
public String[] getCallerExecptAsString(){
String[] callerNameString = new String[this.caller.size()-1];
int count =0;
for (Caller caller:this.caller){
if (!caller.getCallerName().equals("ALL")){
callerNameString[count]=caller.getCallerName();
count++;
}
}
return callerNameString;
}
public Date getDataInsert() {
return dataInsert;
}
public void setDataInsert(Date dataInsert) {
this.dataInsert = dataInsert;
}
public Date getDataUpdate() {
return dataUpdate;
}
public void setDataUpdate(Date dataUpdate) {
this.dataUpdate = dataUpdate;
}
public Boolean getExcludesCaller() {
return excludesCaller;
}
public void setExcludesCaller(Boolean excludesCaller) {
this.excludesCaller = excludesCaller;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((access == null) ? 0 : access.hashCode());
result = prime * result + ((caller == null) ? 0 : caller.hashCode());
result = prime * result
+ ((idPolicy == null) ? 0 : idPolicy.hashCode());
result = prime * result + ((service == null) ? 0 : service.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PolicyAuth other = (PolicyAuth) obj;
if (access == null) {
if (other.access != null)
return false;
} else if (!access.equals(other.access))
return false;
if (caller == null) {
if (other.caller != null)
return false;
} else if (!caller.equals(other.caller))
return false;
if (idPolicy == null) {
if (other.idPolicy != null)
return false;
} else if (!idPolicy.equals(other.idPolicy))
return false;
if (service == null) {
if (other.service != null)
return false;
} else if (!service.equals(other.service))
return false;
return true;
}
@Override
public String toString() {
return "PolicyAuth [idPolicy=" + idPolicy + ", caller=" + caller
+ ", excludesCaller=" + excludesCaller + ", service=" + service
+ ", access=" + access + ", dataInsert=" + dataInsert
+ ", dataUpdate=" + dataUpdate + "]";
}
}

Some files were not shown because too many files have changed in this diff Show More