299 lines
7.8 KiB
Java
299 lines
7.8 KiB
Java
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.gwtservice.shared.monitor.OperationMonitor;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.details.MonitorDetailPanel;
|
|
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.button.ToolButton;
|
|
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;
|
|
import com.sencha.gxt.widget.core.client.form.FieldSet;
|
|
|
|
/**
|
|
* 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 MonitorDialog extends Window implements MonitorUpdaterListener {
|
|
|
|
public static final int STATUS_POLLING_DELAY = 1000;
|
|
private static final String WIDTH = "400px";
|
|
private static final String HEIGHT = "120px";
|
|
private EventBus eventBus;
|
|
private String taskId;
|
|
private MonitorUpdater progressUpdater;
|
|
private TextButton ok;
|
|
private TRId trId;
|
|
private String reason;
|
|
private String details;
|
|
|
|
|
|
protected boolean backgroundBtnEnabled=true;
|
|
protected ToolButton backgroundBtn;
|
|
|
|
protected ArrayList<MonitorDialogListener> listeners = new ArrayList<MonitorDialogListener>();
|
|
private MonitorDetailPanel monitorDetailPanel;
|
|
|
|
|
|
|
|
public MonitorDialog(String taskId, EventBus eventBus) {
|
|
this.eventBus = eventBus;
|
|
this.taskId=taskId;
|
|
trId = null;
|
|
initWindow();
|
|
create();
|
|
|
|
|
|
}
|
|
|
|
protected void initWindow(){
|
|
setWidth(WIDTH);
|
|
setHeight(HEIGHT);
|
|
setBodyBorder(false);
|
|
setResizable(true);
|
|
setModal(true);
|
|
setHeadingText("Progress");
|
|
}
|
|
|
|
protected void create(){
|
|
FramedPanel panel = new FramedPanel();
|
|
panel.setHeaderVisible(false);
|
|
panel.setBodyBorder(false);
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
|
|
ProgressBar progressBar = new ProgressBar();
|
|
|
|
FieldSet detailsSet = new FieldSet();
|
|
detailsSet.setHeadingText("Details");
|
|
detailsSet.setCollapsible(true);
|
|
|
|
monitorDetailPanel=new MonitorDetailPanel(eventBus);
|
|
detailsSet.add(monitorDetailPanel);
|
|
|
|
/*TextField
|
|
|
|
FlowLayoutContainer progressDetailContainer = new FlowLayoutContainer();
|
|
progressDetailContainer.setScrollMode(ScrollMode.ALWAYS);
|
|
MarginData layoutData = new MarginData(new Margins(0, 5, 0, 0));
|
|
c.add(new TextButton("Button 1"), layoutData);
|
|
c.add(new TextButton("Button 2"), layoutData);
|
|
c.add(new TextButton("Button 3"), layoutData);
|
|
Viewport v = new Viewport();
|
|
v.add(c);
|
|
RootPanel.get().add(v);
|
|
*/
|
|
|
|
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)));
|
|
|
|
v.add(detailsSet,new VerticalLayoutData(1, 1, new Margins(5, 5, 5, 5)));
|
|
|
|
panel.add(v);
|
|
panel.addButton(ok);
|
|
add(panel);
|
|
|
|
OperationMonitorSession operationMonitorSession = new OperationMonitorSession(
|
|
taskId);
|
|
progressUpdater = new MonitorUpdater(operationMonitorSession);
|
|
progressUpdater.addListener(new MonitorBarUpdater(progressBar));
|
|
|
|
progressUpdater.addListener(this);
|
|
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
|
|
show();
|
|
ok.setVisible(false);
|
|
}
|
|
|
|
public void addProgressDialogListener(MonitorDialogListener listener) {
|
|
listeners.add(listener);
|
|
}
|
|
|
|
public void removeProgressDialogListener(MonitorDialogListener listener) {
|
|
listeners.remove(listener);
|
|
}
|
|
|
|
@Override
|
|
public void monitorInitializing(OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorUpdate(OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorComplete(TRId trId, OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
Log.debug("Operation Complete return: " + trId.toString());
|
|
this.trId = trId;
|
|
fireOperationComplete(trId);
|
|
hide();
|
|
}
|
|
|
|
@Override
|
|
public void monitorFailed(Throwable caught, String reason, String details, OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
fireOperationFailed(caught,reason,details);
|
|
hide();
|
|
|
|
}
|
|
}
|
|
|
|
public void updateInvocation() {
|
|
if (trId != null) {
|
|
fireOperationStopped(trId, reason, details);
|
|
}
|
|
hide();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorStopped(TRId trId, String reason, String details, OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
Log.debug("Operation Stopped: [" + trId.toString() + ", " + reason
|
|
+ ", " + details + "]");
|
|
this.trId = trId;
|
|
this.reason = reason;
|
|
this.details = details;
|
|
ok.setVisible(true);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorGeneratingView(OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorValidate(OperationMonitor operationMonitor) {
|
|
if(monitorDetailPanel!=null){
|
|
monitorDetailPanel.update(operationMonitor);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public void monitorAborted() {
|
|
fireOperationAborted();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorPutInBackground() {
|
|
fireOperationPutInBackground();
|
|
|
|
}
|
|
|
|
protected void fireOperationComplete(TRId trId) {
|
|
for (MonitorDialogListener listener : listeners)
|
|
listener.operationComplete(trId);
|
|
}
|
|
|
|
protected void fireOperationFailed(Throwable caught, String reason, String details) {
|
|
for (MonitorDialogListener listener : listeners)
|
|
listener.operationFailed(caught,reason, details);
|
|
}
|
|
|
|
protected void fireOperationStopped(TRId trId, String reason, String details) {
|
|
for (MonitorDialogListener listener : listeners)
|
|
listener.operationStopped(trId, reason, details);
|
|
}
|
|
|
|
protected void fireOperationAborted() {
|
|
for (MonitorDialogListener listener : listeners)
|
|
listener.operationAborted();
|
|
}
|
|
|
|
protected void fireOperationPutInBackground() {
|
|
for (MonitorDialogListener listener : listeners)
|
|
listener.operationPutInBackground();
|
|
}
|
|
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
protected void initTools() {
|
|
if (backgroundBtnEnabled) {
|
|
backgroundBtn = new ToolButton(ToolButton.CLOSE);
|
|
backgroundBtn.setToolTip("Put in the background");
|
|
backgroundBtn.addSelectHandler(new SelectHandler() {
|
|
|
|
@Override
|
|
public void onSelect(SelectEvent event) {
|
|
hide();
|
|
}
|
|
});
|
|
|
|
header.addTool(backgroundBtn);
|
|
}
|
|
|
|
super.initTools();
|
|
|
|
closeBtn.addSelectHandler(new SelectHandler() {
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
close();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void close() {
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|