From 4e7c12668f7b82aa8064c21ac5a74f1e2ec3e128 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 15 Apr 2014 18:24:49 +0000 Subject: [PATCH] Minor Update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@94864 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/history/HistoryPanel.java | 214 ++++++++++++++++++ .../properties/OpHistoryProperties.java | 26 +++ 2 files changed, 240 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/history/HistoryPanel.java create mode 100644 src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/OpHistoryProperties.java diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/history/HistoryPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/history/HistoryPanel.java new file mode 100644 index 0000000..41da32a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/history/HistoryPanel.java @@ -0,0 +1,214 @@ +package org.gcube.portlets.user.td.tablewidget.client.history; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; +import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.tablewidget.client.properties.OpHistoryProperties; +import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +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.safehtml.shared.SafeHtmlBuilder; +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.dom.ScrollSupport.ScrollMode; +import com.sencha.gxt.core.client.util.Margins; +import com.sencha.gxt.data.client.loader.RpcProxy; +import com.sencha.gxt.data.shared.ListStore; +import com.sencha.gxt.data.shared.loader.ListLoadConfig; +import com.sencha.gxt.data.shared.loader.ListLoadResult; +import com.sencha.gxt.data.shared.loader.ListLoadResultBean; +import com.sencha.gxt.data.shared.loader.ListLoader; +import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding; +import com.sencha.gxt.widget.core.client.FramedPanel; +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.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.RowExpander; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class HistoryPanel extends FramedPanel { + protected String WIDTH = "640px"; + protected String HEIGHT = "520px"; + + protected TRId trId; + protected TableData table; + protected String headingTitle; + protected VerticalLayoutContainer vl; + protected EventBus eventBus; + + // protected ComboBox comboValidations; + protected ListStore store; + protected ListLoader> loader; + protected Grid grid; + + public HistoryPanel(EventBus eventBus) { + super(); + this.eventBus = eventBus; + retrieveCurrentTR(); + forceLayoutOnResize = true; + init(); + create(); + } + + public HistoryPanel(TRId trId, EventBus eventBus) { + super(); + this.trId = trId; + this.eventBus = eventBus; + forceLayoutOnResize = true; + init(); + create(); + } + + protected void init() { + setWidth(WIDTH); + setHeight(HEIGHT); + setHeaderVisible(false); + setBodyBorder(false); + } + + protected void create() { + OpHistoryProperties props = GWT.create(OpHistoryProperties.class); + + IdentityValueProvider identityProvider = new IdentityValueProvider(); + RowExpander expander = new RowExpander( + identityProvider, new AbstractCell() { + @Override + public void render(Context context, OpHistory value, + SafeHtmlBuilder sb) { + sb.appendHtmlConstant("

Name:" + + value.getName() + "

"); + sb.appendHtmlConstant("

Date:" + + value.getDate() + "

"); + sb.appendHtmlConstant("

Description: " + + value.getDescription()); + } + }); + + ColumnConfig nameCol = new ColumnConfig( + props.name(), 32, "Name"); + ColumnConfig dateCol = new ColumnConfig( + props.date(), 32, "Date"); + + List> l = new ArrayList>(); + l.add(expander); + l.add(nameCol); + l.add(dateCol); + + ColumnModel cm = new ColumnModel(l); + + store = new ListStore(props.id()); + + RpcProxy> proxy = new RpcProxy>() { + + public void load(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + loadData(loadConfig, callback); + } + + }; + + loader = new ListLoader>( + proxy); + + loader.setRemoteSort(false); + loader.addLoadHandler(new LoadResultListStoreBinding>( + store) { + }); + + grid = new Grid(store, cm) { + @Override + protected void onAfterFirstAttach() { + super.onAfterFirstAttach(); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + + public void execute() { + loader.load(); + } + }); + } + }; + + grid.setLoader(loader); + grid.setHeight(360); + grid.getView().setStripeRows(true); + grid.getView().setColumnLines(true); + grid.getView().setAutoFill(true); + grid.setBorders(false); + grid.setLoadMask(true); + grid.setColumnReordering(true); + grid.setColumnResize(true); + grid.getView().setAutoExpandColumn(nameCol); + grid.getView().setEmptyText("Empty"); + + VerticalLayoutContainer v = new VerticalLayoutContainer(); + v.setScrollMode(ScrollMode.AUTO); + v.add(grid, new VerticalLayoutData(1, -1, new Margins(0))); + add(v); + + } + + protected void loadData(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + + TDGWTServiceAsync.INSTANCE.getHistory(trId, + new AsyncCallback>() { + + public void onFailure(Throwable caught) { + Log.error("Error Retrieving History: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error retrieving history", + "Error retrieving history"); + callback.onFailure(caught); + } + + public void onSuccess(ArrayList result) { + Log.debug("loaded " + result.size()); + callback.onSuccess(new ListLoadResultBean( + result)); + } + + }); + + } + + public void update() { + retrieveCurrentTR(); + loader.load(); + } + + protected void retrieveCurrentTR() { + TDGWTServiceAsync.INSTANCE.getCurrentTRId(new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.error("Error retrieving history: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error retrieving history", + "Error retrieving history"); + + } + + public void onSuccess(TRId result) { + Log.debug("retrieved " + result); + trId = result; + } + + }); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/OpHistoryProperties.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/OpHistoryProperties.java new file mode 100644 index 0000000..0b2b143 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/OpHistoryProperties.java @@ -0,0 +1,26 @@ +package org.gcube.portlets.user.td.tablewidget.client.properties; + +import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; + +import com.google.gwt.editor.client.Editor.Path; +import com.sencha.gxt.core.client.ValueProvider; +import com.sencha.gxt.data.shared.ModelKeyProvider; +import com.sencha.gxt.data.shared.PropertyAccess; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface OpHistoryProperties extends + PropertyAccess { + + @Path("historyId") + ModelKeyProvider id(); + + ValueProvider name(); + ValueProvider decription(); + ValueProvider date(); + +}