130 lines
3.5 KiB
Java
130 lines
3.5 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.dataminermanager.client.widgets;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.DataMinerManager;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.ResourceItem;
|
|
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.save.WorkspaceExplorerSaveDialog;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
|
|
|
import com.google.gwt.user.client.Timer;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.sencha.gxt.core.client.dom.XDOM;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi
|
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class ResourcesExporter {
|
|
|
|
|
|
public static void exportResource(final ResourceItem resourceItem) {
|
|
final String fName = resourceItem.getName()
|
|
+ (resourceItem.isTable() ? ".csv" : "");
|
|
//
|
|
List<ItemType> selectableTypes = new ArrayList<ItemType>();
|
|
selectableTypes.add(ItemType.FOLDER);
|
|
List<ItemType> showableTypes = new ArrayList<ItemType>();
|
|
showableTypes.addAll(Arrays.asList(ItemType.values()));
|
|
|
|
final WorkspaceExplorerSaveDialog wsaveDialog = new WorkspaceExplorerSaveDialog(
|
|
"Select the location to save the resource", fName,
|
|
showableTypes);
|
|
|
|
WorskpaceExplorerSaveNotificationListener handler = new WorskpaceExplorerSaveNotificationListener() {
|
|
|
|
@Override
|
|
public void onSaving(Item destinationFolder, String fileName) {
|
|
Timer timer = new Timer() {
|
|
|
|
@Override
|
|
public void run() {
|
|
if (wsaveDialog != null) {
|
|
wsaveDialog.hide();
|
|
}
|
|
|
|
}
|
|
};
|
|
timer.schedule(500);
|
|
|
|
DataMinerManager.getService().exportResource(
|
|
destinationFolder.getId(), fileName, resourceItem,
|
|
new AsyncCallback<String>() {
|
|
@Override
|
|
public void onSuccess(String result) {
|
|
// EventBusProvider.getInstance().fireEvent(
|
|
// new MaskEvent(null));
|
|
UtilsGXT3
|
|
.info("File saved",
|
|
"The file \""
|
|
+ result
|
|
+ "\" has been exported in the workspace.");
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// EventBusProvider.getInstance().fireEvent(
|
|
// new MaskEvent(null));
|
|
UtilsGXT3.alert(
|
|
"Error",
|
|
"Impossible to export the file into the Workspace<br/>Cause: "
|
|
+ caught.getCause()
|
|
+ "<br/>Message: "
|
|
+ caught.getMessage());
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(Throwable throwable) {
|
|
throwable.printStackTrace();
|
|
Timer timer = new Timer() {
|
|
@Override
|
|
public void run() {
|
|
if (wsaveDialog != null) {
|
|
wsaveDialog.hide();
|
|
}
|
|
}
|
|
};
|
|
timer.schedule(500);
|
|
UtilsGXT3.alert("Error",
|
|
"Impossible select destination into the Workspace<br/>Cause: "
|
|
+ throwable.getCause() + "<br/>Message: "
|
|
+ throwable.getMessage());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAborted() {
|
|
Timer timer = new Timer() {
|
|
@Override
|
|
public void run() {
|
|
if (wsaveDialog != null) {
|
|
wsaveDialog.hide();
|
|
}
|
|
}
|
|
};
|
|
timer.schedule(500);
|
|
}
|
|
};
|
|
|
|
wsaveDialog.addWorkspaceExplorerSaveNotificationListener(handler);
|
|
wsaveDialog.setZIndex(XDOM.getTopZIndex());
|
|
wsaveDialog.show();
|
|
|
|
}
|
|
|
|
}
|