From 961bb73a7e503d964e877ddf2897a431b26f7798 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 4 Jun 2015 17:03:01 +0000 Subject: [PATCH] 209: TDM - Show the resources through a ListView widget Task-Url: https://support.d4science.org/issues/209 Updated Resources ListView git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@115231 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ResourcesListViewDetailPanel.java | 128 +++++++++++ .../client/ResourcesListViewDialog.java | 24 +- .../client/ResourcesListViewPanel.java | 207 ++++++++---------- .../client/ResourcesWidgetEntry.java | 62 +++--- 4 files changed, 259 insertions(+), 162 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDetailPanel.java diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDetailPanel.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDetailPanel.java new file mode 100644 index 0000000..1e70ab4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDetailPanel.java @@ -0,0 +1,128 @@ +package org.gcube.portlets.user.td.resourceswidget.client; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD; +import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; +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.resourceswidget.client.resources.ResourceBundle; + +import com.google.gwt.safehtml.shared.SafeUri; +import com.google.gwt.safehtml.shared.UriUtils; +import com.google.gwt.user.client.ui.Image; +import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; +import com.sencha.gxt.core.client.resources.ThemeStyles; +import com.sencha.gxt.core.client.util.Margins; +import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack; +import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; +import com.sencha.gxt.widget.core.client.container.SimpleContainer; +import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; +import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; +import com.sencha.gxt.widget.core.client.form.FieldLabel; +import com.sencha.gxt.widget.core.client.form.FormPanel.LabelAlign; +import com.sencha.gxt.widget.core.client.form.TextArea; +import com.sencha.gxt.widget.core.client.form.TextField; + +/** + * + * @author giancarlo email: g.panichi@isti.cnr.it + * + */ +public class ResourcesListViewDetailPanel extends SimpleContainer { + private static final String DESCRIPTION_HEIGHT = "70px"; + + + private Image thumbnail; + private TextField name; + private TextArea description; + private TextField creationDate; + private VerticalLayoutContainer v; + + public ResourcesListViewDetailPanel() { + super(); + init(); + + } + protected void init(){ + addStyleName(ThemeStyles.get().style().border()); + getElement().getStyle().setBackgroundColor("white"); + + } + + public void setDescriptor(ResourceTDDescriptor descriptor){ + if(v!=null){ + remove(v); + } + + if(descriptor==null){ + forceLayout(); + return; + } + SafeUri thumbnailPath = ResourceBundle.INSTANCE.resources32() + .getSafeUri(); + ResourceTD resourceTD = descriptor.getResourceTD(); + + if (resourceTD instanceof InternalURITD) { + InternalURITD internalURITD = (InternalURITD) resourceTD; + if (internalURITD.getThumbnailTD() != null + && internalURITD.getThumbnailTD().getUrl() != null) { + thumbnailPath = UriUtils.fromTrustedString(internalURITD + .getThumbnailTD().getUrl()); + } + } else { + if (resourceTD instanceof StringResourceTD) { + thumbnailPath = ResourceBundle.INSTANCE.resources32() + .getSafeUri(); + } else { + if (resourceTD instanceof TableResourceTD) { + thumbnailPath = ResourceBundle.INSTANCE.resources32() + .getSafeUri(); + } + } + } + + + thumbnail=new Image(); + + + name=new TextField(); + FieldLabel nameLabel=new FieldLabel(name, "Name"); + nameLabel.setLabelAlign(LabelAlign.TOP); + + description=new TextArea(); + description.setHeight(DESCRIPTION_HEIGHT); + FieldLabel descriptionLabel=new FieldLabel(description, "Description"); + descriptionLabel.setLabelAlign(LabelAlign.TOP); + + creationDate=new TextField(); + FieldLabel creationDateLabel=new FieldLabel(creationDate, "Creation Date"); + creationDateLabel.setLabelAlign(LabelAlign.TOP); + + v=new VerticalLayoutContainer(); + v.setScrollMode(ScrollMode.AUTO); + + HBoxLayoutContainer h=new HBoxLayoutContainer(); + h.setPack(BoxLayoutPack.CENTER); + h.add(thumbnail); + + v.add(h, new VerticalLayoutData(1,-1, new Margins(20,0,10,0))); + v.add(nameLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(descriptionLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(creationDateLabel, new VerticalLayoutData(1, -1, new Margins(1))); + + + thumbnail.setUrl(thumbnailPath); + name.setValue(descriptor.getName()); + description.setValue(descriptor.getDescription()); + creationDate.setValue(descriptor.getCreationDate()); + add(v); + + forceLayout(); + + } + + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDialog.java b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDialog.java index d597c66..0d4804c 100644 --- a/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/resourceswidget/client/ResourcesListViewDialog.java @@ -1,6 +1,5 @@ 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; @@ -16,19 +15,17 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; * */ public class ResourcesListViewDialog extends Window { - protected String WIDTH = "640px"; - protected String HEIGHT = "480px"; - protected TRId trId; - protected EventBus eventBus; - protected UserInfo userInfo; + private static final String WIDTH = "640px"; + private static final String HEIGHT = "480px"; + private ResourcesListViewPanel resourcesPanel; - public ResourcesListViewDialog(TRId trId, EventBus eventBus) { - this.trId = trId; - this.eventBus = eventBus; + public ResourcesListViewDialog(EventBus eventBus) { initWindow(); - ResourcesListViewPanel resourcesPanel = new ResourcesListViewPanel( - trId, eventBus); + resourcesPanel = new ResourcesListViewPanel( + eventBus); add(resourcesPanel); + + } protected void initWindow() { @@ -40,6 +37,11 @@ public class ResourcesListViewDialog extends Window { // getHeader().setIcon(Resources.IMAGES.side_list()); } + public void open(TRId trId){; + resourcesPanel.open(trId); + + } + /** * {@inheritDoc} */ 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 7fd1527..f6bb63a 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 @@ -33,7 +33,6 @@ import com.google.gwt.safehtml.shared.SafeUri; import com.google.gwt.safehtml.shared.UriUtils; import com.google.gwt.text.shared.AbstractSafeHtmlRenderer; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.HTML; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.SimpleSafeHtmlCell; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; @@ -45,7 +44,6 @@ import com.sencha.gxt.core.client.XTemplates.FormatterFactories; import com.sencha.gxt.core.client.XTemplates.FormatterFactory; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; import com.sencha.gxt.core.client.resources.CommonStyles; -import com.sencha.gxt.core.client.resources.ThemeStyles; import com.sencha.gxt.core.client.util.Format; import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.data.client.loader.RpcProxy; @@ -87,6 +85,9 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar; */ public class ResourcesListViewPanel extends FramedPanel { + private static final String HEIGHT = "470px"; + private static final String WIDTH = "630px"; + public interface DetailRenderer extends XTemplates { @XTemplate(source = "ResourcesListViewDetail.html") public SafeHtml render(ResourceTDDescriptor resourceTDDescriptor, @@ -198,9 +199,10 @@ public class ResourcesListViewPanel extends FramedPanel { } // private Dialog chooser; - private HTML details; - private static DetailRenderer detailRenderer; - private static ResourceListViewDetailCSS detailStyle; + // private HTML details; + private ResourcesListViewDetailPanel details; + // private static DetailRenderer detailRenderer; + // private static ResourceListViewDetailCSS detailStyle; private TRId trId; private EventBus eventBus; @@ -208,26 +210,25 @@ public class ResourcesListViewPanel extends FramedPanel { private ListStore store; private ListLoader> loader; - private boolean drawed = false; - private ListView view; private SimpleComboBox comboSort; - public ResourcesListViewPanel(TRId trId, EventBus eventBus) { + public ResourcesListViewPanel(EventBus eventBus) { super(); - this.trId = trId; this.eventBus = eventBus; forceLayoutOnResize = true; - retrieveCurrentTR(); + init(); + create(); } - protected void draw() { + public void open(TRId trId) { try { - drawed = true; - init(); - create(); + this.trId = trId; + loader.load(); + details.setDescriptor(null); + forceLayout(); } catch (Throwable e) { - Log.error(e.getLocalizedMessage()); + Log.error("Error open resources: "+e.getLocalizedMessage()); e.printStackTrace(); } } @@ -235,19 +236,21 @@ public class ResourcesListViewPanel extends FramedPanel { protected void init() { setHeaderVisible(false); setBodyBorder(false); - setResize(true); - setWidth("630px"); - setHeight("470px"); + setResize(true); + setWidth(WIDTH); + setHeight(HEIGHT); } protected void create() { Log.debug("Create Resource List View"); - DetailRendererBundle.INSTANCE.css().ensureInjected(); - detailStyle = DetailRendererBundle.INSTANCE.css(); - - detailRenderer = GWT.create(DetailRenderer.class); + /* + * DetailRendererBundle.INSTANCE.css().ensureInjected(); detailStyle = + * DetailRendererBundle.INSTANCE.css(); + * + * detailRenderer = GWT.create(DetailRenderer.class); + */ RpcProxy> proxy = new RpcProxy>() { @Override @@ -436,16 +439,15 @@ public class ResourcesListViewPanel extends FramedPanel { main.add(toolbar, new VerticalLayoutData(1, -1)); main.add(view, new VerticalLayoutData(1, 1)); - details = new HTML(); - details.addStyleName(ThemeStyles.get().style().border()); - details.getElement().getStyle().setBackgroundColor("white"); - - BorderLayoutData eastData = new BorderLayoutData(200); - eastData.setSplit(true); + details = new ResourcesListViewDetailPanel(); BorderLayoutData centerData = new BorderLayoutData(); + centerData.setMinSize(330); centerData.setMargins(new Margins(0, 5, 0, 0)); + BorderLayoutData eastData = new BorderLayoutData(200); + eastData.setMinSize(150); + BorderLayoutContainer con = new BorderLayoutContainer(); con.setCenterWidget(main, centerData); con.setEastWidget(details, eastData); @@ -457,114 +459,77 @@ public class ResourcesListViewPanel extends FramedPanel { SelectionChangedEvent se) { if (se.getSelection().size() > 0) { ResourceTDDescriptor descriptor = se.getSelection().get(0); - SafeUri thumbnailPath = ResourceBundle.INSTANCE.resources32() - .getSafeUri(); - ResourceTD resourceTD = descriptor.getResourceTD(); + /* + * @SuppressWarnings("unused") SafeUri thumbnailPath = + * ResourceBundle.INSTANCE.resources32() .getSafeUri(); ResourceTD + * resourceTD = descriptor.getResourceTD(); + * + * if (resourceTD instanceof InternalURITD) { InternalURITD + * internalURITD = (InternalURITD) resourceTD; if + * (internalURITD.getThumbnailTD() != null && + * internalURITD.getThumbnailTD().getUrl() != null) { thumbnailPath + * = UriUtils.fromTrustedString(internalURITD + * .getThumbnailTD().getUrl()); } } else { if (resourceTD instanceof + * StringResourceTD) { thumbnailPath = + * ResourceBundle.INSTANCE.resources32() .getSafeUri(); } else { if + * (resourceTD instanceof TableResourceTD) { thumbnailPath = + * ResourceBundle.INSTANCE.resources32() .getSafeUri(); } } } + */ - if (resourceTD instanceof InternalURITD) { - InternalURITD internalURITD = (InternalURITD) resourceTD; - if (internalURITD.getThumbnailTD() != null - && internalURITD.getThumbnailTD().getUrl() != null) { - thumbnailPath = UriUtils.fromTrustedString(internalURITD - .getThumbnailTD().getUrl()); - } - } else { - if (resourceTD instanceof StringResourceTD) { - thumbnailPath = ResourceBundle.INSTANCE.resources32() - .getSafeUri(); - } else { - if (resourceTD instanceof TableResourceTD) { - thumbnailPath = ResourceBundle.INSTANCE.resources32() - .getSafeUri(); - } - } - } - - details.setHTML(detailRenderer.render(descriptor, thumbnailPath, - detailStyle).asString()); + details.setDescriptor(descriptor); + /* + * details.setHTML(detailRenderer.render(descriptor, thumbnailPath, + * detailStyle).asString()); + */ // chooser.getButton(PredefinedButton.OK).enable(); } else { + details.setDescriptor(null); // chooser.getButton(PredefinedButton.OK).disable(); - details.setHTML(""); + // setHTML(""); } + } protected void loadData( final AsyncCallback> callback) { Log.debug("Called loadData"); - TDGWTServiceAsync.INSTANCE.getResourcesTD(trId, - new AsyncCallback>() { + if (trId != null) { + TDGWTServiceAsync.INSTANCE.getResourcesTD(trId, + 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()); + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); } else { - Log.error("Error Retrieving Resources: " - + caught.getLocalizedMessage()); - UtilsGXT3.alert("Error retrieving resources", - caught.getLocalizedMessage()); + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Locked", + caught.getLocalizedMessage()); + } else { + Log.error("Error Retrieving Resources: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert( + "Error retrieving resources", + caught.getLocalizedMessage()); + } + } + callback.onFailure(caught); + } + + public void onSuccess( + ArrayList result) { + Log.debug("Resources loaded " + result.size()); + try { + callback.onSuccess(result); + } catch (Throwable e) { + Log.debug("Error: " + e.getLocalizedMessage()); + e.printStackTrace(); } } - callback.onFailure(caught); - } - public void onSuccess(ArrayList result) { - Log.debug("Resources loaded " + result.size()); - try { - callback.onSuccess(result); - } catch (Throwable e) { - Log.debug("Error: " + e.getLocalizedMessage()); - e.printStackTrace(); - } - } - - }); - - } - - public void update() { - retrieveCurrentTR(); - loader.load(); - forceLayout(); - } - - protected void retrieveCurrentTR() { - TDGWTServiceAsync.INSTANCE.getCurrentTRId(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 { - Log.error("Error retrieving current TRId: " - + caught.getLocalizedMessage()); - UtilsGXT3.alert("Error", - "Error retrieving current tabular resource id"); - } - } - } - - public void onSuccess(TRId result) { - Log.debug("retrieved " + result); - trId = result; - if (!drawed) { - draw(); - } - - } - - }); + }); + } } } 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 4ea5557..0e03879 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 @@ -32,9 +32,11 @@ public class ResourcesWidgetEntry implements EntryPoint { Log.info("Hello!"); eventBus = new SimpleEventBus(); trId = new TRId(); - //TabularResource: [ id=202, type=STANDARD, lastTable=[ id=4901, type=Generic]] - //TabularResource: [ id=68, type=STANDARD, lastTable=[ id=4884, type=Dataset]] - + // TabularResource: [ id=202, type=STANDARD, lastTable=[ id=4901, + // type=Generic]] + // TabularResource: [ id=68, type=STANDARD, lastTable=[ id=4884, + // type=Dataset]] + trId.setId("68"); trId.setTableType("STANDARD"); trId.setTableId("4884"); @@ -54,8 +56,9 @@ public class ResourcesWidgetEntry implements EntryPoint { */ ResourcesListViewDialog resourcesListViewDialog = new ResourcesListViewDialog( - trId, eventBus); + eventBus); resourcesListViewDialog.show(); + resourcesListViewDialog.open(trId); } catch (Throwable e) { Log.error(e.getLocalizedMessage()); e.printStackTrace(); @@ -86,39 +89,38 @@ public class ResourcesWidgetEntry implements EntryPoint { }); } - - protected void getTabularResource(){ - TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId, new AsyncCallback() { + protected void getTabularResource() { + TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId, + new AsyncCallback() { - + @Override + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { - @Override - public void onFailure(Throwable caught) { - if (caught instanceof TDGWTSessionExpiredException) { - eventBus.fireEvent(new SessionExpiredEvent( - SessionExpiredType.EXPIREDONSERVER)); - } else { + Log.error("Error get TR information: " + + caught.getLocalizedMessage()); + UtilsGXT3 + .alert("Error", "Error get TR information"); - Log.error("Error get TR information: " - + caught.getLocalizedMessage()); - UtilsGXT3.alert("Error", "Error get TR information"); + } - } - - } + } - @Override - public void onSuccess(TabResource result) { - Log.debug("TabResource:"+result); - tabResource=result; - setCurrentTabularResource(); - - } - }); + @Override + public void onSuccess(TabResource result) { + Log.debug("TabResource:" + result); + tabResource = result; + setCurrentTabularResource(); + + } + }); } - + protected void setCurrentTabularResource() { - TDGWTServiceAsync.INSTANCE.setTabResource(tabResource, + TDGWTServiceAsync.INSTANCE.setTabResource(tabResource, new AsyncCallback() { @Override