Added Manage Resources

This commit is contained in:
Francesco Mangiacrapa 2024-02-13 12:45:48 +01:00
parent ee7ea99740
commit 0417f98149
8 changed files with 262 additions and 246 deletions

View File

@ -19,7 +19,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCu
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
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.AddedResourcesSummary;
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;
@ -29,7 +29,6 @@ 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.resources.AddResourceContainer;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper;
@ -44,7 +43,6 @@ 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;
@ -52,7 +50,6 @@ 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;
@ -288,9 +285,6 @@ public class CreateDatasetForm extends Composite {
// dataset metadata bean
private DatasetBean receivedBean;
// the owner
private String owner;
// workspace request?
private boolean isWorkspaceRequest = false;
@ -862,13 +856,7 @@ 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, operation);
@ -893,13 +881,6 @@ 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, operation);
@ -917,13 +898,6 @@ 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, operation);
@ -1278,38 +1252,8 @@ public class CreateDatasetForm extends Composite {
// remove content of the main panel
createDatasetMainPanel.clear();
// TabPanelException
tabPanel = new TabPanel(Tabs.LEFT);
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);
// form container
AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel);
// add the new content of the main panel
createDatasetMainPanel.add(container);
// add tabs to resources panel
tabPanel.selectTab(0);
ManageResources manageResources = new ManageResources(eventBus, createdDatasetBean, datasetUrl);
createDatasetMainPanel.add(manageResources);
}
});
} catch (Exception e2) {

View File

@ -20,7 +20,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCu
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
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.AddedResourcesSummary;
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;
@ -32,7 +32,6 @@ 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.resources.AddResourceContainer;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper;
@ -45,17 +44,15 @@ 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.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.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@ -286,7 +283,7 @@ public class UpdateDatasetForm extends Composite {
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 TabPanel tabPanel;
private NavPills tabPanel;
// add resource form
private AddResourceToDataset resourceForm;
@ -304,16 +301,7 @@ public class UpdateDatasetForm extends Composite {
private List<MetaDataField> listOfMetadataFields = new ArrayList<MetaDataField>();
// dataset metadata bean
private DatasetBean receivedBean;
// the owner
private String owner;
// workspace request?
// private boolean isWorkspaceRequest = false;
// resource table
// private TwinColumnSelectionMainPanel resourcesTwinPanel;
private DatasetBean theDatasetBean;
// resource table
private SelectResourceByWEMainPanel resourcesSelectByWEMainPanel;
@ -328,7 +316,7 @@ public class UpdateDatasetForm extends Composite {
private boolean isWorkspaceRequest = false;
private String datasetIdOrName = null;
private DatasetBean theDataset = null;
// private DatasetBean theDataset = null;
/**
* Instantiates a new update dataset form.
@ -423,15 +411,12 @@ public class UpdateDatasetForm extends Composite {
@Override
public void onSuccess(final DatasetBean datasetBean) {
GWT.log("getDatasetBeanForUpdate returns: " + datasetBean);
theDataset = datasetBean;
if (datasetBean == null) {
setAlertBlock("Error while retrieving information.", AlertType.ERROR, true);
} else {
// save it
receivedBean = datasetBean;
theDatasetBean = datasetBean;
// fill the form
titleTextBox.setText(datasetBean.getTitle());
@ -489,19 +474,6 @@ public class UpdateDatasetForm extends Composite {
// set it as visible anyway
tagsPanel.setVisible(true);
// if (isWorkspaceRequest) {
// // if there are not resources, for now just checked it ( and hide so that the
// // step will be skipped)
// if (hideManageResources()) {
// alertNoResources.setType(AlertType.WARNING);
// alertNoResources.setVisible(true);
// } else
// // resourcesSelectByWEMainPanel = new
// // TwinColumnSelectionMainPanel(bean.getResourceRoot());
// resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(
// bean.getResourceRoot());
// }
// The resource root is the folder id. Es. ID of the Workspace Root folder.
if (datasetBean.getResourceRoot() != null) {
resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(
@ -532,38 +504,16 @@ public class UpdateDatasetForm extends Composite {
// get the name of the organization from the title
final String orgName = nameTitleOrganizationMap
.get(organizationsListbox.getSelectedItemText());
//Putting the selected Organization into bena
theDataset.setSelectedOrganization(orgName);
// force tags
// setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true);
// ckanServices.getTagsForOrganization(orgName, new AsyncCallback<List<String>>() {
//
// @Override
// public void onSuccess(List<String> vocabulary) {
//
// tagsPanel.setVocabulary(vocabulary);
// tagsPanel.setVisible(true);
// }
//
// @Override
// public void onFailure(Throwable arg0) {
//
// setAlertBlock(
// "Error while checking if a vocabulary of tags is defined in the selected organization.",
// AlertType.ERROR, true);
// tagsPanel.setVisible(true);
//
// }
// });
// Putting the selected Organization into bena
theDatasetBean.setSelectedOrganization(orgName);
// try to retrieve the profiles
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
// perform remote request of profiles for the selected organization
ckanServices.getProfileForUpdate(orgName, datasetBean.getChosenType(), datasetBean.getId(),
new AsyncCallback<MetadataProfileBeanForUpdate>() {
ckanServices.getProfileForUpdate(orgName, datasetBean.getChosenType(),
datasetBean.getId(), new AsyncCallback<MetadataProfileBeanForUpdate>() {
@Override
public void onFailure(Throwable caught) {
@ -592,8 +542,8 @@ public class UpdateDatasetForm extends Composite {
}
}
receivedBean.setMetadataList(profiles);
prepareMetadataList(receivedBean, operation);
theDatasetBean.setMetadataList(profiles);
prepareMetadataList(theDatasetBean, operation);
addCustomField(metadataProfileForUpdate.getCustomFields());
organizationsListbox.setEnabled(true);
metadataTypeListbox.setEnabled(true);
@ -659,10 +609,11 @@ public class UpdateDatasetForm extends Composite {
false);
continueButton.setEnabled(true);
resetButton.setEnabled(true);
addResourcesButtonStep1.setEnabled(true);
addResourcesButtonStep1
.setEnabled(true);
manageAddResources(datasetBean,
datasetIdOrName);
bindManageResources(datasetBean,
datasetIdOrName, 1);
}
}
@ -744,8 +695,8 @@ public class UpdateDatasetForm extends Composite {
// get the name of the organization from the title
String selectedOrganizationTitle = organizationsListbox.getSelectedItemText();
final String orgName = nameTitleOrganizationMap.get(selectedOrganizationTitle);
theDataset.setSelectedOrganization(orgName);
theDatasetBean.setSelectedOrganization(orgName);
// try to retrieve the profiles
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
@ -766,8 +717,8 @@ public class UpdateDatasetForm extends Composite {
if (profiles != null) {
receivedBean.setMetadataList(profiles);
prepareMetadataList(receivedBean, operation);
theDatasetBean.setMetadataList(profiles);
prepareMetadataList(theDatasetBean, operation);
organizationsListbox.setEnabled(true);
metadataTypeListbox.setEnabled(true);
@ -847,8 +798,8 @@ public class UpdateDatasetForm extends Composite {
/**
* Add the items to the listbox and put data into the metadataPanel.
*
* @param receivedBean the received bean
* @param operation the operation
* @param theDatasetBean the received bean
* @param operation the operation
*/
private void prepareMetadataList(final DatasetBean receivedBean, OPERATION operation) {
@ -929,7 +880,7 @@ public class UpdateDatasetForm extends Composite {
*/
protected void addFields(String selectedItem, OPERATION operation) {
for (MetaDataProfileBean bean : receivedBean.getMetadataList()) {
for (MetaDataProfileBean bean : theDatasetBean.getMetadataList()) {
if (bean.getType().equals(selectedItem)) {
// clear old data
@ -1207,7 +1158,7 @@ public class UpdateDatasetForm extends Composite {
Set<String> tags = new HashSet<String>(tagsPanel.getTags());
// we need to retrieve the organization's name from this title
List<OrganizationBean> orgs = receivedBean.getOrganizationList();
List<OrganizationBean> orgs = theDatasetBean.getOrganizationList();
String chosenOrganization = null;
for (OrganizationBean organizationBean : orgs) {
if (chosenOrganizationTitle.equals(organizationBean.getTitle())) {
@ -1284,25 +1235,25 @@ public class UpdateDatasetForm extends Composite {
}
// fill the bean
receivedBean.setAuthorFullName(author);
receivedBean.setAuthorEmail(authorEmail);
receivedBean.setDescription(description);
receivedBean.setLicense(selectedLicense);
receivedBean.setMaintainer(maintainer);
receivedBean.setMaintainerEmail(maintainerEmail);
receivedBean.setVersion(version);
receivedBean.setVisibile(visibility.equals("Public"));
receivedBean.setTitle(title);
receivedBean.setTags(new ArrayList<String>(tags));
receivedBean.setSelectedOrganization(chosenOrganization);
receivedBean.setGroups(groups);
receivedBean.setGroupsForceCreation(groupsToForceCreation);
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<String>(tags));
theDatasetBean.setSelectedOrganization(chosenOrganization);
theDatasetBean.setGroups(groups);
theDatasetBean.setGroupsForceCreation(groupsToForceCreation);
if (resourcesSelectByWEMainPanel != null) {
receivedBean.setResourceRoot(resourcesSelectByWEMainPanel.getResourcesToPublish());
theDatasetBean.setResourceRoot(resourcesSelectByWEMainPanel.getResourcesToPublish());
}
receivedBean.setCustomFields(customFieldsMap);
theDatasetBean.setCustomFields(customFieldsMap);
// alert
alertOnCreate(TRYING_TO_UPDATE_PRODUCT, true, AlertType.INFO, false);
@ -1311,7 +1262,7 @@ public class UpdateDatasetForm extends Composite {
updateButton.setEnabled(false);
goBackButtonSecondStep.setEnabled(false);
ckanServices.updateCKANDataset(receivedBean, new AsyncCallback<DatasetBean>() {
ckanServices.updateCKANDataset(theDatasetBean, new AsyncCallback<DatasetBean>() {
@Override
public void onSuccess(final DatasetBean createdDatasetBean) {
@ -1362,7 +1313,7 @@ public class UpdateDatasetForm extends Composite {
updateButton.setVisible(false);
// if we are in the "general case" we need to show a form for adding resources
manageAddResources(createdDatasetBean, datasetUrl);
bindManageResources(createdDatasetBean, datasetUrl, 3);
} else {
@ -1381,100 +1332,63 @@ public class UpdateDatasetForm extends Composite {
}
}
private void manageAddResources(final DatasetBean theDatasetBean, final String datasetUrl) {
private void bindManageResources(final DatasetBean theDatasetBean, final String datasetUrl, int step) {
GWT.log("bindManageResources on dataset: " + theDatasetBean.getCkanName());
// if we are in the "general case" we need to show a form for adding resources
if (!isWorkspaceRequest) {
if (step == 1) {
//addResourcesButtonStep1.clear();
addResourcesButtonStep1.setVisible(true);
addResourcesButtonStep1.addClickHandler(new ClickHandler() {
try {
// show the add resources button
addResourcesButtonStep1.setVisible(true);
addResourcesButtonStep3.setVisible(true);
@Override
public void onClick(ClickEvent event) {
GWT.log("Clicked addResourcesButtonStep1");
final AddedResourcesSummary addedResourcesSummary = initTabManageResourcePanel(theDatasetBean,
datasetUrl);
final List<ResourceElementBean> resources = theDatasetBean.getCkanResources();
GWT.log("Resources are: " + resources);
if (resources != null && resources.size() > 0) {
GWT.log("Executing are: " + resources);
for (ResourceElementBean reb : theDatasetBean.getCkanResources()) {
addedResourcesSummary.getEventBus().fireEvent(new AddResourceEvent(reb));
}
manageResourcesOnFire(theDatasetBean, datasetUrl);
}
addResourcesButtonStep1.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
manageResourcesOnFire(datasetUrl);
}
});
addResourcesButtonStep3.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
manageResourcesOnFire(datasetUrl);
}
});
} catch (Exception e2) {
// silent
}
});
}
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(String datasetUrl) {
private void manageResourcesOnFire(final DatasetBean theDatasetBean, String datasetUrl) {
// remove content of the main panel
createDatasetMainPanel.clear();
ManageResources manageResources = new ManageResources(eventBus, theDatasetBean, datasetUrl);
// form container
AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel);
// AddResourceContainer container = new AddResourceContainer(datasetUrl);
// container.add(tabPanel);
// add the new content of the main panel
createDatasetMainPanel.add(container);
createDatasetMainPanel.add(manageResources);
tabPanel.selectTab(0);
}
final List<ResourceElementBean> resources = theDatasetBean.getCkanResources();
private AddedResourcesSummary initTabManageResourcePanel(final DatasetBean theDatasetBean, String datasetUrl) {
// TabPanelException
if (resources != null && resources.size() > 0) {
GWT.log("Executing are: " + resources);
for (ResourceElementBean reb : theDatasetBean.getCkanResources()) {
manageResources.getEventBus().fireEvent(new AddResourceEvent(reb));
}
}
if (tabPanel != null)
tabPanel.clear();
tabPanel = new TabPanel(Tabs.LEFT);
tabPanel.setWidth("100%");
// add the form
resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(), theDatasetBean.getTitle(),
theDatasetBean.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();
AddedResourcesSummary addedResourcesSummary = new AddedResourcesSummary(eventBus);
addedResources.add(addedResourcesSummary);
addedResources.setHeading("Added Resource");
tabPanel.add(addedResources);
return addedResourcesSummary;
// ((NavLink) tabPanel.getWidget(1)).setActive(true);
}
/**
@ -1868,9 +1782,9 @@ public class UpdateDatasetForm extends Composite {
*/
private boolean hideManageResources() {
return receivedBean.getResourceRoot() == null || receivedBean.getResourceRoot().isFolder()
&& (receivedBean.getResourceRoot().getChildrenSize() == null
|| receivedBean.getResourceRoot().getChildrenSize() == 0);
return theDatasetBean.getResourceRoot() == null || theDatasetBean.getResourceRoot().isFolder()
&& (theDatasetBean.getResourceRoot().getChildrenSize() == null
|| theDatasetBean.getResourceRoot().getChildrenSize() == 0);
}
}

View File

@ -61,7 +61,7 @@ public class AddResourceToDataset extends Composite{
@UiField ControlGroup nameControlGroup;
@UiField FlowPanel infoPanel;
public AddResourceToDataset(HandlerManager eventBus, final String datasetId, String datasetTitle, final String datasetOrg, String owner, final String datasetUrl) {
public AddResourceToDataset(HandlerManager eventBus, final String datasetId, String datasetTitle, final String datasetOrg, final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this));
// save bus
this.eventBus = eventBus;

View File

@ -17,7 +17,10 @@ import com.github.gwtbootstrap.client.ui.AccordionGroup;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Paragraph;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.IconPosition;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@ -32,14 +35,23 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* A summary of the resources added by the user.
* The Class AddedResourcesSummary.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* Feb 13, 2024
*/
public class AddedResourcesSummary extends Composite {
private static AddedResourcesSummaryUiBinder uiBinder = GWT.create(AddedResourcesSummaryUiBinder.class);
/**
* The Interface AddedResourcesSummaryUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 13, 2024
*/
interface AddedResourcesSummaryUiBinder extends UiBinder<Widget, AddedResourcesSummary> {
}
@ -47,26 +59,44 @@ public class AddedResourcesSummary extends Composite {
private HandlerManager eventBus;
// list of added resources (beans)
List<ResourceElementBean> addedResources;
private List<ResourceElementBean> addedResources;
LinkedHashMap<Integer, Accordion> mapAddedResources = new LinkedHashMap<Integer, Accordion>();
private LinkedHashMap<Integer, Accordion> mapAddedResources = new LinkedHashMap<Integer, Accordion>();
@UiField
VerticalPanel addResourcesPanel;
@UiField
Alert alertMessage;
FlowPanel alertPanel = new FlowPanel();
public AddedResourcesSummary(HandlerManager eventBus) {
@UiField
Alert alertNoResource;
private FlowPanel alertPanel = new FlowPanel();
private Tab tabAddedResources;
private IconType addedResourcesIcons;
/**
* Instantiates a new added resources summary.
*
* @param eventBus the event bus
*/
public AddedResourcesSummary(HandlerManager eventBus, Tab tabAddedResources, IconType addedResourcesIcons) {
initWidget(uiBinder.createAndBindUi(this));
this.tabAddedResources = tabAddedResources;
this.addedResourcesIcons = addedResourcesIcons;
this.eventBus = eventBus;
alertMessage.setType(AlertType.ERROR);
alertMessage.setClose(true);
alertMessage.add(alertPanel);
// save bus
this.eventBus = eventBus;
alertNoResource.setType(AlertType.WARNING);
alertNoResource.setClose(false);
alertNoResource.setText("No Resources");
checkNoResources();
// bind on add resource event
bind();
// init list
@ -74,7 +104,7 @@ public class AddedResourcesSummary extends Composite {
}
/**
* Bind on add/delete resource event
* Bind on add/delete resource event.
*/
private void bind() {
@ -84,6 +114,8 @@ public class AddedResourcesSummary extends Composite {
@Override
public void onAddedResource(AddResourceEvent addResourceEvent) {
GWT.log("Added resource event: " + addResourceEvent);
tabAddedResources.setIcon(addedResourcesIcons);
tabAddedResources.setIconPosition(IconPosition.RIGHT);
// get the resource
final ResourceElementBean justAddedResource = addResourceEvent.getResource();
@ -92,7 +124,7 @@ public class AddedResourcesSummary extends Composite {
final Accordion accordion = new Accordion();
AccordionGroup accordionGroup = new AccordionGroup();
accordionGroup.setHeading("* " + justAddedResource.getName());
accordionGroup.getHeading().getElement().getStyle().setBackgroundColor("#f1f3f9");
accordionGroup.getHeading().addStyleName("accordion-resource-added");
accordion.add(accordionGroup);
// add sub-info such as url and description
@ -130,6 +162,7 @@ public class AddedResourcesSummary extends Composite {
addResourcesPanel.add(accordion);
mapAddedResources.put(justAddedResource.getBeanID(), accordion);
checkNoResources();
}
});
@ -166,16 +199,16 @@ public class AddedResourcesSummary extends Composite {
@Override
public void onSuccess(Boolean result) {
if (result) {
setAlertMessage(null, "The resource described by " + toDelete.getName()
+ " has been deleted!", AlertType.SUCCESS, true);
setAlertMessage(null, "The resource described by '" + toDelete.getName()
+ "' has been deleted!", AlertType.SUCCESS, true);
// remove from the list
addedResources.remove(toDelete);
addResourcesPanel.remove(toDeleteAccordion);
checkNoResources();
} else {
setAlertMessage(null, "Sorry, the resource described by "
+ toDelete.getName() + " cannot be deleted", AlertType.SUCCESS,
setAlertMessage(null, "Sorry, the resource described by '"
+ toDelete.getName() + "' cannot be deleted", AlertType.SUCCESS,
true);
}
}
@ -184,6 +217,7 @@ public class AddedResourcesSummary extends Composite {
public void onFailure(Throwable caught) {
toDeleteButton.setEnabled(false);
setAlertMessage(null, caught.getMessage(), AlertType.ERROR, true);
checkNoResources();
}
});
@ -194,6 +228,23 @@ public class AddedResourcesSummary extends Composite {
});
}
private void checkNoResources() {
if (addedResources != null && addedResources.size() > 0) {
alertNoResource.setVisible(false);
} else {
alertNoResource.setVisible(true);
}
}
/**
* Sets the alert message.
*
* @param loader the loader
* @param message the message
* @param type the type
* @param visible the visible
*/
private void setAlertMessage(LoaderIcon loader, String message, AlertType type, boolean visible) {
alertPanel.clear();
@ -209,6 +260,11 @@ public class AddedResourcesSummary extends Composite {
}
}
/**
* Gets the event bus.
*
* @return the event bus
*/
public HandlerManager getEventBus() {
return eventBus;
}

View File

@ -7,6 +7,7 @@
<g:VerticalPanel ui:field="addResourcesPanel"
width="100%">
<b:Alert visible="false" ui:field="alertMessage"></b:Alert>
<b:Alert visible="false" ui:field="alertNoResource"></b:Alert>
</g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,78 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs;
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.Widget;
public class ManageResources extends Composite {
private static ManageResourcesUiBinder uiBinder = GWT.create(ManageResourcesUiBinder.class);
interface ManageResourcesUiBinder extends UiBinder<Widget, ManageResources> {
}
@UiField
Tab addResources;
@UiField
Tab addedResources;
@UiField
TabPanel tabPanel;
private AddedResourcesSummary addedResourcesSummary;
private AddResourceToDataset resourceForm;
private HandlerManager eventBus;
private IconType addedResourcesIcon = IconType.CIRCLE;
public ManageResources(HandlerManager eventBus, final DatasetBean theDatasetBean, String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(), theDatasetBean.getTitle(),
theDatasetBean.getSelectedOrganization(), datasetUrl);
addedResourcesSummary = new AddedResourcesSummary(eventBus, addedResources, addedResourcesIcon);
// tab for the form
addResources.add(resourceForm);
addedResources.add(addedResourcesSummary);
tabPanel.setTabPosition(Tabs.LEFT.name());
tabPanel.selectTab(0);
bind();
}
private void bind() {
addedResources.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addedResources.setIcon(null);
//addedResources.removeStyle(addedResourcesIcon);
}
});
}
public HandlerManager getEventBus() {
return eventBus;
}
}

View File

@ -0,0 +1,16 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<b:TabPanel ui:field="tabPanel">
<b:Tab ui:field="addResources" heading="Add Resource"></b:Tab>
<b:Tab ui:field="addedResources" heading="Added Resources"></b:Tab>
</b:TabPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -133,3 +133,10 @@
.wizard-creator .current:after {
border-left-color: #007ACC;
}
.accordion-resource-added {
background-color: #f1f3f9;
padding: 2px;
box-shadow: 3px 3px #888;
border-radius: 3px;
}