Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95138 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-28 08:15:42 +00:00 committed by Giancarlo Panichi
parent f41062fa39
commit 22107f0e32
3 changed files with 145 additions and 156 deletions

View File

@ -55,6 +55,8 @@ import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig; import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfigBean; import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.Loader; import com.sencha.gxt.data.shared.loader.Loader;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.PagingLoadResult; import com.sencha.gxt.data.shared.loader.PagingLoadResult;
import com.sencha.gxt.data.shared.loader.PagingLoader; import com.sencha.gxt.data.shared.loader.PagingLoader;
import com.sencha.gxt.widget.core.client.ContentPanel; import com.sencha.gxt.widget.core.client.ContentPanel;
@ -110,7 +112,7 @@ public class TabularDataXGridPanel extends ContentPanel {
protected DataRowPagingReader reader; protected DataRowPagingReader reader;
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader; protected PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected TableViewConfig tableViewConfig; protected TableViewConfig tableViewConfig;
@ -574,11 +576,11 @@ public class TabularDataXGridPanel extends ContentPanel {
reader = new DataRowPagingReader(tableDefinition); reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata"; String path = GWT.getModuleBaseURL() + "tdwxdata";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
path); path);
builder.setHeader(ServletParameters.TD_SESSION_ID, builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId)); String.valueOf(tdSessionId));
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>( /*HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder); builder);
proxy.setWriter(new PagingLoadUrlEncoder()); proxy.setWriter(new PagingLoadUrlEncoder());
@ -588,7 +590,20 @@ public class TabularDataXGridPanel extends ContentPanel {
protected FilterPagingLoadConfig newLoadConfig() { protected FilterPagingLoadConfig newLoadConfig() {
return new FilterPagingLoadConfigBean(); return new FilterPagingLoadConfigBean();
} }
};*/
HttpProxy<PagingLoadConfig> proxy = new HttpProxy<PagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder());
loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader) {
@Override
protected PagingLoadConfig newLoadConfig() {
return new PagingLoadConfigBean();
}
}; };
loader.setRemoteSort(true); loader.setRemoteSort(true);
/* /*
* loader.addLoadHandler(new * loader.addLoadHandler(new
@ -620,7 +635,7 @@ public class TabularDataXGridPanel extends ContentPanel {
// numberer.initPlugin(grid); // numberer.initPlugin(grid);
// Filter // Filter
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator /*ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel); .generate(columnModel);
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>( ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
loader); loader);
@ -630,7 +645,7 @@ public class TabularDataXGridPanel extends ContentPanel {
Log.debug("Filters: " + filters.size()); Log.debug("Filters: " + filters.size());
for (Filter<DataRow, ?> filterGeneric : filters) { for (Filter<DataRow, ?> filterGeneric : filters) {
gridFilters.addFilter(filterGeneric); gridFilters.addFilter(filterGeneric);
} }*/
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));

View File

