This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
vmereports-manager-portlet/src/main/java/org/gcube/portlets/user/reportgenerator/client/uibinder/ExportOptions.java

85 lines
2.4 KiB
Java

package org.gcube.portlets.user.reportgenerator.client.uibinder;
import org.gcube.portlets.user.exporter.shared.TypeExporter;
import org.gcube.portlets.user.reportgenerator.client.ReportServiceAsync;
import org.gcube.portlets.user.reportgenerator.client.ToolboxPanel;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
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.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
public class ExportOptions extends Composite {
private static ExportOptionsUiBinder uiBinder = GWT
.create(ExportOptionsUiBinder.class);
interface ExportOptionsUiBinder extends UiBinder<Widget, ExportOptions> {
}
enum ExportMode {SAVE_OPEN, SAVE, SAVE_AS }
ToolboxPanel tbp;
@UiField HTML saveOpen;
@UiField HTML save;
@UiField HTML saveAs;
private String filePath;
private String itemName;
private String workspaceFolderId;
private TypeExporter type;
private ReportServiceAsync rpc;
private Presenter p;
public ExportOptions(Presenter p, ToolboxPanel tbp, final String filePath, final String itemName, final TypeExporter type, ReportServiceAsync rpc) {
initWidget(uiBinder.createAndBindUi(this));
this.tbp = tbp;
this.filePath = filePath;
this.itemName = itemName;
this.type= type;
this.rpc = rpc;
this.p = p;
workspaceFolderId = null;
}
@UiHandler("saveOpen")
void onSaveOpenClick(ClickEvent e) {
GWT.log("SaveOPen");
doCallBack(ExportMode.SAVE_OPEN);
}
@UiHandler("save")
void onSaveClick(ClickEvent e) {
doCallBack(ExportMode.SAVE);
}
@UiHandler("saveAs")
void onSaveAs(ClickEvent e) {
doCallBack(ExportMode.SAVE_AS);
}
private void doCallBack(ExportMode mode) {
rpc.save(filePath, workspaceFolderId, itemName, type, true, new AsyncCallback<String>() {
@Override
public void onSuccess(String createdItemId) {
p.clearExportPanel();
tbp.showExportedVersion(createdItemId, itemName);
Window.alert("Success ");
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Error: " + caught.getMessage());
}
});
}
}