Added disabled option for non mandatory listboxes fields

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@130324 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-13 16:13:50 +00:00
parent a24a923616
commit 2ec604e15e
3 changed files with 154 additions and 119 deletions

View File

@ -149,6 +149,9 @@ public class CreateDatasetForm extends Composite{
@UiField Icon infoIconCustomFields;
@UiField FocusPanel focusPanelCustomFields;
@UiField Popover popoverCustomFields;
@UiField Icon infoIconResources;
@UiField FocusPanel focusPanelResources;
@UiField Popover popoverResources;
// tab panel
private TabPanel tabPanel;
@ -290,93 +293,6 @@ public class CreateDatasetForm extends Composite{
}
/**
* Prepare the info icons of all core metadata info
*/
private void prepareInfoIcons() {
// tags
preparePopupPanelAndPopover(
InfoIconsLabels.TAGS_INFO_ID_POPUP,
InfoIconsLabels.TAGS_INFO_TEXT,
InfoIconsLabels.TAGS_INFO_CAPTION,
infoIconTags,
popoverTags,
focusPanelTags
);
// visibility
preparePopupPanelAndPopover(
InfoIconsLabels.VISIBILITY_INFO_ID_POPUP,
InfoIconsLabels.VISIBILITY_INFO_TEXT,
InfoIconsLabels.VISIBILITY_INFO_CAPTION,
infoIconVisibility,
popoverVisibility,
focusPanelVisibility
);
// author
preparePopupPanelAndPopover(
InfoIconsLabels.AUTHOR_INFO_ID_POPUP,
InfoIconsLabels.AUTHOR_INFO_TEXT,
InfoIconsLabels.AUTHOR_INFO_CAPTION,
infoIconAuthor,
popoverAuthor,
focusPanelAuthor
);
// author's email
preparePopupPanelAndPopover(
InfoIconsLabels.AUTHOR_EMAIL_INFO_ID_POPUP,
InfoIconsLabels.AUTHOR_EMAIL_INFO_TEXT,
InfoIconsLabels.AUTHOR_EMAIL_INFO_CAPTION,
infoIconAuthorEmail,
popoverAuthorEmail,
focusPanelAuthorEmail
);
// maintainer
preparePopupPanelAndPopover(
InfoIconsLabels.MAINTAINER_INFO_ID_POPUP,
InfoIconsLabels.MAINTAINER_INFO_TEXT,
InfoIconsLabels.MAINTAINER_INFO_CAPTION,
infoIconMaintainer,
popoverMaintainer,
focusPanelMaintainer
);
// maintainer's email
preparePopupPanelAndPopover(
InfoIconsLabels.MAINTAINER_EMAIL_INFO_ID_POPUP,
InfoIconsLabels.MAINTAINER_EMAIL_INFO_TEXT,
InfoIconsLabels.MAINTAINER_EMAIL_INFO_CAPTION,
infoIconMaintainerEmail,
popoverMaintainerEmail,
focusPanelMaintainerEmail
);
// profiles
preparePopupPanelAndPopover(
InfoIconsLabels.PROFILES_INFO_ID_POPUP,
InfoIconsLabels.PROFILES_INFO_TEXT,
InfoIconsLabels.PROFILES_INFO_CAPTION,
infoIconProfiles,
popoverProfiles,
focusPanelProfiles
);
// custom fields
preparePopupPanelAndPopover(
InfoIconsLabels.CUSTOM_FIELDS_INFO_ID_POPUP,
InfoIconsLabels.CUSTOM_FIELDS_INFO_TEXT,
InfoIconsLabels.CUSTOM_FIELDS_INFO_CAPTION,
infoIconCustomFields,
popoverCustomFields,
focusPanelCustomFields
);
}
/**
* Invoked when the workspace is used.
* @param idFolderWorkspace
@ -387,6 +303,9 @@ public class CreateDatasetForm extends Composite{
this.owner = owner;
// prepare info icons
prepareInfoIcons();
// workspace request
isWorkspaceRequest = true;
@ -853,6 +772,103 @@ public class CreateDatasetForm extends Composite{
}
}
/**
* Prepare the info icons of all core metadata info
*/
private void prepareInfoIcons() {
// tags
preparePopupPanelAndPopover(
InfoIconsLabels.TAGS_INFO_ID_POPUP,
InfoIconsLabels.TAGS_INFO_TEXT,
InfoIconsLabels.TAGS_INFO_CAPTION,
infoIconTags,
popoverTags,
focusPanelTags
);
// visibility
preparePopupPanelAndPopover(
InfoIconsLabels.VISIBILITY_INFO_ID_POPUP,
InfoIconsLabels.VISIBILITY_INFO_TEXT,
InfoIconsLabels.VISIBILITY_INFO_CAPTION,
infoIconVisibility,
popoverVisibility,
focusPanelVisibility
);
// author
preparePopupPanelAndPopover(
InfoIconsLabels.AUTHOR_INFO_ID_POPUP,
InfoIconsLabels.AUTHOR_INFO_TEXT,
InfoIconsLabels.AUTHOR_INFO_CAPTION,
infoIconAuthor,
popoverAuthor,
focusPanelAuthor
);
// author's email
preparePopupPanelAndPopover(
InfoIconsLabels.AUTHOR_EMAIL_INFO_ID_POPUP,
InfoIconsLabels.AUTHOR_EMAIL_INFO_TEXT,
InfoIconsLabels.AUTHOR_EMAIL_INFO_CAPTION,
infoIconAuthorEmail,
popoverAuthorEmail,
focusPanelAuthorEmail
);
// maintainer
preparePopupPanelAndPopover(
InfoIconsLabels.MAINTAINER_INFO_ID_POPUP,
InfoIconsLabels.MAINTAINER_INFO_TEXT,
InfoIconsLabels.MAINTAINER_INFO_CAPTION,
infoIconMaintainer,
popoverMaintainer,
focusPanelMaintainer
);
// maintainer's email
preparePopupPanelAndPopover(
InfoIconsLabels.MAINTAINER_EMAIL_INFO_ID_POPUP,
InfoIconsLabels.MAINTAINER_EMAIL_INFO_TEXT,
InfoIconsLabels.MAINTAINER_EMAIL_INFO_CAPTION,
infoIconMaintainerEmail,
popoverMaintainerEmail,
focusPanelMaintainerEmail
);
// profiles
preparePopupPanelAndPopover(
InfoIconsLabels.PROFILES_INFO_ID_POPUP,
InfoIconsLabels.PROFILES_INFO_TEXT,
InfoIconsLabels.PROFILES_INFO_CAPTION,
infoIconProfiles,
popoverProfiles,
focusPanelProfiles
);
// custom fields
preparePopupPanelAndPopover(
InfoIconsLabels.CUSTOM_FIELDS_INFO_ID_POPUP,
InfoIconsLabels.CUSTOM_FIELDS_INFO_TEXT,
InfoIconsLabels.CUSTOM_FIELDS_INFO_CAPTION,
infoIconCustomFields,
popoverCustomFields,
focusPanelCustomFields
);
// resources field
preparePopupPanelAndPopover(
InfoIconsLabels.RESOURCES_INFO_ID_POPUP,
InfoIconsLabels.RESOURCES_INFO_TEXT,
InfoIconsLabels.RESOURCES_INFO_CAPTION,
infoIconResources,
popoverResources,
focusPanelResources
);
}
/**
* Test if profile data are valid
* @return

View File

@ -107,6 +107,13 @@ public class MetaDataFieldSkeleton extends Composite{
// listbox
holder = new ListBox();
// if it is not mandatory, add a disabled option
if(!field.getMandatory()){
((ListBox)holder).addItem("Select " + field.getFieldName());
((ListBox)holder).setSelectedValue("Select " + field.getFieldName());
((ListBox)holder).getElement().getElementsByTagName("option").getItem(0).setAttribute("disabled", "disabled");
}
// get vocabulary fields
List<String> vocabulary = field.getVocabulary();
@ -117,11 +124,11 @@ public class MetaDataFieldSkeleton extends Composite{
}
// set default value
((ListBox)holder).setSelectedValue(field.getDefaulValue());
if(field.getDefaulValue() != null)
((ListBox)holder).setSelectedValue(field.getDefaulValue());
// add to the elementPanel
elementPanel.add(holder);
}
}
@ -177,39 +184,44 @@ public class MetaDataFieldSkeleton extends Composite{
* Check if this field has a valid values
* @return
*/
public boolean isFieldValueValid() {
public boolean isFieldValueValid(){
GWT.log("Validator is " + field.getValidator());
GWT.log("Is mandatory? " + field.getMandatory());
if(field.getMandatory()){
if(holder.getClass().equals(TextBox.class)){
if(!getFieldCurrentValue().isEmpty())
if(field.getValidator() == null || field.getValidator().isEmpty())
return true;
else return checkValidator(holder, field);
else
return false;
}else
return true;
}else{
if(holder.getClass().equals(TextBox.class) && getFieldCurrentValue().isEmpty())
return true;
return checkValidator(holder, field);
}
}
private boolean checkValidator(Widget holder, MetadataFieldWrapper field){
String validator = field.getValidator();
GWT.log("Validator is " + validator);
// if validator is not present and it is not a textbox
if((validator == null || validator.isEmpty()) && !(holder.getClass().equals(TextBox.class) && field.getMandatory()))
if(validator == null || validator.isEmpty())
return true;
// current value
String value;
// we validate only listbox and textbox
if(holder.getClass().equals(ListBox.class))
value = ((ListBox)holder).getSelectedItemText();
else if(holder.getClass().equals(TextBox.class)){
value = ((TextBox)holder).getText();
// if there is not a validator...
if(validator == null){
if(value.isEmpty() && field.getMandatory())
return false;
else if(value.isEmpty() && !field.getMandatory())
return true;
else if(!value.isEmpty())
return true;
}
}
else
return true; // it's a checkbox (the value doesn't matter)
return value.matches(validator);
return getFieldCurrentValue().matches(field.getValidator().trim());
}else
return true;
}
@ -222,8 +234,15 @@ public class MetaDataFieldSkeleton extends Composite{
String value;
// we validate only listbox and textbox
if(holder.getClass().equals(ListBox.class))
if(holder.getClass().equals(ListBox.class)){
value = ((ListBox)holder).getSelectedItemText();
// if it was not mandatory but there was no choice, returning null
if(!field.getMandatory())
if(value.equals("Select " + field.getFieldName()))
return null;
}
else if(holder.getClass().equals(TextBox.class))
value = ((TextBox)holder).getText();
else

View File

@ -105,7 +105,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/
public String getDevelopmentUser() {
String user = TEST_USER;
// user = "costantino.perciante";
//user = "costantino.perciante";
return user;
}