Added Static Filter
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@98695 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
80e069d1d6
commit
e84e8df316
|
@ -34,6 +34,7 @@ import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle;
|
||||||
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
|
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
|
||||||
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
|
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
|
||||||
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
|
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.ColumnKey;
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnKey;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
|
||||||
|
@ -114,6 +115,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
|
|
||||||
protected ExtendedGridFilters<DataRow> gridFilters;
|
protected ExtendedGridFilters<DataRow> gridFilters;
|
||||||
|
|
||||||
|
protected ArrayList<StaticFilterInformation> staticFilters;
|
||||||
|
|
||||||
protected TableViewConfig tableViewConfig;
|
protected TableViewConfig tableViewConfig;
|
||||||
|
|
||||||
protected Menu contextMenu;
|
protected Menu contextMenu;
|
||||||
|
@ -188,6 +191,24 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
return tableDefinition;
|
return tableDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get static filters
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ArrayList<StaticFilterInformation> getStaticFilters() {
|
||||||
|
return staticFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set static filters
|
||||||
|
*
|
||||||
|
* @param staticFilters
|
||||||
|
*/
|
||||||
|
public void setStaticFilters(ArrayList<StaticFilterInformation> staticFilters) {
|
||||||
|
this.staticFilters = staticFilters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the selected row.
|
* Returns the selected row.
|
||||||
*
|
*
|
||||||
|
@ -246,6 +267,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -683,7 +705,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
|
|
||||||
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
|
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
|
||||||
builder);
|
builder);
|
||||||
proxy.setWriter(new PagingLoadUrlEncoder());
|
proxy.setWriter(new PagingLoadUrlEncoder(staticFilters));
|
||||||
|
|
||||||
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
|
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
|
||||||
proxy, reader) {
|
proxy, reader) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||||
|
|
||||||
import com.google.gwt.cell.client.AbstractCell;
|
import com.google.gwt.cell.client.AbstractCell;
|
||||||
import com.google.gwt.cell.client.Cell.Context;
|
|
||||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||||
import com.google.gwt.safecss.shared.SafeStyles;
|
import com.google.gwt.safecss.shared.SafeStyles;
|
||||||
import com.google.gwt.safecss.shared.SafeStylesBuilder;
|
import com.google.gwt.safecss.shared.SafeStylesBuilder;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||||
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
|
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.SortInformation;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
|
||||||
|
|
||||||
import com.allen_sauer.gwt.log.client.Log;
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
import com.sencha.gxt.data.shared.SortInfo;
|
import com.sencha.gxt.data.shared.SortInfo;
|
||||||
|
@ -28,6 +29,15 @@ public class PagingLoadUrlEncoder implements
|
||||||
|
|
||||||
// protected UrlBuilder urlBuilder = new UrlBuilder();
|
// protected UrlBuilder urlBuilder = new UrlBuilder();
|
||||||
protected RequestData requestData;
|
protected RequestData requestData;
|
||||||
|
protected ArrayList<StaticFilterInformation> staticFilters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param staticFilters
|
||||||
|
*/
|
||||||
|
public PagingLoadUrlEncoder(ArrayList<StaticFilterInformation> staticFilters){
|
||||||
|
this.staticFilters=staticFilters;
|
||||||
|
}
|
||||||
|
|
||||||
public String write(FilterPagingLoadConfig config) {
|
public String write(FilterPagingLoadConfig config) {
|
||||||
|
|
||||||
|
@ -58,6 +68,11 @@ public class PagingLoadUrlEncoder implements
|
||||||
}
|
}
|
||||||
requestData.setFilters(filters);
|
requestData.setFilters(filters);
|
||||||
|
|
||||||
|
if(staticFilters!=null){
|
||||||
|
requestData.setStaticFilters(staticFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log.debug("JSON request:"+requestData.toJsonObject());
|
Log.debug("JSON request:"+requestData.toJsonObject());
|
||||||
return requestData.toJsonObject();
|
return requestData.toJsonObject();
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.gcube.portlets.user.tdwx.server.util.SessionUtil;
|
||||||
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
|
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
|
||||||
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.gcube.portlets.user.tdwx.shared.SortInformation;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -113,7 +114,7 @@ public class TabularDataXServlet extends HttpServlet {
|
||||||
try {
|
try {
|
||||||
filters = jsonRequest.getJSONArray("filters");
|
filters = jsonRequest.getJSONArray("filters");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
logger.debug("sorts: " + e.getLocalizedMessage());
|
logger.debug("filters: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters != null) {
|
if (filters != null) {
|
||||||
|
@ -129,10 +130,32 @@ public class TabularDataXServlet extends HttpServlet {
|
||||||
logger.debug("Filters:" + filtersList.size());
|
logger.debug("Filters:" + filtersList.size());
|
||||||
|
|
||||||
|
|
||||||
|
//STATIC FILTERS
|
||||||
|
JSONArray staticFilters = null;
|
||||||
|
ArrayList<StaticFilterInformation> staticFiltersList=new ArrayList<StaticFilterInformation>();
|
||||||
|
try {
|
||||||
|
staticFilters = jsonRequest.getJSONArray("staticFilters");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
logger.debug("staticFilters: " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (staticFilters != null) {
|
||||||
|
for (int i = 0; i < staticFilters.length(); i++) {
|
||||||
|
JSONObject staticFilter = staticFilters.getJSONObject(i);
|
||||||
|
StaticFilterInformation sfi= new StaticFilterInformation(staticFilter.getString("columnName"),
|
||||||
|
staticFilter.getString("columnLocalId"),
|
||||||
|
staticFilter.getString("filterValue"));
|
||||||
|
staticFiltersList.add(sfi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.debug("StaticFilters:" + staticFiltersList.size());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DataSourceX dataSource = SessionUtil.getDataSource(
|
DataSourceX dataSource = SessionUtil.getDataSource(
|
||||||
request.getSession(), tdSessionId);
|
request.getSession(), tdSessionId);
|
||||||
String json = dataSource.getDataAsJSon(start, limit, sortColumn,
|
String json = dataSource.getDataAsJSon(start, limit, sortColumn,
|
||||||
direction, filtersList);
|
direction, filtersList, staticFiltersList);
|
||||||
|
|
||||||
|
|
||||||
response.getOutputStream().write(json.getBytes());
|
response.getOutputStream().write(json.getBytes());
|
||||||
|
|
|
@ -3,40 +3,50 @@ package org.gcube.portlets.user.tdwx.server.datasource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
|
import org.gcube.portlets.user.tdwx.shared.FilterInformation;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
|
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author "Giancarlo Panichi"
|
* @author "Giancarlo Panichi" <a
|
||||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface DataSourceX {
|
public interface DataSourceX {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the id of the {@link DataSourceXFactory} that have generated it.
|
* Returns the id of the {@link DataSourceXFactory} that have generated it.
|
||||||
|
*
|
||||||
* @return the {@link DataSourceXFactory} id.
|
* @return the {@link DataSourceXFactory} id.
|
||||||
*/
|
*/
|
||||||
public String getDataSourceFactoryId();
|
public String getDataSourceFactoryId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the table definition.
|
* Returns the table definition.
|
||||||
|
*
|
||||||
* @return a table definition.
|
* @return a table definition.
|
||||||
* @throws DataSourceXException if an error occurred retrieving the table definition.
|
* @throws DataSourceXException
|
||||||
|
* if an error occurred retrieving the table definition.
|
||||||
*/
|
*/
|
||||||
public TableDefinition getTableDefinition() throws DataSourceXException;
|
public TableDefinition getTableDefinition() throws DataSourceXException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the table data as JSON object.
|
* Retrieves the table data as JSON object.
|
||||||
|
*
|
||||||
* @param start the starting row index.
|
* @param start the starting row index.
|
||||||
* @param limit the number of rows after the starting index to retrieve.
|
* @param limit the number of rows after the starting index to retrieve.
|
||||||
* @param sortingColumn the column used for sorting.
|
* @param sortingColumn the column used for sorting.
|
||||||
* @param direction the sorting direction.
|
* @param direction the sorting direction.
|
||||||
|
* @param filters dynamic filters
|
||||||
|
* @param staticFilters static filters
|
||||||
* @return the JSON object as String.
|
* @return the JSON object as String.
|
||||||
* @throws DataSourceXException if an error occurred retrieving the table data.
|
* @throws DataSourceXException
|
||||||
|
* if an error occurred retrieving the table data.
|
||||||
*/
|
*/
|
||||||
public String getDataAsJSon(int start, int limit, String sortingColumn, Direction direction, ArrayList<FilterInformation> filters) throws DataSourceXException;
|
public String getDataAsJSon(int start, int limit, String sortingColumn,
|
||||||
|
Direction direction, ArrayList<FilterInformation> filters,
|
||||||
|
ArrayList<StaticFilterInformation> staticFilters)
|
||||||
|
throws DataSourceXException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class RequestData implements Serializable {
|
||||||
private String limit;
|
private String limit;
|
||||||
private ArrayList<SortInformation> sorts;
|
private ArrayList<SortInformation> sorts;
|
||||||
private ArrayList<FilterInformation> filters;
|
private ArrayList<FilterInformation> filters;
|
||||||
|
private ArrayList<StaticFilterInformation> staticFilters;
|
||||||
|
|
||||||
public RequestData() {
|
public RequestData() {
|
||||||
}
|
}
|
||||||
|
@ -52,10 +53,20 @@ public class RequestData implements Serializable {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayList<StaticFilterInformation> getStaticFilters() {
|
||||||
|
return staticFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStaticFilters(ArrayList<StaticFilterInformation> staticFilters) {
|
||||||
|
this.staticFilters = staticFilters;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RequestData [offset=" + offset + ", limit=" + limit
|
return "RequestData [offset=" + offset + ", limit=" + limit
|
||||||
+ ", sorts=" + sorts + ", filters=" + filters + "]";
|
+ ", sorts=" + sorts + ", filters=" + filters
|
||||||
|
+ ", staticFilters=" + staticFilters +"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,16 +112,40 @@ public class RequestData implements Serializable {
|
||||||
json.append("]");
|
json.append("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(staticFilters!=null && !staticFilters.isEmpty()){
|
||||||
|
json.append(",");
|
||||||
|
json.append(" \"staticFilters\": [");
|
||||||
|
boolean first=true;
|
||||||
|
for(StaticFilterInformation staticFilter:staticFilters){
|
||||||
|
if(first){
|
||||||
|
first=false;
|
||||||
|
} else{
|
||||||
|
json.append(",");
|
||||||
|
}
|
||||||
|
json.append("{ \"columnName\":\""+staticFilter.getColumnName()+"\" ," +
|
||||||
|
"\"columnLocalId\":\""+staticFilter.getColumnLocalId()+"\" ," +
|
||||||
|
"\"filterValue\": \""+staticFilter.getFilterValue()+"\" }");
|
||||||
|
|
||||||
|
}
|
||||||
|
json.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
json.append("}");
|
json.append("}");
|
||||||
/* "company": "ACME, Inc",
|
|
||||||
"partNumber": "7402-129",
|
|
||||||
"prices": [
|
/*
|
||||||
{ "minQty": 1, "price": 12.49 },
|
* { "limit": "200",
|
||||||
{ "minQty": 10, "price": 9.99 },
|
* "offset": "330",
|
||||||
{ "minQty": 50, "price": 7.99 }
|
* "filters": [
|
||||||
]
|
* { "filterField":"kqljyp" ,"filterType":"date" ,"filterComparison":"on" ,"filterValue": "1399370400000" },
|
||||||
|
* { "filterField":"kqasdp" ,"filterType":"date" ,"filterComparison":"on" ,"filterValue": "1399370400000" },
|
||||||
|
* ],
|
||||||
|
* "staticFilter: ["
|
||||||
|
* { "columnName:"kdsafd" ,"columnLocalId":"dsafadfacaseasdsafafe","filterValue":"10" }
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.shared;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter Information
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StaticFilterInformation implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 856712991956862922L;
|
||||||
|
|
||||||
|
private String columnName;
|
||||||
|
private String columnLocalId;
|
||||||
|
private String filterValue;
|
||||||
|
|
||||||
|
|
||||||
|
public StaticFilterInformation() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param columnLocalId
|
||||||
|
* @param filterValue
|
||||||
|
*/
|
||||||
|
public StaticFilterInformation(String columnName,String columnLocalId, String filterValue) {
|
||||||
|
this.columnName=columnName;
|
||||||
|
this.columnLocalId=columnLocalId;
|
||||||
|
this.filterValue=filterValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnLocalId() {
|
||||||
|
return columnLocalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumnLocalId(String columnLocalId) {
|
||||||
|
this.columnLocalId = columnLocalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilterValue() {
|
||||||
|
return filterValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilterValue(String filterValue) {
|
||||||
|
this.filterValue = filterValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnName() {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumnName(String columnName) {
|
||||||
|
this.columnName = columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "StaticFilterInformation [columnName=" + columnName
|
||||||
|
+ ", columnLocalId=" + columnLocalId + ", filterValue="
|
||||||
|
+ filterValue + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue