Minor Update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-monitor-widget@99199 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c5c7ddcad0
commit
7d8a0f7142
|
@ -0,0 +1,94 @@
|
|||
package org.gcube.portlets.user.td.monitorwidget.client;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.sencha.gxt.widget.core.client.ProgressBar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ProgressBarUpdater implements ProgressListener {
|
||||
|
||||
protected ProgressBar progressBar;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ProgressBar} updater.
|
||||
* @param progressBar the {@link ProgressBar} to update.
|
||||
*/
|
||||
public ProgressBarUpdater(ProgressBar progressBar) {
|
||||
this.progressBar = progressBar;
|
||||
this.progressBar.updateProgress(0, "Please Wait...");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void operationComplete(TRId trId) {
|
||||
Log.info("Completed");
|
||||
progressBar.updateProgress(1, "Completed");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void operationFailed(Throwable caught, String reason, String failureDetails) {
|
||||
Log.info("Failed");
|
||||
progressBar.updateText("Failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationInitializing() {
|
||||
Log.info("Inizializing");
|
||||
progressBar.updateProgress(0, "Initializing...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationUpdate(float elaborated) {
|
||||
Log.info("Elaborated: "+elaborated);
|
||||
if (elaborated>=0 && elaborated<1) {
|
||||
Log.trace("progress "+elaborated);
|
||||
int elab=new Float(elaborated*100).intValue();
|
||||
progressBar.updateProgress(elaborated,elab+"% Progress...");
|
||||
}
|
||||
if (elaborated == 1) progressBar.updateProgress(1, "Completing...");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationValidate(float elaborated) {
|
||||
Log.info("Validation Elaborated: "+elaborated);
|
||||
if (elaborated == 0) progressBar.updateProgress(0, "Start Validation...");
|
||||
if (elaborated>0 && elaborated<1) {
|
||||
Log.trace("Validation progress "+elaborated);
|
||||
int elab=new Float(elaborated*100).intValue();
|
||||
progressBar.updateProgress(elaborated,elab+"% Validation Progress...");
|
||||
}
|
||||
if (elaborated == 1) progressBar.updateProgress(1, "Validation...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationStopped(TRId trId,String reason, String details) {
|
||||
Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]");
|
||||
progressBar.updateText("Validations failed");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationGeneratingView() {
|
||||
Log.info("Generating View...");
|
||||
progressBar.updateText("Generating View...");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package org.gcube.portlets.user.td.monitorwidget.client;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
||||
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.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.widget.core.client.FramedPanel;
|
||||
import com.sencha.gxt.widget.core.client.ProgressBar;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.button.TextButton;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
* AddColumnProgressDialog is a Dialog that show progress of AddColumn
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ProgressDialog extends Window implements
|
||||
ProgressListener {
|
||||
protected ArrayList<ProgressDialogListener> listeners = new ArrayList<ProgressDialogListener>();
|
||||
|
||||
public static final int STATUS_POLLING_DELAY = 1000;
|
||||
protected String WIDTH = "400px";
|
||||
protected String HEIGHT = "120px";
|
||||
protected EventBus eventBus;
|
||||
protected ProgressUpdater progressUpdater;
|
||||
protected TextButton ok;
|
||||
protected TRId trId;
|
||||
private String reason;
|
||||
private String details;
|
||||
|
||||
public ProgressDialog(
|
||||
EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(true);
|
||||
setModal(true);
|
||||
setHeadingText("Add Column Progress");
|
||||
|
||||
trId = null;
|
||||
|
||||
FramedPanel panel = new FramedPanel();
|
||||
panel.setHeaderVisible(false);
|
||||
panel.setBodyBorder(false);
|
||||
|
||||
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||
|
||||
ProgressBar progressBar = new ProgressBar();
|
||||
|
||||
ok = new TextButton("OK");
|
||||
ok.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
updateInvocation();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
v.add(progressBar,
|
||||
new VerticalLayoutData(1, 1, new Margins(5, 5, 5, 5)));
|
||||
|
||||
panel.add(v);
|
||||
panel.addButton(ok);
|
||||
add(panel);
|
||||
|
||||
progressUpdater = new ProgressUpdater();
|
||||
progressUpdater.addListener(new ProgressBarUpdater(
|
||||
progressBar));
|
||||
|
||||
progressUpdater.addListener(this);
|
||||
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
|
||||
show();
|
||||
ok.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public void addProgressDialogListener(ProgressDialogListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeProgressDialogListener(ProgressDialogListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationInitializing() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationUpdate(float elaborated) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationComplete(TRId trId) {
|
||||
Log.debug("Operation Complete return: " + trId.toString());
|
||||
this.trId = trId;
|
||||
fireOperationComplete(trId);
|
||||
hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationFailed(Throwable caught, String reason,
|
||||
String failureDetails) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
fireOperationFailed(caught,reason);
|
||||
hide();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void updateInvocation() {
|
||||
if (trId != null) {
|
||||
fireOperationStopped(trId, reason, details);
|
||||
}
|
||||
hide();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationStopped(TRId trId, String reason, String details) {
|
||||
Log.debug("Operation Stopped: [" + trId.toString() + ", " + reason
|
||||
+ ", " + details + "]");
|
||||
this.trId = trId;
|
||||
this.reason=reason;
|
||||
this.details=details;
|
||||
ok.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationGeneratingView() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationValidate(float elaborated) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
protected void fireOperationComplete(TRId trId) {
|
||||
for (ProgressDialogListener listener : listeners)
|
||||
listener.operationComplete(trId);
|
||||
}
|
||||
|
||||
protected void fireOperationFailed(Throwable caught, String reason) {
|
||||
for (ProgressDialogListener listener : listeners)
|
||||
listener.operationFailed(caught, reason);
|
||||
}
|
||||
|
||||
protected void fireOperationStopped(TRId trId, String reason, String details) {
|
||||
for (ProgressDialogListener listener : listeners)
|
||||
listener.operationStopped(trId,reason, details);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.portlets.user.td.monitorwidget.client;
|
||||
|
||||
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
public interface ProgressDialogListener {
|
||||
|
||||
|
||||
/**
|
||||
* Called when the operation is complete.
|
||||
*/
|
||||
public void operationComplete(TRId trId);
|
||||
|
||||
/**
|
||||
* Called when the operation is failed.
|
||||
* @param caught the failure exception.
|
||||
* @param reason the failure reason.
|
||||
*/
|
||||
public void operationFailed(Throwable caught, String reason);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when the operation is stopped
|
||||
*
|
||||
* @param trId
|
||||
* @param reason
|
||||
* @param details
|
||||
*/
|
||||
public void operationStopped(TRId trId, String reason, String details);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.gcube.portlets.user.td.monitorwidget.client;
|
||||
|
||||
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Defines a listener for operation progress.
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public interface ProgressListener {
|
||||
|
||||
/**
|
||||
* Called when the operation is starting.
|
||||
*/
|
||||
public void operationInitializing();
|
||||
|
||||
/**
|
||||
* Called when there is a progress for the operation.
|
||||
* @param elaborated the elaborated part.
|
||||
*/
|
||||
public void operationUpdate(float elaborated);
|
||||
|
||||
/**
|
||||
* Called when there is a validate for the operation.
|
||||
* @param elaborated the elaborated part.
|
||||
*/
|
||||
public void operationValidate(float elaborated);
|
||||
|
||||
/**
|
||||
* Called when the operation is complete.
|
||||
*/
|
||||
public void operationComplete(TRId trId);
|
||||
|
||||
/**
|
||||
* Called when the operation is failed.
|
||||
* @param caught the failure exception.
|
||||
* @param reason the failure reason.
|
||||
*/
|
||||
public void operationFailed(Throwable caught, String reason, String failureDetails);
|
||||
|
||||
/**
|
||||
* Called when the operation is stopped
|
||||
*
|
||||
* @param trId
|
||||
* @param reason
|
||||
* @param details
|
||||
*/
|
||||
public void operationStopped(TRId trId, String reason, String details);
|
||||
|
||||
/**
|
||||
* Called when the operation is generating the view
|
||||
*/
|
||||
public void operationGeneratingView();
|
||||
|
||||
}
|
|
@ -0,0 +1,192 @@
|
|||
package org.gcube.portlets.user.td.monitorwidget.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.monitor.AddColumnMonitor;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ProgressUpdater extends Timer {
|
||||
|
||||
protected ArrayList<ProgressListener> listeners = new ArrayList<ProgressListener>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("requesting operation progress");
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getAddColumnMonitor(new AsyncCallback<AddColumnMonitor>() {
|
||||
|
||||
|
||||
public void onFailure(Throwable caught) {
|
||||
cancel();
|
||||
Log.error("Error retrieving the operation state",
|
||||
caught);
|
||||
String message = getStack(caught);
|
||||
fireOperationFailed(caught,
|
||||
"Failed getting operation updates", message);
|
||||
}
|
||||
|
||||
public void onSuccess(AddColumnMonitor result) {
|
||||
Log.info("retrieved AddColumnMonitor: "
|
||||
+ result.getStatus());
|
||||
switch (result.getStatus()) {
|
||||
case INITIALIZING:
|
||||
Log.info("Initializing...");
|
||||
fireOperationInitializing();
|
||||
break;
|
||||
case ABORTED:
|
||||
cancel();
|
||||
Log.info("Aborted");
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
fireOperationUpdate(result.getProgress());
|
||||
break;
|
||||
case VALIDATING_RULES:
|
||||
fireOperationValidate(result.getProgress());
|
||||
break;
|
||||
case GENERATING_VIEW:
|
||||
Log.info("Generating View...");
|
||||
fireOperationGeneratingView();
|
||||
break;
|
||||
case STOPPED:
|
||||
cancel();
|
||||
stopMessage(result);
|
||||
break;
|
||||
case FAILED:
|
||||
cancel();
|
||||
errorMessage(result);
|
||||
break;
|
||||
case SUCCEDED:
|
||||
cancel();
|
||||
Log.info("Fisnish :"
|
||||
+ result.getTrId());
|
||||
fireOperationComplete(result.getTrId());
|
||||
break;
|
||||
default:
|
||||
Log.info("Unknow State");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void errorMessage(AddColumnMonitor result) {
|
||||
Log.info("AddColumn Failed");
|
||||
Throwable th = null;
|
||||
String failure = null;
|
||||
String details = null;
|
||||
if (result.getError() != null) {
|
||||
th = result.getError();
|
||||
failure = "Failed Client Library Add Column";
|
||||
details = result.getError().getLocalizedMessage();
|
||||
} else {
|
||||
th = new Throwable("Failed");
|
||||
failure = "Failed Client Library Add Columnn";
|
||||
details = "Add Column failed";
|
||||
}
|
||||
|
||||
fireOperationFailed(th, failure, details);
|
||||
}
|
||||
|
||||
protected void stopMessage(AddColumnMonitor result) {
|
||||
Log.info("Add Column Stopped");
|
||||
String failure = null;
|
||||
String details = null;
|
||||
if (result.getError() != null) {
|
||||
failure = "Stopped add column";
|
||||
details = result.getError().getLocalizedMessage();
|
||||
} else {
|
||||
failure = "Stopped add column";
|
||||
details = "Add Column stopped";
|
||||
}
|
||||
|
||||
fireOperationStopped(result.getTrId(),failure, details);
|
||||
}
|
||||
|
||||
|
||||
protected String getStack(Throwable e) {
|
||||
String message = e.getLocalizedMessage() + " -> <br>";
|
||||
Throwable c = e.getCause();
|
||||
if (c != null)
|
||||
message += getStack(c);
|
||||
return message;
|
||||
}
|
||||
|
||||
protected void fireOperationInitializing() {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationInitializing();
|
||||
}
|
||||
|
||||
protected void fireOperationGeneratingView() {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationGeneratingView();
|
||||
}
|
||||
|
||||
protected void fireOperationUpdate(float elaborated) {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationUpdate(elaborated);
|
||||
}
|
||||
|
||||
protected void fireOperationValidate(float elaborated) {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationValidate(elaborated);
|
||||
}
|
||||
|
||||
protected void fireOperationComplete(TRId trId) {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationComplete(trId);
|
||||
}
|
||||
|
||||
protected void fireOperationFailed(Throwable caught, String failure,
|
||||
String failureDetails) {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationFailed(caught, failure, failureDetails);
|
||||
}
|
||||
|
||||
protected void fireOperationStopped(TRId trId, String reason, String details) {
|
||||
for (ProgressListener listener : listeners)
|
||||
listener.operationStopped(trId,reason, details);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link ProgressListener} to this
|
||||
* {@link AddColumnProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to add.
|
||||
*/
|
||||
public void addListener(ProgressListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified {@link ProgressListener} from this
|
||||
* {@link AddColumnProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to remove.
|
||||
*/
|
||||
public void removeListener(ProgressListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue