Added Inline Filter

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95015 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-18 17:57:57 +00:00 committed by Giancarlo Panichi
parent 2b9ce09353
commit f41062fa39
10 changed files with 614 additions and 111 deletions

View File

@ -27,6 +27,7 @@ import org.gcube.portlets.user.tdwx.client.model.grid.DataRowColumnConfig;
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowModelKeyProvider; import org.gcube.portlets.user.tdwx.client.model.grid.DataRowModelKeyProvider;
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowPagingReader; import org.gcube.portlets.user.tdwx.client.model.grid.DataRowPagingReader;
import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator; import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator;
import org.gcube.portlets.user.tdwx.client.model.util.FiltersGenerator;
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;
@ -51,13 +52,16 @@ import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.data.client.loader.HttpProxy; import com.sencha.gxt.data.client.loader.HttpProxy;
import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.event.StoreUpdateEvent; import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig; import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfigBean; import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.Loader;
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;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; 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.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.CheckChangeEvent;
import com.sencha.gxt.widget.core.client.event.CheckChangeEvent.CheckChangeHandler;
import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent; import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent;
import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderContextMenuHandler; import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderContextMenuHandler;
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent; import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent;
@ -67,9 +71,14 @@ 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.Grid;
import com.sencha.gxt.widget.core.client.grid.LiveGridView; import com.sencha.gxt.widget.core.client.grid.LiveGridView;
import com.sencha.gxt.widget.core.client.grid.LiveToolItem; import com.sencha.gxt.widget.core.client.grid.LiveToolItem;
import com.sencha.gxt.widget.core.client.grid.filters.AbstractGridFilters;
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
import com.sencha.gxt.widget.core.client.grid.filters.GridFilters;
import com.sencha.gxt.widget.core.client.menu.CheckMenuItem;
import com.sencha.gxt.widget.core.client.menu.Item; import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu; import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem; import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem;
import com.sencha.gxt.widget.core.client.selection.CellSelection; import com.sencha.gxt.widget.core.client.selection.CellSelection;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar; import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
@ -101,7 +110,7 @@ public class TabularDataXGridPanel extends ContentPanel {
protected DataRowPagingReader reader; protected DataRowPagingReader reader;
protected PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>> loader; protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected TableViewConfig tableViewConfig; protected TableViewConfig tableViewConfig;
@ -260,8 +269,8 @@ public class TabularDataXGridPanel extends ContentPanel {
.getCell()); .getCell());
DataRowColumnConfig<?> cSelected = (DataRowColumnConfig<?>) colSelected; DataRowColumnConfig<?> cSelected = (DataRowColumnConfig<?>) colSelected;
ColumnDefinition cdSelected = cSelected.getDefinition(); ColumnDefinition cdSelected = cSelected.getDefinition();
String cellValue = row String cellValue = row.getFieldAsText(cdSelected
.getFieldAsText(cdSelected.getColumnLocalId()); .getColumnLocalId());
String columnIdValue = row.getFieldAsText(columnIdSelected String columnIdValue = row.getFieldAsText(columnIdSelected
.getColumnLocalId()); .getColumnLocalId());
@ -293,8 +302,8 @@ public class TabularDataXGridPanel extends ContentPanel {
* @param columnLocalId * @param columnLocalId
*/ */
public void setVisibleOnlyColumn(String columnLocalId) { public void setVisibleOnlyColumn(String columnLocalId) {
Log.debug("setVisibleOnlyColumn: "+columnLocalId); Log.debug("setVisibleOnlyColumn: " + columnLocalId);
visibleOnlyColumn=columnLocalId; visibleOnlyColumn = columnLocalId;
} }
@ -303,11 +312,11 @@ public class TabularDataXGridPanel extends ContentPanel {
* @param columnModel * @param columnModel
* @return * @return
*/ */
protected ColumnModel<DataRow> checkOnlyColumn(ColumnModel<DataRow> columnModel){ protected ColumnModel<DataRow> checkOnlyColumn(
if (visibleOnlyColumn!=null && !visibleOnlyColumn.isEmpty()) { ColumnModel<DataRow> columnModel) {
if (visibleOnlyColumn != null && !visibleOnlyColumn.isEmpty()) {
Log.debug("setVisibleOnlyColumn: Grid not null"); Log.debug("setVisibleOnlyColumn: Grid not null");
List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns(); List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns();
List<ColumnConfig<DataRow, ?>> columnsNew = new ArrayList<ColumnConfig<DataRow, ?>>(); List<ColumnConfig<DataRow, ?>> columnsNew = new ArrayList<ColumnConfig<DataRow, ?>>();
@ -501,7 +510,8 @@ public class TabularDataXGridPanel extends ContentPanel {
@Override @Override
public void onHeaderMouseDown(HeaderMouseDownEvent event) { public void onHeaderMouseDown(HeaderMouseDownEvent event) {
Log.debug("HeaderMouseDownEvent :"+event.toDebugString()); Log.debug("HeaderMouseDownEvent :"
+ event.toDebugString());
if (event.getEvent().getButton() == NativeEvent.BUTTON_RIGHT) { if (event.getEvent().getButton() == NativeEvent.BUTTON_RIGHT) {
event.getEvent().stopPropagation(); event.getEvent().stopPropagation();
} else { } else {
@ -510,7 +520,8 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
}; };
}; }
;
grid.addHeaderMouseDownHandler(handler); grid.addHeaderMouseDownHandler(handler);
} }
} }
@ -557,23 +568,33 @@ public class TabularDataXGridPanel extends ContentPanel {
ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>( ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>(
columnsConfig); columnsConfig);
columnModel =checkOnlyColumn(columnModel); columnModel = checkOnlyColumn(columnModel);
if (grid == null) { if (grid == null) {
reader = new DataRowPagingReader(tableDefinition); reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata"; String path = GWT.getModuleBaseURL() + "tdwxdata";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
path); path);
builder.setHeader(ServletParameters.TD_SESSION_ID, builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId)); String.valueOf(tdSessionId));
HttpProxy<PagingLoadConfig> proxy = new HttpProxy<PagingLoadConfig>( HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder); builder);
proxy.setWriter(new PagingLoadUrlEncoder()); proxy.setWriter(new PagingLoadUrlEncoder());
loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>>( loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader); proxy, reader) {
@Override
protected FilterPagingLoadConfig newLoadConfig() {
return new FilterPagingLoadConfigBean();
}
};
loader.setRemoteSort(true); loader.setRemoteSort(true);
/*
* loader.addLoadHandler(new
* LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow,
* PagingLoadResult<DataRow>>( store));
*/
liveGridView = new ExtendedLiveGridView(); liveGridView = new ExtendedLiveGridView();
@ -587,8 +608,6 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.setLoader(loader); grid.setLoader(loader);
grid.setView(liveGridView); grid.setView(liveGridView);
// TODO disabled editing rows // TODO disabled editing rows
/* /*
* editing = new GridInlineEditing<DataRow>(grid); * editing = new GridInlineEditing<DataRow>(grid);
@ -600,12 +619,18 @@ public class TabularDataXGridPanel extends ContentPanel {
// numberer.initPlugin(grid); // numberer.initPlugin(grid);
// Filter
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel);
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
loader);
//Filter gridFilters.initPlugin(grid);
// GridFilters<DataRow> filters = new GridFilters(Loader<FilterPagingLoadConfig,?> loader) gridFilters.setLocal(false);
// filters.initPlugin(grid); Log.debug("Filters: " + filters.size());
// filters.setLocal(false); for (Filter<DataRow, ?> filterGeneric : filters) {
// filters.addFilter(lastFilter); gridFilters.addFilter(filterGeneric);
}
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
@ -655,8 +680,8 @@ public class TabularDataXGridPanel extends ContentPanel {
// TODO workaround: the loader is called only if the scroll bar is // TODO workaround: the loader is called only if the scroll bar is
// in the middle // in the middle
if (loader.getOffset() == 0) if (loader.getOffset() == 0)
loader.load(new PagingLoadConfigBean(0, liveGridView // loader.load();
.getCacheSize())); loader.load(0, liveGridView.getCacheSize());
} }
if (tableViewConfig != null) { if (tableViewConfig != null) {
@ -722,6 +747,8 @@ public class TabularDataXGridPanel extends ContentPanel {
menu.addSelectionHandler(handlerHeaderContextMenu); menu.addSelectionHandler(handlerHeaderContextMenu);
Log.debug("Adding Items to menu"); Log.debug("Adding Items to menu");
SeparatorMenuItem separatorItem = new SeparatorMenuItem();
menu.add(separatorItem);
for (MenuItem m : headerColumnMenuItems) { for (MenuItem m : headerColumnMenuItems) {
menu.add(m); menu.add(m);
} }
@ -732,7 +759,6 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.addHeaderContextMenuHandler(headerContextMenuHandler); grid.addHeaderContextMenuHandler(headerContextMenuHandler);
Log.debug("Header Column Menu Added"); Log.debug("Header Column Menu Added");
} }
/** /**
@ -789,4 +815,59 @@ public class TabularDataXGridPanel extends ContentPanel {
*/ */
}; };
protected class ExtendedGridFilters<M> extends GridFilters<M> {
private Menu filterMenu;
private SeparatorMenuItem separatorItem;
private CheckMenuItem checkFilterItem;
/**
* Creates grid filters to be applied remotely. See
* {@link AbstractGridFilters#AbstractGridFilters(Loader)} for more
* information.
*
* @param loader
* the remote loader
*/
public ExtendedGridFilters(Loader<FilterPagingLoadConfig, ?> loader) {
super(loader);
}
@Override
protected void onContextMenu(HeaderContextMenuEvent event) {
int column = event.getColumnIndex();
if (separatorItem == null) {
separatorItem = new SeparatorMenuItem();
}
separatorItem.removeFromParent();
if (checkFilterItem == null) {
checkFilterItem = new CheckMenuItem("Inline Filter");
checkFilterItem
.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {
@Override
public void onCheckChange(
CheckChangeEvent<CheckMenuItem> event) {
onCheckChange(event);
}
});
}
checkFilterItem.setData("index", column);
Filter<M, ?> f = getFilter(grid.getColumnModel().getColumn(column)
.getValueProvider().getPath());
if (f != null) {
filterMenu = f.getMenu();
checkFilterItem.setChecked(f.isActive(), true);
checkFilterItem.setSubMenu(filterMenu);
Menu menu = event.getMenu();
menu.add(separatorItem);
menu.add(checkFilterItem);
}
}
}
} }

