diff --git a/CHANGELOG.md b/CHANGELOG.md index 5154fba..e46c8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [v2.1.3-SNAPSHOT] - 2023-07-25 +## [v2.2.1-SNAPSHOT] - 2024-29-02 **Enhancement** -- [#25433] Added spinner during resource creation +- Implemented the Edit facility [#26640] +- Added spinner during resource creation [#25433] +- Implemented the Delete facility [#26793] + ## [v2.1.2] - 2023-03-10 diff --git a/pom.xml b/pom.xml index 36790ff..5d5e691 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.widgets ckan-metadata-publisher-widget - 2.1.3-SNAPSHOT + 2.2.1-SNAPSHOT gCube Ckan metadata publisher widget @@ -94,11 +94,21 @@ portal-manager provided + + org.gcube.portlets.widgets + metadata-profile-form-builder-widget + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + org.gcube.data-catalogue gcubedatacatalogue-metadata-discovery [3.0.0, 4.0.0-SNAPSHOT) + + org.gcube.portlets.user + uri-resolver-manager + [1.0.0, 2.0.0-SNAPSHOT) + junit junit diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 55363b4..cf4f3cf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -6,17 +6,26 @@ - - + + - - - - + + - + - + + + + + null on error. */ List getLicenses(); /** * Retrieve the list of profiles for a given organization name . + * + * @param orgName the org name * @return a List on success, null on error. + * @throws Exception the exception */ List getProfiles(String orgName) throws Exception; /** * Retrieve a partially filled bean given a folder id/file id and its owner. + * * @param folderIdOrFileId the id of the folder of file to publish * @return @return a DatasetMetadataBean on success, null on error. - * @throws Exception + * @throws Exception the exception */ - DatasetBean getDatasetBean(String folderIdOrFileId) throws Exception; + DatasetBean buildPartialDatasetBean(String folderIdOrFileId) throws Exception; /** - * Try to create such dataset starting from the information contained into the toCreate bean. - * @param toCreate + * Try to create such dataset starting from the information contained into the + * toCreate bean. + * + * @param toCreate the to create * @return the sent bean filled with the needed information + * @throws Exception the exception */ DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception; /** - * Add this resource to the dataset whose id is datasetId - * @param resource - * @param datasetId + * Add this resource to the dataset whose id is datasetId. + * + * @param resource the resource + * @param organizationName the organization name + * @param datasetId the dataset id + * @return the resource element bean + * @throws Exception the exception */ - ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception; + ResourceElementBean addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId) throws Exception; /** - * Delete this resource from the dataset with id datasetId - * @param resource - * @param datasetId + * Delete this resource from the dataset with id datasetId. + * + * @param resource the resource * @return true on success, false otherwise - * @throws Exception + * @throws Exception the exception */ boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception; /** - * Given the title the user wants to give to the new product to create, a check is performed - * to understand if a dataset with the proposed title (and so the id generated at server side) already exists - * @param title + * Given the title the user wants to give to the new product to create, a check + * is performed to understand if a dataset with the proposed title (and so the + * id generated at server side) already exists. + * + * @param title the title + * @param orgName the org name * @return true if it exists, false otherwise - * @throws Exception + * @throws Exception the exception */ boolean datasetIdAlreadyExists(String title, String orgName) throws Exception; /** - * Retrieve the list of groups the user can choose to associate this product with. - * @param orgName retrieve the groups in the context linked to this name. If null, returns - * the one in the current context. + * Retrieve the list of groups the user can choose to associate this product + * with. + * + * @param orgName retrieve the groups in the context linked to this name. If + * null, returns the one in the current context. * @return a list of groups' beans */ List getUserGroups(String orgName); - + /** - * The method checks if the user is a publisher or he/she doesn't have the rights to publish + * The method checks if the user is a publisher or he/she doesn't have the + * rights to publish. + * * @return true if he/she can publish, false otherwise - * @throws Exception + * @throws Exception the exception */ - boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception; - + Boolean isPublisherUser() throws Exception; + /** - * Get the list of vocabulary tags for this scope - * @param orgName - * @return - * @throws Exception + * Get the list of vocabulary tags for this scope. + * + * @param orgName the org name + * @return the tags for organization + * @throws Exception the exception */ List getTagsForOrganization(String orgName) throws Exception; - + /** - * Validate a geo json field - * @param json - * @return + * Validate a geo json field. + * + * @param json the json + * @return true, if is geo JSON valid + * @throws Exception the exception */ boolean isGeoJSONValid(String json) throws Exception; + + /** + * Checks if is owner or admin user. + * + * @param datasetIdOrName the dataset id or name + * @return true, if is owner or admin user + * @throws Exception the exception + */ + Boolean isPublisherOwnerOrAdminUser(String datasetIdOrName) throws Exception; + + /** + * Gets the dataset bean for update. + * + * @param itemID the item ID + * @return the dataset bean for update + * @throws Exception the exception + */ + DatasetBean getDatasetBeanForUpdate(String itemID) throws Exception; + + + /** + * Gets the profile for update. + * + * @param orgName the org name + * @param datasetType the dataset type + * @param datasedIdOrName the datased id or name + * @return the profile for update + * @throws Exception the exception + */ + MetadataProfileBeanForUpdate getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName) throws Exception; + + /** + * Update CKAN dataset. + * + * @param toUpdate the to create + * @return the dataset bean + * @throws Exception the exception + */ + DatasetBean updateCKANDataset(DatasetBean toUpdate) throws Exception; + + /** + * Gets the public link for file item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @return the public link for file item id + * @throws Exception the exception + */ + String getPublicLinkForFileItemId(String itemId, boolean shortenUrl) throws Exception; + + /** + * Gets the basic dataset bean. + * + * @param datasetIdOrName the dataset id or name + * @return the basic dataset bean + * @throws Exception the exception + */ + DatasetBean getBasicDatasetBean(String datasetIdOrName) throws Exception; + + /** + * Delete item. + * + * @param datasetBean the dataset bean + * @return true, if successful + * @throws Exception the exception + */ + boolean deleteItem(DatasetBean datasetBean) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java index 7d2dffb..e0502c3 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java @@ -3,106 +3,225 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client; import java.util.List; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.licenses.LicenseBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetaDataProfileBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; +import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; /** * CKAN publisher services RPC. + * * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ public interface CKanPublisherServiceAsync { + /** + * The Class Util. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 19, 2024 + */ + public static final class Util { + private static CKanPublisherServiceAsync instance; + + /** + * Gets the single instance of Util. + * + * @return single instance of Util + */ + public static final CKanPublisherServiceAsync getInstance() { + if (instance == null) { + instance = (CKanPublisherServiceAsync) GWT.create(CKanPublisherService.class); + } + return instance; + } + + /** + * Instantiates a new util. + */ + private Util() { + // Utility class should not be instantiated + } + } + /** * Retrieve the list of licenses to show to the user. + * + * @param callback the callback * @return a LicenseBean on success, null on error. */ void getLicenses(AsyncCallback> callback); /** * Retrieve a partially filled bean given a folder id/file id and its owner. + * * @param folderIdOrFileId the id of the folder of file to publish + * @param callback the callback * @return @return a DatasetMetadataBean on success, null on error. */ - void getDatasetBean(String folderIdOrFileId, - AsyncCallback callback); + void buildPartialDatasetBean(String folderIdOrFileId, AsyncCallback callback); /** - * Try to create such dataset starting from the information contained into the toCreate bean. - * @param toCreate + * Try to create such dataset starting from the information contained into the + * toCreate bean. + * + * @param toCreate the to create + * @param callback the callback * @return the sent bean full filled with the needed information */ - void createCKanDataset(DatasetBean toCreate, - AsyncCallback callback); + void createCKanDataset(DatasetBean toCreate, AsyncCallback callback); /** - * Add this resource to the dataset whose id is datasetId - * @param resource - * @param datasetId - * @param callback + * Add this resource to the dataset whose id is datasetId. + * + * @param resource the resource + * @param organizationName the organization name + * @param datasetId the dataset id + * @param callback the callback */ - void addResourceToDataset(ResourceElementBean resource, String datasetId, + void addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId, AsyncCallback callback); /** - * Delete this resource from the dataset with id datasetId - * @param resource + * Delete this resource from the dataset with id datasetId. + * + * @param resource the resource + * @param callback the callback * @return true on success, false otherwise */ void deleteResourceFromDataset(ResourceElementBean resource, AsyncCallback callback); /** * Retrieve the list of profiles for a given organization name . + * + * @param orgName the org name + * @param callback the callback * @return a List on success, null on error. */ void getProfiles(String orgName, AsyncCallback> callback); /** - * Given the title the user wants to give to the new product to create, a check is performed - * to understand if a dataset with the proposed title (and so the id generated at server side) already exists - * @param title + * Given the title the user wants to give to the new product to create, a check + * is performed to understand if a dataset with the proposed title (and so the + * id generated at server side) already exists. + * + * @param title the title + * @param orgName the org name + * @param callback the callback * @return true if it exists, false otherwise */ void datasetIdAlreadyExists(String title, String orgName, AsyncCallback callback); - // /** - // * Return a tree object representing the whole folder hierarchy - // * @param folderId - // * @return ResourceElementBean - // */ - // void getTreeFolder(String folderId, - // AsyncCallback callback); + // /** + // * Return a tree object representing the whole folder hierarchy + // * @param folderId + // * @return ResourceElementBean + // */ + // void getTreeFolder(String folderId, + // AsyncCallback callback); /** - * Retrieve the list of groups the user can choose to associate this product with. - * @param orgName retrieve the groups in the context linked to this name. If null, returns - * the one in the current context. + * Retrieve the list of groups the user can choose to associate this product + * with. + * + * @param orgName retrieve the groups in the context linked to this name. If + * null, returns the one in the current context. + * @param callback the callback * @return a list of groups' beans */ void getUserGroups(String orgName, AsyncCallback> callback); /** - * The method checks if the user is a publisher or he/she doesn't have the rights to publish - * @return true if he/she can publish, false otherwise + * Checks if is publisher user. + * + * @param callback the callback */ - void isPublisherUser(boolean isWorkspaceRequest, - AsyncCallback callback); + void isPublisherUser(AsyncCallback callback); /** - * Get the list of vocabulary tags for this scope - * @param orgName - * @return + * Get the list of vocabulary tags for this scope. + * + * @param orgName the org name + * @param callback the callback + * @return the tags for organization */ - void getTagsForOrganization(String orgName, - AsyncCallback> callback); + void getTagsForOrganization(String orgName, AsyncCallback> callback); /** - * Validate a geo json field - * @param json - * @return + * Validate a geo json field. + * + * @param json the json + * @param callback the callback */ void isGeoJSONValid(String json, AsyncCallback callback); + + /** + * Checks if is owner or admin user. + * + * @param datasetIdOrName the dataset id or name + * @param callback the callback + * @return true, if is owner or admin user + */ + void isPublisherOwnerOrAdminUser(String datasetIdOrName, AsyncCallback callback); + + /** + * Gets the dataset bean. + * + * @param itemID the item ID + * @param callback the callback + * @return the dataset bean + */ + void getDatasetBeanForUpdate(String itemID, AsyncCallback callback); + + /** + * Gets the profile for update. + * + * @param orgName the org name + * @param datasetType the dataset type + * @param datasedIdOrName the datased id or name + * @param callaback the callaback + * @return the profile for update + */ + void getProfileForUpdate(String orgName, String datasetType, String datasedIdOrName, + AsyncCallback callaback); + + /** + * Update CKAN dataset. + * + * @param toUpdate the to update + * @param callaback the callaback + */ + void updateCKANDataset(DatasetBean toUpdate, AsyncCallback callaback); + + /** + * Gets the public link for file item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @param callaback the callaback + * @return the public link for file item id + */ + void getPublicLinkForFileItemId(String itemId, boolean shortenUrl, AsyncCallback callaback); + + /** + * Gets the basic dataset bean. + * + * @param datasetIdOrName the dataset id or name + * @param callaback the callaback + * @return the basic dataset bean + */ + void getBasicDatasetBean(String datasetIdOrName, AsyncCallback callaback); + + /** + * Delete item. + * + * @param datasetBean the dataset bean + * @param callaback the callaback + */ + void deleteItem(DatasetBean datasetBean, AsyncCallback callaback); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteCustomFieldEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteCustomFieldEventHandler.java index 6e5b2b4..f029d97 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteCustomFieldEventHandler.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteCustomFieldEventHandler.java @@ -2,10 +2,20 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; import com.google.gwt.event.shared.EventHandler; + /** - * Handler associated to the DeleteCustomFieldEvent - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + * The Interface DeleteCustomFieldEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 12, 2024 */ public interface DeleteCustomFieldEventHandler extends EventHandler { + + /** + * On remove entry. + * + * @param event the event + */ void onRemoveEntry(DeleteCustomFieldEvent event); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteResourceEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteResourceEvent.java index 29a72e0..9ff29ef 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteResourceEvent.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/DeleteResourceEvent.java @@ -2,25 +2,30 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import com.github.gwtbootstrap.client.ui.Button; import com.google.gwt.event.shared.GwtEvent; /** * Deleted resource event. + * * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ public class DeleteResourceEvent extends GwtEvent { public static Type TYPE = new Type(); private ResourceElementBean resource; - - public DeleteResourceEvent(ResourceElementBean resource) { + + private Button deleteButton; + + public DeleteResourceEvent(Button deleteButton, ResourceElementBean resource) { this.resource = resource; + this.deleteButton = deleteButton; } public ResourceElementBean getResource() { return resource; } - + @Override public Type getAssociatedType() { return TYPE; @@ -31,4 +36,19 @@ public class DeleteResourceEvent extends GwtEvent { handler.onDeletedResource(this); } + public Button getDeleteButton() { + return deleteButton; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DeleteResourceEvent [resource="); + builder.append(resource); + builder.append(", deleteButton="); + builder.append(deleteButton); + builder.append("]"); + return builder.toString(); + } + } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEvent.java new file mode 100644 index 0000000..55eab8a --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEvent.java @@ -0,0 +1,50 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class ReloadDatasetPageEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 13, 2024 + */ +public class ReloadDatasetPageEvent extends GwtEvent { + public static Type TYPE = new Type(); + + private String datasetIDorName; + + /** + * Instantiates a new reload dataset page event. + * + * @param resource the resource + */ + public ReloadDatasetPageEvent(String datasetIDorName) { + this.datasetIDorName = datasetIDorName; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(ReloadDatasetPageEventHandler handler) { + handler.onReloadDatasetPage(this); + } + + public String getDatasetIDorName() { + return datasetIDorName; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEventHandler.java new file mode 100644 index 0000000..601a871 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/ReloadDatasetPageEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface ReloadDatasetPageEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 13, 2024 + */ +public interface ReloadDatasetPageEventHandler extends EventHandler { + + /** + * On added resource. + * + * @param addResourceEvent the add resource event + */ + void onReloadDatasetPage(ReloadDatasetPageEvent addResourceEvent); +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java new file mode 100644 index 0000000..0f2c98c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import org.gcube.portlets.widgets.wsexplorer.shared.Item; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class WorkspaceItemSelectedEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 16, 2024 + */ +public class WorkspaceItemSelectedEvent extends GwtEvent { + public static Type TYPE = new Type(); + + private Item item; + + /** + * Instantiates a new workspace item selected event. + * + * @param resource the resource + */ + public WorkspaceItemSelectedEvent(Item item) { + this.item = item; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(WorkspaceItemSelectedEventHandler handler) { + handler.onSelectedItem(this); + } + + public Item getItem() { + return item; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java new file mode 100644 index 0000000..146860f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface WorkspaceItemSelectedEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 16, 2024 + */ +public interface WorkspaceItemSelectedEventHandler extends EventHandler { + + /** + * On selected item. + * + * @param workspaceItemSelectedEvent the workspace item selected event + */ + void onSelectedItem(WorkspaceItemSelectedEvent workspaceItemSelectedEvent); +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.java new file mode 100644 index 0000000..a5ee649 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.java @@ -0,0 +1,160 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.action; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.LoaderIcon; + +import com.github.gwtbootstrap.client.ui.AlertBlock; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +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.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class DeleteItemPanel extends Composite { + + private static DeleteItemPanelUiBinder uiBinder = GWT.create(DeleteItemPanelUiBinder.class); + + @UiField + Button buttonDelete; + + @UiField + AlertBlock infoBlock; + + @UiField + HTMLPanel deleteMessage; + + @UiField + FlowPanel panelConfirm; + + private FlowPanel alertPanel = new FlowPanel(); + + // private Icon iconSpinner = new Icon(IconType.SPINNER); + + private HandlerManager eventBusMainApplication; + + private final CKanPublisherServiceAsync ckanServices = CKanPublisherServiceAsync.Util.getInstance(); + + private String datasetIdOrName; + + protected static final String MISSING_PUBLISH_RIGHTS = "It seems you are not authorized to delete this item. Either you must be the author item or Catalogue Admininistrator in the organization"; + + interface DeleteItemPanelUiBinder extends UiBinder { + } + + private DatasetBean selectedDataset; + + public DeleteItemPanel(HandlerManager eventBusMainApp, String datasetIdOrName) { + initWidget(uiBinder.createAndBindUi(this)); + this.datasetIdOrName = datasetIdOrName; + this.eventBusMainApplication = eventBusMainApp; + + infoBlock.add(alertPanel); + + LoaderIcon loaderIcon = new LoaderIcon("Checking your permissions..."); + setAlertBlock(null, loaderIcon, AlertType.INFO, true); + + ckanServices.isPublisherOwnerOrAdminUser(this.datasetIdOrName, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(MISSING_PUBLISH_RIGHTS + ". Error: " + caught.getMessage(), null, AlertType.ERROR, true); + + } + + @Override + public void onSuccess(Boolean result) { + setAlertBlock("", null, null, false); + + if (result) { + LoaderIcon loaderIcon = new LoaderIcon("Loading the item...."); + setAlertBlock(null, loaderIcon, AlertType.INFO, true); + ckanServices.getBasicDatasetBean(datasetIdOrName, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); + + } + + @Override + public void onSuccess(DatasetBean result) { + setAlertBlock("", null, null, false); + panelConfirm.setVisible(true); + selectedDataset = result; + deleteMessage.add(new HTML("

