fixed time, time interval and list of times
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@133392 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f2c69764d0
commit
bd85d7b595
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.MetaDataFieldSkeleton;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
|
@ -62,28 +61,28 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
//fields.add(new MetadataFieldWrapper("Text Area", false, DataType.Text, "This is the default value", "Text Area", null, "^#\\w+\\.$"));
|
||||
|
||||
// textbox
|
||||
//fields.add(new MetadataFieldWrapper("TextBox", true, DataType.String, null, "TextBox", null, "^#\\w+\\.$"));
|
||||
// fields.add(new MetadataFieldWrapper("TextBox", true, DataType.String, null, "TextBox", null, "^#\\w+\\.$"));
|
||||
|
||||
// listbox
|
||||
//fields.add(new MetadataFieldWrapper("ListBox", true, DataType.String, "prova4", "ListBox", Arrays.asList("prova1", "prova2", "prova3"), null));
|
||||
// fields.add(new MetadataFieldWrapper("ListBox", true, DataType.String, "prova4", "ListBox", Arrays.asList("prova1", "prova2", "prova3"), null));
|
||||
|
||||
// single date
|
||||
//fields.add(new MetadataFieldWrapper("Single date", true, DataType.Time, null, "Single date", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Single date", true, DataType.Time, null, "Single date", null, null));
|
||||
|
||||
// single date
|
||||
//fields.add(new MetadataFieldWrapper("Single date 2", false, DataType.Time, "2045-12-01 18:20", "Single date 2", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Single date 2", true, DataType.Time, "2045-12-01 21:32", "Single date 2", null, null));
|
||||
|
||||
// time interval
|
||||
//fields.add(new MetadataFieldWrapper("Time interval 1", false, DataType.Time_Interval, null, "Time interval 1", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Time interval 1", false, DataType.Time_Interval, "2045-12-01 21:32/2045-12-01 21:32", "Time interval 1", null, null));
|
||||
|
||||
// time interval
|
||||
//fields.add(new MetadataFieldWrapper("Time interval 2", true, DataType.Time_Interval, null, "Time interval 2", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Time interval 2", true, DataType.Time_Interval, null, "Time interval 2", null, null));
|
||||
|
||||
// time interval
|
||||
//fields.add(new MetadataFieldWrapper("Time intervals 2", true, DataType.Time_Interval, null, "Time intervals 2", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Time intervals 2", true, DataType.Time_Interval, null, "Time intervals 2", null, null));
|
||||
|
||||
// time interval lists
|
||||
fields.add(new MetadataFieldWrapper("Time intervals 2", false, DataType.Times_ListOf, null, "Time intervals 2", null, null));
|
||||
// fields.add(new MetadataFieldWrapper("Time intervals 2", false, DataType.Times_ListOf, "2010-10-12 15:23", "Time intervals 2", null, null));
|
||||
|
||||
final ArrayList<MetaDataFieldSkeleton> widgetsList = new ArrayList<MetaDataFieldSkeleton>();
|
||||
for (MetadataFieldWrapper metadataFieldWrapper : fields) {
|
||||
|
@ -107,17 +106,27 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
|
||||
for (MetaDataFieldSkeleton field : widgetsList) {
|
||||
String error = field.isFieldValueValid();
|
||||
if(error != null){
|
||||
if(error != null)
|
||||
Window.alert(field.getFieldName() + " is not valid. Suggestion: " + error);
|
||||
}else
|
||||
{
|
||||
Window.alert("No ERROR: " + field.getFieldCurrentValue() + " and without missing " + field.getTimeIntervalOrTimeListWithoutMissing());
|
||||
}
|
||||
else
|
||||
Window.alert("No ERROR: " + field.getFieldCurrentValue());
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button freezeAll = new Button("Freeze");
|
||||
panel.add(freezeAll);
|
||||
|
||||
freezeAll.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
for (MetaDataFieldSkeleton field : widgetsList)
|
||||
field.freeze();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.reso
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.ResourcesTable;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.TagsPanel;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
||||
|
@ -763,10 +762,7 @@ public class CreateDatasetForm extends Composite{
|
|||
// prepare custom fields
|
||||
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
|
||||
|
||||
MetadataFieldWrapper originalField = field.getField();
|
||||
|
||||
String value = originalField.getType().equals(DataType.Time_Interval) || originalField.getType().equals(DataType.Times_ListOf) ?
|
||||
field.getTimeIntervalOrTimeListWithoutMissing() : field.getFieldCurrentValue();
|
||||
String value = field.getFieldCurrentValue();
|
||||
|
||||
if(!value.isEmpty())
|
||||
customFieldsMap.put(field.getFieldName(), field.getFieldCurrentValue());
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEvent;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.timeandreanges.DataTimeBox;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||
|
||||
|
@ -20,19 +21,16 @@ import com.github.gwtbootstrap.client.ui.TextArea;
|
|||
import com.github.gwtbootstrap.client.ui.TextBox;
|
||||
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.github.gwtbootstrap.datetimepicker.client.ui.DateTimeBox;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.SpanElement;
|
||||
import com.google.gwt.dom.client.Style.Cursor;
|
||||
import com.google.gwt.dom.client.Style.Display;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.logical.shared.ResizeEvent;
|
||||
import com.google.gwt.event.logical.shared.ResizeHandler;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
|
@ -76,31 +74,22 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
// the dialog box for this metadata
|
||||
private GcubeDialogExtended dialog;
|
||||
|
||||
// range list
|
||||
private List<DataTimeBox> rangesList = new ArrayList<DataTimeBox>();
|
||||
|
||||
// save event bus reference
|
||||
private HandlerManager eventBus;
|
||||
|
||||
// the date formatter(s) to use
|
||||
private DateTimeFormat format1 = DateTimeFormat.getFormat("yyyy-MM-dd");
|
||||
private DateTimeFormat format2 = DateTimeFormat.getFormat("yyyy-MM-dd hh:mm");
|
||||
|
||||
// labels
|
||||
private static final String INSERT_TIME_INSTANT_LABEL = "Insert a time instant";
|
||||
private static final String INSERT_TIME_START_LABEL = "Insert a start time instant";
|
||||
private static final String INSERT_TIME_END_LABEL = "Insert an end time instant";
|
||||
|
||||
// errors
|
||||
private static final String MANDATORY_ATTRIBUTE_MISSING = "a mandatory attribute cannot be empty";
|
||||
private static final String MALFORMED_ATTRIBUTE = " the inserted value has a wrong format";
|
||||
private static final String ADD_NEW_TIME_RANGE = "Add a new Time Range";
|
||||
private static final String DELETE_TIME_RANGE = "Delete this Time Range";
|
||||
private static final String DELETE_TIME_RANGE = "Delete the last Time Range";
|
||||
|
||||
// missing range value
|
||||
public static final String MISSING_RANGE_VALUE = "missing";
|
||||
private static final String INSERT_MISSING_VALUE = " one or more range values missing";
|
||||
private static final String INSERT_MISSING_VALUE_MANDATORY = " one or more range values missing in mandatory field(s)";
|
||||
|
||||
private static final String INSERT_MISSING_VALUE = " one or more range value missing";
|
||||
private static final String INSERT_MISSING_VALUE_MANDATORY = " one or more range value missing in mandatory attribute";
|
||||
// time range separator
|
||||
public static final String RANGE_SEPARATOR_START_END = "/";
|
||||
public static final String RANGE_SEPARATOR = ",";
|
||||
|
||||
public MetaDataFieldSkeleton(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception{
|
||||
|
@ -121,7 +110,6 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
// its a checkbox
|
||||
holder = new CheckBox();
|
||||
|
||||
if(field.getDefaultValue() != null)
|
||||
((CheckBox)holder).setValue(Boolean.valueOf(field.getDefaultValue()));
|
||||
break;
|
||||
|
@ -132,59 +120,28 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
if(field.getDefaultValue() != null)
|
||||
((TextArea)holder).setText(field.getDefaultValue());
|
||||
|
||||
break;
|
||||
|
||||
case Time:
|
||||
|
||||
holder = new DateTimeBox();
|
||||
|
||||
((DateTimeBox)holder).setAutoClose(true);
|
||||
((DateTimeBox)holder).setPlaceholder(INSERT_TIME_INSTANT_LABEL);
|
||||
|
||||
// check the formatter to be used
|
||||
DateTimeFormat formatter = checkFormatterToUse(field.getDefaultValue());
|
||||
((DateTimeBox)holder).setFormat(formatter.getPattern());
|
||||
|
||||
if(field.getDefaultValue() != null && !field.getDefaultValue().isEmpty())
|
||||
((DateTimeBox)holder).setValue(formatter.parse(field.getDefaultValue()));
|
||||
else
|
||||
((DateTimeBox)holder).setValue(null);
|
||||
DataTimeBox ref;
|
||||
holder = ref = new DataTimeBox(false);
|
||||
|
||||
// set time, if present
|
||||
if(field.getDefaultValue() != null && !field.getDefaultValue().isEmpty()){
|
||||
String[] dateAndTime = field.getDefaultValue().split(" ");
|
||||
if(dateAndTime.length > 0){
|
||||
ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Time_Interval:
|
||||
|
||||
holder = new FlowPanel();
|
||||
|
||||
DateTimeFormat formatterTimeInterval = checkFormatterToUse(field.getDefaultValue());
|
||||
|
||||
// start and end range date
|
||||
DateTimeBox start = new DateTimeBox();
|
||||
DateTimeBox end = new DateTimeBox();
|
||||
start.setWidth("40%");
|
||||
start.getElement().getStyle().setMarginRight(10, Unit.PCT);
|
||||
end.setWidth("40%");
|
||||
|
||||
// add two calendars
|
||||
((FlowPanel)holder).add(start);
|
||||
((FlowPanel)holder).add(end);
|
||||
|
||||
start.setFormat(formatterTimeInterval.getPattern());
|
||||
end.setFormat(formatterTimeInterval.getPattern());
|
||||
|
||||
start.setPlaceholder(INSERT_TIME_START_LABEL);
|
||||
end.setPlaceholder(INSERT_TIME_END_LABEL);
|
||||
|
||||
if(field.getDefaultValue() != null && !field.getDefaultValue().isEmpty()){
|
||||
Date parsedTime = formatterTimeInterval.parse(field.getDefaultValue());
|
||||
start.setValue(parsedTime);
|
||||
end.setValue(parsedTime);
|
||||
}else{
|
||||
start.setValue(null);
|
||||
end.setValue(null);
|
||||
}
|
||||
|
||||
DataTimeBox rangeBox;
|
||||
holder = rangeBox = new DataTimeBox(true);
|
||||
setRangeTimeInTimeBox(field.getDefaultValue(), rangeBox);
|
||||
rangesList.add(rangeBox);
|
||||
break;
|
||||
|
||||
case Times_ListOf:
|
||||
|
@ -194,28 +151,12 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
// start and end range date
|
||||
final VerticalPanel containerRanges = new VerticalPanel();
|
||||
containerRanges.setWidth("100%");
|
||||
FlowPanel panelFirstRange = new FlowPanel();
|
||||
DateTimeBox startFirstRange = new DateTimeBox();
|
||||
DateTimeBox endFirstRange = new DateTimeBox();
|
||||
startFirstRange.setPlaceholder(INSERT_TIME_START_LABEL);
|
||||
endFirstRange.setPlaceholder(INSERT_TIME_END_LABEL);
|
||||
startFirstRange.setWidth("40%");
|
||||
startFirstRange.getElement().getStyle().setMarginRight(10, Unit.PCT);
|
||||
endFirstRange.setWidth("40%");
|
||||
|
||||
final DateTimeFormat formatterTimeIntervalList = checkFormatterToUse(field.getDefaultValue());
|
||||
|
||||
startFirstRange.setFormat(formatterTimeIntervalList.getPattern());
|
||||
endFirstRange.setFormat(formatterTimeIntervalList.getPattern());
|
||||
|
||||
if(field.getDefaultValue() != null && !field.getDefaultValue().isEmpty()){
|
||||
Date formattedDefaultValueListOf = formatterTimeIntervalList.parse(field.getDefaultValue());
|
||||
startFirstRange.setValue(formattedDefaultValueListOf);
|
||||
endFirstRange.setValue(formattedDefaultValueListOf);
|
||||
}else{
|
||||
startFirstRange.setValue(null);
|
||||
endFirstRange.setValue(null);
|
||||
}
|
||||
SimplePanel panelFirstRange = new SimplePanel();
|
||||
DataTimeBox rangeBoxFirst = new DataTimeBox(true);
|
||||
setRangeTimeInTimeBox(field.getDefaultValue(), rangeBoxFirst);
|
||||
((SimplePanel)panelFirstRange).add(rangeBoxFirst);
|
||||
rangesList.add(rangeBoxFirst);
|
||||
|
||||
// Add more button
|
||||
Button addRangeButton = new Button();
|
||||
|
@ -228,27 +169,9 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
public void onClick(ClickEvent event) {
|
||||
|
||||
final FlowPanel newRange = new FlowPanel();
|
||||
DateTimeBox startNewRange = new DateTimeBox();
|
||||
DateTimeBox endNewRange = new DateTimeBox();
|
||||
|
||||
startNewRange.setWidth("40%");
|
||||
startNewRange.getElement().getStyle().setMarginRight(10, Unit.PCT);
|
||||
endNewRange.setWidth("40%");
|
||||
endNewRange.getElement().getStyle().setMarginRight(2, Unit.PCT);
|
||||
|
||||
startNewRange.setFormat(formatterTimeIntervalList.getPattern());
|
||||
endNewRange.setFormat(formatterTimeIntervalList.getPattern());
|
||||
|
||||
startNewRange.setPlaceholder(INSERT_TIME_START_LABEL);
|
||||
endNewRange.setPlaceholder(INSERT_TIME_END_LABEL);
|
||||
|
||||
if(field.getDefaultValue() != null && !field.getDefaultValue().isEmpty()){
|
||||
startNewRange.setValue(formatterTimeIntervalList.parse(field.getDefaultValue()));
|
||||
endNewRange.setValue(formatterTimeIntervalList.parse(field.getDefaultValue()));
|
||||
}else{
|
||||
startNewRange.setValue(null);
|
||||
endNewRange.setValue(null);
|
||||
}
|
||||
final DataTimeBox newRangeBox = new DataTimeBox(true);
|
||||
setRangeTimeInTimeBox(field.getDefaultValue(), newRangeBox);
|
||||
rangesList.add(newRangeBox);
|
||||
|
||||
// delete button
|
||||
Button deleteRangeButton = new Button("", IconType.MINUS_SIGN, new ClickHandler() {
|
||||
|
@ -257,13 +180,11 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
public void onClick(ClickEvent event) {
|
||||
|
||||
newRange.removeFromParent();
|
||||
|
||||
rangesList.remove(newRangeBox);
|
||||
}
|
||||
});
|
||||
deleteRangeButton.setTitle(DELETE_TIME_RANGE);
|
||||
|
||||
newRange.add(startNewRange);
|
||||
newRange.add(endNewRange);
|
||||
newRange.add(newRangeBox);
|
||||
newRange.add(deleteRangeButton);
|
||||
containerRanges.add(newRange);
|
||||
|
||||
|
@ -271,8 +192,6 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
});
|
||||
|
||||
// add calendars and plus sign
|
||||
panelFirstRange.add(startFirstRange);
|
||||
panelFirstRange.add(endFirstRange);
|
||||
containerRanges.add(panelFirstRange);
|
||||
|
||||
// add the vertical panel first, then the button
|
||||
|
@ -377,25 +296,6 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we need to use format1 or format2
|
||||
* @param defaultValue
|
||||
* @return format2 is returned as default
|
||||
*/
|
||||
private DateTimeFormat checkFormatterToUse(String defaultValue) {
|
||||
if(defaultValue == null || defaultValue.isEmpty())
|
||||
return format2;
|
||||
else{
|
||||
try{
|
||||
format1.parse(defaultValue);
|
||||
return format1;
|
||||
}catch(Exception e){
|
||||
GWT.log("Unable to parse default value with format 1", e);
|
||||
return format2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind on events
|
||||
*/
|
||||
|
@ -471,73 +371,42 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
String dateValue = getFieldCurrentValue();
|
||||
|
||||
if(field.getMandatory()){
|
||||
if(dateValue == null || dateValue.isEmpty())
|
||||
if(dateValue.isEmpty())
|
||||
return MANDATORY_ATTRIBUTE_MISSING;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
case Time_Interval:
|
||||
|
||||
String dateValueInterval = getFieldCurrentValue();
|
||||
String rangeValue = rangesList.get(0).getCurrentValue();
|
||||
|
||||
if(field.getMandatory()){
|
||||
if(dateValueInterval.contains(MISSING_RANGE_VALUE))
|
||||
return INSERT_MISSING_VALUE_MANDATORY; // there cannot be "missing" values here
|
||||
else
|
||||
return null;
|
||||
}else{
|
||||
|
||||
String[] values = dateValueInterval.split(RANGE_SEPARATOR_START_END);
|
||||
|
||||
if(values.length == 1)
|
||||
return null; // same instants
|
||||
else{
|
||||
|
||||
if(values[0].equals(values[1]) && values[0].equals(MISSING_RANGE_VALUE))
|
||||
return null; // missing/missing
|
||||
|
||||
if(!values[0].equals(MISSING_RANGE_VALUE) && !values[1].equals(MISSING_RANGE_VALUE))
|
||||
return null;
|
||||
if(rangeValue.contains(DataTimeBox.MISSING_RANGE_VALUE))
|
||||
return INSERT_MISSING_VALUE_MANDATORY;
|
||||
}
|
||||
|
||||
if(rangeValue.contains(DataTimeBox.MISSING_RANGE_VALUE) && !rangeValue.equals(DataTimeBox.MISSING_RANGE_VALUE + DataTimeBox.RANGE_SEPARATOR_START_END + DataTimeBox.MISSING_RANGE_VALUE))
|
||||
return INSERT_MISSING_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
case Times_ListOf:
|
||||
|
||||
String dateValuesInterval = getFieldCurrentValue();
|
||||
for(DataTimeBox el: rangesList){
|
||||
|
||||
String currentValue = el.getCurrentValue();
|
||||
if(field.getMandatory()){
|
||||
if(dateValuesInterval.contains(MISSING_RANGE_VALUE)) // there cannot be "missing" values here
|
||||
if(currentValue.contains(DataTimeBox.MISSING_RANGE_VALUE))
|
||||
return INSERT_MISSING_VALUE_MANDATORY;
|
||||
else
|
||||
}
|
||||
|
||||
GWT.log("Printing " + currentValue);
|
||||
if(currentValue.contains(DataTimeBox.MISSING_RANGE_VALUE) && !currentValue.equals(DataTimeBox.MISSING_RANGE_VALUE + DataTimeBox.RANGE_SEPARATOR_START_END + DataTimeBox.MISSING_RANGE_VALUE))
|
||||
return INSERT_MISSING_VALUE;
|
||||
|
||||
}
|
||||
return null;
|
||||
}else{
|
||||
|
||||
String[] values = dateValuesInterval.split(RANGE_SEPARATOR);
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
||||
String[] splitSingleRange = values[i].split(RANGE_SEPARATOR_START_END);
|
||||
|
||||
if(splitSingleRange.length == 1)
|
||||
continue; // same instants
|
||||
else{
|
||||
|
||||
if(splitSingleRange[0].equals(splitSingleRange[1]) && splitSingleRange[0].equals(MISSING_RANGE_VALUE))
|
||||
continue; // missing/missing, it's ok
|
||||
|
||||
if(!splitSingleRange[0].equals(MISSING_RANGE_VALUE) && !splitSingleRange[1].equals(MISSING_RANGE_VALUE)) // value/value is ok too
|
||||
continue;
|
||||
|
||||
return INSERT_MISSING_VALUE; // something like missing/x or x/missing
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
case Number:
|
||||
|
||||
|
@ -640,63 +509,43 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
case Time:
|
||||
|
||||
Date date = ((DateTimeBox)holder).getValue();
|
||||
if(date == null)
|
||||
return null;
|
||||
else{
|
||||
DateTimeFormat formatter = checkFormatterToUse(field.getDefaultValue());
|
||||
return formatter.format(date);
|
||||
}
|
||||
toReturn = ((DataTimeBox)holder).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE, "");
|
||||
break;
|
||||
|
||||
case Time_Interval:
|
||||
|
||||
DateTimeBox init = (DateTimeBox)((FlowPanel)holder).getWidget(0);
|
||||
DateTimeBox end = (DateTimeBox)((FlowPanel)holder).getWidget(1);
|
||||
toReturn = rangesList.get(0).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE, "");
|
||||
if(toReturn.equals(DataTimeBox.RANGE_SEPARATOR_START_END))
|
||||
toReturn = "";
|
||||
|
||||
Date initDate = init.getValue();
|
||||
Date endDate = end.getValue();
|
||||
|
||||
DateTimeFormat formatter = checkFormatterToUse(field.getDefaultValue());
|
||||
|
||||
String initDateAsString = initDate == null ? MISSING_RANGE_VALUE : formatter.format(initDate);
|
||||
String endDateAsString = endDate == null ? MISSING_RANGE_VALUE : formatter.format(endDate);
|
||||
|
||||
if(initDateAsString.equals(endDateAsString) && !initDateAsString.equals(MISSING_RANGE_VALUE))
|
||||
toReturn = formatter.format(initDate); // an instant
|
||||
else
|
||||
toReturn = initDateAsString + RANGE_SEPARATOR_START_END + endDateAsString;
|
||||
|
||||
GWT.log("Time_Interval " + toReturn);
|
||||
// split to check if the extreme are equals
|
||||
String[] temp = toReturn.split("/");
|
||||
if(temp[0].equals(temp[1]))
|
||||
toReturn = temp[0];
|
||||
|
||||
break;
|
||||
|
||||
case Times_ListOf:
|
||||
|
||||
// get container
|
||||
VerticalPanel containerRanges = (VerticalPanel)((FlowPanel)holder).getWidget(0);
|
||||
toReturn = "";
|
||||
for (DataTimeBox elem : rangesList) {
|
||||
|
||||
// get its children count
|
||||
int values = containerRanges.getWidgetCount();
|
||||
String currentRange = elem.getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE, "");
|
||||
if(currentRange.equals(DataTimeBox.RANGE_SEPARATOR_START_END))
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < values; i++) {
|
||||
|
||||
// get FlowPanel panel
|
||||
FlowPanel line = (FlowPanel)containerRanges.getWidget(i);
|
||||
DateTimeBox initRangeInLine = (DateTimeBox)line.getWidget(0);
|
||||
DateTimeBox endRangeInLine = (DateTimeBox)line.getWidget(1);
|
||||
DateTimeFormat formatterRange = checkFormatterToUse(field.getDefaultValue());
|
||||
String initRangeAsString = initRangeInLine.getValue() == null ? MISSING_RANGE_VALUE : formatterRange.format(initRangeInLine.getValue());
|
||||
String endRangeAsString = endRangeInLine.getValue() == null ? MISSING_RANGE_VALUE : formatterRange.format(endRangeInLine.getValue());
|
||||
|
||||
if(initRangeAsString.equals(endRangeAsString) && !endRangeAsString.equals(MISSING_RANGE_VALUE))
|
||||
toReturn += (i == 0) ? initRangeAsString :
|
||||
RANGE_SEPARATOR + initRangeAsString; // an instant
|
||||
String[] splitted = currentRange.split(DataTimeBox.RANGE_SEPARATOR_START_END);
|
||||
if(splitted[0].equals(splitted[1]))
|
||||
toReturn += (toReturn.isEmpty()) ? splitted[0] : RANGE_SEPARATOR + splitted[0];
|
||||
else
|
||||
toReturn += (i == 0) ? initRangeAsString + RANGE_SEPARATOR_START_END + endRangeAsString :
|
||||
RANGE_SEPARATOR + initRangeAsString + RANGE_SEPARATOR_START_END + endRangeAsString;
|
||||
toReturn += (toReturn.isEmpty()) ? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1] :
|
||||
RANGE_SEPARATOR + splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1];
|
||||
|
||||
}
|
||||
|
||||
if(toReturn.endsWith(RANGE_SEPARATOR))
|
||||
toReturn = toReturn.substring(0, toReturn.length() - 1);
|
||||
|
||||
break;
|
||||
|
||||
case Number:
|
||||
|
@ -760,34 +609,18 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
case Time:
|
||||
|
||||
((DateTimeBox)holder).setEnabled(false);
|
||||
((DataTimeBox)holder).freeze();
|
||||
break;
|
||||
|
||||
case Time_Interval:
|
||||
|
||||
((DateTimeBox)((FlowPanel)holder).getWidget(0)).setEnabled(false);
|
||||
((DateTimeBox)((FlowPanel)holder).getWidget(1)).setEnabled(false);
|
||||
rangesList.get(0).freeze();
|
||||
break;
|
||||
|
||||
case Times_ListOf:
|
||||
|
||||
// get container
|
||||
VerticalPanel containerRanges = (VerticalPanel)((FlowPanel)holder).getWidget(0);
|
||||
|
||||
// freeze the button too
|
||||
((Button)((FlowPanel)holder).getWidget(1)).setEnabled(false);
|
||||
|
||||
// get its children count
|
||||
int values = containerRanges.getWidgetCount();
|
||||
|
||||
for (int i = 0; i < values; i++) {
|
||||
|
||||
// get FlowPanel panel
|
||||
FlowPanel line = (FlowPanel)containerRanges.getWidget(i);
|
||||
((DateTimeBox)line.getWidget(0)).setEnabled(false);
|
||||
((DateTimeBox)line.getWidget(1)).setEnabled(false);
|
||||
|
||||
}
|
||||
for(DataTimeBox el : rangesList)
|
||||
el.freeze();
|
||||
|
||||
break;
|
||||
|
||||
|
@ -809,56 +642,6 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use it to retrieve TimeInterval or TimeListOf after isValidField() invocation returned true (and only for these types!)
|
||||
* @return
|
||||
*/
|
||||
public String getTimeIntervalOrTimeListWithoutMissing(){
|
||||
|
||||
String currentValue = getFieldCurrentValue();
|
||||
|
||||
switch(field.getType()){
|
||||
|
||||
case Time_Interval:
|
||||
|
||||
String tempCurrentValue = currentValue.replaceAll(MISSING_RANGE_VALUE, "").replaceAll(RANGE_SEPARATOR_START_END, "");
|
||||
if(tempCurrentValue.trim().equals(""))
|
||||
return "";
|
||||
else
|
||||
return currentValue;
|
||||
|
||||
case Times_ListOf:
|
||||
|
||||
String toReturn = "";
|
||||
|
||||
String[] values = currentValue.split(RANGE_SEPARATOR);
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
||||
String[] splitSingleRange = values[i].split(RANGE_SEPARATOR_START_END);
|
||||
|
||||
if(splitSingleRange.length == 1)
|
||||
toReturn += splitSingleRange + RANGE_SEPARATOR; // same instants
|
||||
else{
|
||||
|
||||
if(splitSingleRange[0].equals(splitSingleRange[1]) && splitSingleRange[0].equals(MISSING_RANGE_VALUE))
|
||||
continue; // missing/missing, it's ok
|
||||
|
||||
if(!splitSingleRange[0].equals(MISSING_RANGE_VALUE) && !splitSingleRange[1].equals(MISSING_RANGE_VALUE)) // value/value is ok too
|
||||
toReturn += splitSingleRange[0] + RANGE_SEPARATOR_START_END + splitSingleRange[1] + RANGE_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
if(toReturn.endsWith(RANGE_SEPARATOR))
|
||||
toReturn = toReturn.substring(0, toReturn.length() - 1);
|
||||
|
||||
return toReturn;
|
||||
|
||||
default: return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original MetadataFieldWrapper object
|
||||
* @return
|
||||
|
@ -879,4 +662,27 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the range interval
|
||||
* @param rangeValues
|
||||
* @param tb
|
||||
*/
|
||||
private void setRangeTimeInTimeBox(String rangeValues, DataTimeBox tb){
|
||||
// set time, if present
|
||||
if(rangeValues != null && !rangeValues.isEmpty()){
|
||||
if(!rangeValues.contains(DataTimeBox.RANGE_SEPARATOR_START_END))
|
||||
rangeValues += "/" + rangeValues;
|
||||
|
||||
String[] dateAndTimeRanges = rangeValues.split(DataTimeBox.RANGE_SEPARATOR_START_END);
|
||||
if(dateAndTimeRanges.length > 0){
|
||||
String[] firstRangeDate = dateAndTimeRanges[0].split(" ");
|
||||
tb.setStartDate(firstRangeDate[0], firstRangeDate.length > 1 ? firstRangeDate[1] : null);
|
||||
if(dateAndTimeRanges.length > 1){
|
||||
String[] secondRangeDate = dateAndTimeRanges[1].split(" ");
|
||||
tb.setEndDate(secondRangeDate[0], secondRangeDate.length > 1 ? secondRangeDate[1] : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
|
||||
xmlns:b2="urn:import:com.github.gwtbootstrap.datetimepicker.client.ui">
|
||||
xmlns:b2="urn:import:com.github.gwtbootstrap.datetimepicker.client.ui"
|
||||
xmlns:b3="urn:import:com.github.gwtbootstrap.datepicker.client.ui">
|
||||
|
||||
<ui:style>
|
||||
.note-container {
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.timeandreanges;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.github.gwtbootstrap.datepicker.client.ui.DateBox;
|
||||
import com.github.gwtbootstrap.datetimepicker.client.ui.DateTimeBox;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DataTimeBox extends Composite{
|
||||
|
||||
private static DataTimeBoxUiBinder uiBinder = GWT
|
||||
.create(DataTimeBoxUiBinder.class);
|
||||
|
||||
interface DataTimeBoxUiBinder extends UiBinder<Widget, DataTimeBox> {
|
||||
}
|
||||
|
||||
public static final String RANGE_SEPARATOR_START_END = "/";
|
||||
public static final String MISSING_RANGE_VALUE = "MISSING_RANGE_PART";
|
||||
private static final String MINOR_HYPHEN = "-";
|
||||
private static final String COLON = ":";
|
||||
private static final String INSERT_DATE_INSTANT_LABEL = "Insert a date";
|
||||
private static final String INSERT_TIME_INSTANT_LABEL = "Insert hour and minutes";
|
||||
private static final String INSERT_DATE_START_LABEL = "Insert a start date";
|
||||
private static final String INSERT_DATE_END_LABEL = "Insert an end date";
|
||||
private static final DateTimeFormat formatDate = DateTimeFormat.getFormat("yyyy/MM/dd");
|
||||
private static final DateTimeFormat formatTime = DateTimeFormat.getFormat("HH:mm");
|
||||
|
||||
private boolean isRange;
|
||||
|
||||
@UiField
|
||||
DateBox startRangeDate;
|
||||
@UiField
|
||||
DateTimeBox startRangeTime;
|
||||
@UiField
|
||||
DateBox endRangeDate;
|
||||
@UiField
|
||||
DateTimeBox endRangeTime;
|
||||
@UiField
|
||||
FlowPanel singleDataEnd;
|
||||
@UiField
|
||||
FlowPanel singleDataStart;
|
||||
|
||||
public DataTimeBox(boolean isRange) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.isRange = isRange;
|
||||
startRangeDate.setPlaceholder(INSERT_DATE_INSTANT_LABEL);
|
||||
singleDataEnd.setWidth("50%");
|
||||
if(isRange){
|
||||
singleDataEnd.setVisible(true);
|
||||
singleDataStart.setWidth("50%");
|
||||
startRangeDate.setPlaceholder(INSERT_DATE_START_LABEL);
|
||||
endRangeDate.setPlaceholder(INSERT_DATE_END_LABEL);
|
||||
|
||||
}
|
||||
startRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);
|
||||
endRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);
|
||||
startRangeDate.setValue(null);
|
||||
startRangeTime.setValue(null);
|
||||
endRangeDate.setValue(null);
|
||||
endRangeTime.setValue(null);
|
||||
}
|
||||
|
||||
public boolean getIsRange(){
|
||||
return isRange;
|
||||
}
|
||||
|
||||
public void setStartDate(String date, String time){
|
||||
GWT.log("Date is " + date + " and time is " + time);
|
||||
startRangeDate.setValue(new Date(date.replaceAll(MINOR_HYPHEN, RANGE_SEPARATOR_START_END)));
|
||||
if(time != null && !time.isEmpty()){
|
||||
Date completeDate = new Date();
|
||||
completeDate.setHours(Integer.parseInt(time.split(COLON)[0]));
|
||||
completeDate.setMinutes(Integer.parseInt(time.split(COLON)[1]));
|
||||
startRangeTime.setValue(completeDate);
|
||||
}
|
||||
}
|
||||
|
||||
public void setEndDate(String date, String time){
|
||||
GWT.log("Date is " + date + " and time is " + time);
|
||||
endRangeDate.setValue(new Date(date.replaceAll(MINOR_HYPHEN, RANGE_SEPARATOR_START_END)));
|
||||
if(time != null && !time.isEmpty()){
|
||||
Date completeDate = new Date();
|
||||
completeDate.setHours(Integer.parseInt(time.split(COLON)[0]));
|
||||
completeDate.setMinutes(Integer.parseInt(time.split(COLON)[1]));
|
||||
endRangeTime.setValue(completeDate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current value, with MISSING_RANGE_VALUE in case of missing entry
|
||||
* @return
|
||||
*/
|
||||
public String getCurrentValue(){
|
||||
|
||||
String firstRange = MISSING_RANGE_VALUE;
|
||||
String secondRange = MISSING_RANGE_VALUE;
|
||||
|
||||
if(startRangeDate.getValue() != null){
|
||||
firstRange = formatDate.format(startRangeDate.getValue()) + " " + (startRangeTime.getValue() != null ? formatTime.format(startRangeTime.getValue()) : "");
|
||||
firstRange = firstRange.replaceAll(RANGE_SEPARATOR_START_END, MINOR_HYPHEN);
|
||||
}
|
||||
if(isRange && endRangeDate.getValue() != null){
|
||||
secondRange = formatDate.format(endRangeDate.getValue()) + " " + (endRangeTime.getValue() != null ? formatTime.format(endRangeTime.getValue()) : "");
|
||||
secondRange = secondRange.replaceAll(RANGE_SEPARATOR_START_END, MINOR_HYPHEN);
|
||||
}
|
||||
|
||||
if(isRange){
|
||||
GWT.log("Returning " + firstRange + RANGE_SEPARATOR_START_END + secondRange);
|
||||
return firstRange + RANGE_SEPARATOR_START_END + secondRange;
|
||||
}else {
|
||||
GWT.log("Returning " + firstRange);
|
||||
return firstRange;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze the inputs
|
||||
*/
|
||||
public void freeze(){
|
||||
startRangeDate.setEnabled(false);
|
||||
startRangeTime.setEnabled(false);
|
||||
endRangeDate.setEnabled(false);
|
||||
endRangeTime.setEnabled(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b2="urn:import:com.github.gwtbootstrap.datetimepicker.client.ui"
|
||||
xmlns:b3="urn:import:com.github.gwtbootstrap.datepicker.client.ui">
|
||||
<ui:style>
|
||||
.flow-panel-style {
|
||||
display: inline-block;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:FlowPanel>
|
||||
<g:FlowPanel ui:field="singleDataStart" styleName="{style.flow-panel-style}"
|
||||
visible="true">
|
||||
<b3:DateBox format="yyyy/mm/dd" autoClose="true"
|
||||
language="en" ui:field="startRangeDate" width="40%" />
|
||||
<b2:DateTimeBox format="hh:ii" autoClose="true"
|
||||
language="en" width="15%" ui:field="startRangeTime" />
|
||||
</g:FlowPanel>
|
||||
<g:FlowPanel ui:field="singleDataEnd" visible="false"
|
||||
styleName="{style.flow-panel-style}">
|
||||
<b3:DateBox format="yyyy/mm/dd" autoClose="true" width="40%"
|
||||
language="en" ui:field="endRangeDate" />
|
||||
<b2:DateTimeBox format="hh:ii" autoClose="true"
|
||||
language="en" width="15%" ui:field="endRangeTime" />
|
||||
</g:FlowPanel>
|
||||
</g:FlowPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
|
@ -9,6 +9,7 @@
|
|||
<!-- Responsive design -->
|
||||
<set-property name="bootstrap.responsiveDesign" value="true" />
|
||||
<inherits name='com.github.gwtbootstrap.datetimepicker.Datetimepicker' />
|
||||
<inherits name='com.github.gwtbootstrap.datepicker.Datepicker' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
|
||||
|
||||
|
|
Loading…
Reference in New Issue