From f671ef0280fc87a0b45175b670bfc751f088ab05 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 3 Oct 2016 15:27:12 +0000 Subject: [PATCH] tags panel separated from the main one git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@132483 82a268e6-3cf1-43bd-a215-b396298e98cf --- log.txt | 0 .../client/ui/CreateDatasetForm.java | 328 +++--------------- .../client/ui/CreateDatasetForm.ui.xml | 28 +- .../ui/dataset/resources/TagsPanel.java | 209 +++++++++++ .../ui/dataset/resources/TagsPanel.ui.xml | 34 ++ .../client/ui/utils/InfoIconsLabels.java | 116 +++++++ 6 files changed, 402 insertions(+), 313 deletions(-) create mode 100644 log.txt create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.ui.xml diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java index ea805cd..08a9246 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.gcube.portlets.user.gcubewidgets.client.elements.Span; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEvent; @@ -19,7 +18,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.reso import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddResourceToDataset; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddedResourcesSummary; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.ResourcesTable; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended; +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; @@ -40,36 +39,26 @@ import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; -import com.github.gwtbootstrap.client.ui.base.ListItem; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.Style.Cursor; import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FocusPanel; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; -import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; @@ -90,8 +79,6 @@ public class CreateDatasetForm extends Composite{ @UiField HTMLPanel createDatasetMainPanel; @UiField TextBox titleTextBox; @UiField TextArea descriptionTextarea; - @UiField TextBox tagsEnterTextBox; - @UiField FlowPanel tagsPanel; @UiField ListBox licenseListbox; @UiField ListBox visibilityListbox; @UiField ListBox organizationsListbox; @@ -123,11 +110,9 @@ public class CreateDatasetForm extends Composite{ @UiField Button goBackButtonFirstStep; @UiField Anchor licenseUrlAnchor; @UiField Paragraph unavailableUrl; - + @UiField TagsPanel tagsPanel; + // info panels - @UiField Icon infoIconTags; - @UiField FocusPanel focusPanelTags; - @UiField Popover popoverTags; @UiField Icon infoIconLicenses; @UiField FocusPanel focusPanelLicenses; @UiField Popover popoverLicenses; @@ -182,9 +167,6 @@ public class CreateDatasetForm extends Composite{ // add resource form private AddResourceToDataset resourceForm; - // tags list - private List tagsList = new ArrayList(); - // the licenses private LicensesBean licenseBean; @@ -259,7 +241,7 @@ public class CreateDatasetForm extends Composite{ @Override public void onClose(CloseCreationFormEvent event) { - closeDialogBox(); + InfoIconsLabels.closeDialogBox(popupOpenedIds); } @@ -346,7 +328,7 @@ public class CreateDatasetForm extends Composite{ customFields.add(toAdd); // add as tag - addTagElement(entry.getKey()); + tagsPanel.addTagElement(entry.getKey()); } } @@ -760,7 +742,7 @@ public class CreateDatasetForm extends Composite{ receivedBean.setVersion(version); receivedBean.setVisibility(visibility.equals("Public")); receivedBean.setTitle(title); - receivedBean.setTags(tagsList); + receivedBean.setTags(tagsPanel.getTags()); receivedBean.setSelectedOrganization(chosenOrganization); Map customFieldsMap = new HashMap(); @@ -897,115 +879,118 @@ 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 - ); + tagsPanel.prepareIcon(popupOpenedIds); // licenses - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.LICENSES_INFO_ID_POPUP, InfoIconsLabels.LICENSES_INFO_TEXT, InfoIconsLabels.LICENSES_INFO_CAPTION, infoIconLicenses, popoverLicenses, - focusPanelLicenses + focusPanelLicenses, + popupOpenedIds ); // visibility - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.VISIBILITY_INFO_ID_POPUP, InfoIconsLabels.VISIBILITY_INFO_TEXT, InfoIconsLabels.VISIBILITY_INFO_CAPTION, infoIconVisibility, popoverVisibility, - focusPanelVisibility + focusPanelVisibility, + popupOpenedIds ); // author - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.AUTHOR_INFO_ID_POPUP, InfoIconsLabels.AUTHOR_INFO_TEXT, InfoIconsLabels.AUTHOR_INFO_CAPTION, infoIconAuthor, popoverAuthor, - focusPanelAuthor + focusPanelAuthor, + popupOpenedIds ); // author's email - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.AUTHOR_EMAIL_INFO_ID_POPUP, InfoIconsLabels.AUTHOR_EMAIL_INFO_TEXT, InfoIconsLabels.AUTHOR_EMAIL_INFO_CAPTION, infoIconAuthorEmail, popoverAuthorEmail, - focusPanelAuthorEmail + focusPanelAuthorEmail, + popupOpenedIds ); // maintainer - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.MAINTAINER_INFO_ID_POPUP, InfoIconsLabels.MAINTAINER_INFO_TEXT, InfoIconsLabels.MAINTAINER_INFO_CAPTION, infoIconMaintainer, popoverMaintainer, - focusPanelMaintainer + focusPanelMaintainer, + popupOpenedIds ); // maintainer's email - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.MAINTAINER_EMAIL_INFO_ID_POPUP, InfoIconsLabels.MAINTAINER_EMAIL_INFO_TEXT, InfoIconsLabels.MAINTAINER_EMAIL_INFO_CAPTION, infoIconMaintainerEmail, popoverMaintainerEmail, - focusPanelMaintainerEmail + focusPanelMaintainerEmail, + popupOpenedIds ); // profiles - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.PROFILES_INFO_ID_POPUP, InfoIconsLabels.PROFILES_INFO_TEXT, InfoIconsLabels.PROFILES_INFO_CAPTION, infoIconProfiles, popoverProfiles, - focusPanelProfiles + focusPanelProfiles, + popupOpenedIds ); // custom fields - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.CUSTOM_FIELDS_INFO_ID_POPUP, InfoIconsLabels.CUSTOM_FIELDS_INFO_TEXT, InfoIconsLabels.CUSTOM_FIELDS_INFO_CAPTION, infoIconCustomFields, popoverCustomFields, - focusPanelCustomFields + focusPanelCustomFields, + popupOpenedIds ); // resources field - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.RESOURCES_INFO_ID_POPUP, InfoIconsLabels.RESOURCES_INFO_TEXT, InfoIconsLabels.RESOURCES_INFO_CAPTION, infoIconResources, popoverResources, - focusPanelResources + focusPanelResources, + popupOpenedIds ); // title - preparePopupPanelAndPopover( + InfoIconsLabels.preparePopupPanelAndPopover( InfoIconsLabels.TITLE_INFO_ID_POPUP, InfoIconsLabels.TITLE_INFO_TEXT, InfoIconsLabels.TITLE_INFO_CAPTION, infoIconTitle, popoverTitle, - focusPanelTitle + focusPanelTitle, + popupOpenedIds ); } @@ -1162,7 +1147,7 @@ public class CreateDatasetForm extends Composite{ versionTextbox.setText(""); maintainerTextbox.setText(""); maintainerEmailTextbox.setText(""); - removeTags(); + tagsPanel.removeTags(); // delete custom fields for (CustomFieldEntry customField : customFieldEntriesList) { @@ -1184,22 +1169,11 @@ public class CreateDatasetForm extends Composite{ maintainerTextbox.setEnabled(false); maintainerEmailTextbox.setEnabled(false); visibilityListbox.setEnabled(false); - tagsEnterTextBox.setEnabled(false); + tagsPanel.freeze(); licenseListbox.setEnabled(false); organizationsListbox.setEnabled(false); addCustomFieldButton.setEnabled(false); - // freeze tags - for(int i = 0; i < tagsList.size(); i++){ - - // get tag widget - ListItem tagWidget = (ListItem)tagsPanel.getWidget(i); - - // get the "x" span - tagWidget.getWidget(1).removeFromParent(); - - } - // disable profile fields for (MetaDataFieldSkeleton field : listOfMetadataFields) { @@ -1226,18 +1200,6 @@ public class CreateDatasetForm extends Composite{ } - @UiHandler("tagsEnterTextBox") - void onAddTag(KeyDownEvent event){ - - if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { - if (!tagsEnterTextBox.getValue().trim().isEmpty()) { - - addTagElement(tagsEnterTextBox); - - } - } - } - @UiHandler("licenseListbox") void onSelectedLicenseChange(ChangeEvent c){ @@ -1272,214 +1234,4 @@ public class CreateDatasetForm extends Composite{ } - /** - * Add the tag as an element (inserted by the user) - */ - private void addTagElement(TextBox itemBox){ - - if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) { - - if(tagsList.contains(itemBox.getValue().trim())){ - itemBox.setValue(""); - return; - } - - // ckan accepts only alphanumeric values - String[] subTags = itemBox.getValue().split(" "); - if(subTags.length == 1){ - if(!subTags[0].matches("^[a-zA-Z0-9]*$")) - return; - if(subTags[0].length() <= 1) - return; - }else{ - for (int i = 0; i < subTags.length; i++) { - String subTag = subTags[i]; - if(!subTag.matches("^[a-zA-Z0-9]*$")) - return; - } - } - - final String value = itemBox.getValue(); - final ListItem displayItem = new ListItem(); - displayItem.setStyleName("tag-style"); - Span tagText = new Span(itemBox.getValue()); - - Span tagRemove = new Span("x"); - tagRemove.setTitle("Remove this tag"); - tagRemove.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent clickEvent) { - removeTag(displayItem, value); - } - }); - - tagRemove.setStyleName("tag-style-x"); - displayItem.add(tagText); - displayItem.add(tagRemove); - itemBox.setValue(""); - itemBox.setFocus(true); - tagsPanel.add(displayItem); - tagsList.add(value); - } - } - - /** - * Add the tag as an element (when publishing from workspace) - */ - private void addTagElement(final String tag){ - - if(tagsList.contains(tag)) - return; - - // ckan accepts only alphanumeric values - String[] subTags = tag.split(" "); - if(subTags.length == 1){ - if(!subTags[0].matches("^[a-zA-Z0-9]*$")) - return; - if(subTags[0].length() <= 1) - return; - }else{ - for (int i = 0; i < subTags.length; i++) { - String subTag = subTags[i]; - if(!subTag.matches("^[a-zA-Z0-9]*$")) - return; - } - } - - final ListItem displayItem = new ListItem(); - displayItem.setStyleName("tag-style"); - Span p = new Span(tag); - - Span span = new Span("x"); - span.setTitle("Remove this tag"); - span.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent clickEvent) { - removeTag(displayItem, tag); - } - }); - - span.setStyleName("tag-style-x"); - displayItem.add(p); - displayItem.add(span); - tagsPanel.add(displayItem); - tagsList.add(tag); - } - - /** - * Remove a tag from the list - * @param displayItem - */ - private void removeTag(ListItem displayItem, String value) { - - tagsList.remove(value); - tagsPanel.remove(displayItem); - - } - - /** - * Remove all inserted tags - */ - private void removeTags(){ - - tagsList.clear(); - tagsPanel.clear(); - - } - - /** - * Close any dialog box opened - */ - private void closeDialogBox() { - - for (String popupid : popupOpenedIds) { - GcubeDialogExtended popup = null; - try{ - Element element = DOM.getElementById(popupid); - popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element)); - popup.hide(); - }catch(Exception e){ - GWT.log("ERROR", e); - } - } - } - - /** - * Prepare the popover and the gcube popup panel for information. - * @param text - * @param captionText - * @param iconElement - * @param popover - * @param focusPanel - */ - private void preparePopupPanelAndPopover( - final String popupId, - final String text, - final String captionText, - Icon iconElement, - Popover popover, - FocusPanel focusPanel){ - - // prepare the popover - popover.setText(new HTML("

" + text +"

").getHTML()); - popover.setHeading(new HTML("" + captionText +"").getHTML()); - - // set icon cursor - iconElement.getElement().getStyle().setCursor(Cursor.HELP); - - // prepare the gcube dialog - focusPanel.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - - // Retrieve elemnt that should have this id - GcubeDialogExtended popup = null; - try{ - Element element = DOM.getElementById(popupId); - popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element)); - }catch(Exception e){ - GWT.log("ERROR", e); - } - - // if it doesn't exist, create it - if(popup == null){ - - popup = new GcubeDialogExtended(captionText, text); - popup.getElement().setId(popupId); - popup.setModal(false); - - // add its id - popupOpenedIds.add(popupId); - - } - - // then center and show - popup.center(); - popup.show(); - - } - }); - - } - - /** - * Check if an element of such type is actually a widget - * @param element - * @return - */ - public static IsWidget getWidget(Element element) { - EventListener listener = DOM - .getEventListener(element); - // No listener attached to the element, so no widget exist for this - // element - if (listener == null) { - GWT.log("Widget is NULL"); - return null; - } - if (listener instanceof Widget) { - // GWT uses the widget as event listener - GWT.log("Widget is " + listener); - return (Widget) listener; - } - return null; - } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml index b447625..396024f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml @@ -1,6 +1,7 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" + xmlns:m="urn:import:org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources"> .form-main-style { margin-left: 10px; @@ -86,30 +87,7 @@ - - - - Tags: - - - - - - - - - - - - - - - - - - + License: diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.java new file mode 100644 index 0000000..fef64ac --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.java @@ -0,0 +1,209 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.gcubewidgets.client.elements.Span; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; + +import com.github.gwtbootstrap.client.ui.Icon; +import com.github.gwtbootstrap.client.ui.Popover; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.base.ListItem; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.KeyDownEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.FocusPanel; +import com.google.gwt.user.client.ui.Widget; + +public class TagsPanel extends Composite{ + + private static TagsPanelUiBinder uiBinder = GWT + .create(TagsPanelUiBinder.class); + + interface TagsPanelUiBinder extends UiBinder { + } + + @UiField TextBox tagsEnterTextBox; + @UiField FlowPanel tagsPanel; + @UiField Icon infoIconTags; + @UiField FocusPanel focusPanelTags; + @UiField Popover popoverTags; + + // tags list + private List tagsList = new ArrayList(); + + public TagsPanel() { + initWidget(uiBinder.createAndBindUi(this)); + } + + /** + * Prepare icons + * @param popupOpenedIds + */ + public void prepareIcon(List popupOpenedIds) { + InfoIconsLabels.preparePopupPanelAndPopover( + InfoIconsLabels.TAGS_INFO_ID_POPUP, + InfoIconsLabels.TAGS_INFO_TEXT, + InfoIconsLabels.TAGS_INFO_CAPTION, + infoIconTags, + popoverTags, + focusPanelTags, + popupOpenedIds + ); + } + + /** + * Add the tag as an element (inserted by the user) + */ + private void addTagElement(TextBox itemBox){ + + if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) { + + if(tagsList.contains(itemBox.getValue().trim())){ + itemBox.setValue(""); + return; + } + + // ckan accepts only alphanumeric values + String[] subTags = itemBox.getValue().split(" "); + if(subTags.length == 1){ + if(!subTags[0].matches("^[a-zA-Z0-9]*$")) + return; + if(subTags[0].length() <= 1) + return; + }else{ + for (int i = 0; i < subTags.length; i++) { + String subTag = subTags[i]; + if(!subTag.matches("^[a-zA-Z0-9]*$")) + return; + } + } + + final String value = itemBox.getValue(); + final ListItem displayItem = new ListItem(); + displayItem.setStyleName("tag-style"); + Span tagText = new Span(itemBox.getValue()); + + Span tagRemove = new Span("x"); + tagRemove.setTitle("Remove this tag"); + tagRemove.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent clickEvent) { + removeTag(displayItem, value); + } + }); + + tagRemove.setStyleName("tag-style-x"); + displayItem.add(tagText); + displayItem.add(tagRemove); + itemBox.setValue(""); + itemBox.setFocus(true); + tagsPanel.add(displayItem); + tagsList.add(value); + } + } + + /** + * Add the tag as an element (when publishing from workspace) + */ + public void addTagElement(final String tag){ + + if(tagsList.contains(tag)) + return; + + // ckan accepts only alphanumeric values + String[] subTags = tag.split(" "); + if(subTags.length == 1){ + if(!subTags[0].matches("^[a-zA-Z0-9]*$")) + return; + if(subTags[0].length() <= 1) + return; + }else{ + for (int i = 0; i < subTags.length; i++) { + String subTag = subTags[i]; + if(!subTag.matches("^[a-zA-Z0-9]*$")) + return; + } + } + + final ListItem displayItem = new ListItem(); + displayItem.setStyleName("tag-style"); + Span p = new Span(tag); + + Span span = new Span("x"); + span.setTitle("Remove this tag"); + span.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent clickEvent) { + removeTag(displayItem, tag); + } + }); + + span.setStyleName("tag-style-x"); + displayItem.add(p); + displayItem.add(span); + tagsPanel.add(displayItem); + tagsList.add(tag); + } + + /** + * Remove a tag from the list + * @param displayItem + */ + private void removeTag(ListItem displayItem, String value) { + + tagsList.remove(value); + tagsPanel.remove(displayItem); + + } + + /** + * Remove all inserted tags + */ + public void removeTags(){ + + tagsList.clear(); + tagsPanel.clear(); + + } + + @UiHandler("tagsEnterTextBox") + void onAddTag(KeyDownEvent event){ + + if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { + if (!tagsEnterTextBox.getValue().trim().isEmpty()) { + + addTagElement(tagsEnterTextBox); + + } + } + } + + public List getTags() { + return tagsList; + } + + /** + * Freeze tags + */ + public void freeze() { + + tagsEnterTextBox.setEnabled(false); + for(int i = 0; i < tagsList.size(); i++){ + + // get tag widget + ListItem tagWidget = (ListItem)tagsPanel.getWidget(i); + + // get the "x" span + tagWidget.getWidget(1).removeFromParent(); + + } + + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.ui.xml new file mode 100644 index 0000000..a69bcf9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/TagsPanel.ui.xml @@ -0,0 +1,34 @@ + + + + .tagsPanelStyle { + display: inline-block; + } + + + + + Tags: + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java index f0da701..d1090eb 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java @@ -1,5 +1,21 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; +import java.util.List; + +import com.github.gwtbootstrap.client.ui.Icon; +import com.github.gwtbootstrap.client.ui.Popover; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Style.Cursor; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.EventListener; +import com.google.gwt.user.client.ui.FocusPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.IsWidget; +import com.google.gwt.user.client.ui.Widget; + /** * Labels and texts for core ckan information * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -63,5 +79,105 @@ public class InfoIconsLabels { public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info"; public static final String TITLE_INFO_TEXT = "Product Title must contain only alphanumer characters, dots, underscore or hyphen minus. No others symbols are allowed."; public static final String TITLE_INFO_CAPTION = "Product Title"; + + /** + * Prepare the popover and the gcube popup panel for information. + * @param text + * @param captionText + * @param iconElement + * @param popover + * @param focusPanel + */ + public static void preparePopupPanelAndPopover( + final String popupId, + final String text, + final String captionText, + Icon iconElement, + Popover popover, + FocusPanel focusPanel, + final List popupOpenedIds + ){ + + // prepare the popover + popover.setText(new HTML("

" + text +"

").getHTML()); + popover.setHeading(new HTML("" + captionText +"").getHTML()); + + // set icon cursor + iconElement.getElement().getStyle().setCursor(Cursor.HELP); + + // prepare the gcube dialog + focusPanel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + // Retrieve elemnt that should have this id + GcubeDialogExtended popup = null; + try{ + Element element = DOM.getElementById(popupId); + popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element)); + }catch(Exception e){ + GWT.log("ERROR", e); + } + + // if it doesn't exist, create it + if(popup == null){ + + popup = new GcubeDialogExtended(captionText, text); + popup.getElement().setId(popupId); + popup.setModal(false); + + // add its id + popupOpenedIds.add(popupId); + + } + + // then center and show + popup.center(); + popup.show(); + + } + }); + + } + + /** + * Check if an element of such type is actually a widget + * @param element + * @return + */ + public static IsWidget getWidget(Element element) { + EventListener listener = DOM + .getEventListener(element); + // No listener attached to the element, so no widget exist for this + // element + if (listener == null) { + GWT.log("Widget is NULL"); + return null; + } + if (listener instanceof Widget) { + // GWT uses the widget as event listener + GWT.log("Widget is " + listener); + return (Widget) listener; + } + return null; + } + + /** + * Close any dialog box opened + */ + public static void closeDialogBox(List popupOpenedIds) { + + for (String popupid : popupOpenedIds) { + GcubeDialogExtended popup = null; + try{ + Element element = DOM.getElementById(popupid); + popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element)); + popup.hide(); + }catch(Exception e){ + GWT.log("ERROR", e); + } + } + } }