@ -3,24 +3,13 @@
*/ */
package org.gcube.portlets.user.tdwx.client.util; package org.gcube.portlets.user.tdwx.client.util;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.RequestData; import org.gcube.portlets.user.tdwx.shared.RequestData;
import org.gcube.portlets.user.tdwx.shared.SortInformation; import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamFactory;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
import com.sencha.gxt.data.shared.SortInfo; import com.sencha.gxt.data.shared.SortInfo;
import com.sencha.gxt.data.shared.loader.FilterConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig; import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.writer.DataWriter; import com.sencha.gxt.data.shared.writer.DataWriter;
/** /**
@ -30,91 +19,86 @@ import com.sencha.gxt.data.shared.writer.DataWriter;
* *
*/ */
public class PagingLoadUrlEncoder implements public class PagingLoadUrlEncoder implements
DataWriter<FilterPagingLoadConfig, String> { DataWriter<PagingLoadConfig, String> {
//DataWriter<FilterPagingLoadConfig, String> {
protected UrlBuilder urlBuilder = new UrlBuilder(); protected UrlBuilder urlBuilder = new UrlBuilder();
protected RequestData requestData; protected RequestData requestData;
public String write(FilterPagingLoadConfig config) { public String write(PagingLoadConfig config) {
requestData = new RequestData(); /*
* requestData = new RequestData();
*
* requestData.setOffset(String.valueOf(config.getOffset()));
* requestData.setLimit(String.valueOf(config.getLimit()));
*
* ArrayList<SortInformation> sorts = new ArrayList<SortInformation>();
*
* SortInformation si; for (SortInfo info : config.getSortInfo()) { si =
* new SortInformation(info.getSortField(), (info.getSortDir() == null)
* ? null : info.getSortDir() .toString()); sorts.add(si); }
* requestData.setSorts(sorts);
*
* ArrayList<FilterInformation> filters = new
* ArrayList<FilterInformation>(); FilterInformation fi;
*
* for (FilterConfig filterConfig : config.getFilters()) { fi = new
* FilterInformation(filterConfig.getField(), filterConfig.getType(),
* filterConfig.getComparison(), filterConfig.getValue());
* filters.add(fi); } requestData.setFilters(filters);
*
* SerializationStreamFactory streamFactory =
* (SerializationStreamFactory) GWT.create(RequestData.class);
* SerializationStreamWriter streamWriter =
* streamFactory.createStreamWriter(); try {
* streamWriter.writeObject(requestData); } catch
* (SerializationException e) { Log.error(e.getLocalizedMessage());
* e.printStackTrace(); return null; }
*
*
* return streamWriter.toString();
*/
requestData.setOffset(String.valueOf(config.getOffset())); Log.debug("Offset: " + config.getOffset());
requestData.setLimit(String.valueOf(config.getLimit())); Log.debug("Limit: " + config.getLimit());
ArrayList<SortInformation> sorts = new ArrayList<SortInformation>(); urlBuilder.clear();
SortInformation si; urlBuilder.addParameter(ServletParameters.OFFSET,
for (SortInfo info : config.getSortInfo()) { String.valueOf(config.getOffset()));
si = new SortInformation(info.getSortField(), urlBuilder.addParameter(ServletParameters.LIMIT,
(info.getSortDir() == null) ? null : info.getSortDir() String.valueOf(config.getLimit()));
.toString()); if(config.getSortInfo()!=null && !config.getSortInfo().isEmpty()){
sorts.add(si); SortInfo info = config.getSortInfo().get(0);
Log.debug("SortField: " + info.getSortField());
Log.debug("SortDir: " + info.getSortDir());
urlBuilder.addParameter(ServletParameters.SORTFIELD,
info.getSortField());
urlBuilder.addParameter(ServletParameters.SORTDIR, (info
.getSortDir() == null) ? null : info.getSortDir()
.toString());
} }
requestData.setSorts(sorts);
ArrayList<FilterInformation> filters = new ArrayList<FilterInformation>();
FilterInformation fi;
for (FilterConfig filterConfig : config.getFilters()) {
fi = new FilterInformation(filterConfig.getField(),
filterConfig.getType(), filterConfig.getComparison(),
filterConfig.getValue());
filters.add(fi);
}
requestData.setFilters(filters);
SerializationStreamFactory streamFactory = (SerializationStreamFactory) GWT.create(RequestData.class);
SerializationStreamWriter streamWriter = streamFactory.createStreamWriter();
try {
streamWriter.writeObject(requestData);
} catch (SerializationException e) {
Log.error(e.getLocalizedMessage());
e.printStackTrace();
return null;
}
return streamWriter.toString();
/* /*
* Log.debug("Offset: "+config.getOffset()); for (FilterConfig filterConfig : config.getFilters()) {
* Log.debug("Limit: "+config.getLimit()); Log.debug("FilterField: " + filterConfig.getField());
* Log.debug("FilterType: " + filterConfig.getType());
* Log.debug("FilterComparison: " + filterConfig.getComparison());
* urlBuilder.clear(); Log.debug("FilterValue: " + filterConfig.getValue());
*
* urlBuilder.addParameter(ServletParameters.OFFSET, urlBuilder.addParameter(ServletParameters.FILTERFIELD,
* String.valueOf(config.getOffset())); filterConfig.getField());
* urlBuilder.addParameter(ServletParameters.LIMIT, urlBuilder.addParameter(ServletParameters.FILTERTYPE,
* String.valueOf(config.getLimit())); filterConfig.getType());
* urlBuilder.addParameter(ServletParameters.FILTERCOMPARISON,
* for (SortInfo info:config.getSortInfo()) { filterConfig.getComparison());
* urlBuilder.addParameter(ServletParameters.FILTERVALUE,
* Log.debug("SortField: "+info.getSortField()); filterConfig.getValue());
* Log.debug("SortDir: "+info.getSortDir());
* urlBuilder.addParameter(ServletParameters.SORTFIELD, }*/
* info.getSortField());
* urlBuilder.addParameter(ServletParameters.SORTDIR, return urlBuilder.toString();
* (info.getSortDir()==null)?null:info.getSortDir().toString()); }
*
* for (FilterConfig filterConfig:config.getFilters()) {
* Log.debug("FilterField: "+filterConfig.getField());
* Log.debug("FilterType: "+filterConfig.getType());
* Log.debug("FilterComparison: "+filterConfig.getComparison());
* Log.debug("FilterValue: "+filterConfig.getValue());
*
* urlBuilder.addParameter(ServletParameters.FILTERFIELD,
* filterConfig.getField());
* urlBuilder.addParameter(ServletParameters.FILTERTYPE,
* filterConfig.getType());
* urlBuilder.addParameter(ServletParameters.FILTERCOMPARISON,
* filterConfig.getComparison());
* urlBuilder.addParameter(ServletParameters.FILTERVALUE,
* filterConfig.getValue());
*
* }
*
* return urlBuilder.toString();
*/
} }
} }

View File

