108 lines
2.6 KiB
Java
108 lines
2.6 KiB
Java
package org.gcube.portlet.user.my_vres.client;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.LinkedHashMap;
|
|
|
|
import org.gcube.portlet.user.my_vres.client.widgets.ClickableVRE;
|
|
import org.gcube.portlet.user.my_vres.shared.VO;
|
|
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;
|
|
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();
|
|
private HorizontalPanel changeViewPanel = new HorizontalPanel();
|
|
private HorizontalPanel imagesPanel = new HorizontalPanel();
|
|
|
|
private LinkedHashMap<String, ArrayList<VRE>> cachedVREs = null;
|
|
|
|
boolean hasVres = false;
|
|
|
|
public VresPanel() {
|
|
super();
|
|
|
|
mainPanel.setWidth("100%");
|
|
mainPanel.setStyleName("mainPanel");
|
|
this.flowPanel = new FlowPanel();
|
|
flowPanel.setWidth("100%");
|
|
flowPanel.setStyleName("flowPanel");
|
|
|
|
changeViewPanel.setWidth("95%");
|
|
changeViewPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
|
|
changeViewPanel.add(imagesPanel);
|
|
loadVREs();
|
|
initWidget(mainPanel);
|
|
}
|
|
|
|
private void loadVREs() {
|
|
|
|
myVREsService.getUserVREs(new AsyncCallback<LinkedHashMap<String,ArrayList<VRE>>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
flowPanel.add(new HTML("Could not fetch personal VREs: " + caught.getMessage()));
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(LinkedHashMap<String, ArrayList<VRE>> result) {
|
|
cachedVREs = result;
|
|
showIconView();
|
|
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
private void showIconView() {
|
|
mainPanel.clear();
|
|
flowPanel.clear();
|
|
mainPanel.add(changeViewPanel);
|
|
mainPanel.add(flowPanel);
|
|
|
|
ArrayList<VRE> sortedVREs = new ArrayList<VRE>();
|
|
for (String cat : cachedVREs.keySet()) {
|
|
for (VRE vre: cachedVREs.get(cat)) {
|
|
sortedVREs.add(vre);
|
|
hasVres = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (VRE vre : sortedVREs) {
|
|
ClickableVRE vreButton = new ClickableVRE(vre, myVREsService);
|
|
flowPanel.add(vreButton);
|
|
}
|
|
|
|
if (!hasVres) {
|
|
mainPanel.add(new NoVresPanel());
|
|
imagesPanel.clear();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|