View File

@ -12,8 +12,8 @@ import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
/** /**
* *
* @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>
* *
* @param <N> * @param <N>
*/ */
@ -22,7 +22,8 @@ public class DataRowColumnConfig<N> extends ColumnConfig<DataRow, N> {
protected ColumnDefinition definition; protected ColumnDefinition definition;
public DataRowColumnConfig(ColumnDefinition definition) { public DataRowColumnConfig(ColumnDefinition definition) {
super(new DataRowValueProvider<N>(definition.getKey()), definition.getWidth(), definition.getLabel()); super(new DataRowValueProvider<N>(definition.getKey()), definition
.getWidth(), definition.getLabel());
this.definition = definition; this.definition = definition;
} }
@ -42,4 +43,6 @@ public class DataRowColumnConfig<N> extends ColumnConfig<DataRow, N> {
public Cell<N> getCell() { public Cell<N> getCell() {
return super.getCell(); return super.getCell();
} }
} }

View File

@ -30,6 +30,8 @@ import com.sencha.gxt.widget.core.client.grid.editing.GridInlineEditing;
*/ */
public class ColumnConfigGenerator { public class ColumnConfigGenerator {
public static DataRowColumnConfig<?> generateConfiguration( public static DataRowColumnConfig<?> generateConfiguration(
ColumnDefinition columnDefinition) { ColumnDefinition columnDefinition) {
DataRowColumnConfig<?> columnConfig = null; DataRowColumnConfig<?> columnConfig = null;
@ -123,6 +125,7 @@ public class ColumnConfigGenerator {
return columnConfig; return columnConfig;
} }
protected static <T> DataRowColumnConfig<T> create( protected static <T> DataRowColumnConfig<T> create(
ColumnDefinition columnDefinition) { ColumnDefinition columnDefinition) {
return new DataRowColumnConfig<T>(columnDefinition); return new DataRowColumnConfig<T>(columnDefinition);
@ -189,4 +192,6 @@ public class ColumnConfigGenerator {
} }
} }
} }

