Added Inline Filter

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95236 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-29 17:43:55 +00:00 committed by Giancarlo Panichi
parent 22107f0e32
commit 696e4bf269
9 changed files with 304 additions and 152 deletions

View File

@ -104,6 +104,13 @@
<scope>provided</scope>
</dependency>
<!-- JSON
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency> -->
<!-- LOGGING -->
<dependency>
<groupId>com.allen-sauer.gwt.log</groupId>

View File

@ -2,7 +2,8 @@
<module rename-to='TabularDataWidgetX'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Other module inherits -->
<inherits name='com.sencha.gxt.ui.GXT' />

View File

@ -54,9 +54,8 @@ import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
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.PagingLoader;
import com.sencha.gxt.widget.core.client.ContentPanel;
@ -112,7 +111,7 @@ public class TabularDataXGridPanel extends ContentPanel {
protected DataRowPagingReader reader;
protected PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected TableViewConfig tableViewConfig;
@ -576,11 +575,13 @@ public class TabularDataXGridPanel extends ContentPanel {
reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
path);
builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId));
/*HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
//builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder());
@ -590,27 +591,25 @@ public class TabularDataXGridPanel extends ContentPanel {
protected FilterPagingLoadConfig newLoadConfig() {
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.addLoadHandler(new
* LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow,
* PagingLoadResult<DataRow>>( store));
* 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.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow, PagingLoadResult<DataRow>>(
store));
liveGridView = new ExtendedLiveGridView();
// liveGridView.setRowHeight(19);
@ -635,7 +634,8 @@ public class TabularDataXGridPanel extends ContentPanel {
// numberer.initPlugin(grid);
// Filter
/*ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel);
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
loader);
@ -645,8 +645,9 @@ public class TabularDataXGridPanel extends ContentPanel {
Log.debug("Filters: " + filters.size());
for (Filter<DataRow, ?> filterGeneric : filters) {
gridFilters.addFilter(filterGeneric);
}*/
}
//
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
ToolBar toolBar = new ToolBar();
@ -864,7 +865,9 @@ public class TabularDataXGridPanel extends ContentPanel {
@Override
public void onCheckChange(
CheckChangeEvent<CheckMenuItem> event) {
onCheckChange(event);
onCheckChangeExt(event);
}
});
}
@ -883,6 +886,13 @@ public class TabularDataXGridPanel extends ContentPanel {
menu.add(checkFilterItem);
}
}
protected void onCheckChangeExt(CheckChangeEvent<CheckMenuItem> event) {
getMenuFilter(event).setActive(event.getItem().isChecked(), false);
}
}
}

View File

@ -3,13 +3,16 @@
*/
package org.gcube.portlets.user.tdwx.client.util;
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.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation;
import com.allen_sauer.gwt.log.client.Log;
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.PagingLoadConfig;
import com.sencha.gxt.data.shared.writer.DataWriter;
/**
@ -19,86 +22,88 @@ import com.sencha.gxt.data.shared.writer.DataWriter;
*
*/
public class PagingLoadUrlEncoder implements
DataWriter<PagingLoadConfig, String> {
// DataWriter<PagingLoadConfig, String> {
//DataWriter<FilterPagingLoadConfig, String> {
DataWriter<FilterPagingLoadConfig, String> {
protected UrlBuilder urlBuilder = new UrlBuilder();
// protected UrlBuilder urlBuilder = new UrlBuilder();
protected RequestData requestData;
public String write(PagingLoadConfig config) {
public String write(FilterPagingLoadConfig config) {
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);
Log.debug("JSON request:"+requestData.toJsonObject());
return requestData.toJsonObject();
/*
* requestData = new RequestData();
* Log.debug("Offset: " + config.getOffset()); Log.debug("Limit: " +
* config.getLimit());
*
* requestData.setOffset(String.valueOf(config.getOffset()));
* requestData.setLimit(String.valueOf(config.getLimit()));
* urlBuilder.clear();
*
* 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();
* urlBuilder.addParameter(ServletParameters.OFFSET,
* String.valueOf(config.getOffset()));
* urlBuilder.addParameter(ServletParameters.LIMIT,
* String.valueOf(config.getLimit())); if(config.getSortInfo()!=null &&
* !config.getSortInfo().isEmpty()){ 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()); }
*/
Log.debug("Offset: " + config.getOffset());
Log.debug("Limit: " + config.getLimit());
urlBuilder.clear();
urlBuilder.addParameter(ServletParameters.OFFSET,
String.valueOf(config.getOffset()));
urlBuilder.addParameter(ServletParameters.LIMIT,
String.valueOf(config.getLimit()));
if(config.getSortInfo()!=null && !config.getSortInfo().isEmpty()){
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());
}
/*
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());
* 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());
*
* }
*/
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();
// return urlBuilder.toString();
}
}

