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;
|
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";
|
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;
|
2012-12-23 21:55:39 +01:00
|
|
|
|
|
|
|
boolean hasVres = false;
|
|
|
|
|
|
|
|
public VresPanel() {
|
|
|
|
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%");
|
2015-10-22 18:32:48 +02:00
|
|
|
loadVREs();
|
2012-12-23 21:55:39 +01:00
|
|
|
initWidget(mainPanel);
|
2015-10-22 18:32:48 +02:00
|
|
|
}
|
2012-12-23 21:55:39 +01:00
|
|
|
|
2015-10-22 18:32:48 +02:00
|
|
|
private void loadVREs() {
|
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;
|
|
|
|
showIconView();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private void showIconView() {
|
2015-10-23 13:46:09 +02:00
|
|
|
mainPanel.clear();
|
2016-05-03 17:43:10 +02:00
|
|
|
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
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)) {
|
|
|
|
ClickableVRE vreButton = new ClickableVRE(vre, myVREsService);
|
|
|
|
flowPanel.add(vreButton);
|
|
|
|
}
|
|
|
|
mainPanel.add(flowPanel);
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 18:32:48 +02:00
|
|
|
|
2015-12-01 17:05:28 +01:00
|
|
|
if (! hasAtLeastOneVRE(cachedVREs)) {
|
2012-12-23 21:55:39 +01:00
|
|
|
mainPanel.add(new NoVresPanel());
|
|
|
|
imagesPanel.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-01 17:05:28 +01:00
|
|
|
private boolean hasAtLeastOneVRE(LinkedHashMap<String, ArrayList<VRE>> cachedVREs) {
|
|
|
|
for (String cat : cachedVREs.keySet())
|
|
|
|
if (! cachedVREs.get(cat).isEmpty())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
}
|