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
This commit is contained in:
parent
281a27e875
commit
961bb73a7e
|
@ -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: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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}
|
||||
*/
|
||||
|
|
|
@ -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<ResourceTDDescriptor> store;
|
||||
private ListLoader<ListLoadConfig, ListLoadResult<ResourceTDDescriptor>> loader;
|
||||
|
||||
private boolean drawed = false;
|
||||
|
||||
private ListView<ResourceTDDescriptor, ResourceTDDescriptor> view;
|
||||
private SimpleComboBox<String> comboSort;
|
||||
|
||||
public ResourcesListViewPanel(TRId trId, EventBus eventBus) {
|
||||
public ResourcesListViewPanel(EventBus eventBus) {
|
||||
super();
|
||||
this.trId = trId;
|
||||
this.eventBus = eventBus;
|
||||
forceLayoutOnResize = true;
|
||||
retrieveCurrentTR();
|
||||
}
|
||||
|
||||
protected void draw() {
|
||||
try {
|
||||
drawed = true;
|
||||
init();
|
||||
create();
|
||||
}
|
||||
|
||||
public void open(TRId trId) {
|
||||
try {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -236,18 +237,20 @@ public class ResourcesListViewPanel extends FramedPanel {
|
|||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
setResize(true);
|
||||
setWidth("630px");
|
||||
setHeight("470px");
|
||||
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<Object, List<ResourceTDDescriptor>> proxy = new RpcProxy<Object, List<ResourceTDDescriptor>>() {
|
||||
@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,41 +459,41 @@ public class ResourcesListViewPanel extends FramedPanel {
|
|||
SelectionChangedEvent<ResourceTDDescriptor> 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<List<ResourceTDDescriptor>> callback) {
|
||||
Log.debug("Called loadData");
|
||||
if (trId != null) {
|
||||
TDGWTServiceAsync.INSTANCE.getResourcesTD(trId,
|
||||
new AsyncCallback<ArrayList<ResourceTDDescriptor>>() {
|
||||
|
||||
|
@ -507,14 +509,16 @@ public class ResourcesListViewPanel extends FramedPanel {
|
|||
} else {
|
||||
Log.error("Error Retrieving Resources: "
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error retrieving resources",
|
||||
UtilsGXT3.alert(
|
||||
"Error retrieving resources",
|
||||
caught.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
callback.onFailure(caught);
|
||||
}
|
||||
|
||||
public void onSuccess(ArrayList<ResourceTDDescriptor> result) {
|
||||
public void onSuccess(
|
||||
ArrayList<ResourceTDDescriptor> result) {
|
||||
Log.debug("Resources loaded " + result.size());
|
||||
try {
|
||||
callback.onSuccess(result);
|
||||
|
@ -525,46 +529,7 @@ public class ResourcesListViewPanel extends FramedPanel {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
retrieveCurrentTR();
|
||||
loader.load();
|
||||
forceLayout();
|
||||
}
|
||||
|
||||
protected void retrieveCurrentTR() {
|
||||
TDGWTServiceAsync.INSTANCE.getCurrentTRId(new AsyncCallback<TRId>() {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,8 +32,10 @@ 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");
|
||||
|
@ -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,11 +89,9 @@ public class ResourcesWidgetEntry implements EntryPoint {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
protected void getTabularResource(){
|
||||
TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId, new AsyncCallback<TabResource>() {
|
||||
|
||||
|
||||
protected void getTabularResource() {
|
||||
TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId,
|
||||
new AsyncCallback<TabResource>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -101,7 +102,8 @@ public class ResourcesWidgetEntry implements EntryPoint {
|
|||
|
||||
Log.error("Error get TR information: "
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error", "Error get TR information");
|
||||
UtilsGXT3
|
||||
.alert("Error", "Error get TR information");
|
||||
|
||||
}
|
||||
|
||||
|
@ -109,8 +111,8 @@ public class ResourcesWidgetEntry implements EntryPoint {
|
|||
|
||||
@Override
|
||||
public void onSuccess(TabResource result) {
|
||||
Log.debug("TabResource:"+result);
|
||||
tabResource=result;
|
||||
Log.debug("TabResource:" + result);
|
||||
tabResource = result;
|
||||
setCurrentTabularResource();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue