Added ReplaceExpressionDialog
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@113737 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
275bb0a540
commit
959d99b09e
|
@ -40,7 +40,7 @@ public class ColumnExpressionDialog extends Window {
|
|||
protected C_Expression exp = null;
|
||||
protected ColumnData column = null;
|
||||
protected TRId trId;
|
||||
protected String columnName = null;
|
||||
protected String columnId = null;
|
||||
protected EventBus eventBus;
|
||||
|
||||
public ColumnExpressionDialog(String columnId,
|
||||
|
@ -56,13 +56,13 @@ public class ColumnExpressionDialog extends Window {
|
|||
|
||||
}
|
||||
|
||||
public ColumnExpressionDialog(TRId trId, String columnName,
|
||||
public ColumnExpressionDialog(TRId trId, String columnId,
|
||||
EventBus eventBus) {
|
||||
initWindow();
|
||||
this.eventBus = eventBus;
|
||||
this.trId = trId;
|
||||
this.columnName = columnName;
|
||||
load(trId, columnName);
|
||||
this.columnId = columnId;
|
||||
load();
|
||||
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class ColumnExpressionDialog extends Window {
|
|||
|
||||
protected void close (){
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.EXPRESSIONNULL);
|
||||
ExpressionType.EXPRESSION_NULL);
|
||||
Log.debug(expressionEvent.toString());
|
||||
hide();
|
||||
eventBus.fireEvent(expressionEvent);
|
||||
|
@ -146,8 +146,8 @@ public class ColumnExpressionDialog extends Window {
|
|||
|
||||
}
|
||||
|
||||
protected void load(TRId trId, String columnName) {
|
||||
TDGWTServiceAsync.INSTANCE.getColumn(trId, columnName,
|
||||
protected void load() {
|
||||
TDGWTServiceAsync.INSTANCE.getColumn(columnId,trId,
|
||||
new AsyncCallback<ColumnData>() {
|
||||
|
||||
public void onFailure(Throwable caught) {
|
||||
|
|
|
@ -67,8 +67,6 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
private ArrayList<ColumnData> columns;
|
||||
|
||||
private TextButton btnApply;
|
||||
private TextButton btnSearch;
|
||||
private TextButton btnSave;
|
||||
private TextButton btnClose;
|
||||
|
||||
private FieldSet conditionsField;
|
||||
|
@ -200,32 +198,7 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
|
||||
}
|
||||
});
|
||||
|
||||
btnSearch = new TextButton("Search");
|
||||
btnSearch.setIcon(ExpressionResources.INSTANCE.search());
|
||||
btnSearch.setIconAlign(IconAlign.RIGHT);
|
||||
btnSearch.setTitle("Search rule");
|
||||
btnSearch.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Search");
|
||||
searchRule();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
btnSave = new TextButton("Save");
|
||||
btnSave.setIcon(ExpressionResources.INSTANCE.save());
|
||||
btnSave.setIconAlign(IconAlign.RIGHT);
|
||||
btnSave.setTitle("Save rule");
|
||||
btnSave.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Save");
|
||||
saveRule();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnClose = new TextButton("Close");
|
||||
btnClose.setIcon(ExpressionResources.INSTANCE.close());
|
||||
|
@ -240,11 +213,7 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
});
|
||||
|
||||
flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
||||
// flowButton.add(btnSave, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
||||
/*
|
||||
* flowButton.add(btnSearch, new BoxLayoutData(new Margins(2, 4, 2,
|
||||
* 4)));
|
||||
*/
|
||||
|
||||
flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
||||
|
||||
basicLayout.add(properties, new VerticalLayoutData(1, -1,
|
||||
|
@ -604,7 +573,7 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
case Template:
|
||||
parentRuleDialog.setExpression(exp);
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.COLUMNEXPRESSION);
|
||||
ExpressionType.CONDITION_COLUMN_EXPRESSION);
|
||||
C_ExpressionContainer container = new C_ExpressionContainer();
|
||||
container.setId(C_ExpressionContainer.Contains.C_Expression);
|
||||
container.setExp(exp);
|
||||
|
@ -647,7 +616,7 @@ public class ColumnExpressionPanel extends FramedPanel {
|
|||
switch (type) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.EXPRESSIONNULL);
|
||||
ExpressionType.EXPRESSION_NULL);
|
||||
Log.debug(expressionEvent.toString());
|
||||
parentRuleDialog.hide();
|
||||
eventBus.fireEvent(expressionEvent);
|
||||
|
|
|
@ -108,71 +108,6 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
|
||||
private FieldSet replaceValueFieldSet;
|
||||
|
||||
protected void createPArent() {
|
||||
if (column == null) {
|
||||
UtilsGXT3.info("Attention ", "You must select a column!");
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (column.isViewColumn()) {
|
||||
UtilsGXT3.info("Attention is View Column",
|
||||
"You can not make expressions on view column for now!");
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Integer.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Numeric.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Geometry.toString()) == 0) {
|
||||
setHeight(HEIGHT);
|
||||
} else {
|
||||
setHeight(HEIGHT_REDUCE);
|
||||
}
|
||||
|
||||
if (column.getTypeCode()
|
||||
.compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
ColumnTypeCode.ATTRIBUTE.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
ColumnTypeCode.CODE.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
ColumnTypeCode.CODEDESCRIPTION.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
ColumnTypeCode.CODENAME.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
ColumnTypeCode.MEASURE.toString()) == 0) {
|
||||
switch (replaceColumnByExpressionType) {
|
||||
case Replace:
|
||||
// replaceColumnByExpressionPanel = new
|
||||
// ReplaceColumnByExpressionPanel(
|
||||
// this, column, eventBus);
|
||||
break;
|
||||
case Template:
|
||||
// replaceColumnByExpressionPanel = new
|
||||
// ReplaceColumnByExpressionPanel(
|
||||
// this, column, columns, eventBus,
|
||||
// replaceColumnByExpressionType);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// add(replaceColumnByExpressionPanel);
|
||||
|
||||
} else {
|
||||
HTML errorMessage = new HTML(
|
||||
"This type of column is not supported for now!");
|
||||
add(errorMessage);
|
||||
UtilsGXT3.alert("Error",
|
||||
"This type of column is not supported for now!");
|
||||
}
|
||||
}
|
||||
|
||||
public ReplaceColumnByExpressionPanel(
|
||||
ReplaceColumnByExpressionDialog parent, ColumnData column,
|
||||
|
@ -594,19 +529,19 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
switch (replaceColumnByExpressionType) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.REPLACECOLUMNEXPRESSION);
|
||||
C_ExpressionContainer container;
|
||||
ExpressionType.CONDITION_AND_REPLACE_COLUMN_EXPRESSION);
|
||||
C_ExpressionContainer conditionExpressionContainer;
|
||||
if (allRows) {
|
||||
container = new C_ExpressionContainer(
|
||||
conditionExpressionContainer = new C_ExpressionContainer(
|
||||
C_ExpressionContainer.Contains.C_Expression, true,
|
||||
null, "AllRows()");
|
||||
} else {
|
||||
container = new C_ExpressionContainer(
|
||||
conditionExpressionContainer = new C_ExpressionContainer(
|
||||
C_ExpressionContainer.Contains.C_Expression,
|
||||
cConditionExpression,
|
||||
conditionWidget.getReadableExpression());
|
||||
}
|
||||
expressionEvent.setC_ConditionExpressionContainer(container);
|
||||
expressionEvent.setC_ConditionExpressionContainer(conditionExpressionContainer);
|
||||
expressionEvent.setReplaceByValue(true);
|
||||
expressionEvent.setReplaceValue(replaceValue);
|
||||
expressionEvent.setTrId(column.getTrId());
|
||||
|
@ -636,7 +571,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
switch (replaceColumnByExpressionType) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.REPLACECOLUMNEXPRESSION);
|
||||
ExpressionType.CONDITION_AND_REPLACE_COLUMN_EXPRESSION);
|
||||
C_ExpressionContainer conditionExpressionContainer;
|
||||
if (allRows) {
|
||||
conditionExpressionContainer = new C_ExpressionContainer(
|
||||
|
@ -747,7 +682,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
switch (replaceColumnByExpressionType) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.EXPRESSIONNULL);
|
||||
ExpressionType.EXPRESSION_NULL);
|
||||
Log.debug(expressionEvent.toString());
|
||||
parent.close();
|
||||
eventBus.fireEvent(expressionEvent);
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client.expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceExpressionType;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3;
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_ExpressionContainer;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ReplaceExpressionDialog extends Window {
|
||||
private static final String WIDTH = "880px";
|
||||
private static final String HEIGHT = "490px";
|
||||
|
||||
|
||||
private ColumnData column;
|
||||
private ArrayList<ColumnData> columns;
|
||||
private String columnLocalId;
|
||||
private TRId trId;
|
||||
private EventBus eventBus;
|
||||
|
||||
private ReplaceExpressionPanel replaceExpressionPanel;
|
||||
private ReplaceExpressionType type;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Column must have set columnId, label, columnTypeCode and ColumnDataType.
|
||||
* Column is not used to construct the expression.
|
||||
* Columns are retrieved from TRId.
|
||||
*
|
||||
*
|
||||
* @param column
|
||||
* @param trId
|
||||
* @param eventBus
|
||||
*/
|
||||
public ReplaceExpressionDialog(ColumnData column,
|
||||
TRId trId, EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
this.column = column;
|
||||
type = ReplaceExpressionType.Replace;
|
||||
initWindow();
|
||||
load();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Column and Columns must have set columnId, label, columnTypeCode and ColumnDataType.
|
||||
* Column is not used to construct the expression.
|
||||
*
|
||||
*
|
||||
* @param column
|
||||
* @param columns
|
||||
* @param eventBus
|
||||
*/
|
||||
public ReplaceExpressionDialog(ColumnData column,
|
||||
ArrayList<ColumnData> columns, EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
this.column = column;
|
||||
this.columns = columns;
|
||||
type = ReplaceExpressionType.Template;
|
||||
initWindow();
|
||||
sanitizesColumns();
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Replace Expression");
|
||||
setClosable(true);
|
||||
getHeader().setIcon(
|
||||
ExpressionResources.INSTANCE.columnReplaceByExpression());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void create() {
|
||||
replaceExpressionPanel = new ReplaceExpressionPanel(
|
||||
this, column, columns,type, eventBus);
|
||||
add(replaceExpressionPanel);
|
||||
}
|
||||
|
||||
|
||||
protected void applyReplaceColumnByExpression(ColumnData column,
|
||||
String value) {
|
||||
this.column=column;
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void applyReplaceColumnByExpression(ColumnData column,
|
||||
C_ExpressionContainer expressionContainer) {
|
||||
this.column=column;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void load() {
|
||||
TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
||||
new AsyncCallback<ArrayList<ColumnData>>() {
|
||||
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
if (caught instanceof TDGWTIsLockedException) {
|
||||
Log.error(caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error Locked",
|
||||
caught.getLocalizedMessage());
|
||||
} else {
|
||||
Log.error("Error retrieving column: "
|
||||
+ caught.getMessage());
|
||||
UtilsGXT3.alert("Error retrieving column",
|
||||
caught.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSuccess(ArrayList<ColumnData> result) {
|
||||
Log.debug("Retrived columns: " + result);
|
||||
columns = result;
|
||||
sanitizesColumns();
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void sanitizesColumns() {
|
||||
ArrayList<ColumnData> removableColumn = new ArrayList<ColumnData>();
|
||||
for (ColumnData c : columns) {
|
||||
if (c.getTypeCode().compareTo(
|
||||
ColumnTypeCode.DIMENSION.toString()) == 0
|
||||
|| c.getTypeCode().compareTo(
|
||||
ColumnTypeCode.TIMEDIMENSION
|
||||
.toString()) == 0) {
|
||||
removableColumn.add(c);
|
||||
} else {
|
||||
if (columnLocalId != null
|
||||
&& c.getColumnId().compareTo(
|
||||
columnLocalId) == 0) {
|
||||
removableColumn.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
columns.removeAll(removableColumn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,503 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client.expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.ReplaceWidget;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceExpressionType;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ExpressionEvent;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ExpressionType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_ExpressionContainer;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.regexp.shared.MatchResult;
|
||||
import com.google.gwt.regexp.shared.RegExp;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.widget.core.client.FramedPanel;
|
||||
import com.sencha.gxt.widget.core.client.button.TextButton;
|
||||
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
||||
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
|
||||
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
|
||||
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign;
|
||||
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.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
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.FieldSet;
|
||||
import com.sencha.gxt.widget.core.client.form.TextField;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ReplaceExpressionPanel extends FramedPanel {
|
||||
private static final String GEOMETRY_REGEXPR = "(\\s*POINT\\s*\\(\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*\\)\\s*$)"
|
||||
+ "|(\\s*LINESTRING\\s*\\((\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*,)+\\s*((-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*)\\)\\s*$)";
|
||||
|
||||
private static final String WIDTH = "868px";
|
||||
private static final String HEIGHT = "454px";
|
||||
private static final String HEIGHT_REDUCE = "368px";
|
||||
private static final String PARENT_HEIGHT = "490px";
|
||||
private static final String PARENT_HEIGHT_REDUCE = "404px";
|
||||
|
||||
private static final String REPLACEWIDTH = "832px";
|
||||
private static final String REPLACEHEIGHT = "120px";
|
||||
|
||||
private EventBus eventBus;
|
||||
|
||||
private ReplaceExpressionDialog parent;
|
||||
|
||||
private ColumnData column;
|
||||
private ArrayList<ColumnData> columns;
|
||||
|
||||
private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
|
||||
|
||||
private TextButton btnApply;
|
||||
private TextButton btnClose;
|
||||
|
||||
private TextField columnType;
|
||||
private TextField dataType;
|
||||
|
||||
private ReplaceWidget replaceWidget;
|
||||
private TextField replaceValue;
|
||||
private DateField replaceValueDate;
|
||||
|
||||
private FieldSet replaceValueFieldSet;
|
||||
|
||||
private ReplaceExpressionType type;
|
||||
|
||||
public ReplaceExpressionPanel(ReplaceExpressionDialog parent,
|
||||
ColumnData column, ArrayList<ColumnData> columns,
|
||||
ReplaceExpressionType type, EventBus eventBus) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.column = column;
|
||||
this.columns = columns;
|
||||
this.type = type;
|
||||
this.eventBus = eventBus;
|
||||
Log.debug("Column: " + column);
|
||||
Log.debug("Columns: " + columns);
|
||||
init();
|
||||
create();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setWidth(WIDTH);
|
||||
calcHeight();
|
||||
|
||||
setBodyBorder(false);
|
||||
setHeaderVisible(false);
|
||||
// Important: fixed rendering of widgets
|
||||
forceLayoutOnResize = true;
|
||||
|
||||
}
|
||||
|
||||
protected void calcHeight() {
|
||||
if (column != null
|
||||
&& (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Integer.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Numeric.toString()) == 0 || column
|
||||
.getDataTypeName().compareTo(
|
||||
ColumnDataType.Geometry.toString()) == 0)) {
|
||||
parent.setHeight(PARENT_HEIGHT);
|
||||
setHeight(HEIGHT);
|
||||
|
||||
} else {
|
||||
parent.setHeight(PARENT_HEIGHT_REDUCE);
|
||||
setHeight(HEIGHT_REDUCE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
VerticalLayoutContainer basicLayout = new VerticalLayoutContainer();
|
||||
basicLayout.setAdjustForScroll(true);
|
||||
// basicLayout.setScrollMode(ScrollMode.AUTO);
|
||||
|
||||
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
|
||||
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
|
||||
flowButton.setPack(BoxLayoutPack.CENTER);
|
||||
|
||||
// Properties
|
||||
FieldSet properties = new FieldSet();
|
||||
properties.setHeadingText("Properties");
|
||||
properties.setCollapsible(false);
|
||||
|
||||
VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer();
|
||||
properties.add(propertiesLayout);
|
||||
|
||||
columnType = new TextField();
|
||||
columnType.setToolTip("The type of column");
|
||||
columnType.setReadOnly(true);
|
||||
propertiesLayout.add(new FieldLabel(columnType, "Column Type"),
|
||||
new VerticalLayoutData(1, -1));
|
||||
|
||||
dataType = new TextField();
|
||||
dataType.setToolTip("The data type");
|
||||
dataType.setReadOnly(true);
|
||||
propertiesLayout.add(new FieldLabel(dataType, "Data Type"),
|
||||
new VerticalLayoutData(1, -1));
|
||||
|
||||
// Value
|
||||
replaceValueFieldSet = new FieldSet();
|
||||
replaceValueFieldSet.setHeadingText("Replace Value");
|
||||
replaceValueFieldSet.setCollapsible(false);
|
||||
|
||||
calcReplaceValue();
|
||||
|
||||
//
|
||||
btnApply = new TextButton("Apply");
|
||||
btnApply.setIcon(ExpressionResources.INSTANCE
|
||||
.columnReplaceByExpression());
|
||||
btnApply.setIconAlign(IconAlign.RIGHT);
|
||||
btnApply.setTitle("Apply replace by expression");
|
||||
btnApply.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Apply");
|
||||
applyReplaceColumnByExpression();
|
||||
|
||||
}
|
||||
});
|
||||
if (column == null) {
|
||||
btnApply.disable();
|
||||
}
|
||||
|
||||
btnClose = new TextButton("Close");
|
||||
btnClose.setIcon(ExpressionResources.INSTANCE.close());
|
||||
btnClose.setIconAlign(IconAlign.RIGHT);
|
||||
btnClose.setTitle("Close");
|
||||
btnClose.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Close");
|
||||
close();
|
||||
}
|
||||
});
|
||||
flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
||||
flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
||||
|
||||
// Add to basic layout
|
||||
basicLayout.add(properties, new VerticalLayoutData(1, -1,
|
||||
new Margins(1)));
|
||||
basicLayout.add(replaceValueFieldSet, new VerticalLayoutData(1, -1,
|
||||
new Margins(1)));
|
||||
|
||||
basicLayout.add(flowButton, new VerticalLayoutData(1, 36, new Margins(
|
||||
5, 2, 5, 2)));
|
||||
add(basicLayout);
|
||||
|
||||
setSelectedColumn();
|
||||
|
||||
}
|
||||
|
||||
protected void calcReplaceValue() {
|
||||
replaceValueFieldSet.clear();
|
||||
VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer();
|
||||
replaceValueFieldSet.add(replaceValueFieldSetLayout);
|
||||
|
||||
if (column == null) {
|
||||
replaceValue = new TextField();
|
||||
replaceValue.setToolTip("Replace Value");
|
||||
replaceValue.setValue("");
|
||||
replaceValueFieldSetLayout.add(new FieldLabel(replaceValue,
|
||||
"Replace Value"), new VerticalLayoutData(1, -1));
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Date.toString()) == 0) {
|
||||
replaceValueDate = new DateField();
|
||||
replaceValueDate.setToolTip("Replace Value");
|
||||
replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate,
|
||||
"Replace Value"), new VerticalLayoutData(1, -1));
|
||||
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Integer.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Numeric.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Geometry.toString()) == 0) {
|
||||
|
||||
replaceWidget = new ReplaceWidget(column, columns,
|
||||
REPLACEWIDTH, REPLACEHEIGHT, eventBus);
|
||||
|
||||
replaceValueFieldSetLayout.add(replaceWidget,
|
||||
new VerticalLayoutData(1, -1));
|
||||
} else {
|
||||
replaceValue = new TextField();
|
||||
replaceValue.setToolTip("Replace Value");
|
||||
replaceValue.setValue("");
|
||||
replaceValueFieldSetLayout.add(new FieldLabel(replaceValue,
|
||||
"Replace Value"), new VerticalLayoutData(1, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setSelectedColumn() {
|
||||
if (column == null) {
|
||||
|
||||
} else {
|
||||
ColumnTypeCode typeCode = ColumnTypeCode
|
||||
.getColumnTypeCodeFromId(column.getTypeCode());
|
||||
HTML errorMessage;
|
||||
if (typeCode == null) {
|
||||
errorMessage = new HTML(
|
||||
"This column has column data type null!");
|
||||
UtilsGXT3.alert("Error",
|
||||
"This column has column data type null!!");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (typeCode) {
|
||||
case ANNOTATION:
|
||||
case ATTRIBUTE:
|
||||
case CODE:
|
||||
case CODEDESCRIPTION:
|
||||
case CODENAME:
|
||||
case MEASURE:
|
||||
columnType.setValue(column.getTypeCode());
|
||||
dataType.setValue(column.getDataTypeName());
|
||||
break;
|
||||
case DIMENSION:
|
||||
case TIMEDIMENSION:
|
||||
errorMessage = new HTML(
|
||||
"This type of column is not supported for now!");
|
||||
add(errorMessage);
|
||||
UtilsGXT3.alert("Error",
|
||||
"This type of column is not supported for now!");
|
||||
break;
|
||||
default:
|
||||
errorMessage = new HTML(
|
||||
"This type of column is not supported for now!");
|
||||
add(errorMessage);
|
||||
UtilsGXT3.alert("Error",
|
||||
"This type of column is not supported for now!");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyReplaceColumnByExpression() {
|
||||
String value = null;
|
||||
if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) {
|
||||
|
||||
Date valueDate = replaceValueDate.getCurrentValue();
|
||||
if (valueDate == null) {
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Select a valid date as replace value!");
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
value = sdf.format(valueDate);
|
||||
} catch (Throwable e) {
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Select a valid date as replace value!");
|
||||
return;
|
||||
}
|
||||
callApplyReplaceColumnByExpression(value);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Integer.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Numeric.toString()) == 0
|
||||
|| column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Geometry.toString()) == 0) {
|
||||
C_Expression cReplaceExpression = null;
|
||||
try {
|
||||
cReplaceExpression = replaceWidget.getExpression();
|
||||
if (cReplaceExpression == null) {
|
||||
UtilsGXT3.alert("Attention",
|
||||
"Replace expression is not valid!");
|
||||
return;
|
||||
}
|
||||
} catch (ReplaceTypeMapException e) {
|
||||
UtilsGXT3.alert("Attention", e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
callApplyReplaceColumnByExpression(cReplaceExpression);
|
||||
} else {
|
||||
value = replaceValue.getCurrentValue();
|
||||
if (checkValue(value)) {
|
||||
callApplyReplaceColumnByExpression(value);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void callApplyReplaceColumnByExpression(String replaceValue) {
|
||||
if (column == null) {
|
||||
UtilsGXT3.alert("Attention", "Select a valid column!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
UtilsGXT3.alert("Attention", "Type is null!");
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.REPLACE_COLUMN_EXPRESSION);
|
||||
expressionEvent.setReplaceByValue(true);
|
||||
expressionEvent.setReplaceValue(replaceValue);
|
||||
expressionEvent.setTrId(column.getTrId());
|
||||
expressionEvent.setColumnId(column.getColumnId());
|
||||
expressionEvent.setColumnName(column.getName());
|
||||
Log.debug(expressionEvent.toString());
|
||||
parent.hide();
|
||||
eventBus.fireEvent(expressionEvent);
|
||||
break;
|
||||
case Replace:
|
||||
parent.applyReplaceColumnByExpression(column, replaceValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void callApplyReplaceColumnByExpression(
|
||||
C_Expression cReplaceExpression) {
|
||||
if (column == null) {
|
||||
UtilsGXT3.alert("Attention", "Select a valid column!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
UtilsGXT3.alert("Attention", "Type is null!");
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case Template:
|
||||
ExpressionEvent expressionEvent = new ExpressionEvent(
|
||||
ExpressionType.REPLACE_COLUMN_EXPRESSION);
|
||||
expressionEvent.setReplaceByValue(false);
|
||||
C_ExpressionContainer replaceExpressionContainer = new C_ExpressionContainer(
|
||||
C_ExpressionContainer.Contains.C_Expression,
|
||||
cReplaceExpression, replaceWidget.getReadableExpression());
|
||||
expressionEvent
|
||||
.setC_ReplaceExpressionContainer(replaceExpressionContainer);
|
||||
|
||||
expressionEvent.setTrId(column.getTrId());
|
||||
expressionEvent.setColumnId(column.getColumnId());
|
||||
expressionEvent.setColumnName(column.getName());
|
||||
Log.debug(expressionEvent.toString());
|
||||
parent.hide();
|
||||
eventBus.fireEvent(expressionEvent);
|
||||
break;
|
||||
case Replace:
|
||||
parent.applyReplaceColumnByExpression(column, new C_ExpressionContainer(
|
||||
C_ExpressionContainer.Contains.C_Expression,
|
||||
cReplaceExpression, replaceWidget.getReadableExpression()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkValue(String value) {
|
||||
try {
|
||||
boolean ok = false;
|
||||
ColumnDataType columnDataType = ColumnDataType
|
||||
.getColumnDataTypeFromId(column.getDataTypeName());
|
||||
switch (columnDataType) {
|
||||
case Boolean:
|
||||
Boolean.valueOf(value);
|
||||
ok = true;
|
||||
break;
|
||||
case Date:
|
||||
ok = true;
|
||||
break;
|
||||
case Geometry:
|
||||
try {
|
||||
RegExp regExp = RegExp.compile(GEOMETRY_REGEXPR);
|
||||
MatchResult matcher = regExp.exec(value);
|
||||
boolean matchFound = matcher != null;
|
||||
if (matchFound) {
|
||||
ok = true;
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Insert a valid replace value for Geometry type! ");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Integer:
|
||||
try {
|
||||
Integer.parseInt(value);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Insert a valid replace value for Integer type! ");
|
||||
return false;
|
||||
}
|
||||
ok = true;
|
||||
break;
|
||||
case Numeric:
|
||||
try {
|
||||
Double.parseDouble(value);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Insert a valid replace value for Numeric type! ");
|
||||
return false;
|
||||
}
|
||||
ok = true;
|
||||
break;
|
||||
case Text:
|
||||
ok = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ok;
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Insert a valid replace value! " + e.getLocalizedMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
if (parent != null) {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,11 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client.type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public enum ReplaceColumnByExpressionType {
|
||||
Replace, Template;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client.type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public enum ReplaceExpressionType {
|
||||
Replace, Template;
|
||||
}
|
Loading…
Reference in New Issue