2012-12-23 21:55:39 +01:00
|
|
|
package org.gcube.portlet.user.my_vres.client.widgets;
|
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
import org.gcube.portlet.user.my_vres.client.GetParameters;
|
|
|
|
import org.gcube.portlet.user.my_vres.client.MyVREs;
|
|
|
|
import org.gcube.portlet.user.my_vres.client.MyVREsServiceAsync;
|
|
|
|
import org.gcube.portlet.user.my_vres.shared.AuthorizationBean;
|
2012-12-23 21:55:39 +01:00
|
|
|
import org.gcube.portlet.user.my_vres.shared.VRE;
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2016-12-07 15:34:34 +01:00
|
|
|
import com.google.gwt.event.dom.client.MouseOverEvent;
|
|
|
|
import com.google.gwt.event.dom.client.MouseOverHandler;
|
2016-03-31 12:31:28 +02:00
|
|
|
import com.google.gwt.user.client.Timer;
|
2015-10-22 18:32:48 +02:00
|
|
|
import com.google.gwt.user.client.Window.Location;
|
2017-01-12 18:48:06 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2012-12-23 21:55:39 +01:00
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2017-01-12 18:48:06 +01:00
|
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
2012-12-23 21:55:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante - ISTI CNR
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ClickableVRE extends HTML {
|
|
|
|
|
2016-03-31 12:31:28 +02:00
|
|
|
private final static int WIDTH = 90;
|
|
|
|
private final static int HEIGHT = 100;
|
2012-12-23 21:55:39 +01:00
|
|
|
|
|
|
|
private String name;
|
|
|
|
private String imageUrl;
|
|
|
|
private int imageWidth = 0;
|
|
|
|
|
|
|
|
public static final String LOADING_IMAGE = GWT.getModuleBaseURL() + "../images/loading.gif";
|
2016-12-07 15:34:34 +01:00
|
|
|
public static final String VLAB_IMAGE = GWT.getModuleBaseURL() + "../images/vlab.png";
|
|
|
|
private String html = "";
|
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
public ClickableVRE(final MyVREsServiceAsync myVREsService, final VRE vre, final boolean showImage, final GetParameters params) {
|
2012-12-23 21:55:39 +01:00
|
|
|
super.setPixelSize(WIDTH, HEIGHT);
|
|
|
|
setPixelSize(WIDTH, HEIGHT);
|
2016-09-30 14:37:02 +02:00
|
|
|
if (vre.getName() == null || vre.getName().compareTo("") == 0) {
|
|
|
|
html = "<div class=\"more-vre\"></div>";
|
|
|
|
} else {
|
2016-10-04 12:59:19 +02:00
|
|
|
imageWidth = WIDTH - 12;
|
2016-09-30 14:37:02 +02:00
|
|
|
name = (vre.getName().length() > 15) ? vre.getName().substring(0, 13) + ".." : vre.getName();
|
2016-12-07 15:34:34 +01:00
|
|
|
imageUrl = vre.getImageURL();
|
2016-09-30 14:37:02 +02:00
|
|
|
html = "<div class=\"vreCaption\">" +name + "</div>";
|
2016-12-07 15:34:34 +01:00
|
|
|
if (showImage) {
|
|
|
|
html += "<div style=\"display: table; text-align:center; width: 100%; height: 75px;\">" +
|
|
|
|
"<span style=\"vertical-align:middle; display: table-cell;\"><img style=\"width: " + imageWidth + "px;\" src=\"" +imageUrl + "\" /></span>" +
|
|
|
|
"</div>";
|
|
|
|
} else {
|
|
|
|
html += "<div style=\"display: table; text-align:center; width: 100%; height: 75px;\" class=\"vlab-default\"></div>";
|
|
|
|
}
|
2016-09-30 14:37:02 +02:00
|
|
|
}
|
2014-04-07 18:55:00 +02:00
|
|
|
this.setTitle("Enter");
|
2016-12-07 15:34:34 +01:00
|
|
|
|
2012-12-23 21:55:39 +01:00
|
|
|
setHTML(html);
|
|
|
|
setStyleName("vreButton");
|
2017-01-12 18:48:06 +01:00
|
|
|
if (params != null) {
|
|
|
|
addClickHandler(new ClickHandler() {
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
myVREsService.getUserToken(vre.getContext(), params.getState(), new AsyncCallback<AuthorizationBean>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(AuthorizationBean result) {
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
Location.assign(params.getRedirectURI()+"?"+MyVREs.GET_AUTH_TOKEN_PARAMETER+"="+result.getToken()+"&"+MyVREs.GET_STATE_PARAMETER+"="+result.getState());
|
|
|
|
} else {
|
|
|
|
RootPanel.get("myVREsDIV").add(new HTML("There were issues in managing this request: " + result.getErrorDescription()));
|
|
|
|
}
|
|
|
|
}
|
2012-12-23 21:55:39 +01:00
|
|
|
|
2017-01-12 18:48:06 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
RootPanel.get("myVREsDIV").add(new HTML("An error occurred in the server: " + caught.getMessage()));
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addClickHandler(new ClickHandler() {
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
String html = "<div style=\"display: table; text-align:center; width: 100%; height: 75px;\">" +
|
|
|
|
"<span style=\"vertical-align:middle; display: table-cell;\">redirecting ...</span>" +
|
|
|
|
"</div>";
|
|
|
|
setHTML(html);
|
|
|
|
Timer timer = new Timer() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Location.assign(vre.getFriendlyURL());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
timer.schedule(50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-12-07 16:53:58 +01:00
|
|
|
|
2016-12-07 15:34:34 +01:00
|
|
|
addMouseOverHandler(new MouseOverHandler() {
|
|
|
|
@Override
|
|
|
|
public void onMouseOver(MouseOverEvent event) {
|
|
|
|
if (!showImage) {
|
2016-12-07 16:53:58 +01:00
|
|
|
int imageWidth = WIDTH - 12;
|
|
|
|
String name = (vre.getName().length() > 15) ? vre.getName().substring(0, 13) + ".." : vre.getName();
|
|
|
|
String imageUrl = vre.getImageURL();
|
|
|
|
String html = "<div class=\"vreCaption\">" +name + "</div>";
|
|
|
|
|
2016-12-07 15:34:34 +01:00
|
|
|
html += "<div style=\"display: table; text-align:center; width: 100%; height: 75px;\">" +
|
|
|
|
"<span style=\"vertical-align:middle; display: table-cell;\"><img style=\"width: " + imageWidth + "px;\" src=\"" +imageUrl + "\" /></span>" +
|
|
|
|
"</div>";
|
2016-12-07 16:53:58 +01:00
|
|
|
setHTML(html);
|
2016-12-07 15:34:34 +01:00
|
|
|
}
|
2016-12-07 16:53:58 +01:00
|
|
|
|
2016-12-07 15:34:34 +01:00
|
|
|
}
|
|
|
|
});
|
2012-12-23 21:55:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|