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
This commit is contained in:
Giancarlo Panichi 2014-04-15 18:24:49 +00:00 committed by Giancarlo Panichi
parent 79ad0924ce
commit 4e7c12668f
2 changed files with 240 additions and 0 deletions

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<Validations> comboValidations;
protected ListStore<OpHistory> store;
protected ListLoader<ListLoadConfig, ListLoadResult<OpHistory>> loader;
protected Grid<OpHistory> 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<OpHistory> identityProvider = new IdentityValueProvider<OpHistory>();
RowExpander<OpHistory> expander = new RowExpander<OpHistory>(
identityProvider, new AbstractCell<OpHistory>() {
@Override
public void render(Context context, OpHistory value,
SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><b>Name:</b>"
+ value.getName() + "</p>");
sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><b>Date:</b>"
+ value.getDate() + "</p>");
sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><b>Description:</b> "
+ value.getDescription());
}
});
ColumnConfig<OpHistory, String> nameCol = new ColumnConfig<OpHistory, String>(
props.name(), 32, "Name");
ColumnConfig<OpHistory, String> dateCol = new ColumnConfig<OpHistory, String>(
props.date(), 32, "Date");
List<ColumnConfig<OpHistory, ?>> l = new ArrayList<ColumnConfig<OpHistory, ?>>();
l.add(expander);
l.add(nameCol);
l.add(dateCol);
ColumnModel<OpHistory> cm = new ColumnModel<OpHistory>(l);
store = new ListStore<OpHistory>(props.id());
RpcProxy<ListLoadConfig, ListLoadResult<OpHistory>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<OpHistory>>() {
public void load(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<OpHistory>> callback) {
loadData(loadConfig, callback);
}
};
loader = new ListLoader<ListLoadConfig, ListLoadResult<OpHistory>>(
proxy);
loader.setRemoteSort(false);
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, OpHistory, ListLoadResult<OpHistory>>(
store) {
});
grid = new Grid<OpHistory>(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<ListLoadResult<OpHistory>> callback) {
TDGWTServiceAsync.INSTANCE.getHistory(trId,
new AsyncCallback<ArrayList<OpHistory>>() {
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<OpHistory> result) {
Log.debug("loaded " + result.size());
callback.onSuccess(new ListLoadResultBean<OpHistory>(
result));
}
});
}
public void update() {
retrieveCurrentTR();
loader.load();
}
protected void retrieveCurrentTR() {
TDGWTServiceAsync.INSTANCE.getCurrentTRId(new AsyncCallback<TRId>() {
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;
}
});
}
}

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface OpHistoryProperties extends
PropertyAccess<OpHistory> {
@Path("historyId")
ModelKeyProvider<OpHistory> id();
ValueProvider<OpHistory,String> name();
ValueProvider<OpHistory, String> decription();
ValueProvider<OpHistory, String> date();
}