ckan-content-moderator-widget/src/main/java/org/gcube/portlets/widgets/ckancontentmoderator/client/ui/CkanShowItemFrame.java

161 lines
4.4 KiB
Java
Raw Normal View History

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.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
2021-06-18 12:10:49 +02:00
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
2021-06-18 12:10:49 +02:00
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.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
2021-06-18 12:10:49 +02:00
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.Composite;
2021-06-18 12:10:49 +02:00
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTMLPanel;
2021-06-18 12:10:49 +02:00
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.NamedFrame;
import com.google.gwt.user.client.ui.Widget;
2021-06-18 12:10:49 +02:00
/**
* The Class CkanShowItemFrame.
2021-06-18 12:10:49 +02:00
*
2021-06-24 15:02:49 +02:00
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 4, 2022
2021-06-18 12:10:49 +02:00
*/
public class CkanShowItemFrame extends Composite {
private static CkanShowItemFrameUiBinder uiBinder = GWT.create(CkanShowItemFrameUiBinder.class);
2021-06-18 12:10:49 +02:00
2022-02-25 10:56:05 +01:00
private NamedFrame namedFrame;
2021-06-18 12:10:49 +02:00
private HandlerManager eventBus;
private Image loading = new Image(ContentModeratorWidgetResources.ICONS.loading());
private String messageToSend;
private String iFrameRandomName;
@UiField
Button button_reload;
@UiField
HTMLPanel panel_container;
// @UiField
// AlertBlock alertBlockNav;
private String datasetURL;
2021-06-18 12:10:49 +02:00
/**
* The Interface CkanShowItemFrameUiBinder.
2021-06-18 12:10:49 +02:00
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 4, 2022
2021-06-18 12:10:49 +02:00
*/
interface CkanShowItemFrameUiBinder extends UiBinder<Widget, CkanShowItemFrame> {
2021-06-18 12:10:49 +02:00
}
/**
* Instantiates a new ckan show item frame.
2021-06-18 12:10:49 +02:00
*
* @param eventBus the event bus
2021-06-18 12:10:49 +02:00
*/
public CkanShowItemFrame(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
// alertBlockNav.setType(AlertType.INFO);
button_reload.setIcon(IconType.ROTATE_RIGHT);
button_reload.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
reloadPage();
}
});
}
2021-06-18 12:10:49 +02:00
/**
* Instance frame.
2021-06-18 12:10:49 +02:00
*
* @param datasetURL the dataset URL
* @return the frame
2021-06-18 12:10:49 +02:00
*/
2021-06-29 17:30:44 +02:00
public Frame instanceFrame(String datasetURL) {
this.datasetURL = datasetURL;
2022-02-25 10:11:24 +01:00
GWT.log("Instancing new IFRAME with uri: " + datasetURL);
2021-06-18 12:10:49 +02:00
addLoading();
String urlEncoded = URL.encode(datasetURL);
2022-02-25 10:56:05 +01:00
GWT.log("Encoded url for instanciating namedFrame is " + urlEncoded);
iFrameRandomName = Random.nextInt() + "dataset-internal-iframe" + Random.nextInt();
namedFrame = new NamedFrame(iFrameRandomName);
namedFrame.setUrl(urlEncoded);
2021-06-18 12:10:49 +02:00
2022-02-25 10:56:05 +01:00
namedFrame.getElement().setId(iFrameRandomName);
namedFrame.setWidth("100%");
namedFrame.setHeight("580px");
namedFrame.getElement().getStyle().setBorderWidth(0, Unit.PX);
namedFrame.addLoadHandler(new LoadHandler() {
2021-06-18 12:10:49 +02:00
@Override
public void onLoad(LoadEvent arg0) {
removeLoading();
2022-02-25 10:56:05 +01:00
eventBus.fireEvent(new IFrameInstanciedEvent(namedFrame, OPERATION.ONLOAD));
2021-06-18 12:10:49 +02:00
}
});
panel_container.add(namedFrame);
2022-02-25 10:56:05 +01:00
namedFrame.setVisible(true);
eventBus.fireEvent(new IFrameInstanciedEvent(namedFrame, OPERATION.INIT));
return namedFrame;
2021-06-18 12:10:49 +02:00
}
/**
2022-02-25 10:56:05 +01:00
* Gets the namedFrame.
2021-06-18 12:10:49 +02:00
*
2022-02-25 10:56:05 +01:00
* @return the namedFrame
2021-06-18 12:10:49 +02:00
*/
public Frame getFrame() {
2022-02-25 10:56:05 +01:00
return namedFrame;
2021-06-18 12:10:49 +02:00
}
/**
* add loading image.
*/
2022-02-25 10:11:24 +01:00
private void addLoading() {
panel_container.add(loading);
2021-06-18 12:10:49 +02:00
loading.getElement().getStyle().setProperty("margin", "auto");
loading.getElement().getStyle().setDisplay(Display.BLOCK);
button_reload.setEnabled(false);
2021-06-18 12:10:49 +02:00
}
/**
* Removes the loading.
*/
private void removeLoading() {
try {
panel_container.remove(loading);
button_reload.setEnabled(true);
} catch (Exception e) {
}
}
/**
* Reload page.
*/
public void reloadPage() {
panel_container.clear();
instanceFrame(datasetURL);
}
2021-06-18 12:10:49 +02:00
}