Added ExtendedBooleanFilter
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95268 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
696e4bf269
commit
e796b9b419
|
@ -23,11 +23,12 @@ import org.gcube.portlets.user.tdwx.client.event.OpenTableEvent;
|
||||||
import org.gcube.portlets.user.tdwx.client.event.OpenTableEventHandler;
|
import org.gcube.portlets.user.tdwx.client.event.OpenTableEventHandler;
|
||||||
import org.gcube.portlets.user.tdwx.client.event.TableReadyEvent;
|
import org.gcube.portlets.user.tdwx.client.event.TableReadyEvent;
|
||||||
import org.gcube.portlets.user.tdwx.client.event.TableReadyEventHandler;
|
import org.gcube.portlets.user.tdwx.client.event.TableReadyEventHandler;
|
||||||
|
import org.gcube.portlets.user.tdwx.client.filter.ExtendedGridFilters;
|
||||||
|
import org.gcube.portlets.user.tdwx.client.filter.FiltersGenerator;
|
||||||
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowColumnConfig;
|
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;
|
||||||
|
@ -113,6 +114,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
|
|
||||||
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
|
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
|
||||||
|
|
||||||
|
protected ExtendedGridFilters<DataRow> gridFilters;
|
||||||
|
|
||||||
protected TableViewConfig tableViewConfig;
|
protected TableViewConfig tableViewConfig;
|
||||||
|
|
||||||
protected Menu contextMenu;
|
protected Menu contextMenu;
|
||||||
|
@ -637,7 +640,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
|
|
||||||
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||||
.generate(columnModel);
|
.generate(columnModel);
|
||||||
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
|
gridFilters = new ExtendedGridFilters<DataRow>(
|
||||||
loader);
|
loader);
|
||||||
|
|
||||||
gridFilters.initPlugin(grid);
|
gridFilters.initPlugin(grid);
|
||||||
|
@ -682,8 +685,19 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
// TODO we need to manually reset the sort
|
// TODO we need to manually reset the sort
|
||||||
loader.clearSortInfo();
|
loader.clearSortInfo();
|
||||||
reader.setDefinition(tableDefinition);
|
reader.setDefinition(tableDefinition);
|
||||||
|
|
||||||
grid.reconfigure(store, columnModel);
|
grid.reconfigure(store, columnModel);
|
||||||
|
|
||||||
|
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||||
|
.generate(columnModel);
|
||||||
|
gridFilters.removeAll();
|
||||||
|
|
||||||
|
Log.debug("Filters: " + filters.size());
|
||||||
|
for (Filter<DataRow, ?> filterGeneric : filters) {
|
||||||
|
gridFilters.addFilter(filterGeneric);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO Disabled editing rows
|
// TODO Disabled editing rows
|
||||||
/*
|
/*
|
||||||
* editing = new GridInlineEditing<DataRow>(grid);
|
* editing = new GridInlineEditing<DataRow>(grid);
|
||||||
|
@ -831,67 +845,6 @@ 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) {
|
|
||||||
onCheckChangeExt(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void onCheckChangeExt(CheckChangeEvent<CheckMenuItem> event) {
|
|
||||||
getMenuFilter(event).setActive(event.getItem().isChecked(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,144 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.client.filter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.sencha.gxt.core.client.ValueProvider;
|
||||||
|
import com.sencha.gxt.core.client.dom.XDOM;
|
||||||
|
import com.sencha.gxt.core.client.util.Util;
|
||||||
|
import com.sencha.gxt.data.shared.loader.BooleanFilterHandler;
|
||||||
|
import com.sencha.gxt.data.shared.loader.FilterConfig;
|
||||||
|
import com.sencha.gxt.data.shared.loader.FilterConfigBean;
|
||||||
|
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.grid.filters.Filter;
|
||||||
|
import com.sencha.gxt.widget.core.client.menu.CheckMenuItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
*
|
||||||
|
* @param <M>
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* A boolean filter. See {@link Filter} for more information.
|
||||||
|
*
|
||||||
|
* @param <M> the model type
|
||||||
|
*/
|
||||||
|
public class ExtendedBooleanFilter<M> extends Filter<M, Boolean> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The locale-sensitive messages used by this class.
|
||||||
|
*/
|
||||||
|
public interface BooleanFilterMessages {
|
||||||
|
String noText();
|
||||||
|
|
||||||
|
String yesText();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default locale-sensitive messages used by this class.
|
||||||
|
*/
|
||||||
|
public class DefaultBooleanFilterMessages implements BooleanFilterMessages {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String noText() {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String yesText() {
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private CheckMenuItem yesItem, noItem;
|
||||||
|
private BooleanFilterMessages messages = new DefaultBooleanFilterMessages();
|
||||||
|
private CheckChangeHandler<CheckMenuItem> handler = new CheckChangeHandler<CheckMenuItem>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
|
||||||
|
fireUpdate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a boolean filter for the specified value provider. See
|
||||||
|
* {@link Filter#Filter(ValueProvider)} for more information.
|
||||||
|
*
|
||||||
|
* @param valueProvider the value provider
|
||||||
|
*/
|
||||||
|
public ExtendedBooleanFilter(ValueProvider<? super M, Boolean> valueProvider) {
|
||||||
|
super(valueProvider);
|
||||||
|
|
||||||
|
setHandler(new BooleanFilterHandler());
|
||||||
|
|
||||||
|
yesItem = new CheckMenuItem();
|
||||||
|
yesItem.addCheckChangeHandler(handler);
|
||||||
|
yesItem.setGroup(XDOM.getUniqueId());
|
||||||
|
|
||||||
|
noItem = new CheckMenuItem();
|
||||||
|
noItem.addCheckChangeHandler(handler);
|
||||||
|
noItem.setGroup(yesItem.getGroup());
|
||||||
|
|
||||||
|
menu.add(yesItem);
|
||||||
|
menu.add(noItem);
|
||||||
|
|
||||||
|
setMessages(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FilterConfig> getFilterConfig() {
|
||||||
|
FilterConfigBean config = new FilterConfigBean();
|
||||||
|
config.setType("boolean");
|
||||||
|
config.setValue(getHandler().convertToString((Boolean) getValue()));
|
||||||
|
return Util.<FilterConfig> createList(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale-sensitive messages used by this class.
|
||||||
|
*
|
||||||
|
* @return the local-sensitive messages used by this class.
|
||||||
|
*/
|
||||||
|
public BooleanFilterMessages getMessages() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return Boolean.valueOf(yesItem.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return super.isActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the local-sensitive messages used by this class.
|
||||||
|
*
|
||||||
|
* @param messages the locale sensitive messages used by this class.
|
||||||
|
*/
|
||||||
|
public void setMessages(BooleanFilterMessages messages) {
|
||||||
|
this.messages = messages;
|
||||||
|
yesItem.setText(getMessages().yesText());
|
||||||
|
noItem.setText(getMessages().noText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<Boolean> getType() {
|
||||||
|
return Boolean.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isActivatable() {
|
||||||
|
return super.isActivatable();
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validateModel(M model) {
|
||||||
|
Boolean val = getValueProvider().getValue(model);
|
||||||
|
return getValue().equals(val == null ? Boolean.FALSE : val);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.client.filter;
|
||||||
|
|
||||||
|
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
|
||||||
|
import com.sencha.gxt.data.shared.loader.Loader;
|
||||||
|
import com.sencha.gxt.widget.core.client.event.CheckChangeEvent;
|
||||||
|
import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent;
|
||||||
|
import com.sencha.gxt.widget.core.client.event.CheckChangeEvent.CheckChangeHandler;
|
||||||
|
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.Menu;
|
||||||
|
import com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
*
|
||||||
|
* @param <M>
|
||||||
|
*/
|
||||||
|
public 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) {
|
||||||
|
onCheckChangeExt(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void onCheckChangeExt(CheckChangeEvent<CheckMenuItem> event) {
|
||||||
|
getMenuFilter(event).setActive(event.getItem().isChecked(), false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.portlets.user.tdwx.client.model.util;
|
package org.gcube.portlets.user.tdwx.client.filter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -12,7 +12,6 @@ import com.sencha.gxt.core.client.ValueProvider;
|
||||||
import com.sencha.gxt.widget.core.client.form.NumberPropertyEditor;
|
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.ColumnConfig;
|
||||||
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
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.DateFilter;
|
||||||
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
|
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.NumericFilter;
|
||||||
|
@ -42,7 +41,7 @@ public class FiltersGenerator {
|
||||||
switch (vt) {
|
switch (vt) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
BooleanFilter<DataRow> bFilt = new BooleanFilter<DataRow>(
|
ExtendedBooleanFilter<DataRow> bFilt = new ExtendedBooleanFilter<DataRow>(
|
||||||
(ValueProvider<DataRow, Boolean>) dataRowColConfig
|
(ValueProvider<DataRow, Boolean>) dataRowColConfig
|
||||||
.getValueProvider());
|
.getValueProvider());
|
||||||
filters.add(bFilt);
|
filters.add(bFilt);
|
Loading…
Reference in New Issue