122 lines
3.4 KiB
Java
122 lines
3.4 KiB
Java
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
|
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.BasicTabPanel;
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.Ckan2ZenodoViewManager;
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.LoaderIcon;
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.Label;
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
|
import com.github.gwtbootstrap.client.ui.ModalFooter;
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
import com.github.gwtbootstrap.client.ui.constants.LabelType;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
/**
|
|
* The Class CkanToZendoPublisherWidget.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
*
|
|
* Dec 9, 2019
|
|
*/
|
|
public class CkanToZendoPublisherWidget {
|
|
|
|
private final CkanToZenodoPublisherServiceAsync ckanToZenodoService = CkanToZenodoPublisherServiceAsync.Util
|
|
.getInstance();
|
|
|
|
private Button buttonPublish = new Button("Publish on Zenodo");
|
|
/**
|
|
* Instantiates a new ckan to zendo publisher widget.
|
|
*/
|
|
public CkanToZendoPublisherWidget() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Publish on zenodo.
|
|
*
|
|
* @param item the item
|
|
*/
|
|
public void publishOnZenodo(final CatalogueItem item) {
|
|
|
|
final Modal modal = new Modal(true);
|
|
modal.setTitle("Publishing on Zenodo...");
|
|
modal.addStyleName("ckan2zenodo-modal-style");
|
|
modal.setCloseVisible(true);
|
|
buttonPublish.setEnabled(false);
|
|
final LoaderIcon loader = new LoaderIcon("Loading data from service...");
|
|
modal.add(loader);
|
|
ckanToZenodoService.convertToZenodoItem(item, new AsyncCallback<ZenodoItem>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
loader.setVisible(false);
|
|
modal.remove(loader);
|
|
Alert erroLabel = new Alert();
|
|
erroLabel.setClose(false);
|
|
erroLabel.setType(AlertType.ERROR);
|
|
erroLabel.setText(caught.getLocalizedMessage());
|
|
modal.add(erroLabel);
|
|
Button close = new Button("Close");
|
|
close.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
modal.hide();
|
|
}
|
|
});
|
|
modal.add(close);
|
|
//Window.alert(caught.getMessage());
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ZenodoItem result) {
|
|
loader.setVisible(false);
|
|
modal.remove(loader);
|
|
Ckan2ZenodoViewManager manager = new Ckan2ZenodoViewManager();
|
|
BasicTabPanel basicTabPanel = manager.viewForPublishing(result);
|
|
modal.add(basicTabPanel);
|
|
buttonPublish.setEnabled(true);
|
|
}
|
|
});
|
|
|
|
buttonPublish.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
}
|
|
});
|
|
|
|
ModalFooter modalFooter = new ModalFooter(buttonPublish);
|
|
modal.add(modalFooter);
|
|
modal.show();
|
|
}
|
|
|
|
/**
|
|
* To zenodo item.
|
|
*
|
|
* @param item the item
|
|
*/
|
|
private void toZenodoItem(CatalogueItem item) {
|
|
|
|
ckanToZenodoService.convertToZenodoItem(item, new AsyncCallback<ZenodoItem>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ZenodoItem result) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|