join-vre/src/main/java/org/gcube/portlets/user/joinvre/client/panels/JoinVREPanel.java

87 lines
2.7 KiB
Java

package org.gcube.portlets.user.joinvre.client.panels;
import java.util.ArrayList;
import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.client.JoinServiceAsync;
import org.gcube.portlets.user.joinvre.client.ui.DisplayVRE;
import org.gcube.portlets.user.vremembers.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.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class JoinVREPanel extends Composite {
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final JoinServiceAsync joinService = GWT.create(JoinService.class);
public static final String loading = GWT.getModuleBaseURL() + "../images/members-loader.gif";
private Image loadingImage;
private VerticalPanel mainPanel = new VerticalPanel();
public JoinVREPanel() {
super();
loadingImage = new Image(loading);
mainPanel.add(loadingImage);
showLoader();
joinService.getVREs(new AsyncCallback<ArrayList<VRE>>() {
@Override
public void onSuccess(ArrayList<VRE> vres) {
mainPanel.clear();
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
// TODO
if (vres == null || vres.isEmpty()) {
mainPanel.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>"));
} else {
Grid grid = new Grid(vres.size()/4+1, 4);
mainPanel.add(grid);
for (int i = 0; i < vres.size(); i++) {
grid.setWidget(i/4, i%4, new DisplayVRE(vres.get(i)));
}
}
}
@Override
public void onFailure(Throwable caught) {
mainPanel.add(new HTML("<div class=\"nofeed-message\">" +
"Sorry, looks like something is broken with the server connection<br> " +
"Please check your connection and try refresh this page.</div>"));
}
});
initWidget(mainPanel);
}
private void showLoader() {
mainPanel.clear();
mainPanel.setWidth("100%");
mainPanel.setHeight("300px");
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
mainPanel.add(loadingImage);
}
}