Updated AddColumn

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@113836 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-03-31 16:05:42 +00:00
parent 639a7aa11b
commit 51bc2bbd8e
2 changed files with 263 additions and 67 deletions

View File

@ -20,6 +20,8 @@ import org.gcube.portlets.user.td.columnwidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.expressionwidget.client.expression.ExpressionWrapperNotification;
import org.gcube.portlets.user.td.expressionwidget.client.expression.ExpressionWrapperNotification.ExpressionWrapperNotificationListener;
import org.gcube.portlets.user.td.expressionwidget.client.expression.ReplaceExpressionDialog;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
@ -50,8 +52,8 @@ 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.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
//import com.google.gwt.regexp.shared.MatchResult;
//import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
@ -61,6 +63,10 @@ import com.sencha.gxt.data.shared.LabelProvider;
import com.sencha.gxt.data.shared.ListStore;
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;
@ -79,8 +85,8 @@ import com.sencha.gxt.widget.core.client.info.Info;
*/
public class AddColumnPanel extends FramedPanel implements
CodelistSelectionListener, MonitorDialogListener {
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 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 = "640px";
private static final String HEIGHT = "520px";
@ -123,7 +129,10 @@ public class AddColumnPanel extends FramedPanel implements
private TextField defaultValueString;
private FieldLabel defaultStringLabel;
//private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
private ExpressionWrapper exWrapper;
private TextButton btnRemoveExpression;
// private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
/**
*
@ -167,10 +176,17 @@ public class AddColumnPanel extends FramedPanel implements
// Label
label = new TextField();
//Flow Expression
HBoxLayoutContainer flowExpression = new HBoxLayoutContainer();
flowExpression.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
flowExpression.setPack(BoxLayoutPack.START);
flowExpression.setAdjustForFlexRemainder(true);
// Default Value
defaultValueString = new TextField();
defaultStringLabel = new FieldLabel(defaultValueString, "Expression");
defaultStringLabel.addDomHandler(new ClickHandler() {
//defaultValueString.setWidth("166px");
defaultValueString.addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
@ -178,7 +194,34 @@ public class AddColumnPanel extends FramedPanel implements
}
}, ClickEvent.getType());
btnRemoveExpression = new TextButton();
btnRemoveExpression.setIcon(ExpressionResources.INSTANCE.delete());
btnRemoveExpression.setTitle("Remove expression");
btnRemoveExpression.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
Log.debug("Pressed Remove Expression");
removeExpression();
}
});
btnRemoveExpression.setVisible(false);
BoxLayoutData flex1 = new BoxLayoutData(new Margins(0));
flex1.setFlex(0);
BoxLayoutData flex2 = new BoxLayoutData(new Margins(0));
flex2.setFlex(1);
flowExpression.add(btnRemoveExpression, flex1);
flowExpression.add(defaultValueString, flex2);
defaultStringLabel = new FieldLabel(flowExpression, "Expression");
// comboColumnTypeCode
ColumnTypeCodeProperties propsColumnTypeCode = GWT
.create(ColumnTypeCodeProperties.class);
@ -385,6 +428,13 @@ public class AddColumnPanel extends FramedPanel implements
}
protected void removeExpression() {
exWrapper=null;
defaultValueString.reset();
btnRemoveExpression.setVisible(false);
forceLayout();
}
protected void openReplaceExpressionDialog() {
ColumnMockUp columnMockUp = retrieveColumnMockUp();
if (columnMockUp != null) {
@ -396,29 +446,36 @@ public class AddColumnPanel extends FramedPanel implements
@Override
public void onExpression(
ExpressionWrapperNotification expressionWrapperNotification) {
ExpressionWrapper exWrapper=expressionWrapperNotification.getExpressionWrapper();
if(exWrapper.isReplaceByValue()){
defaultValueString.setValue(exWrapper.getReplaceValue());
exWrapper = expressionWrapperNotification
.getExpressionWrapper();
if (exWrapper.isReplaceByValue()) {
defaultValueString.setValue(exWrapper
.getReplaceValue());
} else {
defaultValueString.setValue(exWrapper.getReplaceExpressionContainer().getReadableExpression());
defaultValueString.setValue(exWrapper
.getReplaceExpressionContainer()
.getReadableExpression());
}
btnRemoveExpression.setVisible(true);
forceLayout();
}
@Override
public void failed(Throwable throwable) {
Log.error("Error in AddColumn during expression creation:"+throwable.getLocalizedMessage());
Log.error("Error in AddColumn during expression creation:"
+ throwable.getLocalizedMessage());
}
@Override
public void aborted() {
defaultValueString.setValue(null);
Log.debug("Expression creation aborted");
}
});
replaceExpressionDialog.show();
}
@ -586,7 +643,11 @@ public class AddColumnPanel extends FramedPanel implements
comboDimensionTypeLabel.setVisible(false);
comboColumnReferenceTypeLabel.setVisible(false);
comboTimeDimensionTypeLabel.setVisible(false);
exWrapper=null;
defaultValueString.reset();
btnRemoveExpression.setVisible(false);
defaultStringLabel.setVisible(true);
break;
case ATTRIBUTE:
comboLocaleTypeLabel.setVisible(false);
@ -613,6 +674,9 @@ public class AddColumnPanel extends FramedPanel implements
comboDimensionTypeLabel.setVisible(false);
comboColumnReferenceTypeLabel.setVisible(false);
comboTimeDimensionTypeLabel.setVisible(false);
exWrapper=null;
defaultValueString.reset();
btnRemoveExpression.setVisible(false);
defaultStringLabel.setVisible(true);
break;
case TIMEDIMENSION:
@ -631,6 +695,9 @@ public class AddColumnPanel extends FramedPanel implements
comboDimensionTypeLabel.setVisible(false);
comboColumnReferenceTypeLabel.setVisible(false);
comboTimeDimensionTypeLabel.setVisible(false);
exWrapper=null;
defaultValueString.reset();
btnRemoveExpression.setVisible(false);
defaultStringLabel.setVisible(true);
break;
}
@ -644,6 +711,9 @@ public class AddColumnPanel extends FramedPanel implements
protected void updateAttributeType(ColumnDataType type) {
Log.debug("Update ColumnTypeCode " + type.toString());
exWrapper=null;
defaultValueString.reset();
btnRemoveExpression.setVisible(false);
defaultStringLabel.setVisible(true);
forceLayout();
@ -682,8 +752,27 @@ public class AddColumnPanel extends FramedPanel implements
ColumnDataType dataType = columnDataTypeElement
.getType();
if (dataType != null) {
columnMockUp = new ColumnMockUp(null, null, labelS,
type, dataType, defaultV);
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType, defaultV);
} else {
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType,
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,
dataType,
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(trId,
columnMockUp);
callAddColumm();
@ -705,34 +794,95 @@ public class AddColumnPanel extends FramedPanel implements
.getType();
if (dataType != null) {
if (dataType == ColumnDataType.Geometry) {
RegExp regExp = RegExp
.compile(GEOMETRY_REGEXPR);
MatchResult matcher = regExp.exec(defaultV);
boolean matchFound = matcher != null;
if (matchFound) {
// RegExp regExp = RegExp
// .compile(GEOMETRY_REGEXPR);
// MatchResult matcher = regExp.exec(defaultV);
// boolean matchFound = matcher != null;
// if (matchFound) {
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType, defaultV);
addColumnSession = new AddColumnSession(
trId, columnMockUp);
callAddColumm();
} else {
UtilsGXT3
.alert("Attention",
"The default value is not a valid text representation for geometry type ( e.g. POINT(34 56) or LINESTRING(65 34, 56.43 78.65)!");
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(null,
null, labelS, type, dataType,
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,
dataType,
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(trId,
columnMockUp);
callAddColumm();
// } else {
// UtilsGXT3
// .alert("Attention",
// "The default value is not a valid text representation for geometry type ( e.g. POINT(34 56) or LINESTRING(65 34, 56.43 78.65)!");
// }
} else {
if (dataType == ColumnDataType.Date) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType, defaultV);
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null,
null, labelS, type, dataType,
defaultV);
} else {
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(
null, null, labelS, type,
dataType,
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,
dataType,
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(
trId, columnMockUp);
callAddColumm();
} else {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType, defaultV);
addColumnSession = new AddColumnSession(
trId, columnMockUp);
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType, defaultV);
} else {
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, dataType,
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,
dataType,
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(trId,
columnMockUp);
callAddColumm();
}
@ -748,17 +898,56 @@ public class AddColumnPanel extends FramedPanel implements
}
break;
case CODE:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
defaultV);
addColumnSession = new AddColumnSession(trId, columnMockUp);
case CODEDESCRIPTION:
case ANNOTATION:
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, defaultV);
} else {
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type,
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(trId,
columnMockUp);
callAddColumm();
break;
case CODENAME:
LocaleTypeElement locale = comboLocaleType
.getCurrentValue();
if (locale != null) {
columnMockUp = new ColumnMockUp(null, null, labelS,
type, locale.getLocaleName(), defaultV);
if (defaultV == null || defaultV.isEmpty()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type,locale.getLocaleName(), defaultV);
} else {
if (exWrapper.isReplaceByValue()) {
columnMockUp = new ColumnMockUp(null, null,
labelS, type, locale.getLocaleName(),
exWrapper.getReplaceValue());
} else {
columnMockUp = new ColumnMockUp(
null,
null,
labelS,
type,locale.getLocaleName(),
exWrapper
.getReplaceExpressionContainer()
.getExp());
}
}
addColumnSession = new AddColumnSession(trId,
columnMockUp);
callAddColumm();
@ -766,18 +955,7 @@ public class AddColumnPanel extends FramedPanel implements
UtilsGXT3.alert("Attention", "No locale selected!");
}
break;
case CODEDESCRIPTION:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
defaultV);
addColumnSession = new AddColumnSession(trId, columnMockUp);
callAddColumm();
break;
case ANNOTATION:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
defaultV);
addColumnSession = new AddColumnSession(trId, columnMockUp);
callAddColumm();
break;
case DIMENSION:
ColumnData columnReference = comboColumnReferenceType
.getCurrentValue();
@ -871,6 +1049,8 @@ public class AddColumnPanel extends FramedPanel implements
}
break;
case CODE:
case CODEDESCRIPTION:
case ANNOTATION:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
"");
break;
@ -886,14 +1066,6 @@ public class AddColumnPanel extends FramedPanel implements
UtilsGXT3.alert("Attention", "No locale selected!");
}
break;
case CODEDESCRIPTION:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
"");
break;
case ANNOTATION:
columnMockUp = new ColumnMockUp(null, null, labelS, type,
"");
break;
case DIMENSION:
ColumnData columnReference = comboColumnReferenceType
.getCurrentValue();
@ -935,7 +1107,7 @@ public class AddColumnPanel extends FramedPanel implements
private void callAddColumm() {
Log.debug(addColumnSession.toString());
TDGWTServiceAsync.INSTANCE.startAddColumn(addColumnSession,
ExpressionServiceAsync.INSTANCE.startAddColumn(addColumnSession,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {

View File

@ -50,6 +50,9 @@ import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.info.Info;
/**
* This Panel is used only with Codelist,
* so only with CODE,CODENAME,CODEDESCRIPTION,ANNOTATION columns
*
*
* @author "Giancarlo Panichi"
*
@ -235,8 +238,8 @@ public class CreateDefColumnPanel extends FramedPanel {
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
flowButton.setPack(BoxLayoutPack.CENTER);
BoxLayoutData boxLayoutData=new BoxLayoutData(new Margins(2, 4, 2, 4));
BoxLayoutData boxLayoutData = new BoxLayoutData(new Margins(2, 4, 2, 4));
flowButton.add(btnSave, boxLayoutData);
flowButton.add(btnClose, boxLayoutData);
@ -250,6 +253,7 @@ public class CreateDefColumnPanel extends FramedPanel {
}
protected void save() {
ColumnMockUp defNewColumn;
ColumnTypeCode currentType = null;
String localeName = null;
@ -280,7 +284,18 @@ public class CreateDefColumnPanel extends FramedPanel {
currentType = typeElement.getCode();
}
}
if (currentType != null && currentType == ColumnTypeCode.CODENAME) {
switch (currentType) {
case ATTRIBUTE:
return;
case CODE:
case CODEDESCRIPTION:
case ANNOTATION:
defNewColumn = new ColumnMockUp(null, null, lab, currentType,
valueDefault);
break;
case CODENAME:
if (localeElement == null) {
UtilsGXT3.alert("Attention", "No locale selected");
btnSave.enable();
@ -293,12 +308,21 @@ public class CreateDefColumnPanel extends FramedPanel {
return;
} else {
localeName = localeElement.getLocaleName();
defNewColumn = new ColumnMockUp(null, null, lab,
currentType, localeName, valueDefault);
}
}
}
break;
case DIMENSION:
return;
case MEASURE:
return;
case TIMEDIMENSION:
return;
default:
return;
ColumnMockUp defNewColumn = new ColumnMockUp(null, null,
lab, currentType, localeName, valueDefault);
}
Log.debug("DefNewColumn:" + defNewColumn);
fireCompleted(defNewColumn);