View File

@ -0,0 +1,112 @@
package org.gcube.portlets.user.tdwx.client.model.util;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowColumnConfig;
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
import org.gcube.portlets.user.tdwx.shared.model.ValueType;
import com.allen_sauer.gwt.log.client.Log;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.widget.core.client.form.NumberPropertyEditor;
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.filters.BooleanFilter;
import com.sencha.gxt.widget.core.client.grid.filters.DateFilter;
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
import com.sencha.gxt.widget.core.client.grid.filters.NumericFilter;
import com.sencha.gxt.widget.core.client.grid.filters.StringFilter;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class FiltersGenerator {
public static ArrayList<Filter<DataRow, ?>> generate(
ColumnModel<DataRow> columnModel) {
ArrayList<Filter<DataRow, ?>> filters = new ArrayList<Filter<DataRow, ?>>();
for (ColumnConfig<DataRow, ?> columnConfig : columnModel.getColumns()) {
DataRowColumnConfig<?> dataRowColConfig = (DataRowColumnConfig<?>) columnConfig;
if (dataRowColConfig != null) {
if (dataRowColConfig.getDefinition() != null
&& dataRowColConfig.getDefinition().getValueType() != null) {
ValueType vt = dataRowColConfig.getDefinition()
.getValueType();
Log.debug("DataRowColConfig: " + vt);
switch (vt) {
case BOOLEAN:
@SuppressWarnings("unchecked")
BooleanFilter<DataRow> bFilt = new BooleanFilter<DataRow>(
(ValueProvider<DataRow, Boolean>) dataRowColConfig
.getValueProvider());
filters.add(bFilt);
break;
case DATE:
@SuppressWarnings("unchecked")
DateFilter<DataRow> dateFilt = new DateFilter<DataRow>(
(ValueProvider<DataRow, Date>) dataRowColConfig
.getValueProvider());
filters.add(dateFilt);
break;
case DOUBLE:
@SuppressWarnings("unchecked")
NumericFilter<DataRow, Double> doubleFilt = new NumericFilter<DataRow, Double>(
(ValueProvider<DataRow, Double>) dataRowColConfig
.getValueProvider(),
new NumberPropertyEditor.DoublePropertyEditor());
filters.add(doubleFilt);
break;
case FLOAT:
@SuppressWarnings("unchecked")
NumericFilter<DataRow, Float> floatFilt = new NumericFilter<DataRow, Float>(
(ValueProvider<DataRow, Float>) dataRowColConfig
.getValueProvider(),
new NumberPropertyEditor.FloatPropertyEditor());
filters.add(floatFilt);
break;
case INTEGER:
@SuppressWarnings("unchecked")
NumericFilter<DataRow, Integer> integerFilt = new NumericFilter<DataRow, Integer>(
(ValueProvider<DataRow, Integer>) dataRowColConfig
.getValueProvider(),
new NumberPropertyEditor.IntegerPropertyEditor());
filters.add(integerFilt);
break;
case LONG:
@SuppressWarnings("unchecked")
NumericFilter<DataRow, Long> longFilt = new NumericFilter<DataRow, Long>(
(ValueProvider<DataRow, Long>) dataRowColConfig
.getValueProvider(),
new NumberPropertyEditor.LongPropertyEditor());
filters.add(longFilt);
break;
case STRING:
@SuppressWarnings("unchecked")
StringFilter<DataRow> stringFilt = new StringFilter<DataRow>(
(ValueProvider<DataRow, String>) dataRowColConfig
.getValueProvider());
filters.add(stringFilt);
break;
default:
break;
}
} else {
Log.debug("DataRowColConfig: ValueType NULL");
}
} else {
Log.debug("DataRowColConfig: NULL");
}
}
return filters;
}
}

