156 lines
4.7 KiB
Java
156 lines
4.7 KiB
Java
package org.gcube.portlets.user.td.tablewidget.client.history;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener;
|
|
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
|
|
public class HistoryDiscard implements MonitorDialogListener {
|
|
protected TRId trId;
|
|
protected EventBus eventBus;
|
|
|
|
public HistoryDiscard(EventBus eventBus) {
|
|
this.eventBus = eventBus;
|
|
}
|
|
|
|
public void discard() {
|
|
retrieveCurrentTR();
|
|
}
|
|
|
|
protected void retrieveCurrentTR() {
|
|
TDGWTServiceAsync.INSTANCE.getCurrentTRId(new AsyncCallback<TRId>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error Locked",
|
|
caught.getLocalizedMessage());
|
|
} else {
|
|
Log.error("Error retrieving trId: "
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error",
|
|
"Error retrieving current tabular resource id");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void onSuccess(TRId result) {
|
|
Log.debug("retrieved " + result);
|
|
trId = result;
|
|
callDiscard();
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
protected void callDiscard() {
|
|
TDGWTServiceAsync.INSTANCE.startDiscard(trId,
|
|
new AsyncCallback<String>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error Locked",
|
|
caught.getLocalizedMessage());
|
|
} else {
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error Final",
|
|
caught.getLocalizedMessage());
|
|
} else {
|
|
Log.error("Error in discard: "
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error in undo",
|
|
caught.getLocalizedMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void onSuccess(String taskId) {
|
|
Log.debug("Discard Session taskId: " + taskId);
|
|
if (taskId == null) {
|
|
Log.info("Attention: undo not applicable");
|
|
UtilsGXT3.info("Attention", "Undo not applicable");
|
|
} else {
|
|
openMonitorDialog(taskId);
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
protected void close() {
|
|
/*
|
|
* if (parent != null) { parent.close(); }
|
|
*/
|
|
}
|
|
|
|
// /
|
|
protected void openMonitorDialog(String taskId) {
|
|
MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus);
|
|
monitorDialog.addProgressDialogListener(this);
|
|
monitorDialog.show();
|
|
}
|
|
|
|
@Override
|
|
public void operationComplete(TRId trId) {
|
|
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
|
ChangeTableRequestType.ROLLBACK, trId, why);
|
|
eventBus.fireEvent(changeTableRequestEvent);
|
|
close();
|
|
}
|
|
|
|
@Override
|
|
public void operationFailed(Throwable caught, String reason, String details) {
|
|
UtilsGXT3.alert(reason, details);
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationStopped(TRId trId, String reason, String details) {
|
|
ChangeTableWhy why = ChangeTableWhy.TABLECURATION;
|
|
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
|
ChangeTableRequestType.ROLLBACK, trId, why);
|
|
eventBus.fireEvent(changeTableRequestEvent);
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationAborted() {
|
|
close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void operationPutInBackground() {
|
|
close();
|
|
|
|
}
|
|
|
|
}
|