" + result.getTitle() + "
")); + + } + }); + } else { + setAlertBlock(MISSING_PUBLISH_RIGHTS, null, AlertType.WARNING, true); + } + } + + }); + } + + @UiHandler("buttonDelete") + void onClick(ClickEvent e) { + + LoaderIcon loaderIcon = new LoaderIcon("Deleting the item...."); + setAlertBlock(null, loaderIcon, AlertType.INFO, true); + panelConfirm.setVisible(false); + ckanServices.deleteItem(selectedDataset, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + setAlertBlock("Sorry, an error occurred on deleting the item. Error: " + caught.getMessage(), null, + AlertType.ERROR, true); + + } + + @Override + public void onSuccess(Boolean result) { + if (result) { + setAlertBlock("Item '" + selectedDataset.getTitle() + "' permanently deleted!", null, + AlertType.SUCCESS, true); + eventBusMainApplication.fireEvent(new ReloadDatasetPageEvent(null)); + } else { + setAlertBlock("Sorry, I cannot delete the item. Refresh and retry or contact the support", null, + AlertType.INFO, true); + } + + } + }); + } + + /** + * change alert block behavior. + * + * @param textToShow the text to show + * @param type the type + * @param visible the visible + */ + private void setAlertBlock(String textToShow, LoaderIcon loader, AlertType type, boolean visible) { + + alertPanel.clear(); + + if (loader != null) + alertPanel.add(loader); + + if (type != null) + infoBlock.setType(type); + + if (textToShow != null) + alertPanel.add(new HTML(textToShow)); + + infoBlock.setVisible(visible); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.ui.xml new file mode 100644 index 0000000..b636a80 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/action/DeleteItemPanel.ui.xml @@ -0,0 +1,36 @@ + + + + .block-alert-style { + margin-top: 10px; + padding: 10px; + margin-bottom: 10px; + } + + .float-right { + float: right; + } + + .delete-message-panel { + margin: 20px; + padding: 5px; + margin-bottom: 30px; + font-size: 14px; + } + + + + + + Do you want to permanently delete the item? + + Permanently delete + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 2317ead..4226293 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -11,28 +11,30 @@ import java.util.Map.Entry; import java.util.Set; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanMetadataPublisher; -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; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CategoryPanel; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CustomFieldEntry; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddResourceContainer; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddResourceToDataset; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddedResourcesSummary; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.tags.TagsPanel; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.ManageResources; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.WizardCreator; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.SelectResourceByWEMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.licenses.LicenseBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.CategoryWrapper; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetaDataProfileBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; +import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; +import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CategoryPanel; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.LoaderIcon; +import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; @@ -42,15 +44,12 @@ import com.github.gwtbootstrap.client.ui.Icon; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.Popover; -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.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.github.gwtbootstrap.client.ui.constants.ResizeType; -import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.SelectElement; import com.google.gwt.dom.client.Style.Unit; @@ -67,7 +66,9 @@ 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.HorizontalPanel; import com.google.gwt.user.client.ui.SimplePanel; @@ -253,7 +254,7 @@ public class CreateDatasetForm extends Composite { private Icon iconSpinner = new Icon(IconType.SPINNER); // Create a remote service proxy to talk to the server-side ckan service. - private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class); + private final CKanPublisherServiceAsync ckanServices = CKanPublisherServiceAsync.Util.getInstance(); // private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]"; private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"; @@ -265,17 +266,14 @@ public class CreateDatasetForm extends Composite { private static final String TRYING_TO_CREATE_PRODUCT = "Trying to publish the item, please wait..."; protected static final String MISSING_PUBLISH_RIGHTS = "It seems you are not authorized to publish on catalogue. Request it to the VRE manager or the portal administrator."; - // tab panel - private TabPanel tabPanel; - - // add resource form - private AddResourceToDataset resourceForm; - // the licenses private List licenseBean; // event bus - private HandlerManager eventBus; + private HandlerManager eventBusPublisherWidget = new HandlerManager(null); + + // event bus of the principal application (it is the Catalogue Portlet) + private HandlerManager eventBusMainApplication; // added custom field entries (by the user) private List customFieldEntriesList = new ArrayList(); @@ -286,9 +284,6 @@ public class CreateDatasetForm extends Composite { // dataset metadata bean private DatasetBean receivedBean; - // the owner - private String owner; - // workspace request? private boolean isWorkspaceRequest = false; @@ -306,23 +301,34 @@ public class CreateDatasetForm extends Composite { private WizardCreator wizCreator; + private FlowPanel alertPanel = new FlowPanel(); + /** * Invoked in the most general case * - * @param eventBus the event bus + * @param eventBusPublisherWidget the event bus */ - public CreateDatasetForm(HandlerManager eventBus) { - createDatasetFormBody(false, null, eventBus); + public CreateDatasetForm(HandlerManager eventBusMainApplication) { + createDatasetFormBody(false, null, eventBusMainApplication, OPERATION.NEW); + } + + /** + * Invoked in the most general case + * + * @param eventBusPublisherWidget the event bus + */ + public CreateDatasetForm(HandlerManager eventBusMainApplication, OPERATION operation) { + createDatasetFormBody(false, null, eventBusMainApplication, operation); } /** * Invoked when the workspace is used * * @param idFolderWorkspace - * @param eventBus the event bus + * @param eventBusPublisherWidget the event bus */ - public CreateDatasetForm(String idFolderOrFileWorkspace, HandlerManager eventBus) { - createDatasetFormBody(true, idFolderOrFileWorkspace, eventBus); + public CreateDatasetForm(String idFolderOrFileWorkspace, HandlerManager eventBusMainApplication) { + createDatasetFormBody(true, idFolderOrFileWorkspace, eventBusMainApplication, OPERATION.NEW); } /** @@ -330,7 +336,7 @@ public class CreateDatasetForm extends Composite { */ private void bind() { // when a custom field is removed, remove it from the list - eventBus.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() { + eventBusPublisherWidget.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() { @Override public void onRemoveEntry(DeleteCustomFieldEvent event) { @@ -340,12 +346,26 @@ public class CreateDatasetForm extends Composite { }); // on close form - eventBus.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() { + eventBusPublisherWidget.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() { @Override public void onClose(CloseCreationFormEvent event) { InfoIconsLabels.closeDialogBox(popupOpenedIds); } }); + + eventBusPublisherWidget.addHandler(ReloadDatasetPageEvent.TYPE, new ReloadDatasetPageEventHandler() { + + @Override + public void onReloadDatasetPage(ReloadDatasetPageEvent addResourceEvent) { + + // Firing the event on the main application bus + if (addResourceEvent.getDatasetIDorName() != null) { + eventBusMainApplication + .fireEvent(new ReloadDatasetPageEvent(addResourceEvent.getDatasetIDorName())); + } + + } + }); } /** @@ -354,24 +374,26 @@ public class CreateDatasetForm extends Composite { * @param isWorkspaceRequest * @param idFolderWorkspace * @param owner - * @param eventBus + * @param eventBusPublisherWidget */ private void createDatasetFormBody(final boolean isWorkspaceRequest, final String idFolderOrFileWorkspace, - final HandlerManager eventBus) { + final HandlerManager eventBusMainApplication, final OPERATION operation) { initWidget(uiBinder.createAndBindUi(this)); - this.eventBus = eventBus; + this.eventBusMainApplication = eventBusMainApplication; this.isWorkspaceRequest = isWorkspaceRequest; iconSpinner.setSpin(true); iconSpinner.getElement().getStyle().setMarginLeft(5, Unit.PX); + iconSpinner.getElement().getStyle().setProperty("animation", "spin 1s infinite linear"); + infoBlock.add(alertPanel); List listOfSteps = null; if (isWorkspaceRequest) { listOfSteps = Arrays.asList("Edit Common Metadata", "Select Item Resources", "Edit Item Specific Metadata & Publish"); } else { - listOfSteps = Arrays.asList("Edit Common Metadata", "Edit Item Specific Metadata & Publish"); + listOfSteps = Arrays.asList("Edit Common Metadata", "Edit Item Specific Metadata & Publish", "Add Resources"); } this.wizCreator = new WizardCreator(listOfSteps); @@ -389,9 +411,10 @@ public class CreateDatasetForm extends Composite { tagsPanel.setVisible(false); // check if the user has publishing rights - setAlertBlock("Checking your permissions, please wait...", AlertType.INFO, true); + LoaderIcon loader = new LoaderIcon("Checking your permissions, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); - ckanServices.isPublisherUser(isWorkspaceRequest, new AsyncCallback() { + ckanServices.isPublisherUser(new AsyncCallback() { @Override public void onSuccess(Boolean result) { @@ -399,15 +422,16 @@ public class CreateDatasetForm extends Composite { if (result) { // set info block - setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); + LoaderIcon loader = new LoaderIcon("Retrieving information, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); // get back the licenses and the metadata information - ckanServices.getDatasetBean(idFolderOrFileWorkspace, new AsyncCallback() { + ckanServices.buildPartialDatasetBean(idFolderOrFileWorkspace, new AsyncCallback() { @Override public void onFailure(Throwable caught) { - setAlertBlock(caught.getMessage(), AlertType.ERROR, true); + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); } @@ -415,8 +439,7 @@ public class CreateDatasetForm extends Composite { public void onSuccess(final DatasetBean bean) { if (bean == null) { - - setAlertBlock("Error while retrieving information.", AlertType.ERROR, true); + setAlertBlock("Error while retrieving information.", null, AlertType.ERROR, true); } else { // save it @@ -431,7 +454,8 @@ public class CreateDatasetForm extends Composite { maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); maintainerEmailTextbox.setText(bean.getMaintainerEmail()); - setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); + LoaderIcon loader = new LoaderIcon("Retrieving information, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); // vocabulary list of tags has preemption List vocabularyTags = bean.getTagsVocabulary(); @@ -455,8 +479,8 @@ public class CreateDatasetForm extends Composite { for (String value : values) { // these are fixed key, variable value custom fields - CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), - value, false); + CustomFieldEntry toAdd = new CustomFieldEntry(eventBusPublisherWidget, + entry.getKey(), value, false); customFieldEntriesList.add(toAdd); customFields.add(toAdd); @@ -499,7 +523,7 @@ public class CreateDatasetForm extends Composite { @Override public void onChange(ChangeEvent event) { event.preventDefault(); - organizationsListboxChangeHandlerBody(); + organizationsListboxChangeHandlerBody(operation); } }); @@ -508,7 +532,8 @@ public class CreateDatasetForm extends Composite { .get(organizationsListbox.getSelectedItemText()); // force tags - setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true); + LoaderIcon loaderT = new LoaderIcon("Checking for tags vocabulary, please wait..."); + setAlertBlock(null, loaderT, AlertType.INFO, true); ckanServices.getTagsForOrganization(orgName, new AsyncCallback>() { @Override @@ -523,21 +548,21 @@ public class CreateDatasetForm extends Composite { setAlertBlock( "Error while checking if a vocabulary of tags is defined in the selected organization.", - AlertType.ERROR, true); + null, AlertType.ERROR, true); tagsPanel.setVisible(true); } }); - // try to retrieve the profiles - setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true); + LoaderIcon loaderTyp = new LoaderIcon("Retrieving types, please wait..."); + setAlertBlock(null, loaderTyp, AlertType.INFO, true); // perform remote request of profiles for the selected organization ckanServices.getProfiles(orgName, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { - setAlertBlock(caught.getMessage(), AlertType.ERROR, true); + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); } @Override @@ -545,7 +570,7 @@ public class CreateDatasetForm extends Composite { if (profiles == null) { setAlertBlock("An unknow error occurred while retrieving types, sorry", - AlertType.ERROR, true); + null, AlertType.ERROR, true); } else { GWT.log("Profile returned are: " + profiles.size()); @@ -557,17 +582,20 @@ public class CreateDatasetForm extends Composite { } receivedBean.setMetadataList(profiles); - prepareMetadataList(receivedBean); + prepareMetadataList(receivedBean, operation); organizationsListbox.setEnabled(true); metadataTypeListbox.setEnabled(true); // try to retrieve the licenses - setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true); + LoaderIcon loaderLic = new LoaderIcon( + "Retrieving licenses, please wait..."); + setAlertBlock(null, loaderLic, AlertType.INFO, true); + ckanServices.getLicenses(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { - setAlertBlock(caught.getMessage(), AlertType.ERROR, true); + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); } @Override @@ -585,9 +613,10 @@ public class CreateDatasetForm extends Composite { // set the url of the license, if any showLicenseUrl(); - // try to retrieve the licenses - setAlertBlock("Retrieving groups, please wait...", - AlertType.INFO, true); + // try to retrieve groups + LoaderIcon loaderLic = new LoaderIcon( + "Retrieving groups, please wait..."); + setAlertBlock(null, loaderLic, AlertType.INFO, true); // request groups ckanServices.getUserGroups(orgName, @@ -599,7 +628,7 @@ public class CreateDatasetForm extends Composite { if (groups == null) { setAlertBlock( "Error while retrieving groups", - AlertType.ERROR, true); + null, AlertType.ERROR, true); } else { if (groups.isEmpty()) { groupsControlGroup.setVisible(false); @@ -614,7 +643,8 @@ public class CreateDatasetForm extends Composite { hideGroupsAlreadyInProfile(profiles); } // everything went ok - setAlertBlock("", AlertType.ERROR, false); + setAlertBlock("", null, AlertType.ERROR, + false); continueButton.setEnabled(true); resetButton.setEnabled(true); } @@ -622,13 +652,13 @@ public class CreateDatasetForm extends Composite { @Override public void onFailure(Throwable caught) { - setAlertBlock(caught.getMessage(), + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); } }); } else { - setAlertBlock("Error while retrieving licenses", + setAlertBlock("Error while retrieving licenses", null, AlertType.ERROR, true); } } @@ -641,14 +671,14 @@ public class CreateDatasetForm extends Composite { }); } else { - setAlertBlock(MISSING_PUBLISH_RIGHTS, AlertType.ERROR, true); + setAlertBlock(MISSING_PUBLISH_RIGHTS, null, AlertType.ERROR, true); } } @Override public void onFailure(Throwable caught) { - setAlertBlock(MISSING_PUBLISH_RIGHTS, AlertType.ERROR, true); + setAlertBlock(MISSING_PUBLISH_RIGHTS, null, AlertType.ERROR, true); } }); @@ -658,7 +688,7 @@ public class CreateDatasetForm extends Composite { * When the organization name is changed we need to retrieve the list of * profiles and groups */ - private void organizationsListboxChangeHandlerBody() { + private void organizationsListboxChangeHandlerBody(final OPERATION operation) { // remove any other product profiles metadataTypeListbox.clear(); @@ -674,7 +704,8 @@ public class CreateDatasetForm extends Composite { final String orgName = nameTitleOrganizationMap.get(selectedOrganizationTitle); // try to retrieve the profiles - setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true); + LoaderIcon loader = new LoaderIcon("Retrieving types, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); // disable the list of organizations name so that the user doesn't change it // again @@ -693,12 +724,13 @@ public class CreateDatasetForm extends Composite { if (profiles != null) { receivedBean.setMetadataList(profiles); - prepareMetadataList(receivedBean); + prepareMetadataList(receivedBean, operation); organizationsListbox.setEnabled(true); metadataTypeListbox.setEnabled(true); - // try to retrieve the licenses - setAlertBlock("Retrieving groups, please wait...", AlertType.INFO, true); + // try to retrieve the groups + LoaderIcon loaderG = new LoaderIcon("Retrieving groups, please wait..."); + setAlertBlock(null, loaderG, AlertType.INFO, true); // request groups ckanServices.getUserGroups(orgName, new AsyncCallback>() { @@ -707,7 +739,8 @@ public class CreateDatasetForm extends Composite { public void onSuccess(List groups) { if (groups == null) { - setAlertBlock("Error while retrieving groups, try later", AlertType.ERROR, true); + setAlertBlock("Error while retrieving groups. Refresh and retry later", null, + AlertType.ERROR, true); } else { if (groups.isEmpty()) { groupsControlGroup.setVisible(false); @@ -720,19 +753,22 @@ public class CreateDatasetForm extends Composite { groupsListbox.setEnabled(true); hideGroupsAlreadyInProfile(profiles); } - setAlertBlock("", AlertType.ERROR, false); + setAlertBlock("", null, AlertType.ERROR, false); } } @Override public void onFailure(Throwable caught) { - setAlertBlock("Error while retrieving groups, try later", AlertType.ERROR, true); + setAlertBlock("Error while retrieving groups. Refresh and retry later", null, + AlertType.ERROR, true); } }); // check also for tags (if for that context there is a vocabulary or not) tagsPanel.setVisible(false); - setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true); + LoaderIcon loaderV = new LoaderIcon("Checking for tags vocabulary, please wait..."); + setAlertBlock(null, loaderV, AlertType.INFO, true); + ckanServices.getTagsForOrganization(orgName, new AsyncCallback>() { @Override @@ -740,7 +776,7 @@ public class CreateDatasetForm extends Composite { tagsPanel.setVocabulary(vocabulary); tagsPanel.setVisible(true); - setAlertBlock("", AlertType.ERROR, false); + setAlertBlock("", null, AlertType.ERROR, false); } @Override @@ -748,7 +784,7 @@ public class CreateDatasetForm extends Composite { setAlertBlock( "Error while checking if a vocabulary of tags is defined in the selected organization.", - AlertType.ERROR, true); + null, AlertType.ERROR, true); tagsPanel.setVocabulary(null); tagsPanel.setVisible(true); @@ -756,14 +792,14 @@ public class CreateDatasetForm extends Composite { }); } else - setAlertBlock("Error while retrieving types, sorry", AlertType.ERROR, true); + setAlertBlock("Error while retrieving types. Refresh and retry", null, AlertType.ERROR, true); } @Override public void onFailure(Throwable caught) { - setAlertBlock("Error while retrieving types, sorry", AlertType.ERROR, true); + setAlertBlock("Error while retrieving types. Refresh and retry", null, AlertType.ERROR, true); } }); @@ -775,7 +811,7 @@ public class CreateDatasetForm extends Composite { * * @param receivedBean */ - private void prepareMetadataList(final DatasetBean receivedBean) { + private void prepareMetadataList(final DatasetBean receivedBean, final OPERATION operation) { List profiles = receivedBean.getMetadataList(); @@ -797,7 +833,7 @@ public class CreateDatasetForm extends Composite { receivedBean.setChosenType(null); } else { receivedBean.setChosenType(selectedItemText); - addFields(selectedItemText); + addFields(selectedItemText, operation); } } }); @@ -835,7 +871,7 @@ public class CreateDatasetForm extends Composite { * * @param selectedItem */ - protected void addFields(String selectedItem) { + protected void addFields(String selectedItem, OPERATION operation) { for (MetaDataProfileBean bean : receivedBean.getMetadataList()) { if (bean.getType().equals(selectedItem)) { @@ -851,16 +887,10 @@ public class CreateDatasetForm extends Composite { if (categories == null || categories.isEmpty()) { for (MetadataFieldWrapper field : fields) { - /* - * MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new - * MetaDataFieldSkeleton(field, eventBus); metadataFieldsPanel.add(fieldWidget); - * listOfMetadataFields.add(fieldWidget); } catch (Exception e) { - * GWT.log("Unable to build such widget", e); } - */ MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(field, eventBus); + fieldWidget = new MetaDataField(field, eventBusPublisherWidget, operation); metadataFieldsPanel.add(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { @@ -882,16 +912,10 @@ public class CreateDatasetForm extends Composite { for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) { - /* - * MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new - * MetaDataFieldSkeleton(metadataFieldWrapper, eventBus); - * cp.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch - * (Exception e) { GWT.log("Unable to build such widget", e); } - */ - MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus); + fieldWidget = new MetaDataField(metadataFieldWrapper, eventBusPublisherWidget, + operation); cp.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { @@ -906,16 +930,9 @@ public class CreateDatasetForm extends Composite { CategoryPanel extrasCategory = new CategoryPanel("Other", null); for (MetadataFieldWrapper field : fields) { - /* - * MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new - * MetaDataFieldSkeleton(field, eventBus); extrasCategory.addField(fieldWidget); - * listOfMetadataFields.add(fieldWidget); } catch (Exception e) { - * GWT.log("Unable to build such widget", e); } - */ - MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(field, eventBus); + fieldWidget = new MetaDataField(field, eventBusPublisherWidget, operation); extrasCategory.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { @@ -932,7 +949,7 @@ public class CreateDatasetForm extends Composite { @UiHandler("addCustomFieldButton") void addCustomFieldEvent(ClickEvent e) { - CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, "", "", true); + CustomFieldEntry toAdd = new CustomFieldEntry(eventBusPublisherWidget, "", "", true); customFieldEntriesList.add(toAdd); customFields.add(toAdd); @@ -1267,37 +1284,9 @@ public class CreateDatasetForm extends Composite { // remove content of the main panel createDatasetMainPanel.clear(); - - // TabPanelException - tabPanel = new TabPanel(Tabs.ABOVE); - tabPanel.setWidth("100%"); - - // add the form - resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(), - createdDatasetBean.getTitle(), - createdDatasetBean.getSelectedOrganization(), owner, datasetUrl); - - // tab for the form - Tab formContainer = new Tab(); - formContainer.add(resourceForm); - formContainer.setHeading("Add New Resource"); - tabPanel.add(formContainer); - - // tab for the added resources - Tab addedResources = new Tab(); - addedResources.add(new AddedResourcesSummary(eventBus)); - addedResources.setHeading("Added Resource"); - tabPanel.add(addedResources); - - // add tabs to resources panel - tabPanel.selectTab(0); - - // form container - AddResourceContainer container = new AddResourceContainer(datasetUrl); - container.add(tabPanel); - - // add the new content of the main panel - createDatasetMainPanel.add(container); + ManageResources manageResources = new ManageResources(eventBusPublisherWidget, + createdDatasetBean, datasetUrl); + createDatasetMainPanel.add(manageResources); } }); } catch (Exception e2) { @@ -1305,6 +1294,9 @@ public class CreateDatasetForm extends Composite { } } + // firing the event to load the dataset in the Portlet + eventBusPublisherWidget.fireEvent(new ReloadDatasetPageEvent(createdDatasetBean.getId())); + } else { alertOnCreate(ERROR_PRODUCT_CREATION, false, AlertType.ERROR, true); @@ -1615,7 +1607,7 @@ public class CreateDatasetForm extends Composite { // disable profile fields for (MetaDataField metaField : listOfMetadataFields) { for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) { - field.freeze(); + field.freeze(true); } } @@ -1625,19 +1617,42 @@ public class CreateDatasetForm extends Composite { resourcesSelectByWEMainPanel.freeze(); } +// /** +// * change alert block behavior. +// * +// * @param textToShow +// * @param type +// * @param visible +// */ +// private void setAlertBlock(String textToShow, AlertType type, boolean visible) { +// +// infoBlock.setText(textToShow); +// infoBlock.setType(type); +// infoBlock.setVisible(visible); +// +// } + /** * change alert block behavior. - * - * @param textToShow - * @param type - * @param visible + * + * @param textToShow the text to show + * @param type the type + * @param visible the visible */ - private void setAlertBlock(String textToShow, AlertType type, boolean visible) { + private void setAlertBlock(String textToShow, LoaderIcon loader, AlertType type, boolean visible) { - infoBlock.setText(textToShow); + alertPanel.clear(); + + if (loader != null) { + alertPanel.add(loader); + } infoBlock.setType(type); infoBlock.setVisible(visible); + if (textToShow != null) { + alertPanel.add(new HTML(textToShow)); + } + } @UiHandler("licenseListbox") diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index f047f41..971dca9 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -2,7 +2,7 @@ + xmlns:m="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.tags"> .form-main-style { margin-left: 10px; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.java deleted file mode 100644 index 69015ca..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; - -import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.Label; -import com.github.gwtbootstrap.client.ui.constants.LabelType; -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.shared.HandlerManager; -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.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; - - -/** - * The Class MetaDataField. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * - * Jun 10, 2019 - */ -public class MetaDataField extends Composite { - - private static MetaDataFieldUiBinder uiBinder = GWT.create(MetaDataFieldUiBinder.class); - - @UiField VerticalPanel panelMetaDataFieldsSkeleton; - - @UiField Label repeatabilityLabel; - - //@UiField ControlGroup cgMetaDataFieldSkeletonFields; - - @UiField Button addFieldButton; - - @UiField Button removeFieldButton; - - private List listOfMetadataFields = new ArrayList(); - - private MetadataFieldWrapper fieldWrapper; - - private HandlerManager eventBus; - - /** - * The Interface MetaDataFieldUiBinder. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * - * Jun 10, 2019 - */ - interface MetaDataFieldUiBinder extends UiBinder { - } - - - /** - * Instantiates a new meta data field. - * - * @param field the field - * @param eventBus the event bus - * @throws Exception the exception - */ - public MetaDataField(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception { - initWidget(uiBinder.createAndBindUi(this)); - this.fieldWrapper = field; - this.eventBus = eventBus; - addNewOccurrenceOfField(); - checkAllowedAddField(); - checkAllowedRemoveField(); - - addFieldButton.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - addNewOccurrenceOfField(); - checkAllowedAddField(); - checkAllowedRemoveField(); - } - }); - - removeFieldButton.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - removeLatestOccurrenceOfFiled(); - checkAllowedAddField(); - checkAllowedRemoveField(); - } - }); - - //The field is repeatable - if(field.getMaxOccurs()>1) { - repeatabilityLabel.setVisible(true); - repeatabilityLabel.setType(LabelType.INFO); - addFieldButton.setTitle("Add another "+field.getFieldName()); - removeFieldButton.setTitle("Remove latest "+field.getFieldName()); -// String maxTxt = field.getMaxOccurs()==Integer.MAX_VALUE?"":"(max occurs declared are "+field.getMaxOccurs()+" times)"; - } - } - - - /** - * Check allowed remove field. - */ - private void checkAllowedRemoveField() { - boolean removeCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size()>1; - removeFieldButton.setVisible(removeCond); - } - - /** - * Checks if is allowed add occurrence. - */ - private void checkAllowedAddField() { - - boolean repeatibilityCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size() getListOfMetadataFields() { - return listOfMetadataFields; - } - -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.ui.xml deleted file mode 100644 index eaf8b01..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/MetaDataField.ui.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - .margin-left-max-occurrs { - padding-left: 50px; - } - - - - - - - Repeatable field - - - - - - \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java new file mode 100644 index 0000000..29a1128 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java @@ -0,0 +1,1701 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanMetadataPublisher; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent; +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.events.DeleteCustomFieldEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEventHandler; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CustomFieldEntry; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddResourceToDataset; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.ManageResources; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.WizardCreator; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataProfileBeanForUpdate; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; +import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CategoryPanel; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.LoaderIcon; +import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; + +import com.github.gwtbootstrap.client.ui.AlertBlock; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.Form; +import com.github.gwtbootstrap.client.ui.Icon; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.NavPills; +import com.github.gwtbootstrap.client.ui.Paragraph; +import com.github.gwtbootstrap.client.ui.Popover; +import com.github.gwtbootstrap.client.ui.TextArea; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.github.gwtbootstrap.client.ui.constants.IconType; +import com.github.gwtbootstrap.client.ui.constants.ResizeType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.SelectElement; +import com.google.gwt.dom.client.Style.Unit; +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.DomEvent; +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.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.HorizontalPanel; +import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * Create metadata form for ckan product. + * + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class UpdateDatasetForm extends Composite { + + private static EditMetadataFormUiBinder uiBinder = GWT.create(EditMetadataFormUiBinder.class); + + /** + * The Interface EditMetadataFormUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 6, 2024 + */ + interface EditMetadataFormUiBinder extends UiBinder { + } + + @UiField + HTMLPanel createDatasetMainPanel; + @UiField + TextBox titleTextBox; + @UiField + TextArea descriptionTextarea; + @UiField + ListBox licenseListbox; + @UiField + ListBox visibilityListbox; + @UiField + ListBox organizationsListbox; + @UiField + TextBox versionTextbox; + @UiField + TextBox authorTextbox; + @UiField + TextBox authorEmailTextbox; + @UiField + TextBox maintainerTextbox; + @UiField + TextBox maintainerEmailTextbox; + @UiField + ControlGroup customFields; + @UiField + Button addCustomFieldButton; + @UiField + Button updateButton; + @UiField + Button resetButton; + @UiField + AlertBlock infoBlock; + @UiField + AlertBlock alertNoResources; + @UiField + AlertBlock onContinueAlertBlock; + @UiField + AlertBlock onCreateAlertBlock; + @UiField + VerticalPanel metadataFieldsPanel; + @UiField + ListBox metadataTypeListbox; + @UiField + Form formFirstStep; + @UiField + Form formSecondStep; + @UiField + Form formThirdStep; + @UiField + Button continueButton; + @UiField + Button goBackButtonSecondStep; + @UiField + Paragraph selectedProfile; + @UiField + Button goToDatasetButton; + @UiField + HorizontalPanel goToDatasetButtonPanel; + @UiField + Button addResourcesButtonStep1; + + @UiField + Button addResourcesButtonStep3; + + @UiField + SimplePanel workspaceResourcesContainer; + @UiField + Button continueThirdStep; + @UiField + Button goBackButtonFirstStep; + @UiField + Anchor licenseUrlAnchor; + @UiField + Paragraph unavailableUrl; + @UiField + TagsPanel tagsPanel; + @UiField + ListBox groupsListbox; + + // info panels + @UiField + Icon infoIconLicenses; + @UiField + FocusPanel focusPanelLicenses; + @UiField + Popover popoverLicenses; + @UiField + Icon infoIconVisibility; + @UiField + FocusPanel focusPanelVisibility; + @UiField + Popover popoverVisibility; + @UiField + Icon infoIconAuthor; + @UiField + FocusPanel focusPanelAuthor; + @UiField + Popover popoverAuthor; + @UiField + Icon infoIconMaintainerEmail; + @UiField + FocusPanel focusPanelMaintainerEmail; + @UiField + Popover popoverMaintainerEmail; + @UiField + Icon infoIconAuthorEmail; + @UiField + FocusPanel focusPanelAuthorEmail; + @UiField + Popover popoverAuthorEmail; + @UiField + Icon infoIconTypes; + @UiField + FocusPanel focusPanelTypes; + @UiField + Popover popoverTypes; + @UiField + Icon infoIconMaintainer; + @UiField + FocusPanel focusPanelMaintainer; + @UiField + Popover popoverMaintainer; + @UiField + Icon infoIconCustomFields; + @UiField + FocusPanel focusPanelCustomFields; + @UiField + Popover popoverCustomFields; + @UiField + Icon infoIconResources; + @UiField + FocusPanel focusPanelResources; + @UiField + Popover popoverResources; + @UiField + Icon infoIconTitle; + @UiField + FocusPanel focusPanelTitle; + @UiField + Popover popoverGroups; + @UiField + Icon infoIconGroups; + @UiField + FocusPanel focusPanelGroups; + @UiField + Popover popoverTitle; + @UiField + Icon infoIconDescription; + @UiField + Popover popoverDescription; + @UiField + FocusPanel focusPanelDescription; + @UiField + ControlGroup metadataTypesControlGroup; + @UiField + ControlGroup productTitleGroup; + @UiField + ControlGroup maintainerControlGroup; + @UiField + ControlGroup versionControlGroup; + @UiField + ControlGroup organizationsGroup; + @UiField + ControlGroup groupsControlGroup; + + @UiField + HTMLPanel wizardCreatorPanel; + + private Icon iconSpinner = new Icon(IconType.SPINNER); + + // Create a remote service proxy to talk to the server-side ckan service. + private final CKanPublisherServiceAsync ckanServices = CKanPublisherServiceAsync.Util.getInstance(); + + // private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]"; + private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"; + private static final String NONE_PROFILE = "none"; + + // error/info messages + protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to update the item."; + protected static final String PRODUCT_UPDATED_OK = "Item correctly updated!"; + private static final String TRYING_TO_UPDATE_PRODUCT = "Trying to update the item, please wait..."; + protected static final String MISSING_PUBLISH_RIGHTS = "It seems you are not authorized to edit this item. Either you must be the author item or Catalogue Admininistrator in the organization"; + + // tab panel + private NavPills tabPanel; + + // add resource form + private AddResourceToDataset resourceForm; + + // the licenses + private List licenseBean; + + // event bus of the principal application (it is the Catalogue Portlet) + private HandlerManager eventBusMainApplication; + + private HandlerManager eventBusPublisherWidget = new HandlerManager(null); + + // added custom field entries (by the user) + private List customFieldEntriesList = new ArrayList(); + + // the list of MetaDataField added + private List listOfMetadataFields = new ArrayList(); + + // dataset metadata bean + private DatasetBean theDatasetBean; + + // resource table + //private SelectResourceByWEMainPanel resourcesSelectByWEMainPanel; + + // List of opened popup'ids + private List popupOpenedIds = new ArrayList(); + + // map of organization name title + private Map nameTitleOrganizationMap = new HashMap(); + + private WizardCreator wizCreator; + + private boolean isWorkspaceRequest = false; + + private String datasetIdOrName = null; + + private FlowPanel alertPanel = new FlowPanel(); + + /** + * Instantiates a new update dataset form. + * + * @param eventBusMainApplication the event bus + * @param itemId the item id + */ + public UpdateDatasetForm(HandlerManager mainApplicationBusRef, String itemId) { + updateDatasetFormBody(mainApplicationBusRef, itemId, OPERATION.UPDATE); + } + + /** + * Bind on events. + */ + private void bind() { + // when a custom field is removed, remove it from the list + eventBusPublisherWidget.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() { + + @Override + public void onRemoveEntry(DeleteCustomFieldEvent event) { + customFieldEntriesList.remove(event.getRemovedEntry()); + customFields.remove(event.getRemovedEntry()); + } + }); + + // on close form + eventBusPublisherWidget.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() { + @Override + public void onClose(CloseCreationFormEvent event) { + InfoIconsLabels.closeDialogBox(popupOpenedIds); + } + }); + + eventBusPublisherWidget.addHandler(ReloadDatasetPageEvent.TYPE, new ReloadDatasetPageEventHandler() { + + @Override + public void onReloadDatasetPage(ReloadDatasetPageEvent addResourceEvent) { + + // Firing the event on the main application bus + if (addResourceEvent.getDatasetIDorName() != null) { + eventBusMainApplication + .fireEvent(new ReloadDatasetPageEvent(addResourceEvent.getDatasetIDorName())); + } + + } + }); + } + + /** + * The real constructor. + * + * @param eventBusMainApplication the event bus + * @param datasetIdOrName the item id + * @param operation the operation + */ + private void updateDatasetFormBody(final HandlerManager mainApplicationBusRef, final String datasetIdOrName, + final OPERATION operation) { + + initWidget(uiBinder.createAndBindUi(this)); + + this.eventBusMainApplication = mainApplicationBusRef; + this.datasetIdOrName = datasetIdOrName; + + iconSpinner.setSpin(true); + iconSpinner.getElement().getStyle().setMarginLeft(5, Unit.PX); + iconSpinner.getElement().getStyle().setProperty("animation", "spin 1s infinite linear"); + + infoBlock.add(alertPanel); + + List listOfSteps = Arrays.asList("Edit Common Metadata", "Edit Item Specific Metadata & Update", "Manage Resources"); + + this.wizCreator = new WizardCreator(listOfSteps); + wizardCreatorPanel.add(wizCreator); + + this.descriptionTextarea.setResize(ResizeType.VERTICAL); + bind(); + prepareInfoIcons(); + + // disable continue button + continueButton.setEnabled(false); + resetButton.setEnabled(false); + addResourcesButtonStep1.setEnabled(false); + + // hide reset button + resetButton.setVisible(false); + + // hide tags panel + tagsPanel.setVisible(false); + + // check if the user has publishing rights + LoaderIcon loader = new LoaderIcon("Checking your permissions, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); + + ckanServices.isPublisherOwnerOrAdminUser(this.datasetIdOrName, new AsyncCallback() { + + @Override + public void onSuccess(Boolean result) { + GWT.log("isPublisherOwnerOrAdminUser: " + result); + if (result) { + + // set info block + + LoaderIcon loader = new LoaderIcon("Retrieving information, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); + + // get back the licenses and the metadata information + ckanServices.getDatasetBeanForUpdate(datasetIdOrName, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); + + } + + @Override + public void onSuccess(final DatasetBean datasetBean) { + GWT.log("getDatasetBeanForUpdate returns: " + datasetBean); + + if (datasetBean == null) { + setAlertBlock("Error while retrieving information.", null, AlertType.ERROR, true); + } else { + // save it + theDatasetBean = datasetBean; + + // fill the form + titleTextBox.setText(datasetBean.getTitle()); + descriptionTextarea.setText(datasetBean.getDescription()); + versionTextbox.setText(String.valueOf(datasetBean.getVersion())); + authorTextbox.setText(datasetBean.getAuthorFullName()); + authorEmailTextbox.setText(datasetBean.getAuthorEmail()); + maintainerTextbox.setText(datasetBean.getMaintainer()); + maintainerEmailTextbox.setText(datasetBean.getMaintainerEmail()); + + LoaderIcon loader = new LoaderIcon("Retrieving dataset information, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); + + // vocabulary list of tags has preemption + List vocabularyTags = datasetBean.getTagsVocabulary(); + if (vocabularyTags != null) { + tagsPanel.setVocabulary(vocabularyTags); +// if (datasetBean.getTags() != null) { +// for (String tag : datasetBean.getTags()) { +// tagsPanel.addTagElement(tag); +// } +// +// } + } + + // Settings the tags + if (datasetBean.getTags() != null) { + for (String tag : datasetBean.getTags()) { + tagsPanel.addTagElement(tag); + } + + } + + // THIS BLOCK is it required? Probably not. + + // retrieve custom fields + Map> customFieldsMap = datasetBean.getCustomFields(); + // TODO Check if these tags are ok for the vocabulary + if (customFieldsMap != null && vocabularyTags == null) { + // get the keys and put them as tags + Iterator>> iteratorOverCustomField = customFieldsMap + .entrySet().iterator(); + + while (iteratorOverCustomField.hasNext()) { + Map.Entry> entry = iteratorOverCustomField + .next(); + + List values = entry.getValue(); + + for (String value : values) { + // these are fixed key, variable value custom fields + CustomFieldEntry toAdd = new CustomFieldEntry(eventBusPublisherWidget, + entry.getKey(), value, false); + customFieldEntriesList.add(toAdd); + customFields.add(toAdd); + + // add as tag + tagsPanel.addTagElement(entry.getKey()); + } + } + } + // END BLOCK + + // set it as visible anyway + tagsPanel.setVisible(true); + +// // The resource root is the folder id. Es. ID of the Workspace Root folder. +// if (datasetBean.getResourceRoot() != null) { +// resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel( +// datasetBean.getResourceRoot()); +// } + + // set organizations + List organizations = datasetBean.getOrganizationList(); + + for (OrganizationBean organization : organizations) { + organizationsListbox.addItem(organization.getTitle()); + nameTitleOrganizationMap.put(organization.getTitle(), organization.getName()); + break; // expecting only one + } + + // force the selection of the first one, and retrieve the list of profiles + organizationsListbox.setSelectedIndex(0); + +// // add change handler to dynamically retrieve the list of profiles +// organizationsListbox.addChangeHandler(new ChangeHandler() { +// +// @Override +// public void onChange(ChangeEvent event) { +// event.preventDefault(); +// organizationsListboxChangeHandlerBody(operation); +// } +// }); + + // get the name of the organization from the title + final String orgName = nameTitleOrganizationMap + .get(organizationsListbox.getSelectedItemText()); + + // Putting the selected Organization into bena + theDatasetBean.setSelectedOrganization(orgName); + + // try to retrieve the profiles + loader = new LoaderIcon("Retrieving types, please wait..."); + setAlertBlock(null, loader, AlertType.INFO, true); + + // perform remote request of profiles for the selected organization + ckanServices.getProfileForUpdate(orgName, datasetBean.getChosenType(), + datasetBean.getId(), new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, true); + } + + @Override + public void onSuccess( + final MetadataProfileBeanForUpdate metadataProfileForUpdate) { + setAlertBlock("", null, AlertType.ERROR, false); + + List profiles = metadataProfileForUpdate + .getListProfileBean(); + + if (profiles == null) { + setAlertBlock( + "An unknow error occurred while retrieving types, sorry", + null, AlertType.ERROR, true); + } else { + + GWT.log("Profile returned are: " + profiles.size()); + if (!GWT.isProdMode()) { + for (MetaDataProfileBean profile : profiles) { + GWT.log("Profile title: " + profile.getTitle() + ", type: " + + profile.getType()); + } + } + + theDatasetBean.setMetadataList(profiles); + prepareMetadataList(theDatasetBean, operation); + addCustomField(metadataProfileForUpdate.getCustomFields()); + organizationsListbox.setEnabled(true); + metadataTypeListbox.setEnabled(true); + + // try to retrieve the licenses + LoaderIcon loaderLic = new LoaderIcon( + "Retrieving types, please wait..."); + setAlertBlock(null, loaderLic, AlertType.INFO, true); + + ckanServices.getLicenses(new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(caught.getMessage(), null, AlertType.ERROR, + true); + } + + @Override + public void onSuccess(List licenses) { + setAlertBlock("", null, AlertType.ERROR, false); + + if (licenses != null && !licenses.isEmpty()) { + + licenseBean = licenses; + + // fill the listbox + for (int i = 0; i < licenses.size(); i++) { + licenseListbox.addItem(licenses.get(i).getTitle()); + } + + // set the url of the license, if any + showLicenseUrl(); + + LoaderIcon loaderLic = new LoaderIcon( + "Retrieving groups, please wait..."); + setAlertBlock(null, loaderLic, AlertType.INFO, true); + + // request groups + ckanServices.getUserGroups(orgName, + new AsyncCallback>() { + + @Override + public void onSuccess( + List groups) { + if (groups == null) { + setAlertBlock( + "Error while retrieving groups", + null, AlertType.ERROR, + true); + } else { + if (groups.isEmpty()) { + groupsControlGroup + .setVisible(false); + } else { + + // add groups + for (OrganizationBean group : groups) { + groupsListbox.addItem( + group.getTitle(), + group.getName()); + } + hideGroupsAlreadyInProfile( + profiles); + } + // everything went ok + setAlertBlock("", null, + AlertType.ERROR, false); + continueButton.setEnabled(true); + resetButton.setEnabled(true); + addResourcesButtonStep1 + .setEnabled(true); + + bindManageResources(datasetBean, + datasetIdOrName, 1); + } + } + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(caught.getMessage(), null, + AlertType.ERROR, true); + } + }); + + } else { + setAlertBlock("Error while retrieving licenses", null, + AlertType.ERROR, true); + } + } + }); + } + } + }); + } + } + }); + + } else { + setAlertBlock(MISSING_PUBLISH_RIGHTS, null, AlertType.WARNING, true); + } + + } + + @Override + public void onFailure(Throwable caught) { + setAlertBlock(MISSING_PUBLISH_RIGHTS, null, AlertType.ERROR, true); + } + }); + + } + + private void addCustomField(Map> customFieldsMap) { + // TODO Check if these tags are ok for the vocabulary + if (customFieldsMap != null) { + + // get the keys and put them as tags + Iterator>> iteratorOverCustomField = customFieldsMap.entrySet().iterator(); + + while (iteratorOverCustomField.hasNext()) { + Map.Entry> entry = iteratorOverCustomField.next(); + + List values = entry.getValue(); + + for (String value : values) { + // these are fixed key, variable value custom fields + CustomFieldEntry toAdd = new CustomFieldEntry(eventBusPublisherWidget, entry.getKey(), value, + false); + customFieldEntriesList.add(toAdd); + customFields.add(toAdd); + } + } + } + } + + /** + * Add the items to the listbox and put data into the metadataPanel. + * + * @param theDatasetBean the received bean + * @param operation the operation + */ + private void prepareMetadataList(final DatasetBean receivedBean, OPERATION operation) { + + // the profile should be one + List profiles = receivedBean.getMetadataList(); + + if (profiles != null && !profiles.isEmpty()) { + for (final MetaDataProfileBean metadataBean : profiles) { + + metadataTypeListbox.addItem(metadataBean.getType()); + + // add handler on select + metadataTypeListbox.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + String selectedItemText = metadataTypeListbox.getSelectedItemText(); + metadataFieldsPanel.clear(); + if (selectedItemText.equals(NONE_PROFILE)) { + metadataFieldsPanel.setVisible(false); + receivedBean.setChosenType(null); + } else { + receivedBean.setChosenType(selectedItemText); + addFields(selectedItemText, operation); + } + } + }); + } + + // hide elements or show them if needed (groups in profiles cannot be present + // again in groups listbox) + if (groupsControlGroup.isVisible()) { + List groupsToHide = new ArrayList(); + for (MetaDataProfileBean profile : profiles) + groupsToHide.add(profile.getType().toString()); + + SelectElement se = groupsListbox.getElement().cast(); + + for (int i = 0; i < groupsListbox.getItemCount(); i++) { + if (groupsToHide.contains(groupsListbox.getItemText(i))) { + se.getOptions().getItem(i).getStyle().setProperty("display", "none"); + } else + se.getOptions().getItem(i).getStyle().setProperty("display", ""); + } + } + + metadataTypesControlGroup.setVisible(true); + } else { + // just hide this listbox + metadataTypesControlGroup.setVisible(false); + metadataFieldsPanel.clear(); + listOfMetadataFields.clear(); + receivedBean.setChosenType(null); + } + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + + @Override + public void execute() { + if (profiles.size() == 1) { + // showChooseProfileForm(false); + metadataTypeListbox.setSelectedValue(profiles.get(0).getType()); + // customLegend.setText("Insert Information for: " + profiles.get(0).getType(), + // true); + DomEvent.fireNativeEvent(Document.get().createChangeEvent(), metadataTypeListbox); + } + } + + }); + } + + /** + * Add fields of the selected metadata profile to the widget. + * + * @param selectedItem the selected item + * @param operation the operation + */ + protected void addFields(String selectedItem, OPERATION operation) { + + for (MetaDataProfileBean bean : theDatasetBean.getMetadataList()) { + if (bean.getType().equals(selectedItem)) { + + // clear old data + listOfMetadataFields.clear(); + + // prepare the data + List fields = bean.getMetadataFields(); + List categories = bean.getCategories(); + + GWT.log("There are " + categories.size() + " categories for profile " + bean.getTitle()); + + if (categories == null || categories.isEmpty()) { + for (MetadataFieldWrapper field : fields) { + + MetaDataField fieldWidget; + try { + fieldWidget = new MetaDataField(field, eventBusPublisherWidget, operation); + metadataFieldsPanel.add(fieldWidget); + listOfMetadataFields.add(fieldWidget); + } catch (Exception e) { + GWT.log("Unable to build such widget", e); + } + } + } else { + + // create the categories, then parse the fields. Fields do not belonging to a + // category are put at the end + for (CategoryWrapper categoryWrapper : categories) { + if (categoryWrapper.getFieldsForThisCategory() != null + && categoryWrapper.getFieldsForThisCategory().size() > 0) { + CategoryPanel cp = new CategoryPanel(categoryWrapper.getTitle(), + categoryWrapper.getDescription()); + List fieldsForThisCategory = categoryWrapper + .getFieldsForThisCategory(); + fields.removeAll(fieldsForThisCategory); + + for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) { + + MetaDataField fieldWidget; + try { + fieldWidget = new MetaDataField(metadataFieldWrapper, eventBusPublisherWidget, + operation); + cp.addField(fieldWidget); + listOfMetadataFields.add(fieldWidget); + } catch (Exception e) { + GWT.log("Unable to build such widget", e); + } + } + metadataFieldsPanel.add(cp); + } + } + + // add the remaining one at the end of the categories + CategoryPanel extrasCategory = new CategoryPanel("Other", null); + for (MetadataFieldWrapper field : fields) { + + MetaDataField fieldWidget; + try { + fieldWidget = new MetaDataField(field, eventBusPublisherWidget, operation); + extrasCategory.addField(fieldWidget); + listOfMetadataFields.add(fieldWidget); + } catch (Exception e) { + GWT.log("Unable to build such widget", e); + } + } + metadataFieldsPanel.add(extrasCategory); + } + metadataFieldsPanel.setVisible(true); + } + } + } + + /** + * Adds the custom field event. + * + * @param e the e + */ + @UiHandler("addCustomFieldButton") + void addCustomFieldEvent(ClickEvent e) { + + CustomFieldEntry toAdd = new CustomFieldEntry(eventBusPublisherWidget, "", "", true); + customFieldEntriesList.add(toAdd); + customFields.add(toAdd); + + } + + /** + * On continue button. + * + * @param e the e + */ + @UiHandler("continueButton") + void onContinueButton(ClickEvent e) { + + // validate data + final String errorMsg = validateDataOnContinue(); + + if (errorMsg != null) { + + alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR); + return; + + } else { + + // better check for title (only if the dataset was not created.. if it is the + // case, fields are not frozen) + if (!titleTextBox.isEnabled()) + actionsAfterOnContinue(); + else { + actionsAfterOnContinue(); + } + } + } + + /** + * After onContinue ... + */ + private void actionsAfterOnContinue() { + + // check what to do + if (isWorkspaceRequest) { + + // we need to show the page to handle resources one by one from the workspace + formFirstStep.setVisible(false); + boolean hideManageRes = hideManageResources(); + int stepActive = -1; + if (hideManageRes) { + stepActive = 3; + } else { + stepActive = 2; + } + + formSecondStep.setVisible(!hideManageRes); + formThirdStep.setVisible(hideManageRes); + activeWizardStep(stepActive); + + // add the resources to the container panel + if (workspaceResourcesContainer.getWidget() == null) { + workspaceResourcesContainer.getElement().getStyle().setMarginLeft(20, Unit.PX); + //workspaceResourcesContainer.add(resourcesSelectByWEMainPanel); + } + + } else { + + // this is not a workspace request + formFirstStep.setVisible(false); + formThirdStep.setVisible(true); + activeWizardStep(2); + + } + + if (metadataTypeListbox.getSelectedItemText().equals(NONE_PROFILE)) + selectedProfile.setText(""); + else + selectedProfile.setText("Selected Type is " + metadataTypeListbox.getSelectedItemText()); + + } + + /** + * Active wizard step. + * + * @param step the step + */ + private void activeWizardStep(int step) { + if (wizCreator != null) { + wizCreator.activeStep(step); + } + } + + /** + * On go back button first step. + * + * @param e the e + */ + @UiHandler("goBackButtonFirstStep") + void onGoBackButtonFirstStep(ClickEvent e) { + + // swap forms + formFirstStep.setVisible(true); + activeWizardStep(1); + formSecondStep.setVisible(false); + formThirdStep.setVisible(false); + + } + + /** + * On go back button. + * + * @param e the e + */ + @UiHandler("goBackButtonSecondStep") + void onGoBackButton(ClickEvent e) { + + // swap forms + if (isWorkspaceRequest) { + boolean hideManageRes = hideManageResources(); + int stepActive = -1; + if (hideManageRes) { + stepActive = 1; + } else { + stepActive = 2; + } + formFirstStep.setVisible(hideManageRes); + formSecondStep.setVisible(!hideManageRes); + activeWizardStep(stepActive); + } else { + + formFirstStep.setVisible(true); + formSecondStep.setVisible(false); + activeWizardStep(1); + } + formThirdStep.setVisible(false); + + } + + /** + * On continue third step. + * + * @param e the e + */ + @UiHandler("continueThirdStep") + void onContinueThirdStep(ClickEvent e) { + + // swap forms + formSecondStep.setVisible(false); + formThirdStep.setVisible(true); + activeWizardStep(3); + + } + + /** + * Creates the dataset event. + * + * @param e the e + */ + @UiHandler("updateButton") + void updateDatasetEvent(ClickEvent e) { + + String errorMessage = areProfileDataValid(); + + if (errorMessage != null) { + alertOnUpdated("Please check the inserted values and the mandatory fields [" + errorMessage + "]", false, + AlertType.ERROR, true); + } else { + + String title = titleTextBox.getValue().trim(); + String description = descriptionTextarea.getText().trim(); + String selectedLicense = licenseListbox.getSelectedItemText(); + String visibility = visibilityListbox.getSelectedItemText(); + long version = Long.valueOf(versionTextbox.getValue().trim()); + String author = authorTextbox.getValue(); + String authorEmail = authorEmailTextbox.getValue(); + String maintainer = maintainerTextbox.getValue().trim(); + String maintainerEmail = maintainerEmailTextbox.getValue().trim(); + String chosenOrganizationTitle = organizationsListbox.getSelectedItemText(); + Set tags = new HashSet(tagsPanel.getTags()); + + // we need to retrieve the organization's name from this title + List orgs = theDatasetBean.getOrganizationList(); + String chosenOrganization = null; + for (OrganizationBean organizationBean : orgs) { + if (chosenOrganizationTitle.equals(organizationBean.getTitle())) { + chosenOrganization = organizationBean.getName(); + break; + } + } + + List groups = new ArrayList(); + List groupsToForceCreation = new ArrayList(); + + // get groups, if any + int items = groupsListbox.getItemCount(); + for (int i = 0; i < items; i++) { + String groupTitle = groupsListbox.getItemText(i); + String groupName = groupsListbox.getValue(i); + if (groupsListbox.isItemSelected(i)) { + groups.add(new OrganizationBean(groupTitle, groupName, false)); + } + } + + Map> customFieldsMap = new HashMap>(); + + // prepare custom fields + for (MetaDataField metaField : listOfMetadataFields) { + + for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) { + + List valuesForField = field.getFieldCurrentValue(); + if (!valuesForField.isEmpty()) { + String key = field.getFieldNameQualified(); + List valuesForThisField = null; + if (customFieldsMap.containsKey(key)) + valuesForThisField = customFieldsMap.get(key); + else + valuesForThisField = new ArrayList(); + + valuesForThisField.addAll(valuesForField); + customFieldsMap.put(key, valuesForThisField); + + // get also tag/group if it is the case for this field + List tagsField = field.getTagFromThisField(); + if (tagsField != null) + tags.addAll(tagsField); + + List groupsTitle = field.getGroupTitleFromThisGroup(); + if (groupsTitle != null) { + for (String groupTitle : groupsTitle) { + if (field.isGroupToForce()) + groupsToForceCreation.add( + new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp())); + else + groups.add( + new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp())); + } + } + } + } + } + + for (CustomFieldEntry customEntry : customFieldEntriesList) { + String key = customEntry.getKey(); + String value = customEntry.getValue(); + if (value != null && !value.isEmpty()) { + List valuesForThisField = null; + if (customFieldsMap.containsKey(key)) + valuesForThisField = customFieldsMap.get(key); + else + valuesForThisField = new ArrayList(); + valuesForThisField.add(value); + customFieldsMap.put(key, valuesForThisField); + } + + } + + // fill the bean + theDatasetBean.setAuthorFullName(author); + theDatasetBean.setAuthorEmail(authorEmail); + theDatasetBean.setDescription(description); + theDatasetBean.setLicense(selectedLicense); + theDatasetBean.setMaintainer(maintainer); + theDatasetBean.setMaintainerEmail(maintainerEmail); + theDatasetBean.setVersion(version); + theDatasetBean.setVisibile(visibility.equals("Public")); + theDatasetBean.setTitle(title); + theDatasetBean.setTags(new ArrayList(tags)); + theDatasetBean.setSelectedOrganization(chosenOrganization); + theDatasetBean.setGroups(groups); + theDatasetBean.setGroupsForceCreation(groupsToForceCreation); + +// if (resourcesSelectByWEMainPanel != null) { +// theDatasetBean.setResourceRoot(resourcesSelectByWEMainPanel.getResourcesToPublish()); +// } + + theDatasetBean.setCustomFields(customFieldsMap); + + // alert + alertOnUpdated(TRYING_TO_UPDATE_PRODUCT, true, AlertType.INFO, false); + + // invoke the create method + updateButton.setEnabled(false); + goBackButtonSecondStep.setEnabled(false); + + ckanServices.updateCKANDataset(theDatasetBean, new AsyncCallback() { + + @Override + public void onSuccess(final DatasetBean createdDatasetBean) { + CKanMetadataPublisher.printJs("createCKanDataset returned"); + + GWT.log("Updated the dataset: " + createdDatasetBean); + + if (createdDatasetBean != null) { + + CKanMetadataPublisher.printJs(createdDatasetBean.toString()); + + final String datasetUrl = createdDatasetBean.getSource(); + + alertOnUpdated(PRODUCT_UPDATED_OK, false, AlertType.SUCCESS, false); + + try { + // disable dataset fields + disableDatasetFields(); + } catch (Exception e) { + // TODO: handle exception + } + + // disable reset + resetButton.setEnabled(false); + + // show the go to dataset button + + goToDatasetButtonPanel.setVisible(true); + goToDatasetButton.setVisible(true); + + String title = createdDatasetBean.getTitle(); + String link = "(click here) "; + link += title.length() > 90 ? title.substring(0, 90) + "..." : title; + + goToDatasetButton.setTitle("Go to the item: " + title); + + goToDatasetButton.setText(link); + goToDatasetButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + Window.open(datasetUrl, "_blank", ""); + // Window.Location.assign(datasetUrl); + } + }); + + // set hidden the create button + updateButton.setVisible(false); + + // if we are in the "general case" we need to show a form for adding resources + bindManageResources(createdDatasetBean, datasetUrl, 3); + + eventBusPublisherWidget.fireEvent(new ReloadDatasetPageEvent(createdDatasetBean.getId())); + + } else { + + alertOnUpdated(ERROR_PRODUCT_CREATION, false, AlertType.ERROR, true); + } + + } + + @Override + public void onFailure(Throwable caught) { + alertOnUpdated(ERROR_PRODUCT_CREATION + " Error message is : " + caught.getMessage(), false, + AlertType.ERROR, true); + CKanMetadataPublisher.printJs(caught.toString()); + } + }); + } + } + + private void bindManageResources(final DatasetBean theDatasetBean, final String datasetUrl, int step) { + GWT.log("bindManageResources on dataset: " + theDatasetBean.getCkanName()); + + if (step == 1) { + // addResourcesButtonStep1.clear(); + addResourcesButtonStep1.setVisible(true); + addResourcesButtonStep3.setVisible(false); + addResourcesButtonStep1.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked addResourcesButtonStep1"); + + manageResourcesOnFire(theDatasetBean, datasetUrl); + } + }); + } + + if (step == 3) { + // addResourcesButtonStep3.clear(); + addResourcesButtonStep3.setVisible(true); + addResourcesButtonStep3.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + GWT.log("Clicked addResourcesButtonStep3"); + + manageResourcesOnFire(theDatasetBean, datasetUrl); + + } + }); + } + } + + private void manageResourcesOnFire(final DatasetBean theDatasetBean, String datasetUrl) { + + // remove content of the main panel + createDatasetMainPanel.clear(); + + ManageResources manageResources = new ManageResources(eventBusPublisherWidget, theDatasetBean, datasetUrl); + + // add the new content of the main panel + createDatasetMainPanel.add(manageResources); + + final List resources = theDatasetBean.getCkanResources(); + + if (resources != null && resources.size() > 0) { + GWT.log("Executing are: " + resources); + for (ResourceElementBean reb : theDatasetBean.getCkanResources()) { + manageResources.getEventBus().fireEvent(new AddResourceEvent(reb)); + } + } + } + + /** + * Prepare the info icons of all core metadata info. + */ + private void prepareInfoIcons() { + + // tags + tagsPanel.prepareIcon(popupOpenedIds); + + // licenses + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.LICENSES_INFO_ID_POPUP, + InfoIconsLabels.LICENSES_INFO_TEXT, InfoIconsLabels.LICENSES_INFO_CAPTION, infoIconLicenses, + popoverLicenses, focusPanelLicenses, popupOpenedIds); + + // visibility + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.VISIBILITY_INFO_ID_POPUP, + InfoIconsLabels.VISIBILITY_INFO_TEXT, InfoIconsLabels.VISIBILITY_INFO_CAPTION, infoIconVisibility, + popoverVisibility, focusPanelVisibility, popupOpenedIds); + + // author + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.AUTHOR_INFO_ID_POPUP, + InfoIconsLabels.AUTHOR_INFO_TEXT, InfoIconsLabels.AUTHOR_INFO_CAPTION, infoIconAuthor, popoverAuthor, + focusPanelAuthor, popupOpenedIds); + + // author's email + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.AUTHOR_EMAIL_INFO_ID_POPUP, + InfoIconsLabels.AUTHOR_EMAIL_INFO_TEXT, InfoIconsLabels.AUTHOR_EMAIL_INFO_CAPTION, infoIconAuthorEmail, + popoverAuthorEmail, focusPanelAuthorEmail, popupOpenedIds); + + // maintainer + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.MAINTAINER_INFO_ID_POPUP, + InfoIconsLabels.MAINTAINER_INFO_TEXT, InfoIconsLabels.MAINTAINER_INFO_CAPTION, infoIconMaintainer, + popoverMaintainer, focusPanelMaintainer, popupOpenedIds); + + // maintainer's email + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.MAINTAINER_EMAIL_INFO_ID_POPUP, + InfoIconsLabels.MAINTAINER_EMAIL_INFO_TEXT, InfoIconsLabels.MAINTAINER_EMAIL_INFO_CAPTION, + infoIconMaintainerEmail, popoverMaintainerEmail, focusPanelMaintainerEmail, popupOpenedIds); + + // profiles (or types) + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.PROFILES_INFO_ID_POPUP, + InfoIconsLabels.PROFILES_INFO_TEXT, InfoIconsLabels.PROFILES_INFO_CAPTION, infoIconTypes, popoverTypes, + focusPanelTypes, popupOpenedIds); + + // custom fields + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.CUSTOM_FIELDS_INFO_ID_POPUP, + InfoIconsLabels.CUSTOM_FIELDS_INFO_TEXT, InfoIconsLabels.CUSTOM_FIELDS_INFO_CAPTION, + infoIconCustomFields, popoverCustomFields, focusPanelCustomFields, popupOpenedIds); + + // resources field + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.RESOURCES_INFO_ID_POPUP, + InfoIconsLabels.RESOURCES_INFO_TEXT, InfoIconsLabels.RESOURCES_INFO_CAPTION, infoIconResources, + popoverResources, focusPanelResources, popupOpenedIds); + + // title + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.TITLE_INFO_ID_POPUP, + InfoIconsLabels.TITLE_INFO_TEXT, InfoIconsLabels.TITLE_INFO_CAPTION, infoIconTitle, popoverTitle, + focusPanelTitle, popupOpenedIds); + + // description + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.DESCRIPTION_INFO_ID_POPUP, + InfoIconsLabels.DESCRIPTION_INFO_TEXT, InfoIconsLabels.DESCRIPTION_INFO_CAPTION, infoIconDescription, + popoverDescription, focusPanelDescription, popupOpenedIds); + + // groups + InfoIconsLabels.preparePopupPanelAndPopover(InfoIconsLabels.GROUPS_INFO_ID_POPUP, + InfoIconsLabels.GROUPS_INFO_TEXT, InfoIconsLabels.GROUPS_INFO_CAPTION, infoIconGroups, popoverGroups, + focusPanelGroups, popupOpenedIds); + } + + /** + * Test if profile data are valid. + * + * @return the string + */ + private String areProfileDataValid() { + + for (MetaDataField metaField : listOfMetadataFields) { + + for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) { + + field.removeError(); + + String error = field.isFieldValueValid(); + if (error != null) { + field.showError(); + return field.getFieldNameOriginal() + " is not valid. Suggestion: " + error; + } + } + } + + return null; + } + + /** + * On continue show alert box and enable buttons. + * + * @param text the text + * @param type the type + */ + private void alertOnContinue(String text, AlertType type) { + + onContinueAlertBlock.setText(text); + onContinueAlertBlock.setType(type); + onContinueAlertBlock.setVisible(true); + continueButton.setEnabled(true); + resetButton.setEnabled(true); + + // hide after some seconds + Timer t = new Timer() { + + @Override + public void run() { + + onContinueAlertBlock.setVisible(false); + + } + }; + + t.schedule(4000); + } + + /** + * On continue show alert box and enable buttons. + * + * @param text the text + * @param showSpinner the show spinner + * @param type the type + * @param hideAfterAWhile the hide after A while + */ + private void alertOnUpdated(String text, boolean showSpinner, AlertType type, boolean hideAfterAWhile) { + + onCreateAlertBlock.clear(); + + try { + onCreateAlertBlock.remove(iconSpinner); + } catch (Exception e) { + } + + if (showSpinner) { + onCreateAlertBlock.add(iconSpinner); + } + + onCreateAlertBlock.setText(text); + onCreateAlertBlock.setType(type); + onCreateAlertBlock.setVisible(true); + updateButton.setEnabled(true); + goBackButtonSecondStep.setEnabled(true); + + if (hideAfterAWhile) { + // hide after some seconds + Timer t = new Timer() { + + @Override + public void run() { + + onCreateAlertBlock.setVisible(false); + + } + }; + t.schedule(15000); + } + } + + /** + * Validate data. + * + * @return true on success, false otherwise + */ + private String validateDataOnContinue() { + + // remove errors + productTitleGroup.setType(ControlGroupType.NONE); + maintainerControlGroup.setType(ControlGroupType.NONE); + versionControlGroup.setType(ControlGroupType.NONE); + metadataTypesControlGroup.setType(ControlGroupType.NONE); + organizationsGroup.setType(ControlGroupType.NONE); + tagsPanel.setGroupPanelType(ControlGroupType.NONE); + + String title = titleTextBox.getText().trim(); + if (title.isEmpty()) { + productTitleGroup.setType(ControlGroupType.ERROR); + return "Missing title"; + } + + if (title.length() < 2) { + productTitleGroup.setType(ControlGroupType.ERROR); + return "The field title is too short"; + } + + // better check for the title + // String[] splittedTitle = title.split(" "); + + /* + * No check, see #20828 for (String word : splittedTitle) { String replaced = + * word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, ""); if(!replaced.equals(word)){ + * productTitleGroup.setType(ControlGroupType.ERROR); return + * "Please note not all characters are allowed for the title"; } } + */ + + // email reg expression + String maintainerMail = maintainerEmailTextbox.getText(); + if (!maintainerMail.isEmpty() && !maintainerMail.matches(REGEX_MAIL)) { + maintainerControlGroup.setType(ControlGroupType.ERROR); + return "Not valid maintainer email"; + } + + // check if version is a number + try { + int number = Integer.valueOf(versionTextbox.getText().trim()); + if (number <= 0) + throw new Exception(); + } catch (Exception e) { + versionControlGroup.setType(ControlGroupType.ERROR); + return "Version must be a natural number greater than zero"; + } + + // check if metadata profile is different from none and its mandatory fields + // have been fulfilled + if (checkSelectedMetaDataProfile()) { + metadataTypesControlGroup.setType(ControlGroupType.ERROR); + return "You must select a Type different frome none"; + } + + if (organizationsListbox.getSelectedItemText() == null) { + organizationsGroup.setType(ControlGroupType.ERROR); + return "You must select an organization in which you want to publish"; + } + + // at least one tag.. + if (tagsPanel.getTags().isEmpty()) { + tagsPanel.setGroupPanelType(ControlGroupType.ERROR); + return "Please add at least one meaningful tag for the item"; + } + + return null; + } + + /** + * Checks if a metadata profile has been chosen and its fields have been + * fulfilled. + * + * @return true, if successful + */ + private boolean checkSelectedMetaDataProfile() { + return metadataTypeListbox.getSelectedItemText().equals(NONE_PROFILE) + && metadataTypeListbox.getItemCount() != 1; + } + + /** + * Reset form event. + * + * @param e the e + */ + @UiHandler("resetButton") + void resetFormEvent(ClickEvent e) { + + // reset main fields + titleTextBox.setText(""); + descriptionTextarea.setText(""); + versionTextbox.setText(""); + maintainerTextbox.setText(""); + maintainerEmailTextbox.setText(""); + tagsPanel.removeTags(); + + // unselect all groups + for (int i = 0; i < groupsListbox.getItemCount(); i++) + groupsListbox.setItemSelected(i, false); + + // delete custom fields + for (CustomFieldEntry customField : customFieldEntriesList) { + customField.removeFromParent(); + } + customFieldEntriesList.clear(); + } + + /** + * Disable dataset editable fields once the dataset has been successfully + * created. + */ + protected void disableDatasetFields() { + + titleTextBox.setEnabled(false); + descriptionTextarea.setEnabled(false); + versionTextbox.setEnabled(false); + maintainerTextbox.setEnabled(false); + maintainerEmailTextbox.setEnabled(false); + visibilityListbox.setEnabled(false); + tagsPanel.freeze(); + licenseListbox.setEnabled(false); + organizationsListbox.setEnabled(false); + addCustomFieldButton.setEnabled(false); + metadataTypeListbox.setEnabled(false); + groupsListbox.setEnabled(false); + + for (CustomFieldEntry ce : customFieldEntriesList) + ce.freeze(); + + // disable profile fields + for (MetaDataField metaField : listOfMetadataFields) { + for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) { + field.freeze(true); + } + + } + +// // freeze table of resources +// if (resourcesSelectByWEMainPanel != null) +// resourcesSelectByWEMainPanel.freeze(); + } + + /** + * change alert block behavior. + * + * @param textToShow the text to show + * @param type the type + * @param visible the visible + */ + private void setAlertBlock(String textToShow, LoaderIcon loader, AlertType type, boolean visible) { + + alertPanel.clear(); + + if (loader != null) { + alertPanel.add(loader); + } + infoBlock.setType(type); + infoBlock.setVisible(visible); + + if (textToShow != null) { + alertPanel.add(new HTML(textToShow)); + } + + } + + /** + * On selected license change. + * + * @param c the c + */ + @UiHandler("licenseListbox") + void onSelectedLicenseChange(ChangeEvent c) { + + showLicenseUrl(); + + } + + /** + * The body of the onSelectedLicenseChange. + */ + private void showLicenseUrl() { + + String selectedLicense = licenseListbox.getSelectedItemText(); + int index = -1; + if ((index = licenseBean.indexOf(new LicenseBean(selectedLicense, null))) >= 0) { + LicenseBean foundLicense = licenseBean.get(index); + licenseUrlAnchor.setText(foundLicense.getUrl()); + licenseUrlAnchor.setHref(foundLicense.getUrl()); + licenseUrlAnchor.setVisible(true); + unavailableUrl.setVisible(false); + } else { + licenseUrlAnchor.setVisible(false); + unavailableUrl.setVisible(true); + } + } + + /** + * Hide the groups that are already listed in the profiles page. + * + * @param profiles the profiles + */ + private void hideGroupsAlreadyInProfile(List profiles) { + + List groupsToHide = new ArrayList(); + for (MetaDataProfileBean profile : profiles) + groupsToHide.add(profile.getType()); + + SelectElement se = groupsListbox.getElement().cast(); + + int hiddenElements = 0; + for (int i = 0; i < groupsListbox.getItemCount(); i++) { + if (groupsToHide.contains(groupsListbox.getItemText(i))) { + se.getOptions().getItem(i).getStyle().setProperty("display", "none"); + hiddenElements++; + } + } + + if (hiddenElements == groupsListbox.getItemCount()) + groupsControlGroup.setVisible(false); + else + groupsControlGroup.setVisible(true); + + } + + /** + * Check if resource(s) are missing. + * + * @return true, if successful + */ + private boolean hideManageResources() { + + return theDatasetBean.getResourceRoot() == null || theDatasetBean.getResourceRoot().isFolder() + && (theDatasetBean.getResourceRoot().getChildrenSize() == null + || theDatasetBean.getResourceRoot().getChildrenSize() == 0); + + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.ui.xml new file mode 100644 index 0000000..fad55f6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.ui.xml @@ -0,0 +1,447 @@ + + + + .form-main-style { + margin-left: 10px; + } + + .fieldset-border-style { + border: 1px groove #444 !important; + box-shadow: 0px 0px 0px 0px #000 !important; + padding: 10px !important; + margin: 5px !important; + } + + .legend-style { + width: auto !important; + padding: 10px !important; + margin-bottom: 0 !important; + border-bottom: 0 !important; + } + + @external .form-horizontal .input-large; + .form-horizontal .input-large .input-prepend { + width: 95%; + } + + .block-alert-style { + margin-top: 10px; + padding: 10px; + margin-bottom: 10px; + } + + .tagsPanelStyle { + display: inline-block; + } + + .selected-profile { + font-weight: bold; + } + + .label-go-to-product { + display: inline-block; + vertical-align: middle; + font-weight: bold; + } + + .the-margin-gotoitem { + margin-left: 5px; + margin-top: 10px; + margin-bottom: 10px; + } + + + + + + + + Insert Item Information + + * + is required + + + + + + + + + * + Title : + + + + + + + + + + + + + + + + Description: + + + + + + + + + + + + + + + + + + License: + + + + + + + + + + + + + + + Selected + License Url: + + + Unavailable + + + + + + + Visibility: + + + Restricted + Public + + + + + + + + + + + + + Publish in: + + + + + + + + + Version: + + + + + + + + + * + Author: + + + + + + + + + + + + + + + + * + Author Email: + + + + + + + + + + + + + + + + Maintainer: + + + + + + + + + + + + + + + + Maintainer Email: + + + + + + + + + + + + + + + Types: + + + none + + + + + + + + + + + + + Item Groups: + + + + + + + + + + + + + + + + + + + + + + Continue + Reset + + Manage Resources + + + + + + + + + Select Item Resources + + + + + + + + + + + + + Continue + + Go + Back + + + + + + + + + Insert Item Profile Information + + * + is required + + + + + + + + + + + Custom Field(s): + + + + + + + + + + + + + + + + + + + + + Go to the Item + + + + Update + + Go + Back + + Manage Resources + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.java deleted file mode 100644 index 4e5326b..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form.MetaDataField; - -import com.github.gwtbootstrap.client.ui.PageHeader; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Style.Float; -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.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; - -public class CategoryPanel extends Composite{ - - private static CategoryPanelUiBinder uiBinder = GWT - .create(CategoryPanelUiBinder.class); - - interface CategoryPanelUiBinder extends UiBinder { - } - - @UiField VerticalPanel fieldsPanel; - @UiField PageHeader categoryHeader; - //private List fieldsForThisCategory; - - private List fieldsForThisCategory; - - public CategoryPanel() { - initWidget(uiBinder.createAndBindUi(this)); - } - - /** - * - * @param fieldsForThisCategory - * @param title - * @param description - */ - public CategoryPanel(String title, String description) { - initWidget(uiBinder.createAndBindUi(this)); - title = title == null ? "" : title; - description = description == null ? "" : description; - categoryHeader.setTitle(title); - categoryHeader.setText(title); - categoryHeader.setSubtext(description); - categoryHeader.getElement().getStyle().setFloat(Float.LEFT); - } - - /** - * Add a field to this widget - * @param fieldWidget - */ - /*public void addField(MetaDataFieldSkeleton fieldWidget) { - if(fieldsForThisCategory == null){ - fieldsForThisCategory = new ArrayList(); - fieldWidget.setVisible(true); - fieldsPanel.setVisible(true); - } - fieldsForThisCategory.add(fieldWidget); - fieldsPanel.add(fieldWidget); - }*/ - - - /** - * Add a field to this widget - * @param fieldWidget - */ - public void addField(MetaDataField fieldWidget) { - if(fieldsForThisCategory == null){ - fieldsForThisCategory = new ArrayList(); - fieldWidget.setVisible(true); - fieldsPanel.setVisible(true); - } - fieldsForThisCategory.add(fieldWidget); - fieldsPanel.add(fieldWidget); - } - -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.ui.xml deleted file mode 100644 index 68e9845..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CategoryPanel.ui.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CustomFieldEntry.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CustomFieldEntry.ui.xml index 780c41a..7cae843 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CustomFieldEntry.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/CustomFieldEntry.ui.xml @@ -1,13 +1,17 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> - + - + - + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java deleted file mode 100644 index 3eb43ca..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java +++ /dev/null @@ -1,906 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata; - -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.openlayerwidget.GeoJsonAreaSelectionDialog; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.timeandreanges.DataTimeBox; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsGroup; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsTag; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.TaggingGroupingValue; - -import com.github.gwtbootstrap.client.ui.Alert; -import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.CheckBox; -import com.github.gwtbootstrap.client.ui.ControlGroup; -import com.github.gwtbootstrap.client.ui.ControlLabel; -import com.github.gwtbootstrap.client.ui.Controls; -import com.github.gwtbootstrap.client.ui.Icon; -import com.github.gwtbootstrap.client.ui.ListBox; -import com.github.gwtbootstrap.client.ui.Popover; -import com.github.gwtbootstrap.client.ui.TextArea; -import com.github.gwtbootstrap.client.ui.TextBox; -import com.github.gwtbootstrap.client.ui.constants.AlertType; -import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; -import com.github.gwtbootstrap.client.ui.constants.IconType; -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.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.Window; -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.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.SimplePanel; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; - -public class MetaDataFieldSkeleton extends Composite{ - - private static MetaDataFieldSkeletonUiBinder uiBinder = GWT - .create(MetaDataFieldSkeletonUiBinder.class); - - interface MetaDataFieldSkeletonUiBinder extends - UiBinder { - } - - @UiField Element mandatorySymbol; - @UiField SpanElement name; - @UiField SimplePanel elementPanel; - @UiField FlowPanel noteFieldContainer; - @UiField Popover noteFieldPopover; - @UiField ControlLabel controlLabel; - @UiField Controls controls; - @UiField Icon infoIcon; - @UiField FocusPanel focusPanelIconContainer; - @UiField ControlGroup metafieldControlGroup; - - // private static final String REGEX_IS_NUMBER = "[0-9]+[.]?[0-9]+"; - - // the element that holds the value (it could be a checkbox, textbox or listbox, textarea, calendar, two calendars, more calendars) - private Widget holder; - - // the field this object represents - private MetadataFieldWrapper field; - - // the dialog box for this metadata - private GcubeDialogExtended dialog; - - // range list - private List rangesList = new ArrayList(); - - private List