View File

@ -3,42 +3,118 @@
*/ */
package org.gcube.portlets.user.tdwx.client.util; package org.gcube.portlets.user.tdwx.client.util;
import org.gcube.portlets.user.tdwx.shared.ServletParameters; 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.SortInformation;
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.PagingLoadConfig; import com.sencha.gxt.data.shared.loader.FilterConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.writer.DataWriter; import com.sencha.gxt.data.shared.writer.DataWriter;
/** /**
* *
* @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 class PagingLoadUrlEncoder implements DataWriter<PagingLoadConfig, String> { public class PagingLoadUrlEncoder implements
DataWriter<FilterPagingLoadConfig, String> {
protected UrlBuilder urlBuilder = new UrlBuilder(); protected UrlBuilder urlBuilder = new UrlBuilder();
protected RequestData requestData;
public String write(FilterPagingLoadConfig config) {
requestData = new RequestData();
public String write(PagingLoadConfig config) { requestData.setOffset(String.valueOf(config.getOffset()));
requestData.setLimit(String.valueOf(config.getLimit()));
System.out.println("Offset: "+config.getOffset()); ArrayList<SortInformation> sorts = new ArrayList<SortInformation>();
System.out.println("Limit: "+config.getLimit());
urlBuilder.clear(); 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);
urlBuilder.addParameter(ServletParameters.OFFSET, String.valueOf(config.getOffset())); ArrayList<FilterInformation> filters = new ArrayList<FilterInformation>();
urlBuilder.addParameter(ServletParameters.LIMIT, String.valueOf(config.getLimit())); FilterInformation fi;
for (SortInfo info:config.getSortInfo()) { for (FilterConfig filterConfig : config.getFilters()) {
fi = new FilterInformation(filterConfig.getField(),
filterConfig.getType(), filterConfig.getComparison(),
filterConfig.getValue());
filters.add(fi);
}
requestData.setFilters(filters);
System.out.println("SORTFIELD: "+info.getSortField()); SerializationStreamFactory streamFactory = (SerializationStreamFactory) GWT.create(RequestData.class);
System.out.println("SORTDIR: "+info.getSortDir()); SerializationStreamWriter streamWriter = streamFactory.createStreamWriter();
urlBuilder.addParameter(ServletParameters.SORTFIELD, info.getSortField()); try {
urlBuilder.addParameter(ServletParameters.SORTDIR, (info.getSortDir()==null)?null:info.getSortDir().toString()); streamWriter.writeObject(requestData);
} catch (SerializationException e) {
Log.error(e.getLocalizedMessage());
e.printStackTrace();
return null;
} }
return urlBuilder.toString();
}
return streamWriter.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()));
*
* for (SortInfo info:config.getSortInfo()) {
*
* 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());
*
* 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,42 @@
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" * @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 class TabularDataXServlet extends HttpServlet { public class TabularDataXServlet extends HttpServlet {
private static final long serialVersionUID = 3995054634540860599L; private static final long serialVersionUID = 3995054634540860599L;
protected Logger log = LoggerFactory.getLogger(TabularDataXServlet.class); protected Logger logger = LoggerFactory
.getLogger(TabularDataXServlet.class);
protected void doPost(HttpServletRequest req, HttpServletResponse resp) protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { throws ServletException, IOException {
@ -38,50 +50,80 @@ public class TabularDataXServlet extends HttpServlet {
protected void handleRequest(HttpServletRequest request, protected void handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { HttpServletResponse response) throws ServletException, IOException {
log.debug("TabularDataServlet handleRequest"); logger.debug("TabularDataServlet handleRequest");
try { 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 // TD SESSION ID
String tdSessionIdParameter = request String tdSessionIdParameter = request
.getHeader(ServletParameters.TD_SESSION_ID); .getHeader(ServletParameters.TD_SESSION_ID);
log.trace("tdSessionIdParameter: " + tdSessionIdParameter); logger.trace("tdSessionIdParameter: " + tdSessionIdParameter);
int tdSessionId = Integer.parseInt(tdSessionIdParameter); int tdSessionId = Integer.parseInt(tdSessionIdParameter);
// SORTING DIRECTION /*
String sortDirectionParameter = request * // SORTING DIRECTION String sortDirectionParameter = request
.getParameter(ServletParameters.SORTDIR); * .getParameter(ServletParameters.SORTDIR);
log.trace("sortDirectionParameter: " + sortDirectionParameter); * log.trace("sortDirectionParameter: " + sortDirectionParameter);
Direction direction = (sortDirectionParameter == null) ? Direction.ASC * Direction direction = (sortDirectionParameter == null) ?
: Direction.valueOf(sortDirectionParameter); * Direction.ASC : Direction.valueOf(sortDirectionParameter);
*
// SORTING COLUMN * // SORTING COLUMN String sortColumn = request
String sortColumn = request * .getParameter(ServletParameters.SORTFIELD);
.getParameter(ServletParameters.SORTFIELD); * log.trace("sortColumn: " + sortColumn);
log.trace("sortColumn: " + sortColumn); *
* // START
// START * String startParameter = request
String startParameter = request * .getParameter(ServletParameters.OFFSET);
.getParameter(ServletParameters.OFFSET); * log.trace("startParameter: " + startParameter); int start =
log.trace("startParameter: " + startParameter); * Integer.parseInt(startParameter);
int start = Integer.parseInt(startParameter); *
* // LIMIT String limitParameter = request
// LIMIT * .getParameter(ServletParameters.LIMIT);
String limitParameter = request * log.trace("limitParameter: " + limitParameter); int limit =
.getParameter(ServletParameters.LIMIT); * Integer.parseInt(limitParameter);
log.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());
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, 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);
log.trace("Response sent (" + json.length() + " bytes)"); logger.trace("Response sent (" + json.length() + " bytes)");
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing the json data request", e); logger.error("Error processing the json data request", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Error processing the json data request: " + e.getMessage()); "Error processing the json data request: " + e.getMessage());
return; return;

View File

@ -0,0 +1,70 @@
package org.gcube.portlets.user.tdwx.shared;
import java.io.Serializable;
/**
* Filter Information
*
* @author "Giancarlo Panichi"
*
*/
public class FilterInformation implements Serializable {
private static final long serialVersionUID = 856712991956862922L;
private String filterField;
private String filterType;
private String filterComparison;
private String filterValue;
public FilterInformation() {
}
public FilterInformation(String filterField, String filterType,
String filterComparison, String filterValue) {
this.filterField = filterField;
this.filterType = filterType;
this.filterComparison = filterComparison;
this.filterValue = filterValue;
}
public String getFilerField() {
return filterField;
}
public void setFilerField(String filerField) {
this.filterField = filerField;
}
public String getFilterType() {
return filterType;
}
public void setFilterType(String filterType) {
this.filterType = filterType;
}
public String getFilterComparison() {
return filterComparison;
}
public void setFilterComparison(String filterComparison) {
this.filterComparison = filterComparison;
}
public String getFilterValue() {
return filterValue;
}
public void setFilterValue(String filterValue) {
this.filterValue = filterValue;
}
@Override
public String toString() {
return "FilterInformation [filterField=" + filterField
+ ", filterType=" + filterType + ", filterComparison="
+ filterComparison + ", filterValue=" + filterValue + "]";
}
}