View File

@ -1,8 +1,12 @@
package org.gcube.portlets.user.tdwx.server;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -10,7 +14,12 @@ import javax.servlet.http.HttpServletResponse;
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.util.SessionUtil;
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,70 +52,127 @@ public class TabularDataXServlet extends HttpServlet {
try {
/*
* ObjectInputStream in = new
* ObjectInputStream(request.getInputStream()); RequestData
* requestData=null; try { requestData = (RequestData)
* in.readObject(); logger.debug("RequestData: "+requestData); }
* catch (ClassNotFoundException e) {
* response.sendError(HttpServletResponse.SC_BAD_REQUEST,
* "ERROR-Error retreiving expression in request: "
* +e.getLocalizedMessage()); }
*
* logger.debug(requestData.toString());
*/
// TD SESSION ID
String tdSessionIdParameter = request
.getHeader(ServletParameters.TD_SESSION_ID);
logger.trace("tdSessionIdParameter: " + tdSessionIdParameter);
int tdSessionId = Integer.parseInt(tdSessionIdParameter);
// SORTING DIRECTION
String sortDirectionParameter = request
.getParameter(ServletParameters.SORTDIR);
logger.trace("sortDirectionParameter: " + sortDirectionParameter);
Direction direction = (sortDirectionParameter == null) ? Direction.ASC
: Direction.valueOf(sortDirectionParameter);
ServletInputStream in = request.getInputStream();
InputStreamReader buffIn = new InputStreamReader(in);
char[] buffer = new char[1024];
int n = 0;
StringWriter out = new StringWriter();
// SORTING COLUMN
String sortColumn = request
.getParameter(ServletParameters.SORTFIELD);
logger.trace("sortColumn: " + sortColumn);
while (-1 != (n = buffIn.read(buffer))) {
out.write(buffer, 0, n);
}
;
logger.debug("Stream: " + out);
// START
String startParameter = request
.getParameter(ServletParameters.OFFSET);
logger.trace("startParameter: " + startParameter);
int start = Integer.parseInt(startParameter);
JSONObject jsonRequest = new JSONObject(out.toString());
logger.debug("JSON request:" + jsonRequest.toString());
int limit = jsonRequest.getInt("limit");
int start = jsonRequest.getInt("offset");
// LIMIT
String limitParameter = request
.getParameter(ServletParameters.LIMIT);
logger.trace("limitParameter: " + limitParameter);
int limit = Integer.parseInt(limitParameter);
logger.debug("Start: " + start + " Limit:" + limit);
//SORT
JSONArray sorts = null;
SortInformation sortInfo = null;
try {
sorts = jsonRequest.getJSONArray("sorts");
} catch (JSONException e) {
logger.debug("sorts: " + e.getLocalizedMessage());
}
if (sorts != null) {
for (int i = 0; i < sorts.length(); i++) {
JSONObject sort = sorts.getJSONObject(i);
sortInfo = new SortInformation(sort.getString("sortField"),
sort.getString("sortDir"));
}
}
logger.debug("SortInformation:" + sortInfo);
Direction direction;
String sortColumn = null;
if (sortInfo == null) {
direction = Direction.ASC;
} else {
direction = sortInfo.getSortDir().compareTo("ASC") == 0 ? Direction.ASC
: Direction.DESC;
sortColumn = sortInfo.getSortField();
}
//FILTERS
JSONArray filters = null;
ArrayList<FilterInformation> filtersList=new ArrayList<FilterInformation>();
try {
filters = jsonRequest.getJSONArray("filters");
} catch (JSONException e) {
logger.debug("sorts: " + e.getLocalizedMessage());
}
if (filters != null) {
for (int i = 0; i < filters.length(); i++) {
JSONObject filter = filters.getJSONObject(i);
FilterInformation fi= new FilterInformation(filter.getString("filterField"),
filter.getString("filterType"),
filter.getString("filterComparison"),
filter.getString("filterValue"));
filtersList.add(fi);
}
}
logger.debug("Filters:" + filtersList.size());
/*
* // SORTING DIRECTION String sortDirectionParameter = request
* .getParameter(ServletParameters.SORTDIR);
* logger.trace("sortDirectionParameter: " +
* sortDirectionParameter); Direction direction =
* (sortDirectionParameter == null) ? Direction.ASC :
* Direction.valueOf(sortDirectionParameter);
*
* // SORTING COLUMN String sortColumn = request
* .getParameter(ServletParameters.SORTFIELD);
* logger.trace("sortColumn: " + sortColumn);
*
* // START String startParameter = request
* .getParameter(ServletParameters.OFFSET);
* logger.trace("startParameter: " + startParameter); int start =
* Integer.parseInt(startParameter);
*
* // LIMIT String limitParameter = request
* .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);
direction, filtersList);
/*DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId);
int start = Integer.parseInt(requestData.getOffset());
int limit = Integer.parseInt(requestData.getLimit());
ArrayList<SortInformation> sorts = requestData.getSorts();
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,
direction);
*/
/*
* DataSourceX dataSource = SessionUtil.getDataSource(
* request.getSession(), tdSessionId); int start =
* Integer.parseInt(requestData.getOffset()); int limit =
* Integer.parseInt(requestData.getLimit());
* ArrayList<SortInformation> sorts = requestData.getSorts();
*
* 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,
* direction);
*/
response.getOutputStream().write(json.getBytes());
response.setStatus(HttpServletResponse.SC_OK);
// logger.trace("JSON: "+json);

View File

@ -1,5 +1,8 @@
package org.gcube.portlets.user.tdwx.server.datasource;
import java.util.ArrayList;
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
/**
@ -32,6 +35,6 @@ public interface DataSourceX {
* @return the JSON object as String.
* @throws DataSourceXException if an error occurred retrieving the table data.
*/
public String getDataAsJSon(int start, int limit, String sortingColumn, Direction direction) throws DataSourceXException;
public String getDataAsJSon(int start, int limit, String sortingColumn, Direction direction, ArrayList<FilterInformation> filters) throws DataSourceXException;
}

View File

@ -28,12 +28,12 @@ public class FilterInformation implements Serializable {
this.filterValue = filterValue;
}
public String getFilerField() {
public String getFilterField() {
return filterField;
}
public void setFilerField(String filerField) {
this.filterField = filerField;
public void setFilterField(String filterField) {
this.filterField = filterField;
}
public String getFilterType() {

View File

@ -57,5 +57,65 @@ public class RequestData implements Serializable {
return "RequestData [offset=" + offset + ", limit=" + limit
+ ", sorts=" + sorts + ", filters=" + filters + "]";
}
public String toJsonObject(){
StringBuilder json=new StringBuilder();
json.append("{"+
" \"limit\": \""+limit+"\","+
" \"offset\": \""+offset+"\"");
if(sorts!=null && !sorts.isEmpty()){
json.append(",");
json.append(" \"sorts\": [");
boolean first=true;
for(SortInformation sort:sorts){
if(first){
first=false;
} else{
json.append(",");
}
json.append("{ \"sortDir\":\""+sort.getSortDir()+"\" ," +
"\"sortField\": \""+sort.getSortField()+"\" }");
}
json.append("]");
}
if(filters!=null && !filters.isEmpty()){
json.append(",");
json.append(" \"filters\": [");
boolean first=true;
for(FilterInformation filter:filters){
if(first){
first=false;
} else{
json.append(",");
}
json.append("{ \"filterField\":\""+filter.getFilterField()+"\" ," +
"\"filterType\":\""+filter.getFilterType()+"\" ," +
"\"filterComparison\":\""+filter.getFilterComparison()+"\" ," +
"\"filterValue\": \""+filter.getFilterValue()+"\" }");
}
json.append("]");
}
json.append("}");
/* "company": "ACME, Inc",
"partNumber": "7402-129",
"prices": [
{ "minQty": 1, "price": 12.49 },
{ "minQty": 10, "price": 9.99 },
{ "minQty": 50, "price": 7.99 }
]
*/
return json.toString();
}
}

View File

@ -2,12 +2,12 @@
<module rename-to='TabularDataWidgetX'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Other module inherits -->
<inherits name='com.sencha.gxt.ui.GXT' />
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name='org.gcube.portlets.user.td.widgetcommonevent.WidgetCommonEvent' />
<!-- Specify the paths for translatable code -->