diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewPanel.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewPanel.java index ddfed46..4f2cc0d 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewPanel.java @@ -149,10 +149,11 @@ public class ResourcesListViewPanel extends FramedPanel { public enum ResourcesSortInfo { Name("Name"), CreationDate("Creation Date"); - - private static ResourcesMessages msgs=GWT.create(ResourcesMessages.class); + + private static ResourcesMessages msgs = GWT + .create(ResourcesMessages.class); private String id; - + private static List resourcesSortInfoI18NList; static { @@ -163,7 +164,7 @@ public class ResourcesListViewPanel extends FramedPanel { } private ResourcesSortInfo(String id) { - this.id = id; + this.id = id; } public String getId() { @@ -173,12 +174,11 @@ public class ResourcesListViewPanel extends FramedPanel { public String toString() { return id; } - - public String getIdI18N(){ + + public String getIdI18N() { return msgs.resourceSortInfo(this); } - - + public static List asList() { List list = Arrays.asList(values()); return list; @@ -188,7 +188,7 @@ public class ResourcesListViewPanel extends FramedPanel { return resourcesSortInfoI18NList; } - + } private ResourcesListViewDetailPanel details; @@ -221,8 +221,8 @@ public class ResourcesListViewPanel extends FramedPanel { init(); create(); } - - protected void initMessages(){ + + protected void initMessages() { msgs = GWT.create(ResourcesMessages.class); msgsCommon = GWT.create(CommonMessages.class); } @@ -277,7 +277,8 @@ public class ResourcesListViewPanel extends FramedPanel { if (v.equals(ResourcesSortInfo.Name.getIdI18N())) { return o1.getName().compareToIgnoreCase( o2.getName()); - } else if (v.equals(ResourcesSortInfo.CreationDate.getIdI18N())) { + } else if (v.equals(ResourcesSortInfo.CreationDate + .getIdI18N())) { return o1.getCreationDate().compareTo( o2.getCreationDate()); @@ -539,7 +540,8 @@ public class ResourcesListViewPanel extends FramedPanel { } else { Log.error("Error Retrieving Resources: " + caught.getLocalizedMessage()); - UtilsGXT3.alert(msgs.errorRetrievingResourcesHead(), + UtilsGXT3.alert( + msgs.errorRetrievingResourcesHead(), caught.getLocalizedMessage()); } } @@ -551,12 +553,14 @@ public class ResourcesListViewPanel extends FramedPanel { Log.debug("Resources loaded " + result.size()); if (result != null && result.size() > 0) { statusBar.clear(); - statusBar - .add(new LabelToolItem(msgs.statusBarNumberOfResources(result.size()))); + statusBar.add(new LabelToolItem(msgs + .statusBarNumberOfResources(result + .size()))); } else { statusBar.clear(); - statusBar.add(new LabelToolItem(msgs.statusBarNoResource())); - + statusBar.add(new LabelToolItem(msgs + .statusBarNoResource())); + } statusBar.forceLayout(); try { @@ -581,11 +585,11 @@ public class ResourcesListViewPanel extends FramedPanel { @Override public void onSelection(SelectionEvent event) { - List resources= listView.getSelectionModel() - .getSelectedItems(); - ResourceTDDescriptor selected=null; - if(resources!=null&&resources.size()>0){ - selected=resources.get(0); + List resources = listView + .getSelectionModel().getSelectedItems(); + ResourceTDDescriptor selected = null; + if (resources != null && resources.size() > 0) { + selected = resources.get(0); } Log.debug("selected: " + selected); requestOpen(selected); @@ -600,11 +604,11 @@ public class ResourcesListViewPanel extends FramedPanel { @Override public void onSelection(SelectionEvent event) { - List resources= listView.getSelectionModel() - .getSelectedItems(); - ResourceTDDescriptor selected=null; - if(resources!=null&&resources.size()>0){ - selected=resources.get(0); + List resources = listView + .getSelectionModel().getSelectedItems(); + ResourceTDDescriptor selected = null; + if (resources != null && resources.size() > 0) { + selected = resources.get(0); } Log.debug("selected: " + selected); requestSave(selected); @@ -619,10 +623,11 @@ public class ResourcesListViewPanel extends FramedPanel { @Override public void onSelection(SelectionEvent event) { - List selected= listView.getSelectionModel() - .getSelectedItems(); + List selected = listView + .getSelectionModel().getSelectedItems(); Log.debug("selected: " + selected); - ArrayList resources=new ArrayList(selected); + ArrayList resources = new ArrayList( + selected); requestRemove(resources); } @@ -756,7 +761,8 @@ public class ResourcesListViewPanel extends FramedPanel { public void onSuccess() { SaveResourceWizard saveResourceWizard = new SaveResourceWizard( - saveResourceSession, msgs.saveResourceWizardHead(), eventBus); + saveResourceSession, msgs.saveResourceWizardHead(), + eventBus); saveResourceWizard.addListener(new WizardListener() { @@ -792,10 +798,10 @@ public class ResourcesListViewPanel extends FramedPanel { } protected void requestRemove(ArrayList resourcesList) { - ArrayList resources=new ArrayList(resourcesList); - - removeResourceSession = new RemoveResourceSession(trId, - resources); + ArrayList resources = new ArrayList( + resourcesList); + + removeResourceSession = new RemoveResourceSession(trId, resources); TDGWTServiceAsync.INSTANCE.removeResource(removeResourceSession, new AsyncCallback() { @@ -915,9 +921,8 @@ public class ResourcesListViewPanel extends FramedPanel { } else { Log.error("Error with uri resolver: " + caught.getLocalizedMessage()); - UtilsGXT3 - .alert(msgsCommon.error(), - msgs.errorRetrievingURIFromResolver()); + UtilsGXT3.alert(msgsCommon.error(), msgs + .errorRetrievingURIFromResolver()); } } @@ -950,69 +955,74 @@ public class ResourcesListViewPanel extends FramedPanel { InternalURITD genericFileResourceTD = (InternalURITD) resource; String name = resourceTDDescriptor.getName(); - + /* - MimeTypeSupport ext=null; - String extentionInName=null; - if(name!=null){ - List nameS=null; - try{ - nameS=Arrays.asList(name.split("\\.(?=[^\\.]+$)")); - } catch(Throwable e) { - Log.error("No valid name for resource: "+name); - } - - if(nameS!=null&&nameS.size()>1){ - extentionInName=nameS.get(nameS.size()-1); - ext=MimeTypeSupport.getMimeTypeSupportFromExtension("."+extentionInName); - - } - } - if(ext==null){ - - */ - + * MimeTypeSupport ext=null; String extentionInName=null; + * if(name!=null){ List nameS=null; try{ + * nameS=Arrays.asList(name.split("\\.(?=[^\\.]+$)")); } + * catch(Throwable e) { + * Log.error("No valid name for resource: "+name); } + * + * if(nameS!=null&&nameS.size()>1){ + * extentionInName=nameS.get(nameS.size()-1); + * ext=MimeTypeSupport.getMimeTypeSupportFromExtension + * ("."+extentionInName); + * + * } } if(ext==null){ + */ + MimeTypeSupport mts = MimeTypeSupport .getMimeTypeSupportFromMimeName(genericFileResourceTD .getMimeType()); if (mts != null) { name = name + mts.getExtension(); } - + /* - } + * } */ - UriResolverSession uriResolverSession = new UriResolverSession( - genericFileResourceTD.getId(), ApplicationType.SMP_ID, - name, genericFileResourceTD.getMimeType()); + if (genericFileResourceTD.getId() != null + && !genericFileResourceTD.getId().isEmpty() + && (genericFileResourceTD.getId().startsWith("http:") || genericFileResourceTD + .getId().startsWith("https:"))) { + + Log.debug("Use direct http link"); + Window.open(genericFileResourceTD.getId(), + resourceTDDescriptor.getName(), ""); - TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession, - new AsyncCallback() { + } else { - 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(msgsCommon.error(), - msgs.errorRetrievingURIFromResolver()); + UriResolverSession uriResolverSession = new UriResolverSession( + genericFileResourceTD.getId(), ApplicationType.SMP_ID, + name, genericFileResourceTD.getMimeType()); + + 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(msgsCommon.error(), msgs + .errorRetrievingURIFromResolver()); + } } - } - public void onSuccess(String link) { - Log.debug("Retrieved link: " + link); - Window.open(link, resourceTDDescriptor.getName(), - ""); - } + public void onSuccess(String link) { + Log.debug("Retrieved link: " + link); + Window.open(link, + resourceTDDescriptor.getName(), ""); + } - }); + }); + } } else { Log.error("Error with resource: no valid resource"); - UtilsGXT3 - .alert(msgsCommon.error(), msgs.errorNoValidInternalUri()); + UtilsGXT3.alert(msgsCommon.error(), msgs.errorNoValidInternalUri()); } }