[jbpm-commits] JBoss JBPM SVN: r4586 - in projects/gwt-console/branches/hbraun: server/src/main/java/org/jboss/bpm/console/server and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Apr 20 11:06:02 EDT 2009


Author: heiko.braun at jboss.com
Date: 2009-04-20 11:06:01 -0400 (Mon, 20 Apr 2009)
New Revision: 4586

Added:
   projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/StateChangeAction.java
Modified:
   projects/gwt-console/branches/hbraun/plugin-api/src/main/java/org/jboss/bpm/console/client/URLBuilder.java
   projects/gwt-console/branches/hbraun/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java
   projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/InstanceListView.java
   projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/ProcessEditor.java
Log:
Implement cancel instance

Modified: projects/gwt-console/branches/hbraun/plugin-api/src/main/java/org/jboss/bpm/console/client/URLBuilder.java
===================================================================
--- projects/gwt-console/branches/hbraun/plugin-api/src/main/java/org/jboss/bpm/console/client/URLBuilder.java	2009-04-20 14:30:21 UTC (rev 4585)
+++ projects/gwt-console/branches/hbraun/plugin-api/src/main/java/org/jboss/bpm/console/client/URLBuilder.java	2009-04-20 15:06:01 UTC (rev 4586)
@@ -86,7 +86,7 @@
 
   public String getStateChangeURL(String instanceId, ProcessInstanceRef.STATE state)
   {
-    return getConsoleServerUrl() + "/rs/process/instances/" + adoptExecutionId(instanceId) + "/state/" + state;
+    return getConsoleServerUrl() + "/rs/process/instances/" + instanceId + "/state/" + state;
   }
 
   public String getStartNewInstanceURL(String processId)
@@ -132,21 +132,15 @@
 
   public String getExecutionSignalUrl(TokenReference tok)
   {
-    return getConsoleServerUrl() + "/rs/process/tokens/" + adoptExecutionId(tok.getId()) + "/transition/default";
+    return getConsoleServerUrl() + "/rs/process/tokens/" + tok.getId() + "/transition/default";
   }
 
   public String getExecutionSignalUrl(TokenReference tok, String signal)
   {
     String encodedSignal = URL.encode(signal);
-    return getConsoleServerUrl() + "/rs/process/tokens/" + adoptExecutionId(tok.getId()) + "/transition?signal=" + encodedSignal;
+    return getConsoleServerUrl() + "/rs/process/tokens/" + tok.getId() + "/transition?signal=" + encodedSignal;
   }
 
-  private String adoptExecutionId(String actual)
-  {
-    // TDOD: https://jira.jboss.org/jira/browse/JBPM-2054
-    return actual.replace("/", "_");
-  }
-
   public String getAvailableActorsUrl(String actorId)
   {
     return getConsoleServerUrl() + "/rs/identity/user/" + actorId + "/actors";

Modified: projects/gwt-console/branches/hbraun/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java
===================================================================
--- projects/gwt-console/branches/hbraun/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java	2009-04-20 14:30:21 UTC (rev 4585)
+++ projects/gwt-console/branches/hbraun/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java	2009-04-20 15:06:01 UTC (rev 4586)
@@ -134,11 +134,9 @@
       @PathParam("next")
       String next)
   {
-    String actualExecutionId = adoptExecutionId(executionId);
-    log.debug("Change instance (ID "+actualExecutionId+") to state " +next);
-
-    //ProcessInstanceRef.STATE state = ProcessInstanceRef.STATE.valueOf(next);
-    getProcessManagement().setProcessState(actualExecutionId, ProcessInstanceRef.STATE.ENDED);
+    ProcessInstanceRef.STATE state = ProcessInstanceRef.STATE.valueOf(next);
+    log.debug("Change instance (ID "+executionId+") to state " +state);
+    getProcessManagement().setProcessState(executionId, state);
     return Response.ok().type("application/json").build();
   }
 
@@ -156,7 +154,7 @@
     if ("default transition".equals(signalName))
       signalName = null;
 
-    getProcessManagement().signalExecution(adoptExecutionId(id), signalName);
+    getProcessManagement().signalExecution(id, signalName);
     return Response.ok().type("application/json").build();
   }
 
@@ -169,16 +167,10 @@
   {
     log.debug("Signal token " + id);
 
-    getProcessManagement().signalExecution(adoptExecutionId(id), null);
+    getProcessManagement().signalExecution(id, null);
     return Response.ok().type("application/json").build();
   }
 
-  private String adoptExecutionId(String modified)
-  {
-    // TODO: https://jira.jboss.org/jira/browse/JBPM-2054
-    return modified.replace("_", "/");
-  }
-
   @POST
   @Path("definitions/new")
   @Produces("application/json")

Modified: projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/InstanceListView.java
===================================================================
--- projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/InstanceListView.java	2009-04-20 14:30:21 UTC (rev 4585)
+++ projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/InstanceListView.java	2009-04-20 15:06:01 UTC (rev 4586)
@@ -29,6 +29,7 @@
 import org.gwt.mosaic.ui.client.ListBox;
 import org.gwt.mosaic.ui.client.ToolBar;
 import org.gwt.mosaic.ui.client.ToolButton;
