improved MetadataFieldWrapper by adding current values (as list)

This commit is contained in:
Francesco Mangiacrapa 2023-04-21 15:24:08 +02:00
parent ca51fc0543
commit 669dbb34e8
5 changed files with 72 additions and 41 deletions

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.widgets.mpformbuilder.client.form.generic; package org.gcube.portlets.widgets.mpformbuilder.client.form.generic;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;

View File

@ -149,7 +149,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentSingleValue() != null)
((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue())); ((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue()));
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@ -171,8 +171,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentSingleValue() != null)
textArea.setText((String) field.getCurrentValue()); textArea.setText((String) field.getCurrentSingleValue());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -243,8 +243,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentSingleValue() != null)
((TextArea) holder).setText((String) field.getCurrentValue()); ((TextArea) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -268,8 +268,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
// set time, if present // set time, if present
try { try {
if (field.getCurrentValue() != null) { if (field.getCurrentSingleValue() != null) {
String currentValue = (String) field.getCurrentValue(); String currentValue = (String) field.getCurrentSingleValue();
String[] dateAndTime = currentValue.split(" "); String[] dateAndTime = currentValue.split(" ");
if (dateAndTime.length > 0) { if (dateAndTime.length > 0) {
ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null); ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null);
@ -290,7 +290,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
// set time, if present // set time, if present
try { try {
setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBox); setRangeTimeInTimeBox((String) field.getCurrentSingleValue(), rangeBox);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -313,7 +313,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBoxFirst); setRangeTimeInTimeBox((String) field.getCurrentSingleValue(), rangeBoxFirst);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -373,8 +373,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentSingleValue() != null)
((TextBox) holder).setText((String) field.getCurrentValue()); ((TextBox) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -401,8 +401,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentSingleValue() != null)
((TextBox) holder).setText((String) field.getCurrentValue()); ((TextBox) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
@ -431,17 +431,31 @@ public class MetaDataFieldSkeleton extends Composite {
List<String> vocabulary = field.getVocabulary(); List<String> vocabulary = field.getVocabulary();
for (String term : vocabulary) { for (String term : vocabulary) {
tempListBox.addItem(term); tempListBox.addItem(term, term);
} }
// set default value // set default value
if (field.getDefaultValue() != null) if (field.getDefaultValue() != null)
tempListBox.setSelectedValue(field.getDefaultValue()); tempListBox.setSelectedValue(field.getDefaultValue());
//to be sure
tempListBox.setMultipleSelect(field.isMultiSelection());
if (operation.equals(OPERATION.UPDATE)) { if (operation.equals(OPERATION.UPDATE)) {
try { try {
if (field.getCurrentValue() != null) if (field.getCurrentValues() != null) {
tempListBox.setSelectedValue((String) field.getCurrentValue()); if (field.isMultiSelection()) {
//Buggy in Bootstrap
for (String value : field.getCurrentValues()) {
GWT.log("Multiple Selecting: "+value);
tempListBox.setSelectedValue((String) value);
}
}else {
GWT.log("Selecting: "+field.getCurrentSingleValue());
tempListBox.setSelectedValue((String) field.getCurrentSingleValue());
}
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }

View File

@ -21,7 +21,6 @@ import org.gcube.common.metadataprofilediscovery.jaxb.MetadataValidator;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataVocabulary; import org.gcube.common.metadataprofilediscovery.jaxb.MetadataVocabulary;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory; import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.widgets.mpformbuilder.server.util.WsUtil;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.DataTypeWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.FieldAsGroup; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.FieldAsGroup;
@ -119,10 +118,10 @@ public class MetadataDiscovery {
MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName()); MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName());
beans.add(bean); beans.add(bean);
if(!WsUtil.isWithinPortal()) { // if(!WsUtil.isWithinPortal()) {
LOG.info("DEV MODE ENABLED - Out of portal!"); // LOG.info("DEV MODE ENABLED - Out of portal!");
randomizeCurrentValues(bean.getMetadataFields()); // randomizeCurrentValues(bean.getMetadataFields());
} // }
} }
prettyPrintList(beans); prettyPrintList(beans);
@ -145,14 +144,14 @@ public class MetadataDiscovery {
switch (dtw) { switch (dtw) {
case Boolean: case Boolean:
metadataFieldWrapper.setCurrentValue(Boolean.FALSE.toString()); metadataFieldWrapper.setCurrentValues(Boolean.FALSE.toString());
break; break;
case Number: case Number:
metadataFieldWrapper.setCurrentValue(new Random().nextInt()+""); metadataFieldWrapper.setCurrentValues(new Random().nextInt()+"");
break; break;
case String: case String:
case Text: case Text:
metadataFieldWrapper.setCurrentValue("Text "+UUID.randomUUID()); metadataFieldWrapper.setCurrentValues("Text "+UUID.randomUUID());
break; break;
default: default:
break; break;

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.metadata; package org.gcube.portlets.widgets.mpformbuilder.shared.metadata;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -29,7 +30,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
private Integer maxOccurs = 1; private Integer maxOccurs = 1;
private String currentValue; private String[] currentValues;
/** /**
* Instantiates a new metadata field. * Instantiates a new metadata field.
@ -331,24 +332,42 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
} }
/** /**
* Sets the current value. * Gets the current values.
* *
* @param value the new current value * @return the current values
*/ */
public void setCurrentValue(String value) { public List<String> getCurrentValues() {
this.currentValue = value; if (currentValues == null)
return null;
return Arrays.asList(currentValues);
} }
/** /**
* Gets the current value. * Sets the current values.
* *
* @return the current value * @param currentValues the new current values
*/ */
public String getCurrentValue() { public void setCurrentValues(String... currentValues) {
return currentValue; this.currentValues = currentValues;
} }
/**
* Gets the current single value.
*
* @return the current single value
*/
public String getCurrentSingleValue() {
if (this.currentValues != null && this.currentValues.length > 0)
return this.currentValues[0];
return null;
}
/**
* To string.
*
* @return the string
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -380,12 +399,10 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
builder.append(asTag); builder.append(asTag);
builder.append(", maxOccurs="); builder.append(", maxOccurs=");
builder.append(maxOccurs); builder.append(maxOccurs);
builder.append(", currentValue="); builder.append(", currentValues=");
builder.append(currentValue); builder.append(currentValues);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -1,8 +1,10 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.metadata; package org.gcube.portlets.widgets.mpformbuilder.shared.metadata;
import java.util.List;
public interface UpdatableField { public interface UpdatableField {
void setCurrentValue(String value); void setCurrentValues(String... values);
String getCurrentValue(); List<String> getCurrentValues();
} }