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:
parent
2b9ce09353
commit
f41062fa39
|
@ -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.DataRowPagingReader;
|
||||
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.PagingLoadUrlEncoder;
|
||||
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.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
|
||||
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
|
||||
import com.sencha.gxt.data.shared.loader.PagingLoadConfigBean;
|
||||
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
|
||||
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.PagingLoader;
|
||||
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.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.HeaderContextMenuHandler;
|
||||
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.LiveGridView;
|
||||
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.Menu;
|
||||
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.toolbar.ToolBar;
|
||||
|
||||
|
@ -101,7 +110,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
protected DataRowPagingReader reader;
|
||||
|
||||
protected PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>> loader;
|
||||
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
|
||||
|
||||
protected TableViewConfig tableViewConfig;
|
||||
|
||||
|
@ -260,8 +269,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
.getCell());
|
||||
DataRowColumnConfig<?> cSelected = (DataRowColumnConfig<?>) colSelected;
|
||||
ColumnDefinition cdSelected = cSelected.getDefinition();
|
||||
String cellValue = row
|
||||
.getFieldAsText(cdSelected.getColumnLocalId());
|
||||
String cellValue = row.getFieldAsText(cdSelected
|
||||
.getColumnLocalId());
|
||||
|
||||
String columnIdValue = row.getFieldAsText(columnIdSelected
|
||||
.getColumnLocalId());
|
||||
|
@ -293,20 +302,20 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
* @param columnLocalId
|
||||
*/
|
||||
public void setVisibleOnlyColumn(String columnLocalId) {
|
||||
Log.debug("setVisibleOnlyColumn: "+columnLocalId);
|
||||
visibleOnlyColumn=columnLocalId;
|
||||
|
||||
Log.debug("setVisibleOnlyColumn: " + columnLocalId);
|
||||
visibleOnlyColumn = columnLocalId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param columnModel
|
||||
* @return
|
||||
*/
|
||||
protected ColumnModel<DataRow> checkOnlyColumn(ColumnModel<DataRow> columnModel){
|
||||
if (visibleOnlyColumn!=null && !visibleOnlyColumn.isEmpty()) {
|
||||
protected ColumnModel<DataRow> checkOnlyColumn(
|
||||
ColumnModel<DataRow> columnModel) {
|
||||
if (visibleOnlyColumn != null && !visibleOnlyColumn.isEmpty()) {
|
||||
Log.debug("setVisibleOnlyColumn: Grid not null");
|
||||
|
||||
|
||||
List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns();
|
||||
|
||||
|
@ -328,7 +337,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
}
|
||||
columnModel = new ColumnModel<DataRow>(columnsNew);
|
||||
|
||||
|
||||
} else {
|
||||
Log.debug("visibleOnlyColumn null");
|
||||
}
|
||||
|
@ -488,33 +497,35 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
container.clear();
|
||||
unmask();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
protected void addHeaderMouseDownHandler(HeaderMouseDownHandler handler) {
|
||||
if (grid != null) {
|
||||
|
||||
|
||||
if (handler == null) {
|
||||
handler = new HeaderMouseDownHandler() {
|
||||
|
||||
@Override
|
||||
public void onHeaderMouseDown(HeaderMouseDownEvent event) {
|
||||
Log.debug("HeaderMouseDownEvent :"+event.toDebugString());
|
||||
Log.debug("HeaderMouseDownEvent :"
|
||||
+ event.toDebugString());
|
||||
if (event.getEvent().getButton() == NativeEvent.BUTTON_RIGHT) {
|
||||
event.getEvent().stopPropagation();
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
;
|
||||
grid.addHeaderMouseDownHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Define the grid
|
||||
*
|
||||
|
@ -556,27 +567,37 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>(
|
||||
columnsConfig);
|
||||
|
||||
columnModel =checkOnlyColumn(columnModel);
|
||||
|
||||
|
||||
columnModel = checkOnlyColumn(columnModel);
|
||||
|
||||
if (grid == null) {
|
||||
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<PagingLoadConfig> proxy = new HttpProxy<PagingLoadConfig>(
|
||||
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
|
||||
builder);
|
||||
proxy.setWriter(new PagingLoadUrlEncoder());
|
||||
|
||||
loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>>(
|
||||
proxy, reader);
|
||||
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
|
||||
proxy, reader) {
|
||||
@Override
|
||||
protected FilterPagingLoadConfig newLoadConfig() {
|
||||
return new FilterPagingLoadConfigBean();
|
||||
}
|
||||
};
|
||||
loader.setRemoteSort(true);
|
||||
|
||||
/*
|
||||
* loader.addLoadHandler(new
|
||||
* LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow,
|
||||
* PagingLoadResult<DataRow>>( store));
|
||||
*/
|
||||
|
||||
liveGridView = new ExtendedLiveGridView();
|
||||
|
||||
|
||||
// liveGridView.setRowHeight(19);
|
||||
|
||||
grid = new Grid<DataRow>(store, columnModel);
|
||||
|
@ -586,9 +607,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
grid.setLoadMask(true);
|
||||
grid.setLoader(loader);
|
||||
grid.setView(liveGridView);
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO disabled editing rows
|
||||
/*
|
||||
* editing = new GridInlineEditing<DataRow>(grid);
|
||||
|
@ -599,13 +618,19 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
*/
|
||||
|
||||
// numberer.initPlugin(grid);
|
||||
|
||||
|
||||
//Filter
|
||||
// GridFilters<DataRow> filters = new GridFilters(Loader<FilterPagingLoadConfig,?> loader)
|
||||
// filters.initPlugin(grid);
|
||||
// filters.setLocal(false);
|
||||
// filters.addFilter(lastFilter);
|
||||
|
||||
// Filter
|
||||
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||
.generate(columnModel);
|
||||
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
|
||||
loader);
|
||||
|
||||
gridFilters.initPlugin(grid);
|
||||
gridFilters.setLocal(false);
|
||||
Log.debug("Filters: " + filters.size());
|
||||
for (Filter<DataRow, ?> filterGeneric : filters) {
|
||||
gridFilters.addFilter(filterGeneric);
|
||||
}
|
||||
|
||||
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
|
||||
// in the middle
|
||||
if (loader.getOffset() == 0)
|
||||
loader.load(new PagingLoadConfigBean(0, liveGridView
|
||||
.getCacheSize()));
|
||||
// loader.load();
|
||||
loader.load(0, liveGridView.getCacheSize());
|
||||
}
|
||||
|
||||
if (tableViewConfig != null) {
|
||||
|
@ -668,7 +693,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
} else {
|
||||
grid.getView().setViewConfig(null);
|
||||
}
|
||||
|
||||
|
||||
eventBus.fireEvent(new GridReadyEvent());
|
||||
}
|
||||
|
||||
|
@ -722,6 +747,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
menu.addSelectionHandler(handlerHeaderContextMenu);
|
||||
|
||||
Log.debug("Adding Items to menu");
|
||||
SeparatorMenuItem separatorItem = new SeparatorMenuItem();
|
||||
menu.add(separatorItem);
|
||||
for (MenuItem m : headerColumnMenuItems) {
|
||||
menu.add(m);
|
||||
}
|
||||
|
@ -731,7 +758,6 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
Log.debug("Created Handler");
|
||||
grid.addHeaderContextMenuHandler(headerContextMenuHandler);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,17 +12,18 @@ import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @param <N>
|
||||
*/
|
||||
public class DataRowColumnConfig<N> extends ColumnConfig<DataRow, N> {
|
||||
|
||||
protected ColumnDefinition definition;
|
||||
|
||||
protected 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;
|
||||
}
|
||||
|
||||
|
@ -35,11 +36,13 @@ public class DataRowColumnConfig<N> extends ColumnConfig<DataRow, N> {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setCell(AbstractCell<Boolean> cell) {
|
||||
Cell<N> cell2 = (Cell<N>) cell;
|
||||
Cell<N> cell2 = (Cell<N>) cell;
|
||||
super.setCell(cell2);
|
||||
}
|
||||
|
||||
|
||||
public Cell<N> getCell() {
|
||||
return super.getCell();
|
||||
return super.getCell();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ import com.sencha.gxt.widget.core.client.grid.editing.GridInlineEditing;
|
|||
*
|
||||
*/
|
||||
public class ColumnConfigGenerator {
|
||||
|
||||
|
||||
|
||||
|
||||
public static DataRowColumnConfig<?> generateConfiguration(
|
||||
ColumnDefinition columnDefinition) {
|
||||
DataRowColumnConfig<?> columnConfig = null;
|
||||
|
@ -122,7 +124,8 @@ public class ColumnConfigGenerator {
|
|||
|
||||
return columnConfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static <T> DataRowColumnConfig<T> create(
|
||||
ColumnDefinition columnDefinition) {
|
||||
return new DataRowColumnConfig<T>(columnDefinition);
|
||||
|
@ -189,4 +192,6 @@ public class ColumnConfigGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
|
@ -3,42 +3,118 @@
|
|||
*/
|
||||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi" <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 RequestData requestData;
|
||||
|
||||
|
||||
public String write(PagingLoadConfig config) {
|
||||
|
||||
System.out.println("Offset: "+config.getOffset());
|
||||
System.out.println("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()) {
|
||||
|
||||
System.out.println("SORTFIELD: "+info.getSortField());
|
||||
System.out.println("SORTDIR: "+info.getSortDir());
|
||||
urlBuilder.addParameter(ServletParameters.SORTFIELD, info.getSortField());
|
||||
urlBuilder.addParameter(ServletParameters.SORTDIR, (info.getSortDir()==null)?null:info.getSortDir().toString());
|
||||
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);
|
||||
|
||||
return urlBuilder.toString();
|
||||
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());
|
||||
* 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();
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +1,42 @@
|
|||
package org.gcube.portlets.user.tdwx.server;
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
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;
|
||||
|
||||
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.Direction;
|
||||
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.SortInformation;
|
||||
import org.slf4j.Logger;
|
||||
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 href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class TabularDataXServlet extends HttpServlet {
|
||||
|
||||
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)
|
||||
throws ServletException, IOException {
|
||||
|
@ -38,50 +50,80 @@ public class TabularDataXServlet extends HttpServlet {
|
|||
|
||||
protected void handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
log.debug("TabularDataServlet handleRequest");
|
||||
logger.debug("TabularDataServlet handleRequest");
|
||||
|
||||
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);
|
||||
log.trace("tdSessionIdParameter: " + tdSessionIdParameter);
|
||||
logger.trace("tdSessionIdParameter: " + tdSessionIdParameter);
|
||||
int tdSessionId = Integer.parseInt(tdSessionIdParameter);
|
||||
|
||||
// SORTING DIRECTION
|
||||
String sortDirectionParameter = request
|
||||
.getParameter(ServletParameters.SORTDIR);
|
||||
log.trace("sortDirectionParameter: " + sortDirectionParameter);
|
||||
Direction direction = (sortDirectionParameter == null) ? Direction.ASC
|
||||
: Direction.valueOf(sortDirectionParameter);
|
||||
|
||||
// SORTING COLUMN
|
||||
String sortColumn = request
|
||||
.getParameter(ServletParameters.SORTFIELD);
|
||||
log.trace("sortColumn: " + sortColumn);
|
||||
|
||||
// START
|
||||
String startParameter = request
|
||||
.getParameter(ServletParameters.OFFSET);
|
||||
log.trace("startParameter: " + startParameter);
|
||||
int start = Integer.parseInt(startParameter);
|
||||
|
||||
// LIMIT
|
||||
String limitParameter = request
|
||||
.getParameter(ServletParameters.LIMIT);
|
||||
log.trace("limitParameter: " + limitParameter);
|
||||
int limit = Integer.parseInt(limitParameter);
|
||||
/*
|
||||
* // SORTING DIRECTION String sortDirectionParameter = request
|
||||
* .getParameter(ServletParameters.SORTDIR);
|
||||
* log.trace("sortDirectionParameter: " + sortDirectionParameter);
|
||||
* Direction direction = (sortDirectionParameter == null) ?
|
||||
* Direction.ASC : Direction.valueOf(sortDirectionParameter);
|
||||
*
|
||||
* // SORTING COLUMN String sortColumn = request
|
||||
* .getParameter(ServletParameters.SORTFIELD);
|
||||
* log.trace("sortColumn: " + sortColumn);
|
||||
*
|
||||
* // START
|
||||
* String startParameter = request
|
||||
* .getParameter(ServletParameters.OFFSET);
|
||||
* log.trace("startParameter: " + startParameter); int start =
|
||||
* Integer.parseInt(startParameter);
|
||||
*
|
||||
* // LIMIT String limitParameter = request
|
||||
* .getParameter(ServletParameters.LIMIT);
|
||||
* 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(
|
||||
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);
|
||||
log.trace("Response sent (" + json.length() + " bytes)");
|
||||
logger.trace("Response sent (" + json.length() + " bytes)");
|
||||
|
||||
} 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,
|
||||
"Error processing the json data request: " + e.getMessage());
|
||||
return;
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -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 + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package org.gcube.portlets.user.tdwx.shared;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
|
@ -17,5 +18,9 @@ public class ServletParameters {
|
|||
public static final String SORTDIR = "sortDir";
|
||||
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";
|
||||
|
||||
}
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue