From 254871f2b34965c12c6b194501ed07193c84a801 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 23 Feb 2015 17:27:25 +0000 Subject: [PATCH] Added Generic File to ResourceType git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@112243 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ResourcesPanel.java | 184 ++++++++++++------ .../ResourceTDTypeButtonCellAppearance.java | 6 + .../client/resources/ResourceBundle.java | 6 + .../resourceswidget/client/resources/file.png | Bin 0 -> 517 bytes .../client/resources/file_32.png | Bin 0 -> 827 bytes .../client/save/WorkSpaceSelectionCard.java | 11 +- .../resourceswidget/client/resources/file.png | Bin 0 -> 517 bytes .../client/resources/file_32.png | Bin 0 -> 827 bytes 8 files changed, 142 insertions(+), 65 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png create mode 100644 src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png create mode 100644 src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png 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 4eefca7..8c1517f 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 @@ -27,6 +27,7 @@ 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.mime.MimeTypeSupport; import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; import org.gcube.portlets.user.td.wizardwidget.client.WizardListener; @@ -108,7 +109,7 @@ public class ResourcesPanel extends FramedPanel { private MenuItem saveItem; private MenuItem removeItem; - private RemoveResourceSession removeResourceSession; + private RemoveResourceSession removeResourceSession; private SaveResourceSession saveResourceSession; public ResourcesPanel(ResourcesDialog parent, TRId trId, EventBus eventBus) { @@ -232,11 +233,16 @@ public class ResourcesPanel extends FramedPanel { String resourceData = ""; if (resource instanceof InternalURITD) { InternalURITD internalURITD = (InternalURITD) resource; - resourceData = "" - + "File Id: " - + "" - + SafeHtmlUtils.htmlEscape(internalURITD - .getFileId()) + "" + ""; + if (internalURITD.getFileId() != null + && !internalURITD.getFileId().isEmpty()) { + resourceData = "" + + "File Id: " + + "" + + SafeHtmlUtils + .htmlEscape(internalURITD + .getFileId()) + "" + + ""; + } } else { if (resource instanceof StringResourceTD) { @@ -290,35 +296,34 @@ public class ResourcesPanel extends FramedPanel { ColumnConfig typeColumn = new ColumnConfig( props.resourceType(), 30, "Type"); - + ResourceTDTypeButtonCell button = new ResourceTDTypeButtonCell(); button.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { Log.debug("Button Pressed"); - + Context c = event.getContext(); int rowIndex = c.getIndex(); - int columnIndex=c.getColumn(); - - Element el=grid.getView().getCell(rowIndex, columnIndex); - - NativeEvent contextEvent = Document.get().createMouseEvent(BrowserEvents.CONTEXTMENU, true, true,0, 0, 0, - el.getAbsoluteLeft(), el.getAbsoluteTop(), false, false, false, false, - NativeEvent.BUTTON_RIGHT, null); - - //NativeEvent contextEvent = Document.get().createContextMenuEvent(); + int columnIndex = c.getColumn(); + + Element el = grid.getView().getCell(rowIndex, columnIndex); + + NativeEvent contextEvent = Document.get().createMouseEvent( + BrowserEvents.CONTEXTMENU, true, true, 0, 0, 0, + el.getAbsoluteLeft(), el.getAbsoluteTop(), false, + false, false, false, NativeEvent.BUTTON_RIGHT, null); + + // NativeEvent contextEvent = + // Document.get().createContextMenuEvent(); el.dispatchEvent(contextEvent); - //DomEvent + // DomEvent } }); typeColumn.setCell(button); - - - List> l = new ArrayList>(); l.add(expander); l.add(nameCol); @@ -358,9 +363,7 @@ public class ResourcesPanel extends FramedPanel { } }); } - - - + }; grid.setLoader(loader); @@ -487,6 +490,19 @@ public class ResourcesPanel extends FramedPanel { contextMenu.add(removeItem); grid.setContextMenu(contextMenu); break; + case GENERIC_FILE: + contextMenu.clear(); + openItem.setIcon(ResourceBundle.INSTANCE.file()); + contextMenu.add(openItem); + contextMenu.add(saveItem); + contextMenu.add(removeItem); + grid.setContextMenu(contextMenu); + break; + case GENERIC_TABLE: + contextMenu.clear(); + contextMenu.add(removeItem); + grid.setContextMenu(contextMenu); + break; default: contextMenu.clear(); contextMenu.add(removeItem); @@ -504,23 +520,28 @@ public class ResourcesPanel extends FramedPanel { protected void requestSave(ResourceTDDescriptor resourceTDDescriptor) { switch (resourceTDDescriptor.getResourceType()) { case CHART: - requestSaveResource(resourceTDDescriptor, ".jpg", "image/jpeg"); + requestSaveResource(resourceTDDescriptor, MimeTypeSupport._jpg); break; case CODELIST: break; case CSV: - requestSaveResource(resourceTDDescriptor, ".csv", "text/csv"); + requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv); break; case GUESSER: break; case JSON: - requestSaveResource(resourceTDDescriptor, ".json", - "application/json"); + requestSaveResource(resourceTDDescriptor, MimeTypeSupport._json); break; case MAP: break; case SDMX: break; + case GENERIC_FILE: + requestSaveResource(resourceTDDescriptor, MimeTypeSupport._unknow); + break; + case GENERIC_TABLE: + // requestSaveResource(resourceTDDescriptor, MimeTypeSupport._csv); + break; default: break; @@ -529,29 +550,16 @@ public class ResourcesPanel extends FramedPanel { } protected void requestSaveResource( - ResourceTDDescriptor resourceTDDescriptor, String extension, - String mimeType) { - - InternalURITD internalURITD; - ResourceTD resource = resourceTDDescriptor.getResourceTD(); - if (resource instanceof InternalURITD) { - internalURITD=(InternalURITD)resource; - } else { - UtilsGXT3.alert("Attention", "This resource does not have valid internal URI!"); - Log.debug("Attention, this resource does not have valid Internal URI!"); - return; - } - Log.debug("InteranlURI: "+internalURITD); - + ResourceTDDescriptor resourceTDDescriptor, MimeTypeSupport mime) { + saveResourceSession = new SaveResourceSession(); - saveResourceSession.setMimeType(mimeType); - saveResourceSession.setExtension(extension); - saveResourceSession.setFileName(resourceTDDescriptor.getName() - + extension); + saveResourceSession.setResourceTDDescriptor(resourceTDDescriptor); + saveResourceSession.setMime(mime); + saveResourceSession.setFileName(resourceTDDescriptor.getName()); saveResourceSession.setFileDescription(resourceTDDescriptor .getDescription()); - saveResourceSession.setUri(internalURITD.getUri()); + GWT.runAsync(new RunAsyncCallback() { public void onSuccess() { @@ -561,9 +569,9 @@ public class ResourcesPanel extends FramedPanel { saveResourceWizard.addListener(new WizardListener() { - public void failed(String title, String message, String details, - Throwable throwable) { - Log.debug(title + ", " + message+" "+details); + public void failed(String title, String message, + String details, Throwable throwable) { + Log.debug(title + ", " + message + " " + details); } public void completed(TRId id) { @@ -647,6 +655,11 @@ public class ResourcesPanel extends FramedPanel { break; case SDMX: break; + case GENERIC_FILE: + requestOpenGenericFile(resourceTDDescriptor); + break; + case GENERIC_TABLE: + break; default: break; @@ -655,9 +668,10 @@ public class ResourcesPanel extends FramedPanel { } private void repquestOpenChart(ResourceTDDescriptor resourceTDDescriptor) { - ChartViewerDialog chartDialog=new ChartViewerDialog(resourceTDDescriptor, trId, eventBus); + ChartViewerDialog chartDialog = new ChartViewerDialog( + resourceTDDescriptor, trId, eventBus); chartDialog.show(); - + } protected void requestOpenMap( @@ -693,20 +707,10 @@ public class ResourcesPanel extends FramedPanel { } else { if (resource instanceof InternalURITD) { - /* - * Log.error( - * "Error with resource: is internal uri resource no uri present" - * ); UtilsGXT3.alert("Error with resource", - * "Error is string resource no uri present"); - */ + } else { if (resource instanceof TableResourceTD) { - /* - * Log.error( - * "Error with resource: is table resource no uri present"); - * UtilsGXT3.alert("Error with resource", - * "Error is table resource no uri present"); - */ + } else { Log.error("Error with resource: no valid resource"); UtilsGXT3.alert("Error with resource", @@ -717,6 +721,58 @@ public class ResourcesPanel extends FramedPanel { } } } + + + protected void requestOpenGenericFile( + final ResourceTDDescriptor resourceTDDescriptor) { + ResourceTD resource = resourceTDDescriptor.getResourceTD(); + if (resource instanceof StringResourceTD) { + StringResourceTD genericFileResourceTD = (StringResourceTD) resource; + UriResolverSession uriResolverSession = new UriResolverSession( + genericFileResourceTD.getStringValue(), ApplicationType.SMP); + + 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 { + if (resource instanceof InternalURITD) { + + } else { + if (resource instanceof TableResourceTD) { + + } else { + Log.error("Error with resource: no valid resource"); + UtilsGXT3.alert("Error with resource", + "Error no valid InternalUri"); + + } + + } + } + } + + + + protected void loadData(ListLoadConfig loadConfig, final AsyncCallback> callback) { diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/custom/ResourceTDTypeButtonCellAppearance.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/custom/ResourceTDTypeButtonCellAppearance.java index c9117ba..3e96fcb 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/custom/ResourceTDTypeButtonCellAppearance.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/custom/ResourceTDTypeButtonCellAppearance.java @@ -74,6 +74,12 @@ public class ResourceTDTypeButtonCellAppearance { case SDMX: imageResource = ResourceBundle.INSTANCE.sdmx(); break; + case GENERIC_FILE: + imageResource = ResourceBundle.INSTANCE.file(); + break; + case GENERIC_TABLE: + imageResource = ResourceBundle.INSTANCE.table(); + break; default: imageResource = ResourceBundle.INSTANCE.resources(); break; diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/ResourceBundle.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/ResourceBundle.java index 8029646..1447405 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/ResourceBundle.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/ResourceBundle.java @@ -132,6 +132,12 @@ public interface ResourceBundle extends ClientBundle { @Source("application.png") ImageResource application(); + @Source("file_32.png") + ImageResource file32(); + + @Source("file.png") + ImageResource file(); + @Source("Resources.css") ResourceCSS resourceCSS(); } diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png new file mode 100644 index 0000000000000000000000000000000000000000..d42d592e86acd095a6dac6279ea4e0d8164fa453 GIT binary patch literal 517 zcmV+g0{Z=lP)HxNSJDc}R>RS-n*<{KDK z{yXiMWngz_XS#C8IN9u~S?khGHT~oJ>MH>RxPN%?@ZN0Jw5*nQry#H2eEwDx*_X*= zKBsTP7I3pFkAKeV^h*Gd?xnkn2z8z0^tAlC|LoP%(I}U)oYnx^ff`XU@Ys5a)4GXO zwTP2R9m{eazyGM>U=Vg=%pZUJaQLY#rw?{^@@yFZfT|Ew$xN|K$uh-E8EhHui9FBP zjl)Op-@P~)kEeG4vsKF?prV*1nuQaBkdojo6x+u3jf}f{x1IoFK-T~lN`RyUqlZ*g zP1`!|PSB!Pul%J{K?N)mG{_|w=?DBz06++eil8c}Dk6gFmH!yml&WAT4QVO){{V<| z>7clS_M5eVg)1PyOpqXJ0A17d2NfX*!o{AfS||W@_iI&z0JPnzF9C)?^5h#C34t{Q zEnvx6q~vFt%)^u4{vCh;XTaXeqqomzv$ov?FdSL{M!@(SJ~VrYj|db$00000NkvXX Hu0mjfk^tZq literal 0 HcmV?d00001 diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png new file mode 100644 index 0000000000000000000000000000000000000000..d8108590e68285957edab057983e1b34498c3405 GIT binary patch literal 827 zcmV-B1H}A^P)((s`-M9eU0tWOqJ_28tEhuK5ZUJFCL`_ruS3?>)Ic9#3|G3Gij^+Eec`^@jK1%oThf zgk_fzLjKnn42r#1&mTSohQM{;+ByK*VFunC-W$y{a6IuG{ho4oIOX7=VLYBN9#0sJ zCJcvv`1$iU-@YFqBA9_IgsO6TZ(l#!zj(2Bz%FoQZ2%&mDkq**1$FW6oTl$_PDF5; zrDN2UqbP-X;PzhbKUm0wF3V-!SP(?wdz{E~dJ3!nQ9nhY)K!6VLR~LrLRSfD7DQ%2 zq+>=zW|-*GS5`_PS+CKxHjY2HAVd-qDj?vTo?#?nk=9aTmE;7@_kq>U;$pNS^X3%q1EbNO zwt@`9%$Ry(_wvq4BRU6&6rls}!7#8cdNTtgMl6C6um$$2n>bx&Ag4xCDpci!8|HVF z#m=sqS#8uoF3(&Y8N`_?N#4*KfE=L+Er^*?=>SSzCu?=XjhF}_2B(gs_84tDm!5k~ z!8|=ElJwB2O-|jn2H>RlI**8cv3!ev2C!bwknI9k-7~f%!t?ZutuwHwXNVAc#u5NC z8S7`XAlkGn^dYqEm+{htD>nck2%0*lEzv-g|H+4mK2u`W9aL5UP{5hR7P?Hin>gh% z0A*TI0NN)5xo4z<$U+V1?9s*gM!;$#$|M>8VHD|}+v002ovPDHLk FV1lBaWzqlu literal 0 HcmV?d00001 diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java index 287a23d..0d496a7 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/save/WorkSpaceSelectionCard.java @@ -8,6 +8,7 @@ import java.util.List; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; import org.gcube.portlets.user.td.resourceswidget.client.workspace.WorkspacePanel; +import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import org.gcube.portlets.widgets.lighttree.client.Item; import org.gcube.portlets.widgets.lighttree.client.ItemType; @@ -56,7 +57,15 @@ public class WorkSpaceSelectionCard extends WizardCard { fileName = new TextField(); fileName.setAllowBlank(false); fileName.setWidth("410px"); - fileName.setValue(saveResourceSession.getFileName()); + + + MimeTypeSupport mime=saveResourceSession.getMime(); + if(mime==null|| mime.compareTo(MimeTypeSupport._unknow)==0){ + fileName.setValue(saveResourceSession.getFileName()); + } else { + fileName.setValue(saveResourceSession.getFileName()+ + mime.getExtension()); + } p.add(new FieldLabel(fileName, "File Name"), new VerticalLayoutData(-1, -1)); diff --git a/src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png b/src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file.png new file mode 100644 index 0000000000000000000000000000000000000000..d42d592e86acd095a6dac6279ea4e0d8164fa453 GIT binary patch literal 517 zcmV+g0{Z=lP)HxNSJDc}R>RS-n*<{KDK z{yXiMWngz_XS#C8IN9u~S?khGHT~oJ>MH>RxPN%?@ZN0Jw5*nQry#H2eEwDx*_X*= zKBsTP7I3pFkAKeV^h*Gd?xnkn2z8z0^tAlC|LoP%(I}U)oYnx^ff`XU@Ys5a)4GXO zwTP2R9m{eazyGM>U=Vg=%pZUJaQLY#rw?{^@@yFZfT|Ew$xN|K$uh-E8EhHui9FBP zjl)Op-@P~)kEeG4vsKF?prV*1nuQaBkdojo6x+u3jf}f{x1IoFK-T~lN`RyUqlZ*g zP1`!|PSB!Pul%J{K?N)mG{_|w=?DBz06++eil8c}Dk6gFmH!yml&WAT4QVO){{V<| z>7clS_M5eVg)1PyOpqXJ0A17d2NfX*!o{AfS||W@_iI&z0JPnzF9C)?^5h#C34t{Q zEnvx6q~vFt%)^u4{vCh;XTaXeqqomzv$ov?FdSL{M!@(SJ~VrYj|db$00000NkvXX Hu0mjfk^tZq literal 0 HcmV?d00001 diff --git a/src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png b/src/main/resources/org/gcube/portlets/user/td/resourceswidget/client/resources/file_32.png new file mode 100644 index 0000000000000000000000000000000000000000..d8108590e68285957edab057983e1b34498c3405 GIT binary patch literal 827 zcmV-B1H}A^P)((s`-M9eU0tWOqJ_28tEhuK5ZUJFCL`_ruS3?>)Ic9#3|G3Gij^+Eec`^@jK1%oThf zgk_fzLjKnn42r#1&mTSohQM{;+ByK*VFunC-W$y{a6IuG{ho4oIOX7=VLYBN9#0sJ zCJcvv`1$iU-@YFqBA9_IgsO6TZ(l#!zj(2Bz%FoQZ2%&mDkq**1$FW6oTl$_PDF5; zrDN2UqbP-X;PzhbKUm0wF3V-!SP(?wdz{E~dJ3!nQ9nhY)K!6VLR~LrLRSfD7DQ%2 zq+>=zW|-*GS5`_PS+CKxHjY2HAVd-qDj?vTo?#?nk=9aTmE;7@_kq>U;$pNS^X3%q1EbNO zwt@`9%$Ry(_wvq4BRU6&6rls}!7#8cdNTtgMl6C6um$$2n>bx&Ag4xCDpci!8|HVF z#m=sqS#8uoF3(&Y8N`_?N#4*KfE=L+Er^*?=>SSzCu?=XjhF}_2B(gs_84tDm!5k~ z!8|=ElJwB2O-|jn2H>RlI**8cv3!ev2C!bwknI9k-7~f%!t?ZutuwHwXNVAc#u5NC z8S7`XAlkGn^dYqEm+{htD>nck2%0*lEzv-g|H+4mK2u`W9aL5UP{5hR7P?Hin>gh% z0A*TI0NN)5xo4z<$U+V1?9s*gM!;$#$|M>8VHD|}+v002ovPDHLk FV1lBaWzqlu literal 0 HcmV?d00001