Minor Update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@93415 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e5c2db4956
commit
12820ca654
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.td.tablewidget.client.progress;
|
||||
|
||||
|
||||
|
||||
|
||||
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 TemplateApplyProgressBarUpdater implements TemplateApplyProgressListener {
|
||||
|
||||
protected ProgressBar progressBar;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ProgressBar} updater.
|
||||
* @param progressBar the {@link ProgressBar} to update.
|
||||
*/
|
||||
public TemplateApplyProgressBarUpdater(ProgressBar progressBar) {
|
||||
this.progressBar = progressBar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void operationComplete(TRId trId) {
|
||||
Log.info("Completed");
|
||||
progressBar.updateProgress(1, "Completed");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void operationFailed(Throwable caught, String reason, String failureDetails) {
|
||||
Log.info("Failed");
|
||||
progressBar.updateText("Failed");
|
||||
}
|
||||
|
||||
public void operationInitializing() {
|
||||
Log.info("Inizializing");
|
||||
progressBar.updateProgress(0, "Initializing...");
|
||||
}
|
||||
|
||||
public void operationUpdate(float elaborated) {
|
||||
Log.info("Import elaborated: "+elaborated);
|
||||
if (elaborated == 0) progressBar.updateProgress(0, "Initializing...");
|
||||
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 operationStopped(TRId trId,String reason, String details) {
|
||||
Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]");
|
||||
progressBar.updateText("Stopped");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package org.gcube.portlets.user.td.tablewidget.client.progress;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession;
|
||||
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.type.ChangeTableRequestType;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* LabelColumnProgressDialog is a Dialog that show progress of change the column label
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class TemplateApplyProgressDialog extends Window implements TemplateApplyProgressListener {
|
||||
public static final int STATUS_POLLING_DELAY = 1000;
|
||||
protected String WIDTH = "400px";
|
||||
protected String HEIGHT = "120px";
|
||||
protected TemplateApplySession templateApplySession;
|
||||
protected EventBus eventBus;
|
||||
protected TemplateApplyProgressUpdater progressUpdater;
|
||||
protected TextButton ok;
|
||||
protected TRId trId;
|
||||
|
||||
public TemplateApplyProgressDialog(TemplateApplySession templateApplySession, EventBus eventBus) {
|
||||
this.templateApplySession=templateApplySession;
|
||||
this.eventBus=eventBus;
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(true);
|
||||
setModal(true);
|
||||
setHeadingText("Template Apply 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 TemplateApplyProgressUpdater();
|
||||
progressUpdater.addListener(new TemplateApplyProgressBarUpdater(progressBar));
|
||||
|
||||
progressUpdater.addListener(this);
|
||||
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
|
||||
show();
|
||||
ok.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public void operationInitializing() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void operationUpdate(float elaborated) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void operationComplete(TRId trId) {
|
||||
Log.debug("Operation Complete return: "+trId.toString());
|
||||
ok.setVisible(true);
|
||||
this.trId=trId;
|
||||
}
|
||||
|
||||
public void operationFailed(Throwable caught, String reason,
|
||||
String failureDetails) {
|
||||
ok.setVisible(true);
|
||||
this.trId=null;
|
||||
UtilsGXT3.alert("Error in Template Apply", reason);
|
||||
|
||||
}
|
||||
|
||||
public void updateInvocation(){
|
||||
if(trId!=null){
|
||||
ChangeTableRequestEvent changeTableRequestEvent=
|
||||
new ChangeTableRequestEvent(ChangeTableRequestType.TEMPLATEAPPLY, trId);
|
||||
eventBus.fireEvent(changeTableRequestEvent);
|
||||
}
|
||||
hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationStopped(TRId trId,String reason, String details) {
|
||||
Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]");
|
||||
ok.setVisible(true);
|
||||
this.trId=trId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.td.tablewidget.client.progress;
|
||||
|
||||
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 TemplateApplyProgressListener {
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.td.tablewidget.client.progress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplyMonitor;
|
||||
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 TemplateApplyProgressUpdater extends Timer {
|
||||
|
||||
protected ArrayList<TemplateApplyProgressListener> listeners = new ArrayList<TemplateApplyProgressListener>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("requesting operation progress");
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getTemplateApplyMonitor(new AsyncCallback<TemplateApplyMonitor>() {
|
||||
|
||||
|
||||
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(TemplateApplyMonitor result) {
|
||||
Log.info("retrieved TemplateApplyMonitor: "
|
||||
+ result.getStatus());
|
||||
switch (result.getStatus()) {
|
||||
case INITIALIZING:
|
||||
Log.info("Initializing...");
|
||||
fireOperationInitializing();
|
||||
break;
|
||||
case ABORTED:
|
||||
cancel();
|
||||
Log.info("Template Apply Operation Aborted");
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
fireOperationUpdate(result.getProgress());
|
||||
break;
|
||||
case VALIDATING_RULES:
|
||||
fireOperationUpdate(result.getProgress());
|
||||
break;
|
||||
case STOPPED:
|
||||
cancel();
|
||||
stopMessage(result);
|
||||
break;
|
||||
case FAILED:
|
||||
cancel();
|
||||
errorMessage(result);
|
||||
break;
|
||||
case SUCCEDED:
|
||||
cancel();
|
||||
Log.info("Fisnish TableId :"
|
||||
+ result.getTrId());
|
||||
fireOperationComplete(result.getTrId());
|
||||
break;
|
||||
default:
|
||||
Log.info("Unknow State");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void errorMessage(TemplateApplyMonitor result) {
|
||||
Log.info("Template Apply Failed");
|
||||
Throwable th = null;
|
||||
String failure = null;
|
||||
String details = null;
|
||||
if (result.getError() != null) {
|
||||
th = result.getError();
|
||||
failure = "Failed Client Library applying template";
|
||||
details = result.getError().getLocalizedMessage();
|
||||
} else {
|
||||
th = new Throwable("Failed");
|
||||
failure = "Failed Client Library applying template";
|
||||
details = "Template Apply failed";
|
||||
}
|
||||
|
||||
fireOperationFailed(th, failure, details);
|
||||
}
|
||||
|
||||
protected void stopMessage(TemplateApplyMonitor result) {
|
||||
Log.info("Template Apply Stopped");
|
||||
String failure = null;
|
||||
String details = null;
|
||||
if (result.getError() != null) {
|
||||
failure = "Stopped applying template";
|
||||
details = result.getError().getLocalizedMessage();
|
||||
} else {
|
||||
failure = "Stopped applying template";
|
||||
details = "Apply template 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 (TemplateApplyProgressListener listener : listeners)
|
||||
listener.operationInitializing();
|
||||
}
|
||||
|
||||
protected void fireOperationUpdate(float elaborated) {
|
||||
for (TemplateApplyProgressListener listener : listeners)
|
||||
listener.operationUpdate(elaborated);
|
||||
}
|
||||
|
||||
protected void fireOperationComplete(TRId trId) {
|
||||
for (TemplateApplyProgressListener listener : listeners)
|
||||
listener.operationComplete(trId);
|
||||
}
|
||||
|
||||
protected void fireOperationFailed(Throwable caught, String failure,
|
||||
String failureDetails) {
|
||||
for (TemplateApplyProgressListener listener : listeners)
|
||||
listener.operationFailed(caught, failure, failureDetails);
|
||||
}
|
||||
|
||||
protected void fireOperationStopped(TRId trId, String reason, String details) {
|
||||
for (TemplateApplyProgressListener listener : listeners)
|
||||
listener.operationStopped(trId,reason, details);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link TemplateApplyProgressListener} to this
|
||||
* {@link TemplateApplyProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to add.
|
||||
*/
|
||||
public void addListener(TemplateApplyProgressListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified {@link TemplateApplyProgressListener} from this
|
||||
* {@link TemplateApplyProgressUpdater}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to remove.
|
||||
*/
|
||||
public void removeListener(TemplateApplyProgressListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateApplySession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData;
|
||||
import org.gcube.portlets.user.td.tablewidget.client.resources.ResourceBundle;
|
||||
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
|
||||
|
@ -220,11 +221,38 @@ public class TemplateApplyPanel extends FramedPanel {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected TemplateData getSelectedItem() {
|
||||
return grid.getSelectionModel().getSelectedItem();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void apply(){
|
||||
TemplateApplySession applyTemplateSession=new TemplateApplySession();
|
||||
applyTemplateSession.setTemplateData(getSelectedItem());
|
||||
applyTemplateSession.setTrId(trId);
|
||||
Log.debug("applyTemplateSession: "+applyTemplateSession);
|
||||
|
||||
TDGWTServiceAsync.INSTANCE.startTemplateApply(applyTemplateSession,
|
||||
new AsyncCallback<Void>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
Log.debug("Apply Template Error: "
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Apply Template Error ",
|
||||
"Error in invocation of apply template operation!");
|
||||
|
||||
}
|
||||
|
||||
public void onSuccess(Void result) {
|
||||
/*TemplateApplyProgressDialog = new ChangeColumnTypeProgressDialog(
|
||||
changeColumnTypeSession, eventBus);*/
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void close(){
|
||||
|
|
Loading…
Reference in New Issue