Fixed Filter on type date

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@95412 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-05-07 13:52:46 +00:00
parent f004197631
commit 251bfac433
2 changed files with 173 additions and 91 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.td.expressionwidget.client;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@ -19,6 +20,7 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
@ -34,6 +36,7 @@ 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.BeforeShowEvent;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.form.DateField;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.Radio;
import com.sencha.gxt.widget.core.client.form.TextField;
@ -52,46 +55,47 @@ public class ConditionWidget extends SimpleContainer {
protected FieldLabel matchLabel;
protected ToggleGroup groupMatch;
protected String itemIdCombo;
protected String itemIdCombo;
protected String itemIdFirstArg;
protected String itemIdSecondArg;
protected String itemIdFirstArgDate;
protected String itemIdSecondArgDate;
protected String itemIdBtnAdd;
protected String itemIdBtnDel;
protected VerticalLayoutContainer vert;
protected ColumnData column;
protected String readableExpression;
public ConditionWidget(ColumnData column) {
super();
create(column,WIDTH, HEIGHT);
create(column, WIDTH, HEIGHT);
}
public ConditionWidget(ColumnData column, String width,String height) {
public ConditionWidget(ColumnData column, String width, String height) {
super();
create(column,width,height);
create(column, width, height);
}
protected void create(ColumnData column, String width, String height){
protected void create(ColumnData column, String width, String height) {
this.column = column;
setBorders(true);
setWidth(width);
setHeight(height);
forceLayoutOnResize = true;
thisCont = this;
itemIdCombo = "ComboConditions"+column.getName();
itemIdFirstArg = "FirstArg"+column.getName();
itemIdSecondArg = "SecondArg"+column.getName();
itemIdBtnAdd = "BtnAdd"+column.getName();
itemIdBtnDel = "BtnDel"+column.getName();
itemIdCombo = "ComboConditions" + column.getName();
itemIdFirstArg = "FirstArg" + column.getName();
itemIdSecondArg = "SecondArg" + column.getName();
itemIdFirstArgDate = "FirstArgDate" + column.getName();
itemIdSecondArgDate = "SecondArgDate" + column.getName();
itemIdBtnAdd = "BtnAdd" + column.getName();
itemIdBtnDel = "BtnDel" + column.getName();
VerticalLayoutContainer baseLayout = new VerticalLayoutContainer();
Radio radioAll = new Radio();
radioAll.setName("All");
radioAll.setBoxLabel("All conditions");
@ -119,16 +123,13 @@ public class ConditionWidget extends SimpleContainer {
vert = new VerticalLayoutContainer();
vert.setScrollMode(ScrollMode.AUTO);
vert.setAdjustForScroll(true);
setup();
baseLayout.add(vert, new VerticalLayoutData(1, 1, new Margins(0)));
add(baseLayout);
}
protected void setup() {
@ -138,7 +139,11 @@ public class ConditionWidget extends SimpleContainer {
firstArg.setItemId(itemIdFirstArg);
firstArg.setVisible(false);
final HTML andText = new HTML(
final DateField firstArgDate = new DateField();
firstArgDate.setItemId(itemIdFirstArgDate);
firstArgDate.setVisible(false);
final HTML andText = new HTML(
"<div style='vertical-align:middle; margin-left:2px;margin-right:2px;margin-top:4px;'>and</div>");
andText.setVisible(false);
@ -146,7 +151,11 @@ public class ConditionWidget extends SimpleContainer {
secondArg.setItemId(itemIdSecondArg);
secondArg.setVisible(false);
final IconButton btnAdd = new IconButton();
final DateField secondArgDate = new DateField();
secondArgDate.setItemId(itemIdSecondArgDate);
secondArgDate.setVisible(false);
final IconButton btnAdd = new IconButton();
btnAdd.setItemId(itemIdBtnAdd);
btnAdd.setIcon(ExpressionResources.INSTANCE.add());
btnAdd.addClickHandler(new ClickHandler() {
@ -162,7 +171,7 @@ public class ConditionWidget extends SimpleContainer {
});
btnAdd.setVisible(false);
final IconButton btnDel = new IconButton();
final IconButton btnDel = new IconButton();
btnDel.setItemId(itemIdBtnDel);
btnDel.setIcon(ExpressionResources.INSTANCE.delete());
btnDel.addClickHandler(new ClickHandler() {
@ -186,16 +195,16 @@ public class ConditionWidget extends SimpleContainer {
btnDel.setVisible(false);
OperationProperties props = GWT.create(OperationProperties.class);
Log.debug("Props: "+props);
Log.debug("Props: " + props);
ListStore<Operation> storeOp = new ListStore<Operation>(props.id());
Log.debug("Store: "+storeOp);
OperationsStore factory=new OperationsStore();
Log.debug("Store: " + storeOp);
OperationsStore factory = new OperationsStore();
storeOp.addAll(factory.getAll(column.getDataTypeName()));
Log.debug("Store created");
ComboBox<Operation> comboOp = new ComboBox<Operation>(storeOp,
props.label());
Log.debug("Combo created");
comboOp.addSelectionHandler(new SelectionHandler<Operation>() {
@ -214,34 +223,52 @@ public class ConditionWidget extends SimpleContainer {
case NOT_GREATER:
case NOT_LESSER:
case BEGINS_WITH:
case ENDS_WITH:
case ENDS_WITH:
case MATCH_REGEX:
case CONTAINS:
case NOT_BEGINS_WITH:
case NOT_ENDS_WITH:
case NOT_CONTAINS:
case NOT_MATCH_REGEX:
case NOT_MATCH_REGEX:
case IN:
case NOT_IN:
firstArg.setVisible(true);
andText.setVisible(false);
secondArg.setVisible(false);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(true);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(true);
andText.setVisible(false);
secondArg.setVisible(false);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
case BETWEEN:
case NOT_BETWEEN:
firstArg.setVisible(true);
andText.setVisible(true);
secondArg.setVisible(true);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(false);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(true);
andText.setVisible(true);
secondArg.setVisible(true);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
case IS_NULL:
case IS_NOT_NULL:
firstArg.setVisible(false);
andText.setVisible(false);
secondArg.setVisible(false);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(false);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(false);
andText.setVisible(false);
secondArg.setVisible(false);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
@ -255,7 +282,7 @@ public class ConditionWidget extends SimpleContainer {
}
});
comboOp.setEmptyText("Select a condition...");
comboOp.setItemId(itemIdCombo);
comboOp.setWidth("230px");
@ -263,37 +290,44 @@ public class ConditionWidget extends SimpleContainer {
comboOp.setTriggerAction(TriggerAction.ALL);
horiz.add(comboOp, new BoxLayoutData(new Margins(0)));
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
if (column.getDataTypeName().compareTo("Date") == 0) {
horiz.add(firstArgDate, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArgDate, new BoxLayoutData(new Margins(0)));
} else {
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
}
horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0)));
horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0)));
vert.add(horiz, new VerticalLayoutData(-1,-1,new Margins(1)));
vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1)));
addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
@Override
public void onBeforeShow(BeforeShowEvent event) {
forceLayout();
}
});
}
protected void addCondition() {
final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
final TextField firstArg = new TextField();
firstArg.setItemId(itemIdFirstArg);
firstArg.setVisible(false);
final DateField firstArgDate = new DateField();
firstArgDate.setItemId(itemIdFirstArgDate);
firstArgDate.setVisible(false);
final HTML andText = new HTML(
"<div style='vertical-align:middle; margin-left:2px;margin-right:2px;margin-top:4px;'>and</div>");
andText.setVisible(false);
@ -302,6 +336,10 @@ public class ConditionWidget extends SimpleContainer {
secondArg.setItemId(itemIdSecondArg);
secondArg.setVisible(false);
final DateField secondArgDate = new DateField();
secondArgDate.setItemId(itemIdSecondArgDate);
secondArgDate.setVisible(false);
final IconButton btnAdd = new IconButton();
btnAdd.setItemId(itemIdBtnAdd);
btnAdd.setIcon(ExpressionResources.INSTANCE.add());
@ -339,12 +377,12 @@ public class ConditionWidget extends SimpleContainer {
});
OperationProperties props = GWT.create(OperationProperties.class);
Log.debug("Props: "+props);
Log.debug("Props: " + props);
ListStore<Operation> storeOp = new ListStore<Operation>(props.id());
Log.debug("Store: "+storeOp);
OperationsStore factory=new OperationsStore();
Log.debug("Store: " + storeOp);
OperationsStore factory = new OperationsStore();
storeOp.addAll(factory.getAll(column.getDataTypeName()));
Log.trace("Store created");
final ComboBox<Operation> comboOp = new ComboBox<Operation>(storeOp,
@ -368,34 +406,52 @@ public class ConditionWidget extends SimpleContainer {
case NOT_GREATER:
case NOT_LESSER:
case BEGINS_WITH:
case ENDS_WITH:
case ENDS_WITH:
case MATCH_REGEX:
case CONTAINS:
case NOT_BEGINS_WITH:
case NOT_ENDS_WITH:
case NOT_CONTAINS:
case NOT_MATCH_REGEX:
case NOT_MATCH_REGEX:
case IN:
case NOT_IN:
firstArg.setVisible(true);
andText.setVisible(false);
secondArg.setVisible(false);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(true);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(true);
andText.setVisible(false);
secondArg.setVisible(false);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
case BETWEEN:
case NOT_BETWEEN:
firstArg.setVisible(true);
andText.setVisible(true);
secondArg.setVisible(true);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(false);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(true);
andText.setVisible(true);
secondArg.setVisible(true);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
case IS_NULL:
case IS_NOT_NULL:
firstArg.setVisible(false);
andText.setVisible(false);
secondArg.setVisible(false);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate.setVisible(false);
andText.setVisible(false);
secondArgDate.setVisible(false);
} else {
firstArg.setVisible(false);
andText.setVisible(false);
secondArg.setVisible(false);
}
btnAdd.setVisible(true);
btnDel.setVisible(true);
break;
@ -417,14 +473,20 @@ public class ConditionWidget extends SimpleContainer {
comboOp.setTriggerAction(TriggerAction.ALL);
horiz.add(comboOp, new BoxLayoutData(new Margins(0)));
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
if (column.getDataTypeName().compareTo("Date") == 0) {
horiz.add(firstArgDate, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArgDate, new BoxLayoutData(new Margins(0)));
} else {
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
horiz.add(andText, new BoxLayoutData(new Margins(0)));
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
}
horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0)));
horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0)));
vert.add(horiz, new VerticalLayoutData(-1,-1,new Margins(1)));
vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1)));
}
public C_Expression getExpression() {
@ -434,8 +496,12 @@ public class ConditionWidget extends SimpleContainer {
List<String> readableExpressionList = new ArrayList<String>();
TextField firstArg;
TextField secondArg;
DateField firstArgDate;
DateField secondArgDate;
C_Expression expression;
// yyyy/MM/dd HH:mm:ss
DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
OperatorTypeMap mapOp = new OperatorTypeMap();
Iterator<Widget> iteratorVert = vert.iterator();
HBoxLayoutContainer horiz;
@ -444,16 +510,33 @@ public class ConditionWidget extends SimpleContainer {
@SuppressWarnings("unchecked")
ComboBox<Operation> comboOp = (ComboBox<Operation>) horiz
.getItemByItemId(itemIdCombo);
Log.debug("combo:" + comboOp.getCurrentValue().toString());
Log.debug("combo: " + comboOp.getCurrentValue().toString());
firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg);
secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg);
Log.debug("argLeft:" + firstArg + " argRight:" + secondArg);
if (column.getDataTypeName().compareTo("Date") == 0) {
firstArgDate = (DateField) horiz
.getItemByItemId(itemIdFirstArgDate);
secondArgDate = (DateField) horiz
.getItemByItemId(itemIdSecondArgDate);
Log.debug("argLeft: " + firstArgDate + " argRight:"
+ secondArgDate);
Date firstDate=firstArgDate.getCurrentValue();
Date secondDate=secondArgDate.getCurrentValue();
expression = mapOp.map(
column,
comboOp.getCurrentValue().getOperatorType(),
firstDate == null ? null : sdf.format(firstDate),
secondDate == null ? null : sdf.format(secondDate));
} else {
expression = mapOp.map(column, comboOp.getCurrentValue()
.getOperatorType(),
firstArg == null ? null : firstArg.getCurrentValue(),
secondArg == null ? null : secondArg.getCurrentValue());
firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg);
secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg);
Log.debug("argLeft: " + firstArg.getCurrentValue() + " argRight: " + secondArg.getCurrentValue());
expression = mapOp.map(column, comboOp.getCurrentValue()
.getOperatorType(),
firstArg == null ? null : firstArg.getCurrentValue(),
secondArg == null ? null : secondArg.getCurrentValue());
}
readableExpressionList.add(mapOp.getReadableExpression());
Log.debug(expression.toString());
arguments.add(expression);
@ -502,8 +585,7 @@ public class ConditionWidget extends SimpleContainer {
Log.debug("C_Expression:" + exp.toString());
return exp;
}
public String getReadableExpression() {
return readableExpression;
}

View File

@ -80,7 +80,7 @@ public class C_ExpressionParser {
protected static Logger logger = LoggerFactory
.getLogger(C_ExpressionParser.class);
protected SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public Expression parse(C_Expression exp) {
Expression ex = null;
@ -338,9 +338,9 @@ public class C_ExpressionParser {
case Date:
Date d = null;
try {
d = ft.parse(value.getValue());
d = sdf.parse(value.getValue());
} catch (ParseException e) {
logger.error("Unparseable using " + ft);
logger.error("Unparseable using " + sdf);
return null;
}
ex = new TDDate(d);