2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
|
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GCubeCkanDataCatalog;
|
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources;
|
2016-06-23 12:49:45 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
2016-06-20 17:08:46 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
2016-07-05 12:57:02 +02:00
|
|
|
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-01 15:36:20 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2016-06-13 09:48:29 +02:00
|
|
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
|
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Frame;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
2016-06-29 16:50:18 +02:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class GCubeCkanDataCatalogPanel.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 9, 2016
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
private CkanMetadataManagementPanel managementPanel;
|
|
|
|
private ScrollPanel centerScrollable = new ScrollPanel();
|
2016-06-23 12:49:45 +02:00
|
|
|
private CkanFramePanel ckanFramePanel;
|
2016-06-29 16:50:18 +02:00
|
|
|
private CkanOrganizationsPanel ckanOrganizationsPanel;
|
2016-06-13 09:48:29 +02:00
|
|
|
private Image loading = new Image(CkanPortletResources.ICONS.loading());
|
|
|
|
private RootPanel rootPanel;
|
|
|
|
private HandlerManager eventBus;
|
2016-06-23 18:30:01 +02:00
|
|
|
private CkanConnectorAccessPoint ckanAccessPoint;
|
2016-07-15 18:19:05 +02:00
|
|
|
public static final int IFRAME_FIX_HEIGHT = 1800;
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
* Instantiates a new g cube ckan data catalog panel.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @param rootPanel
|
|
|
|
* the root panel
|
|
|
|
* @param eventManager
|
|
|
|
* the event manager
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public GCubeCkanDataCatalogPanel(
|
|
|
|
RootPanel rootPanel, HandlerManager eventManager) {
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
this.rootPanel = rootPanel;
|
|
|
|
this.eventBus = eventManager;
|
2016-06-23 12:49:45 +02:00
|
|
|
ckanFramePanel = new CkanFramePanel(eventBus);
|
2016-06-13 09:48:29 +02:00
|
|
|
managementPanel = new CkanMetadataManagementPanel(eventBus);
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanOrganizationsPanel = new CkanOrganizationsPanel(this);
|
2016-06-13 09:48:29 +02:00
|
|
|
initPanel();
|
2016-06-29 18:35:01 +02:00
|
|
|
setTopPanelVisible(true);
|
2016-07-15 18:19:05 +02:00
|
|
|
String pathParameter =
|
|
|
|
Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
|
|
|
|
String queryParameter =
|
|
|
|
Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
|
|
|
|
GCubeCkanDataCatalog.service.getCKanConnector(
|
|
|
|
pathParameter, queryParameter,
|
|
|
|
new AsyncCallback<CkanConnectorAccessPoint>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(CkanConnectorAccessPoint ckan) {
|
|
|
|
|
|
|
|
ckanAccessPoint = ckan;
|
|
|
|
instanceCkanFrame(ckan.buildURI());
|
|
|
|
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
|
|
|
|
}
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
|
|
|
|
Window.alert("Sorry, An error occurred during contacting Gcube Ckan Data Catalogue!");
|
|
|
|
}
|
|
|
|
});
|
2016-06-29 18:35:01 +02:00
|
|
|
GCubeCkanDataCatalog.service.outsidePortal(new AsyncCallback<Boolean>() {
|
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
@Override
|
2016-06-29 18:35:01 +02:00
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
if (result) {
|
|
|
|
// the portlet is outside the portal and no user is logged
|
|
|
|
// in
|
2016-06-29 18:35:01 +02:00
|
|
|
// show only home and statistics
|
2016-07-02 23:41:11 +02:00
|
|
|
managementPanel.doNotShowUserRelatedInfo();
|
2016-07-15 18:19:05 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// polling for session expired check
|
2016-07-05 12:57:02 +02:00
|
|
|
CheckSession.getInstance().startPolling();
|
2016-06-29 18:35:01 +02:00
|
|
|
// RETRIEVE USER'S ORGANIZATIONS
|
2016-07-15 18:19:05 +02:00
|
|
|
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<Map<String, String>>() {
|
2016-06-29 18:35:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Map<String, String> result) {
|
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
if (result != null)
|
2016-06-29 18:35:01 +02:00
|
|
|
ckanOrganizationsPanel.setOrganizations(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-29 18:35:01 +02:00
|
|
|
}
|
|
|
|
});
|
2016-07-15 18:19:05 +02:00
|
|
|
// MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
|
2016-06-29 18:35:01 +02:00
|
|
|
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<CkanRole>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-29 18:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(CkanRole result) {
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case ADMIN:
|
|
|
|
showEditInsertButtons(true);
|
|
|
|
break;
|
|
|
|
case EDITOR:
|
|
|
|
showEditInsertButtons(true);
|
|
|
|
break;
|
|
|
|
case MEMBER:
|
|
|
|
showEditInsertButtons(false);
|
|
|
|
break;
|
|
|
|
case SYSADMIN:
|
|
|
|
showEditInsertButtons(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-07-01 15:36:20 +02:00
|
|
|
|
2016-06-29 18:35:01 +02:00
|
|
|
// the portlet is outside the portal and no user is logged in
|
|
|
|
// show only home and statistics
|
2016-07-02 23:41:11 +02:00
|
|
|
managementPanel.doNotShowUserRelatedInfo();
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
2016-06-20 17:08:46 +02:00
|
|
|
});
|
2016-06-13 09:48:29 +02:00
|
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResize(ResizeEvent event) {
|
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
GWT.log("onWindowResized width: " + event.getWidth() +
|
|
|
|
" height: " + event.getHeight());
|
2016-06-13 09:48:29 +02:00
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
});
|
2016-07-18 11:34:34 +02:00
|
|
|
// Window.enableScrolling(false);
|
2016-06-13 09:48:29 +02:00
|
|
|
rootPanel.add(loading);
|
|
|
|
rootPanel.add(this);
|
|
|
|
updateSize();
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-07-18 11:34:34 +02:00
|
|
|
listenForPostMessage();
|
2016-07-15 18:19:05 +02:00
|
|
|
// postMessage("Un messaggio");
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the top panel height.
|
|
|
|
*
|
|
|
|
* @return the top panel height
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public int getTopPanelHeight() {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
if (managementPanel.isVisible())
|
2016-06-13 09:48:29 +02:00
|
|
|
return managementPanel.getCurrentHeight();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the top panel visible.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @param bool
|
|
|
|
* the new top panel visible
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void setTopPanelVisible(boolean bool) {
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
managementPanel.setVisible(bool);
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2016-06-22 16:23:51 +02:00
|
|
|
/**
|
2016-06-23 12:49:45 +02:00
|
|
|
* show or hide edit/insert buttons according to the role.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @param show
|
|
|
|
* the show
|
2016-06-22 16:23:51 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void showEditInsertButtons(boolean show) {
|
|
|
|
|
2016-06-22 16:23:51 +02:00
|
|
|
managementPanel.showInsertAndEditProductButtons(show);
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
* Instance ckan frame.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @param ckanUrlConnector
|
|
|
|
* the ckan url connector
|
2016-06-13 09:48:29 +02:00
|
|
|
* @return the frame
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public Frame instanceCkanFrame(String ckanUrlConnector) {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanFramePanel.setVisible(true);
|
|
|
|
ckanOrganizationsPanel.setVisible(false);
|
2016-06-13 09:48:29 +02:00
|
|
|
return ckanFramePanel.instanceFrame(ckanUrlConnector);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the panel.
|
|
|
|
*/
|
|
|
|
private void initPanel() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
setTopPanelVisible(false);
|
|
|
|
addToTop(managementPanel);
|
2016-06-29 16:50:18 +02:00
|
|
|
VerticalPanel containerIntoScrollPanel = new VerticalPanel();
|
|
|
|
containerIntoScrollPanel.setWidth("100%");
|
|
|
|
containerIntoScrollPanel.add(ckanFramePanel);
|
|
|
|
containerIntoScrollPanel.add(ckanOrganizationsPanel);
|
|
|
|
centerScrollable.add(containerIntoScrollPanel);
|
|
|
|
ckanOrganizationsPanel.setVisible(false);
|
2016-06-22 16:23:51 +02:00
|
|
|
addToMiddle(centerScrollable);
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update window size.
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void updateSize() {
|
|
|
|
/*RootPanel workspace = rootPanel;
|
|
|
|
int topBorder = workspace.getAbsoluteTop();
|
|
|
|
GWT.log("top: "+topBorder);
|
|
|
|
int footer = 30; // 85 footer is bottombar + sponsor
|
|
|
|
int rootHeight = Window.getClientHeight() - topBorder - 5 - footer;
|
|
|
|
int height = rootHeight - getTopPanelHeight();
|
|
|
|
if (ckanFramePanel.getFrame() != null) {
|
|
|
|
int newH =managementPanel != null && managementPanel.getCurrentHeight() > 0 ? managementPanel.getOffsetHeight() + height : height;
|
|
|
|
ckanFramePanel.getFrame().setHeight(2000+"px");
|
|
|
|
}*/
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
RootPanel workspace = this.rootPanel;
|
2016-06-22 16:23:51 +02:00
|
|
|
int topBorder = workspace.getAbsoluteTop();
|
2016-07-15 18:19:05 +02:00
|
|
|
int footer = 55;
|
|
|
|
int rootHeight = Window.getClientHeight() - topBorder - 5 - footer;
|
2016-06-22 16:23:51 +02:00
|
|
|
int height = rootHeight - getTopPanelHeight();
|
2016-07-15 18:19:05 +02:00
|
|
|
if (this.ckanFramePanel.getFrame() != null) {
|
|
|
|
int newH = this.managementPanel != null &&this.managementPanel.getCurrentHeight() > 0? this.managementPanel.getOffsetHeight() + height : height;
|
2016-07-18 11:34:34 +02:00
|
|
|
// this.ckanFramePanel.getFrame().setHeight(newH + "px");
|
2016-06-23 18:30:01 +02:00
|
|
|
}
|
2016-07-15 18:19:05 +02:00
|
|
|
// workspace.setHeight(height+"px");
|
2016-06-22 16:23:51 +02:00
|
|
|
}
|
2016-06-22 18:40:38 +02:00
|
|
|
|
2016-07-18 11:34:34 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:40:38 +02:00
|
|
|
/**
|
2016-06-23 12:49:45 +02:00
|
|
|
* Gets the base urlckan connector.
|
|
|
|
*
|
2016-06-23 18:30:01 +02:00
|
|
|
* @return the base urlckan connector
|
2016-06-22 18:40:38 +02:00
|
|
|
*/
|
|
|
|
public String getBaseURLCKANConnector() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-07-01 16:51:51 +02:00
|
|
|
return ckanAccessPoint.getBaseUrlWithContext();
|
2016-06-22 18:40:38 +02:00
|
|
|
}
|
2016-06-23 12:49:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the gcube token value to ckan connector.
|
|
|
|
*
|
|
|
|
* @return the gcube token value to ckan connector
|
|
|
|
*/
|
|
|
|
public String getGcubeTokenValueToCKANConnector() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-23 18:30:01 +02:00
|
|
|
return ckanAccessPoint.getGcubeTokenValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the path info.
|
|
|
|
*
|
|
|
|
* @return the path info
|
|
|
|
*/
|
|
|
|
public String getPathInfo() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-23 18:30:01 +02:00
|
|
|
return ckanAccessPoint.getPathInfoParameter();
|
2016-06-23 12:49:45 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
/**
|
2016-07-15 18:19:05 +02:00
|
|
|
* Show the organizations panel.
|
2016-06-29 16:50:18 +02:00
|
|
|
*/
|
|
|
|
public void showOrganizations() {
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanOrganizationsPanel.setVisible(true);
|
|
|
|
ckanFramePanel.setVisible(false);
|
|
|
|
}
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|