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;
|
|
|
|
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;
|
|
|
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
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
|
|
|
|
* @version 1.1 Dec 2012
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class VresPanel extends Composite {
|
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side service
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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() {
|
2012-12-23 21:55:39 +01:00
|
|
|
|
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();
|
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-10-23 13:46:09 +02:00
|
|
|
if (cachedVREs.isEmpty()) {
|
2012-12-23 21:55:39 +01:00
|
|
|
mainPanel.add(new NoVresPanel());
|
|
|
|
imagesPanel.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|