View File

@ -0,0 +1,61 @@
package org.gcube.portlets.user.tdwx.shared;
import java.io.Serializable;
import java.util.ArrayList;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class RequestData implements Serializable {
private static final long serialVersionUID = -7854462973039253712L;
private String offset;
private String limit;
private ArrayList<SortInformation> sorts;
private ArrayList<FilterInformation> filters;
public RequestData() {
}
public String getOffset() {
return offset;
}
public void setOffset(String offset) {
this.offset = offset;
}
public String getLimit() {
return limit;
}
public void setLimit(String limit) {
this.limit = limit;
}
public ArrayList<SortInformation> getSorts() {
return sorts;
}
public void setSorts(ArrayList<SortInformation> sorts) {
this.sorts = sorts;
}
public ArrayList<FilterInformation> getFilters() {
return filters;
}
public void setFilters(ArrayList<FilterInformation> filters) {
this.filters = filters;
}
@Override
public String toString() {
return "RequestData [offset=" + offset + ", limit=" + limit
+ ", sorts=" + sorts + ", filters=" + filters + "]";
}
}

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.portlets.user.tdwx.shared; package org.gcube.portlets.user.tdwx.shared;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi"
@ -17,5 +18,9 @@ public class ServletParameters {
public static final String SORTDIR = "sortDir"; public static final String SORTDIR = "sortDir";
public static final String TD_SESSION_ID = "tdSessionId"; public static final String TD_SESSION_ID = "tdSessionId";
public static final String FILTERFIELD="filerField";
public static final String FILTERTYPE="filterType";
public static final String FILTERCOMPARISON="filterComparison";
public static final String FILTERVALUE="filterValue";
} }

View File

@ -0,0 +1,48 @@
package org.gcube.portlets.user.tdwx.shared;
import java.io.Serializable;
/**
* Sort Information of column
*
* @author "Giancarlo Panichi"
*
*/
public class SortInformation implements Serializable {
private static final long serialVersionUID = 3030241316222415997L;
private String sortField;
private String sortDir;
public SortInformation() {
}
public SortInformation(String sortField, String sortDir) {
this.sortField = sortField;
this.sortDir = sortDir;
}
public String getSortField() {
return sortField;
}
public void setSortField(String sortField) {
this.sortField = sortField;
}
public String getSortDir() {
return sortDir;
}
public void setSortDir(String sortDir) {
this.sortDir = sortDir;
}
@Override
public String toString() {
return "SortInformation [sortField=" + sortField + ", sortDir="
+ sortDir + "]";
}
}