2016-03-17 17:46:10 +01:00
|
|
|
package org.gcube.portlets.admin.createusers.client;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.admin.createusers.client.ui.AddUserForm;
|
|
|
|
import org.gcube.portlets.admin.createusers.client.ui.LoadingText;
|
|
|
|
import org.gcube.portlets.admin.createusers.client.ui.RegisteredUsersTable;
|
|
|
|
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TabPane;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TabPanel;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
2016-03-18 18:29:29 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2016-03-17 17:46:10 +01:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2016-03-18 18:29:29 +01:00
|
|
|
import com.google.gwt.user.client.ui.Button;
|
2016-03-17 17:46:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The panel that contains the list of users already registered and the form to add new ones.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
|
|
|
public class CreateUsersPanel extends Composite {
|
|
|
|
|
|
|
|
// main vertical panel
|
|
|
|
private VerticalPanel mainPanel = new VerticalPanel();
|
|
|
|
|
|
|
|
// Tab panel
|
|
|
|
private TabPanel navTabs = new TabPanel();
|
|
|
|
|
|
|
|
// add user subpanel
|
|
|
|
private TabPane addUserSubPanel = new TabPane("Create New User");
|
|
|
|
|
|
|
|
// registered users subpanel
|
|
|
|
private TabPane registeredUsersSubPanel = new TabPane("Already Created Users") ;
|
2016-03-18 18:29:29 +01:00
|
|
|
|
|
|
|
// TODO remove
|
|
|
|
private TabPane sendMailTabPane = new TabPane("Send Mail");
|
2016-03-17 17:46:10 +01:00
|
|
|
|
|
|
|
// Create a remote service proxy to talk to the server-side user manager service.
|
|
|
|
private final HandleUsersServiceAsync userServices = GWT.create(HandleUsersService.class);
|
|
|
|
|
|
|
|
// table of registered users
|
|
|
|
private RegisteredUsersTable registeredUsersTable;
|
|
|
|
|
|
|
|
// event bus
|
|
|
|
private final HandlerManager eventBus = new HandlerManager(null);
|
|
|
|
|
|
|
|
public CreateUsersPanel(){
|
|
|
|
|
|
|
|
super();
|
|
|
|
initWidget(mainPanel);
|
|
|
|
|
|
|
|
// form panel
|
|
|
|
AddUserForm addUserForm = new AddUserForm(userServices, eventBus, this);
|
|
|
|
addUserSubPanel.add(addUserForm);
|
|
|
|
|
|
|
|
// add temporary loader for registered users table
|
|
|
|
LoadingText loader = new LoadingText();
|
|
|
|
loader.setVisible(true);
|
|
|
|
registeredUsersSubPanel.add(loader);
|
2016-03-18 18:29:29 +01:00
|
|
|
|
|
|
|
// TODO remove
|
|
|
|
Button sendMail = new Button("Test send email");
|
|
|
|
sendMail.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
GWT.log("send email requested");
|
|
|
|
userServices.sendEmailToUser("costantino.perciante@isti.cnr.it", new AsyncCallback<Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
GWT.log("ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
GWT.log("not ok");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sendMailTabPane.add(sendMail);
|
|
|
|
navTabs.add(sendMailTabPane);
|
2016-03-17 17:46:10 +01:00
|
|
|
|
|
|
|
// add stuff to the main panel
|
|
|
|
navTabs.add(addUserSubPanel);
|
|
|
|
navTabs.add(registeredUsersSubPanel);
|
|
|
|
mainPanel.add(navTabs);
|
|
|
|
|
|
|
|
// select add user form tab
|
|
|
|
navTabs.selectTab(0);
|
|
|
|
|
|
|
|
// enlarge navTabs
|
|
|
|
mainPanel.setWidth("100%");
|
|
|
|
|
|
|
|
// squeeze the form panel
|
|
|
|
addUserSubPanel.setWidth("50%");
|
|
|
|
|
|
|
|
// require already registered users
|
|
|
|
userServices.getAlreadyRegisterdUsers(new AsyncCallback<List<VreUserBean>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<VreUserBean> result) {
|
|
|
|
|
|
|
|
if(result == null){
|
|
|
|
showProblemsRetrievingList();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GWT.log("List of registered users received!");
|
|
|
|
registeredUsersTable = new RegisteredUsersTable(result, eventBus);
|
|
|
|
registeredUsersSubPanel.clear();
|
|
|
|
registeredUsersSubPanel.add(registeredUsersTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
GWT.log("Unable to retrieve list of registered users!" + caught.toString());
|
|
|
|
showProblemsRetrievingList();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show error block if retrieving registered data fails.
|
|
|
|
*/
|
|
|
|
private void showProblemsRetrievingList() {
|
|
|
|
|
|
|
|
registeredUsersSubPanel.clear();
|
|
|
|
AlertBlock error = new AlertBlock(AlertType.ERROR);
|
|
|
|
error.setText("It is not possible to retrieve the requested data at the moment. Retry later...");
|
|
|
|
error.setAnimation(true);
|
|
|
|
error.setClose(false);
|
|
|
|
registeredUsersSubPanel.add(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a user with this email has been already registered
|
|
|
|
* @param actualEmail
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean isUserPresent(String actualEmail) {
|
|
|
|
return registeredUsersTable.isUserPresent(actualEmail);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|