2012-12-23 21:55:39 +01:00
|
|
|
package org.gcube.portlet.user.my_vres.client;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-10-22 18:32:48 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2012-12-23 21:55:39 +01:00
|
|
|
|
|
|
|
import org.gcube.portlet.user.my_vres.client.widgets.ClickableVRE;
|
|
|
|
import org.gcube.portlet.user.my_vres.shared.VRE;
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
2017-02-02 19:24:36 +01:00
|
|
|
import com.google.gwt.core.client.ScriptInjector;
|
2016-05-03 17:43:10 +02:00
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
2012-12-23 21:55:39 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2016-05-03 17:43:10 +02:00
|
|
|
import com.google.gwt.user.client.ui.HasAlignment;
|
2012-12-23 21:55:39 +01:00
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
2016-05-03 17:43:10 +02:00
|
|
|
import com.google.gwt.user.client.ui.Image;
|
2015-10-23 13:46:09 +02:00
|
|
|
import com.google.gwt.user.client.ui.SimplePanel;
|
2012-12-23 21:55:39 +01:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante - ISTI CNR
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class VresPanel extends Composite {
|
2016-05-03 17:43:10 +02:00
|
|
|
public static final String loading = GWT.getModuleBaseURL() + "../images/loading.gif";
|
2016-12-07 15:34:34 +01:00
|
|
|
private static final int LOAD_MAX_IMAGE_NO = 10;
|
2012-12-23 21:55:39 +01:00
|
|
|
private final MyVREsServiceAsync myVREsService = GWT.create(MyVREsService.class);
|
|
|
|
private FlowPanel flowPanel;
|
|
|
|
private VerticalPanel mainPanel = new VerticalPanel();
|
2015-10-23 13:46:09 +02:00
|
|
|
private SimplePanel catPanel = new SimplePanel();
|
2012-12-23 21:55:39 +01:00
|
|
|
private HorizontalPanel imagesPanel = new HorizontalPanel();
|
2016-05-03 17:43:10 +02:00
|
|
|
private Image loadingImage = new Image(loading);
|
2015-10-22 18:32:48 +02:00
|
|
|
private LinkedHashMap<String, ArrayList<VRE>> cachedVREs = null;
|
2017-02-02 19:24:36 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
boolean hasVres = false;
|
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
public VresPanel(GetParameters params) {
|
|
|
|
super();
|
2016-05-03 17:43:10 +02:00
|
|
|
loadingImage.getElement().getStyle().setMarginTop(59, Unit.PX);
|
|
|
|
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
2012-12-23 21:55:39 +01:00
|
|
|
mainPanel.setWidth("100%");
|
|
|
|
mainPanel.setStyleName("mainPanel");
|
|
|
|
this.flowPanel = new FlowPanel();
|
|
|
|
flowPanel.setWidth("100%");
|
|
|
|
flowPanel.setStyleName("flowPanel");
|
2015-10-23 13:46:09 +02:00
|
|
|
catPanel.setWidth("95%");
|
2017-01-12 18:48:06 +01:00
|
|
|
loadVREs(params);
|
2012-12-23 21:55:39 +01:00
|
|
|
initWidget(mainPanel);
|
2017-02-02 19:24:36 +01:00
|
|
|
//change the portlet title only if is an authorisation
|
|
|
|
if (params != null)
|
|
|
|
ScriptInjector.fromString("$wnd.jQuery(\".portlet-title-text\").text('Please select in which of your VREs you approve this application');").inject();
|
|
|
|
|
2015-10-22 18:32:48 +02:00
|
|
|
}
|
2012-12-23 21:55:39 +01:00
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
private void loadVREs(final GetParameters params) {
|
2017-02-02 19:24:36 +01:00
|
|
|
|
2016-05-03 17:43:10 +02:00
|
|
|
mainPanel.add(loadingImage);
|
2015-10-22 18:32:48 +02:00
|
|
|
myVREsService.getUserVREs(new AsyncCallback<LinkedHashMap<String,ArrayList<VRE>>>() {
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2015-10-22 18:32:48 +02:00
|
|
|
@Override
|
2012-12-23 21:55:39 +01:00
|
|
|
public void onFailure(Throwable caught) {
|
2015-10-22 18:32:48 +02:00
|
|
|
flowPanel.add(new HTML("Could not fetch personal VREs: " + caught.getMessage()));
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2015-10-22 18:32:48 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(LinkedHashMap<String, ArrayList<VRE>> result) {
|
|
|
|
cachedVREs = result;
|
2017-01-12 18:48:06 +01:00
|
|
|
showIconView(params);
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
2015-10-22 18:32:48 +02:00
|
|
|
});
|
|
|
|
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
private void showIconView(final GetParameters params) {
|
2016-09-30 14:46:41 +02:00
|
|
|
boolean hasVREs = false;
|
2015-10-23 13:46:09 +02:00
|
|
|
mainPanel.clear();
|
2016-05-03 17:43:10 +02:00
|
|
|
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
2016-12-07 15:34:34 +01:00
|
|
|
int i = 0;
|
2015-10-22 18:32:48 +02:00
|
|
|
for (String cat : cachedVREs.keySet()) {
|
2015-10-23 13:46:09 +02:00
|
|
|
if (! cachedVREs.get(cat).isEmpty()) {
|
|
|
|
SimplePanel catPanel = new SimplePanel();
|
|
|
|
catPanel.setStyleName("category-panel");
|
|
|
|
HTML categ = new HTML(cat);
|
|
|
|
categ.setStyleName("category-name");
|
|
|
|
catPanel.add(categ);
|
|
|
|
mainPanel.add(catPanel);
|
|
|
|
FlowPanel flowPanel = new FlowPanel();
|
|
|
|
flowPanel.setWidth("100%");
|
|
|
|
flowPanel.setStyleName("flowPanel");
|
|
|
|
for (VRE vre: cachedVREs.get(cat)) {
|
2016-09-30 14:46:41 +02:00
|
|
|
if (vre.getName().compareTo("")!= 0)
|
|
|
|
hasVREs = true;
|
2017-01-12 18:48:06 +01:00
|
|
|
ClickableVRE vreButton = new ClickableVRE(myVREsService, vre, (i < LOAD_MAX_IMAGE_NO), params);
|
2015-10-23 13:46:09 +02:00
|
|
|
flowPanel.add(vreButton);
|
2017-02-02 19:24:36 +01:00
|
|
|
//do not show the add more placeholder VRE is is an authorisation
|
|
|
|
if (params != null && vre.getName().compareTo("") == 0) {
|
|
|
|
mainPanel.remove(catPanel);
|
|
|
|
flowPanel.remove(vreButton);
|
|
|
|
}
|
2016-12-07 15:34:34 +01:00
|
|
|
i++;
|
2015-10-23 13:46:09 +02:00
|
|
|
}
|
2017-02-02 19:24:36 +01:00
|
|
|
|
2015-10-23 13:46:09 +02:00
|
|
|
mainPanel.add(flowPanel);
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 15:34:34 +01:00
|
|
|
GWT.log("i="+i);
|
2015-10-22 18:32:48 +02:00
|
|
|
|
2016-09-30 14:46:41 +02:00
|
|
|
if (! hasVREs) {
|
|
|
|
mainPanel.clear();
|
2012-12-23 21:55:39 +01:00
|
|
|
mainPanel.add(new NoVresPanel());
|
|
|
|
imagesPanel.clear();
|
2016-09-30 14:37:02 +02:00
|
|
|
}
|
2012-12-23 21:55:39 +01:00
|
|
|
|
|
|
|
}
|
2017-02-02 19:24:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
|
2013-02-06 12:13:52 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|