minor fix in tags panel

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@132484 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-10-03 15:30:27 +00:00
parent f671ef0280
commit d8c6205b44
1 changed files with 23 additions and 16 deletions

View File

@ -37,6 +37,9 @@ public class TagsPanel extends Composite{
@UiField FocusPanel focusPanelTags; @UiField FocusPanel focusPanelTags;
@UiField Popover popoverTags; @UiField Popover popoverTags;
// regular expression for tags
private static final String REGEX_TAG = "^[a-zA-Z0-9]*$";
// tags list // tags list
private List<String> tagsList = new ArrayList<String>(); private List<String> tagsList = new ArrayList<String>();
@ -60,6 +63,18 @@ public class TagsPanel extends Composite{
); );
} }
@UiHandler("tagsEnterTextBox")
void onAddTag(KeyDownEvent event){
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox);
}
}
}
/** /**
* Add the tag as an element (inserted by the user) * Add the tag as an element (inserted by the user)
*/ */
@ -75,14 +90,14 @@ public class TagsPanel extends Composite{
// ckan accepts only alphanumeric values // ckan accepts only alphanumeric values
String[] subTags = itemBox.getValue().split(" "); String[] subTags = itemBox.getValue().split(" ");
if(subTags.length == 1){ if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$")) if(!subTags[0].matches(REGEX_TAG))
return; return;
if(subTags[0].length() <= 1) if(subTags[0].length() <= 1)
return; return;
}else{ }else{
for (int i = 0; i < subTags.length; i++) { for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i]; String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$")) if(!subTag.matches(REGEX_TAG))
return; return;
} }
} }
@ -121,14 +136,14 @@ public class TagsPanel extends Composite{
// ckan accepts only alphanumeric values // ckan accepts only alphanumeric values
String[] subTags = tag.split(" "); String[] subTags = tag.split(" ");
if(subTags.length == 1){ if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$")) if(!subTags[0].matches(REGEX_TAG))
return; return;
if(subTags[0].length() <= 1) if(subTags[0].length() <= 1)
return; return;
}else{ }else{
for (int i = 0; i < subTags.length; i++) { for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i]; String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$")) if(!subTag.matches(REGEX_TAG))
return; return;
} }
} }
@ -173,18 +188,10 @@ public class TagsPanel extends Composite{
} }
@UiHandler("tagsEnterTextBox") /**
void onAddTag(KeyDownEvent event){ * Return the tag list
* @return
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { */
if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox);
}
}
}
public List<String> getTags() { public List<String> getTags() {
return tagsList; return tagsList;
} }