2021-06-18 12:10:49 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.IFrameInstanciedEvent;
|
2021-06-28 15:40:53 +02:00
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.IFrameInstanciedEvent.OPERATION;
|
2021-06-18 12:10:49 +02:00
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.ContentModeratorWidgetResources;
|
|
|
|
|
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
import com.google.gwt.dom.client.Style.Display;
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
import com.google.gwt.event.dom.client.LoadEvent;
|
|
|
|
import com.google.gwt.event.dom.client.LoadHandler;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.http.client.URL;
|
|
|
|
import com.google.gwt.user.client.Random;
|
|
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Frame;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.NamedFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class CkanFramePanel.
|
|
|
|
*
|
2021-06-24 15:02:49 +02:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Jun 23, 2021
|
2021-06-18 12:10:49 +02:00
|
|
|
*/
|
|
|
|
public class CkanFramePanel extends FlowPanel{
|
|
|
|
|
|
|
|
private NamedFrame frame;
|
|
|
|
//private static final String FRAME_NAME = "ckan-content-frame";
|
|
|
|
private HandlerManager eventBus;
|
|
|
|
private Image loading = new Image(ContentModeratorWidgetResources.ICONS.loading());
|
|
|
|
private String messageToSend;
|
|
|
|
private String iFrameRandomName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new ckan frame panel.
|
|
|
|
*
|
|
|
|
* @param eventBus the event bus
|
|
|
|
*/
|
|
|
|
public CkanFramePanel(HandlerManager eventBus) {
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
addLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints the.
|
|
|
|
*
|
|
|
|
* @param msg the msg
|
|
|
|
*/
|
|
|
|
private static native void print(String msg)/*-{
|
|
|
|
console.log(msg);
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
2021-06-29 17:30:44 +02:00
|
|
|
|
2021-06-18 12:10:49 +02:00
|
|
|
/**
|
|
|
|
* Instance frame.
|
|
|
|
*
|
|
|
|
* @param datasetURL the dataset URL
|
|
|
|
* @return the frame
|
|
|
|
*/
|
2021-06-29 17:30:44 +02:00
|
|
|
public Frame instanceFrame(String datasetURL) {
|
2021-06-18 12:10:49 +02:00
|
|
|
GWT.log("Instancing new IFRAME with uri: "+datasetURL);
|
|
|
|
try{
|
|
|
|
if(frame != null)
|
|
|
|
remove(frame);
|
|
|
|
}catch(Exception e){
|
|
|
|
print("Error " + e);
|
|
|
|
}
|
|
|
|
|
|
|
|
addLoading();
|
|
|
|
String urlEncoded = URL.encode(datasetURL);
|
|
|
|
GWT.log("Encoded url for instanciating frame is " + urlEncoded);
|
|
|
|
iFrameRandomName = Random.nextInt() + "dataset-iframe"+Random.nextInt();
|
|
|
|
frame = new NamedFrame(iFrameRandomName);
|
|
|
|
frame.setUrl(urlEncoded);
|
|
|
|
|
|
|
|
frame.getElement().setId(iFrameRandomName);
|
|
|
|
frame.setWidth("100%");
|
2021-06-24 15:02:49 +02:00
|
|
|
frame.setHeight("580px");
|
2021-06-18 12:10:49 +02:00
|
|
|
// frame.setHeight("100%");
|
|
|
|
// frame.getElement().getStyle().setOverflow(Overflow.HIDDEN);
|
|
|
|
// frame.getElement().setAttribute("scrolling", "no");
|
|
|
|
frame.getElement().getStyle().setBorderWidth(0, Unit.PX);
|
|
|
|
frame.addLoadHandler(new LoadHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoad(LoadEvent arg0) {
|
|
|
|
|
|
|
|
CkanFramePanel.this.remove(loading);
|
2021-06-28 15:40:53 +02:00
|
|
|
eventBus.fireEvent(new IFrameInstanciedEvent(frame, OPERATION.ONLOAD));
|
2021-06-18 12:10:49 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
add(frame);
|
|
|
|
frame.setVisible(true);
|
2021-06-28 15:40:53 +02:00
|
|
|
eventBus.fireEvent(new IFrameInstanciedEvent(frame, OPERATION.INIT));
|
2021-06-18 12:10:49 +02:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the frame.
|
|
|
|
*
|
|
|
|
* @return the frame
|
|
|
|
*/
|
|
|
|
public Frame getFrame() {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add loading image.
|
|
|
|
*/
|
|
|
|
private void addLoading(){
|
|
|
|
this.add(loading);
|
|
|
|
loading.getElement().getStyle().setProperty("margin", "auto");
|
|
|
|
loading.getElement().getStyle().setDisplay(Display.BLOCK);
|
|
|
|
}
|
|
|
|
}
|