diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java index bd14628..8841e2e 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java @@ -161,12 +161,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { updateSize(); } }); - Window.enableScrolling(false); +// Window.enableScrolling(false); rootPanel.add(loading); rootPanel.add(this); updateSize(); -// listenForPostMessage(); + listenForPostMessage(); // postMessage("Un messaggio"); } @@ -257,11 +257,81 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { int height = rootHeight - getTopPanelHeight(); if (this.ckanFramePanel.getFrame() != null) { int newH = this.managementPanel != null &&this.managementPanel.getCurrentHeight() > 0? this.managementPanel.getOffsetHeight() + height : height; - this.ckanFramePanel.getFrame().setHeight(newH + "px"); +// this.ckanFramePanel.getFrame().setHeight(newH + "px"); } // workspace.setHeight(height+"px"); } + /** + * Post message. + * + * @param msg the msg + */ + protected native void postMessage(String msg) /*-{ + $wnd.postMessage(msg, "*"); + }-*/; + + /** + * Listen for post message. + */ + private final native void listenForPostMessage() /*-{ + var that = this; + $wnd.addEventListener("message", function(msg) { + console.log("read message..."); + that.@org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel::onPostMessage(Ljava/lang/String;Ljava/lang/String;)(msg.data, msg.origin); + }); + }-*/; + + /** + * On post message. + * + * @param data the data + * @param origin the origin + */ + private void onPostMessage(String data, String origin) { + GWT.log("Read data: "+data+", from origin: "+origin); + GWT.log("Ckan base url: "+ckanAccessPoint.getBaseUrl()); + + if (ckanAccessPoint.getBaseUrl().indexOf(origin)>=0) { + GWT.log("Data has been sent by ckan "+origin +", Is it the height?"); + // The data has been sent from your site + // The data sent with postMessage is stored in event.data + setIFrameHeight(data); + } else { + // The data hasn't been sent from your site! + // Be careful! Do not use it. + return; + } + + } + + /** + * Sets the i frame height. + * + * @param height the new i frame height + */ + private void setIFrameHeight(String height){ + String parsedHeight = null; + if(height==null || height.isEmpty()) + return; + + if(height.contains("px")){ + parsedHeight = height; + }else{ + try{ + int intH = Integer.parseInt(height); + parsedHeight = intH + " px"; + }catch(Exception e ){ + + } + } + + if(parsedHeight!=null){ + GWT.log("Setting new height for ckan iFrame: "+height); + this.ckanFramePanel.getFrame().setHeight(height); + } + } + /** * Gets the base urlckan connector. *