@ -1,30 +1,19 @@
package org.gcube.portlets.user.tdwx.server; package org.gcube.portlets.user.tdwx.server;
import java.beans.XMLDecoder;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.Direction; import org.gcube.portlets.user.tdwx.server.datasource.Direction;
import org.gcube.portlets.user.tdwx.server.util.SessionUtil; import org.gcube.portlets.user.tdwx.server.util.SessionUtil;
import org.gcube.portlets.user.tdwx.shared.RequestData;
import org.gcube.portlets.user.tdwx.shared.ServletParameters; import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.SerializationStreamFactory;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
/** /**
* *
* @author "Giancarlo Panichi" <a * @author "Giancarlo Panichi" <a
@ -54,69 +43,70 @@ public class TabularDataXServlet extends HttpServlet {
try { try {
ObjectInputStream in = new ObjectInputStream(request.getInputStream()); /*
RequestData requestData=null; * ObjectInputStream in = new
try { * ObjectInputStream(request.getInputStream()); RequestData
requestData = (RequestData) in.readObject(); * requestData=null; try { requestData = (RequestData)
logger.debug("RequestData: "+requestData); * in.readObject(); logger.debug("RequestData: "+requestData); }
} catch (ClassNotFoundException e) { * catch (ClassNotFoundException e) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, * response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"ERROR-Error retreiving expression in request: "+e.getLocalizedMessage()); * "ERROR-Error retreiving expression in request: "
} * +e.getLocalizedMessage()); }
*
logger.debug(requestData.toString()); * logger.debug(requestData.toString());
*/
// TD SESSION ID // TD SESSION ID
String tdSessionIdParameter = request String tdSessionIdParameter = request
.getHeader(ServletParameters.TD_SESSION_ID); .getHeader(ServletParameters.TD_SESSION_ID);
logger.trace("tdSessionIdParameter: " + tdSessionIdParameter); logger.trace("tdSessionIdParameter: " + tdSessionIdParameter);
int tdSessionId = Integer.parseInt(tdSessionIdParameter); int tdSessionId = Integer.parseInt(tdSessionIdParameter);
/* // SORTING DIRECTION
* // SORTING DIRECTION String sortDirectionParameter = request String sortDirectionParameter = request
* .getParameter(ServletParameters.SORTDIR); .getParameter(ServletParameters.SORTDIR);
* log.trace("sortDirectionParameter: " + sortDirectionParameter); logger.trace("sortDirectionParameter: " + sortDirectionParameter);
* Direction direction = (sortDirectionParameter == null) ? Direction direction = (sortDirectionParameter == null) ? Direction.ASC
* Direction.ASC : Direction.valueOf(sortDirectionParameter); : Direction.valueOf(sortDirectionParameter);
*
* // SORTING COLUMN String sortColumn = request // SORTING COLUMN
* .getParameter(ServletParameters.SORTFIELD); String sortColumn = request
* log.trace("sortColumn: " + sortColumn); .getParameter(ServletParameters.SORTFIELD);
* logger.trace("sortColumn: " + sortColumn);
* // START
* String startParameter = request // START
* .getParameter(ServletParameters.OFFSET); String startParameter = request
* log.trace("startParameter: " + startParameter); int start = .getParameter(ServletParameters.OFFSET);
* Integer.parseInt(startParameter); logger.trace("startParameter: " + startParameter);
* int start = Integer.parseInt(startParameter);
* // LIMIT String limitParameter = request
* .getParameter(ServletParameters.LIMIT); // LIMIT
* log.trace("limitParameter: " + limitParameter); int limit = String limitParameter = request
* Integer.parseInt(limitParameter); .getParameter(ServletParameters.LIMIT);
* logger.trace("limitParameter: " + limitParameter);
* int limit = Integer.parseInt(limitParameter);
* DataSourceX dataSource = SessionUtil.getDataSource(
* request.getSession(), tdSessionId); String json =
* dataSource.getDataAsJSon(start, limit, sortColumn, direction);
*/
DataSourceX dataSource = SessionUtil.getDataSource( DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId); request.getSession(), tdSessionId);
int start=Integer.parseInt(requestData.getOffset()); String json = dataSource.getDataAsJSon(start, limit, sortColumn,
int limit=Integer.parseInt(requestData.getLimit()); direction);
ArrayList<SortInformation> sorts=requestData.getSorts();
Direction direction=Direction.ASC; /*DataSourceX dataSource = SessionUtil.getDataSource(
String sortColumn=null; request.getSession(), tdSessionId);
for(SortInformation sort:sorts){ int start = Integer.parseInt(requestData.getOffset());
direction = (sort.getSortDir() == null) ? int limit = Integer.parseInt(requestData.getLimit());
Direction.ASC : Direction.valueOf(sort.getSortDir()); ArrayList<SortInformation> sorts = requestData.getSorts();
sortColumn=sort.getSortField();
Direction direction = Direction.ASC;
String sortColumn = null;
for (SortInformation sort : sorts) {
direction = (sort.getSortDir() == null) ? Direction.ASC
: Direction.valueOf(sort.getSortDir());
sortColumn = sort.getSortField();
} }
String json = dataSource.getDataAsJSon(start, limit, sortColumn, String json = dataSource.getDataAsJSon(start, limit, sortColumn,
direction); direction);
*/
response.getOutputStream().write(json.getBytes()); response.getOutputStream().write(json.getBytes());
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
// logger.trace("JSON: "+json); // logger.trace("JSON: "+json);