+import org.gwt.mosaic.ui.client.MessageBox;
 import org.gwt.mosaic.ui.client.layout.BoxLayout;
 import org.gwt.mosaic.ui.client.layout.BoxLayoutData;
 import org.gwt.mosaic.ui.client.layout.LayoutPanel;
@@ -113,8 +114,10 @@
     toolBar.addSeparator();
 
     toolBar.add(
-        new ToolButton("Start new instance", new ClickListener() {
-          public void onClick(Widget sender) {
+        new ToolButton("Start new instance", new ClickListener()
+        {
+          public void onClick(Widget sender)
+          {
             controller.handleEvent(
                 new Event(
                     StartNewInstanceAction.ID,
@@ -126,7 +129,34 @@
         )
     );
 
+    toolBar.addSeparator();
 
+    toolBar.add(
+        new ToolButton("Cancel execution", new ClickListener()
+        {
+          public void onClick(Widget sender)
+          {
+            ProcessInstanceRef selection = getSelection();
+            if(selection!=null)
+            {
+              selection.setState(ProcessInstanceRef.STATE.ENDED);
+              
+              controller.handleEvent(
+                  new Event(
+                      StateChangeAction.ID,
+                      selection
+                  )
+              );
+            }
+            else
+            {
+              MessageBox.alert("Missing selection", "Please select an instance"); 
+            }
+          }
+        }
+        )
+    );
+
     toolBox.add(toolBar, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
 
     instanceList.add(toolBox, new BoxLayoutData(BoxLayoutData.FillStyle.HORIZONTAL));
@@ -136,8 +166,16 @@
     
   }
 
-  private ProcessDefinitionRef getCurrentDefinition()
+  public ProcessInstanceRef getSelection()
   {
+    ProcessInstanceRef selection = null;
+    if(listBox.getSelectedIndex()!=-1)
+      selection = listBox.getItem( listBox.getSelectedIndex());
+    return selection;
+  }
+
+  public ProcessDefinitionRef getCurrentDefinition()
+  {
     return this.currentDefinition;
   }
 

Modified: projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/ProcessEditor.java
===================================================================
--- projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/ProcessEditor.java	2009-04-20 14:30:21 UTC (rev 4585)
+++ projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/ProcessEditor.java	2009-04-20 15:06:01 UTC (rev 4586)
@@ -67,7 +67,8 @@
       addAction(LoadDefinitionsAction.ID, new LoadDefinitionsAction(appContext));
       addAction(LoadInstancesAction.ID, new LoadInstancesAction(appContext));
       addAction(StartNewInstanceAction.ID, new StartNewInstanceAction(appContext));
-      
+      addAction(StateChangeAction.ID, new StateChangeAction(appContext));
+            
       // tab Listener
       tabPanel.addTabListener(
           new TabListener()

Added: projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/StateChangeAction.java
===================================================================
--- projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/StateChangeAction.java	                        (rev 0)
+++ projects/gwt-console/branches/hbraun/war/src/main/java/org/jboss/bpm/console/client/v2/process/StateChangeAction.java	2009-04-20 15:06:01 UTC (rev 4586)
@@ -0,0 +1,105 @@
+/*
+ * 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.v2.process;
+
+import org.jboss.bpm.console.client.ApplicationContext;
+import org.jboss.bpm.console.client.model.ProcessInstanceRef;
+import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
+import com.mvc4g.client.Controller;
+import com.mvc4g.client.Event;
+import com.google.gwt.http.client.*;
+
+/**
+ * Starts a new process instance.
+ * Triggered through {@link org.jboss.bpm.console.client.model.ProcessInstanceRef}
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+class StateChangeAction extends AbstractContextAwareAction
+{
+  public final static String ID = StateChangeAction.class.getName();
+
+  public StateChangeAction(ApplicationContext appContext)
+  {
+    super(appContext);
+  }
+
+  /**
+   *
+   * @param controller
+   * @param object a {@link org.jboss.bpm.console.client.model.ProcessInstanceRef}
+   */
+  public void execute(final Controller controller, Object object)
+  {
+    final ProcessInstanceRef inst = (ProcessInstanceRef)object;
+
+    String url = appContext.getUrlBuilder().getStateChangeURL(inst.getId(), inst.getState());
+    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
+
+    try {
+      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(exception);
+        }
+
+        public void onResponseReceived(Request request, Response response) {
+          if (200 == response.getStatusCode()) {
+
+            InstanceListView view = (InstanceListView)
+                controller.getView(InstanceListView.ID);
+            ProcessDefinitionRef def = view.getCurrentDefinition();
+
+            // force reload instance list
+            controller.handleEvent(
+                new Event(LoadInstancesAction.ID, def)
+            );
+
+          } else {
+            // Handle the error.  Can get the status text from response.getStatusText()
+            appContext.displayMessage("Failed to cancel instance. " +
+                "HTTP " + response.getStatusCode()+
+                ": " +response.getText(),
+                true
+            );
+          }
+        }
+      });
+    }
+    catch (RequestException e)
+    {
+      // Couldn't connect to server
+      handleError(e);
+    }
+  }
+
+  private void handleError(Throwable t)
+  {
+    // Couldn't connect to server
+      appContext.displayMessage("Failed to cancel instance. " +
+          "RequestException( "+t.getClass() +"): "+
+          t.getMessage(),
+          true
+      );
+  }
+}
+




More information about the jbpm-commits mailing list