[jbpm-commits] JBoss JBPM SVN: r4913 - projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed May 27 08:44:31 EDT 2009
Author: heiko.braun at jboss.com
Date: 2009-05-27 08:44:31 -0400 (Wed, 27 May 2009)
New Revision: 4913
Added:
projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderDispatchEvent.java
projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderReportAction.java
Modified:
projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/ReportView.java
Log:
Dispatch report generation through action to get load indicator and async callback
Added: projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderDispatchEvent.java
===================================================================
--- projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderDispatchEvent.java (rev 0)
+++ projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderDispatchEvent.java 2009-05-27 12:44:31 UTC (rev 4913)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.report;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public final class RenderDispatchEvent
+{
+ String targetView;
+ String dispatchUrl;
+
+ public RenderDispatchEvent(String targetView, String dispatchUrl)
+ {
+ this.targetView = targetView;
+ this.dispatchUrl = dispatchUrl;
+ }
+
+ public String getTargetView()
+ {
+ return targetView;
+ }
+
+ public String getDispatchUrl()
+ {
+ return dispatchUrl;
+ }
+}
Added: projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderReportAction.java
===================================================================
--- projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderReportAction.java (rev 0)
+++ projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/RenderReportAction.java 2009-05-27 12:44:31 UTC (rev 4913)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.console.client.report;
+
+import com.google.gwt.http.client.*;
+import com.google.gwt.user.client.Timer;
+import com.mvc4g.client.ActionInterface;
+import com.mvc4g.client.Controller;
+import org.jboss.bpm.console.client.ApplicationContext;
+import org.jboss.bpm.console.client.LoadingStatusAction;
+import org.jboss.bpm.console.client.util.ConsoleLog;
+
+import java.io.IOException;
+
+/**
+ * Engage a report generation and update {@link org.jboss.bpm.console.client.report.ReportView}
+ * when the report is finished.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class RenderReportAction implements ActionInterface
+{
+
+ public final static String ID = RenderReportAction.class.getName();
+
+ private ApplicationContext appContext;
+
+ public RenderReportAction(ApplicationContext appContext)
+ {
+ this.appContext = appContext;
+ }
+
+ public void execute(final Controller controller, Object object)
+ {
+ final RenderDispatchEvent event = (RenderDispatchEvent)object;
+
+ final String url = event.getDispatchUrl();
+ RequestBuilder builder = new RequestBuilder(
+ RequestBuilder.GET, url);
+
+ ConsoleLog.debug(RequestBuilder.GET +": " + url);
+ final ReportView view = (ReportView)controller.getView(event.getTargetView());
+
+ try
+ {
+ controller.handleEvent( LoadingStatusAction.ON );
+ view.setLoading(true);
+
+ final Request request = builder.sendRequest(null,
+ new RequestCallback()
+ {
+ public void onError(Request request, Throwable exception) {
+ // Couldn't connect to server (could be timeout, SOP violation, etc.)
+ handleError(url, exception);
+ controller.handleEvent( LoadingStatusAction.OFF );
+ }
+
+ public void onResponseReceived(Request request, Response response) {
+ try
+ {
+ if (200 == response.getStatusCode())
+ {
+ // update view
+
+ view.update(event.getDispatchUrl());
+ }
+ else
+ {
+ final String msg = response.getText().equals("") ? "Unknown error" : response.getText();
+ handleError(
+ url,
+ new RequestException("HTTP "+ response.getStatusCode()+ ": " + msg)
+ );
+ }
+ }
+ finally
+ {
+ controller.handleEvent( LoadingStatusAction.OFF );
+ view.setLoading(false);
+ }
+ }
+ }
+ );
+
+ // Timer to handle pending request
+ Timer t = new Timer() {
+
+ public void run()
+ {
+ if(request.isPending())
+ {
+ request.cancel();
+ handleError(
+ url,
+ new IOException("Request timeout")
+ );
+ }
+
+ }
+ };
+ t.schedule(20000);
+
+ }
+ catch (RequestException e)
+ {
+ // Couldn't connect to server
+ handleError(url, e);
+ controller.handleEvent( LoadingStatusAction.OFF );
+ view.setLoading(false);
+ }
+ }
+
+ protected void handleError(String url, Throwable t)
+ {
+ final String out =
+ "<ul>"+
+ "<li>URL: '" + url + "'\n"+
+ "<li>Action: '" + ID + "'\n" +
+ "<li>Exception: '" + t.getClass() +"'"+
+ "</ul>\n\n"+
+ t.getMessage();
+
+ ConsoleLog.error(out, t);
+ appContext.displayMessage(out, true);
+
+ }
+}
Modified: projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/ReportView.java
===================================================================
--- projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/ReportView.java 2009-05-27 12:05:01 UTC (rev 4912)
+++ projects/gwt-console/trunk/gui/war/src/main/java/org/jboss/bpm/console/client/report/ReportView.java 2009-05-27 12:44:31 UTC (rev 4913)
@@ -22,16 +22,17 @@
package org.jboss.bpm.console.client.report;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Frame;
+import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.user.client.ui.MenuBar;
import com.mvc4g.client.Controller;
import com.mvc4g.client.Event;
+import org.gwt.mosaic.ui.client.PopupMenu;
import org.gwt.mosaic.ui.client.ToolBar;
import org.gwt.mosaic.ui.client.ToolButton;
-import org.gwt.mosaic.ui.client.PopupMenu;
+import org.gwt.mosaic.ui.client.Label;
import org.gwt.mosaic.ui.client.layout.BoxLayout;
import org.gwt.mosaic.ui.client.layout.BoxLayoutData;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;
@@ -42,6 +43,7 @@
import org.jboss.bpm.console.client.search.SearchDelegate;
import org.jboss.bpm.console.client.search.SearchWindow;
import org.jboss.bpm.console.client.search.UpdateSearchDefinitionsAction;
+import org.jboss.bpm.console.client.util.ConsoleLog;
import java.util.Date;
@@ -60,6 +62,8 @@
private SearchDefinitionView search;
+ private LayoutPanel loadingPanel;
+
public ReportView(ApplicationContext appContext)
{
super();
@@ -91,11 +95,16 @@
{
public void handleResult(String procDefId)
{
- String reportUrl = appContext.getUrlBuilder().getDefinitionReportUrl(
- procDefId
+ String reportUrl = appContext.getUrlBuilder().getDefinitionReportUrl(procDefId);
+
+ // load report
+ controller.handleEvent(
+ new Event(RenderReportAction.ID,
+ new RenderDispatchEvent(
+ ReportView.ID, reportUrl
+ )
+ )
);
-
- setFrameUrl(reportUrl);
}
public String getActionName()
@@ -120,8 +129,14 @@
toolBar.add(createMenuBtn());
toolBox.add(toolBar, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
+ // loading panel
+ loadingPanel = new LayoutPanel();
+ loadingPanel.add(new Label("Generating report, please wait..."));
+ loadingPanel.setVisible(false);
+
// assembly
layout.add(toolBox, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
+ layout.add(loadingPanel, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
layout.add(frame, new BoxLayoutData(BoxLayoutData.FillStyle.BOTH));
this.add(layout);
@@ -131,17 +146,29 @@
"report.definition.search", search
);
- controller.addAction(
- UpdateSearchDefinitionsAction.ID, new UpdateSearchDefinitionsAction(appContext)
+ controller.addAction(UpdateSearchDefinitionsAction.ID, new UpdateSearchDefinitionsAction(appContext));
+ controller.addAction(RenderReportAction.ID, new RenderReportAction(appContext));
+
+ // initial report
+ controller.handleEvent(
+ new Event(RenderReportAction.ID,
+ new RenderDispatchEvent(
+ ReportView.ID, appContext.getUrlBuilder().getOverviewReportUrl()
+ )
+ )
);
- // default report
- setFrameUrl(appContext.getUrlBuilder().getOverviewReportUrl());
-
this.isInitialized = true;
}
}
+
+ public void onClick(Widget widget)
+ {
+ System.out.println(widget);
+ }
+
+
private Widget createMenuBtn()
{
// Add a menu button
@@ -224,4 +251,14 @@
return menu;
}
+
+ public void update(String reportUrl)
+ {
+ setFrameUrl(reportUrl);
+ }
+
+ void setLoading(boolean b)
+ {
+ loadingPanel.setVisible(b);
+ }
}
More information about the jbpm-commits
mailing list