From 907e9c51eb920ec850745fbbac9d6670211e54ca Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 17 Oct 2014 16:41:23 +0000 Subject: [PATCH] Added Uri Resolver git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@100793 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 1 + .../client/ResourcesDialog.java | 8 +- .../client/ResourcesPanel.java | 329 ++++++++++++------ .../client/ResourcesWidgetEntry.java | 1 + 4 files changed, 218 insertions(+), 121 deletions(-) diff --git a/pom.xml b/pom.xml index f10baf6..5d3170a 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,7 @@ provided + diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesDialog.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesDialog.java index 1b0acf4..4cbfef4 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesDialog.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.td.resourceswidget.client; +import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import com.google.web.bindery.event.shared.EventBus; @@ -18,15 +19,10 @@ public class ResourcesDialog extends Window { protected String WIDTH = "320px"; protected String HEIGHT = "540px"; protected TRId trId; - protected EventBus eventBus; + protected UserInfo userInfo; public ResourcesDialog(TRId trId, EventBus eventBus) { - create(trId, eventBus); - } - - - protected void create(TRId trId, EventBus eventBus) { this.trId = trId; this.eventBus=eventBus; diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java index 65d2243..0f8836c 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesPanel.java @@ -14,21 +14,29 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescr import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD; +import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; +import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; import org.gcube.portlets.user.td.resourceswidget.client.properties.ResourceTDDescriptorProperties; +import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.event.logical.shared.SelectionEvent; +import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.core.client.IdentityValueProvider; +import com.sencha.gxt.core.client.Style.SelectionMode; import com.sencha.gxt.data.client.loader.RpcProxy; import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.loader.ListLoadConfig; @@ -42,7 +50,11 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.grid.ColumnConfig; import com.sencha.gxt.widget.core.client.grid.ColumnModel; import com.sencha.gxt.widget.core.client.grid.Grid; +import com.sencha.gxt.widget.core.client.grid.GridSelectionModel; import com.sencha.gxt.widget.core.client.grid.RowExpander; +import com.sencha.gxt.widget.core.client.menu.Item; +import com.sencha.gxt.widget.core.client.menu.Menu; +import com.sencha.gxt.widget.core.client.menu.MenuItem; /** * @@ -58,6 +70,7 @@ public class ResourcesPanel extends FramedPanel { protected String HEIGHT = "520px"; protected ResourcesDialog parent; + protected UserInfo userInfo; protected TRId trId; protected TableData table; protected String headingTitle; @@ -73,14 +86,17 @@ public class ResourcesPanel extends FramedPanel { protected RollBackSession rollBackSession; private boolean drawed = false; + private Menu contextMenu; + private MenuItem openItem; - public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) { + public ResourcesPanel(ResourcesDialog parent, TRId trId, + EventBus eventBus) { super(); this.parent = parent; this.trId = trId; this.eventBus = eventBus; forceLayoutOnResize = true; - draw(); + retrieveUserInfo(); } public ResourcesPanel(TRId trId, EventBus eventBus) { @@ -88,7 +104,33 @@ public class ResourcesPanel extends FramedPanel { this.trId = trId; this.eventBus = eventBus; forceLayoutOnResize = true; - draw(); + retrieveUserInfo(); + } + + protected void retrieveUserInfo(){ + TDGWTServiceAsync.INSTANCE.hello( + new AsyncCallback() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + + Log.error("Error Retrieving User Info: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error", + "Error retrieving User Info"); + + } + } + + public void onSuccess(UserInfo userInfo) { + Log.debug("User Info: " + userInfo); + draw(); + } + + }); } protected void draw() { @@ -111,81 +153,103 @@ public class ResourcesPanel extends FramedPanel { .create(ResourceTDDescriptorProperties.class); IdentityValueProvider identityProvider = new IdentityValueProvider(); + + final GridSelectionModel sm = new GridSelectionModel(); + sm.setSelectionMode(SelectionMode.SINGLE); + RowExpander expander = new RowExpander( identityProvider, new AbstractCell() { - - - + @Override public void render(Context context, ResourceTDDescriptor value, SafeHtmlBuilder sb) { - sb.appendHtmlConstant("" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + ""); + sb.appendHtmlConstant( + "
Name: " - + value.getName() - + "
Description: " - + value.getDescription() - + "
Creation Date: " - + value.getCreationDate() - + "
Creator Id: " - + value.getCreatorId() - + "
Type: " - + value.getResourceType().toString() - + "
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + ""); ResourceTD resource = value.getResourceTD(); if (resource instanceof InternalURITD) { InternalURITD internalURITD = (InternalURITD) resource; - sb.appendHtmlConstant("" - + "" - + "" + ""); - sb.appendHtmlConstant("" - + "" - + "" - + ""); + sb.appendHtmlConstant( + "" + + "" + + "" + ""); + + + + /* + sb.appendHtmlConstant( + "" + + "" + + "" + "");*/ } else { if (resource instanceof StringResourceTD) { StringResourceTD stringResourceTD = (StringResourceTD) resource; - sb.appendHtmlConstant("" - + "" - + "" + ""); + sb.appendHtmlConstant( + "" + + "" + + "" + ""); } else { if (resource instanceof TableResourceTD) { TableResourceTD tableResourceTD = (TableResourceTD) resource; - sb.appendHtmlConstant("" - + "" - + "" + ""); + sb.appendHtmlConstant( + "" + + "" + + "" + ""); } else { @@ -205,8 +269,9 @@ public class ResourcesPanel extends FramedPanel { @Override public void render(Context context, String value, SafeHtmlBuilder sb) { - sb.appendHtmlConstant("" + value - + ""); + sb.appendHtmlConstant("").appendEscaped(value) + .appendHtmlConstant(""); } @@ -214,18 +279,7 @@ public class ResourcesPanel extends FramedPanel { ColumnConfig typeColumn = new ColumnConfig( props.resourceType(), 40, "Type"); - /* - * ActionButtonCellNoFirst button = new ActionButtonCellNoFirst(); - * button.setIcon(ResourceBundle.INSTANCE.undo()); - * button.setTitle("Undo"); button.addSelectHandler(new SelectHandler() - * { - * - * @Override public void onSelect(SelectEvent event) { - * Log.debug("Button Undo Pressed"); Context c = event.getContext(); int - * rowIndex = c.getIndex(); startSearchRollBackId(rowIndex); } }); - * - * typeColumn.setCell(button); - */ + List> l = new ArrayList>(); l.add(expander); l.add(nameCol); @@ -268,8 +322,8 @@ public class ResourcesPanel extends FramedPanel { }; grid.setLoader(loader); + grid.setSelectionModel(sm); grid.setSize("200px", "300px"); - grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); grid.getView().setAutoFill(true); @@ -279,56 +333,99 @@ public class ResourcesPanel extends FramedPanel { grid.setColumnResize(true); grid.getView().setAutoExpandColumn(nameCol); grid.getView().setEmptyText("Empty"); + expander.initPlugin(grid); + + createContextMenu(); - /* - * VerticalLayoutContainer v = new VerticalLayoutContainer(); - * v.setScrollMode(ScrollMode.AUTO); v.add(grid, new - * VerticalLayoutData(1, 1, new Margins(0))); v.forceLayout(); - */ + add(grid, new MarginData(0)); onResize(); } - protected void startSearchRollBackId(int rowIndex) { - currentRowIndex = rowIndex; - currentTDDescriptor = store.get(rowIndex - 1); - Log.debug(currentTDDescriptor.toString() + " was clicked.[rowIndex=" - + currentRowIndex + " ]"); - callRollBack(); + protected void createContextMenu() { + contextMenu = new Menu(); - } + openItem = new MenuItem(); + openItem.setText("Open"); + openItem.setIcon(ResourceBundle.INSTANCE.codelistLink()); + openItem.addSelectionHandler(new SelectionHandler() { - protected void callRollBack() { - /* - * rollBackSession = new RollBackSession(trId, - * - * currentTDDescriptor.getHistoryId()); - * TDGWTServiceAsync.INSTANCE.startRollBack(rollBackSession, new - * AsyncCallback() { - * - * public void onFailure(Throwable caught) { if (caught instanceof - * TDGWTSessionExpiredException) { eventBus.fireEvent(new - * SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { - * if (caught instanceof TDGWTIsLockedException) { - * Log.error(caught.getLocalizedMessage()); - * UtilsGXT3.alert("Error Locked", caught.getLocalizedMessage()); } else - * { if (caught instanceof TDGWTIsFinalException) { - * Log.error(caught.getLocalizedMessage()); - * UtilsGXT3.alert("Error Final", caught.getLocalizedMessage()); } else - * { Log.error("Error in rollback: " + caught.getLocalizedMessage()); - * UtilsGXT3 .alert("Error in rollback", "Error: " + - * caught.getLocalizedMessage()); } } } } - * - * public void onSuccess(String taskId) { Log.debug("Rollback started"); - * //openMonitorDialog(taskId); - * - * } - * - * }); - */ + @Override + public void onSelection(SelectionEvent event) { + ResourceTDDescriptor selected = grid.getSelectionModel().getSelectedItem(); + Log.debug("selected: "+selected); + requestOpen(selected); + } + + + }); + contextMenu.add(openItem); + grid.setContextMenu(contextMenu); } + + protected void requestOpen(ResourceTDDescriptor resourceTDDescriptor) { + switch (resourceTDDescriptor.getResourceType()){ + case CHART: + break; + case CODELIST: + break; + case CSV: + break; + case GUESSER: + break; + case JSON: + break; + case MAP: + requestOpenMap(resourceTDDescriptor); + break; + case SDMX: + break; + default: + break; + + } + + } + + protected void requestOpenMap(final ResourceTDDescriptor resourceTDDescriptor){ + ResourceTD resource=resourceTDDescriptor.getResourceTD(); + if (resource instanceof InternalURITD) { + InternalURITD internalURITD = (InternalURITD) resource; + UriResolverSession uriResolverSession=new UriResolverSession(internalURITD.getUri(), ApplicationType.GIS); + + TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession, new AsyncCallback() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("Error with uri resolver: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error", + "Error retrieving uri from resolver"); + } + } + + public void onSuccess(String link) { + Log.debug("Retrieved link: " + link); + Window.open(link, resourceTDDescriptor.getName(), ""); + } + + }); + + + } else { + Log.error("Error with resource: no valid InternalUri"); + UtilsGXT3.alert("Error with resource", + "Error no valid InternalUri"); + } + } + + + protected void loadData(ListLoadConfig loadConfig, final AsyncCallback> callback) { @@ -404,6 +501,8 @@ public class ResourcesPanel extends FramedPanel { }); } + + protected void close() { if (parent != null) { diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesWidgetEntry.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesWidgetEntry.java index fc961d5..dacca7f 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesWidgetEntry.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesWidgetEntry.java @@ -20,6 +20,7 @@ public class ResourcesWidgetEntry implements EntryPoint { public void onModuleLoad() { EventBus eventBus= new SimpleEventBus(); + TRId trId=new TRId(); //For example Tabular Resource 7 and table 402
Name: ") + .appendEscaped(value.getName()) + .appendHtmlConstant( + "
Description: ") + .appendEscaped(value.getDescription()) + .appendHtmlConstant( + "
Creation Date: ") + .appendEscaped(value.getCreationDate()) + .appendHtmlConstant( + "
Creator Id: ") + .append(value.getCreatorId()) + .appendHtmlConstant( + "
Type: ") + .appendEscaped( + value.getResourceType().toString()) + .appendHtmlConstant("
File Id: " - + internalURITD.getFileId() - + "
URI: " - + "link" - + "
File Id: ") + .appendEscaped(internalURITD.getFileId()) + .appendHtmlConstant("
URI: " + + "link" + "
Value: " - + stringResourceTD.getStringValue() - + "
Value: ") + .appendEscaped( + stringResourceTD + .getStringValue()) + .appendHtmlConstant("
Table Id: " - + tableResourceTD.getTableId() - + "
Table Id: ") + .append(tableResourceTD + .getTableId()) + .appendHtmlConstant( + "