[jbpm-commits] JBoss JBPM SVN: r3027 - in projects/gwt-console/trunk: war/src/main/java/org/jboss/bpm/console/client/process and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 21 06:42:46 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-11-21 06:42:46 -0500 (Fri, 21 Nov 2008)
New Revision: 3027

Added:
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceDetailForm.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/widgets/ModelModificationCallback.java
Modified:
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/integration/InvocationProxy.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceListEditor.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/TokenEditor.java
Log:
Use ModelListenerRegistry to propagate state changes in process instance list editor

Modified: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/integration/InvocationProxy.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/integration/InvocationProxy.java	2008-11-21 11:31:29 UTC (rev 3026)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/integration/InvocationProxy.java	2008-11-21 11:42:46 UTC (rev 3027)
@@ -30,7 +30,8 @@
 import java.lang.reflect.Method;
 
 /**
- * Decorates management invocations with common system aspects, i.e. transaction demarcation.
+ * Decorates management invocations with common system aspects,
+ * i.e. transaction demarcation.
  *
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */

Added: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceDetailForm.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceDetailForm.java	                        (rev 0)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceDetailForm.java	2008-11-21 11:42:46 UTC (rev 3027)
@@ -0,0 +1,178 @@
+/*
+ * 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.process;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.http.client.*;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.widgets.Button;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.event.ButtonListenerAdapter;
+import com.gwtext.client.widgets.form.DateField;
+import com.gwtext.client.widgets.form.FormPanel;
+import com.gwtext.client.widgets.form.TextField;
+import com.gwtext.client.data.Record;
+import org.jboss.bpm.console.client.MainView;
+import org.jboss.bpm.console.client.model.ProcessInstanceRef;
+import org.jboss.bpm.console.client.widgets.FormWidgets;
+import org.jboss.bpm.console.client.widgets.ModelChangeListener;
+import org.jboss.bpm.console.client.widgets.ModelListenerRegistry;
+import org.jboss.bpm.console.client.widgets.ModelModificationCallback;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class ProcessInstanceDetailForm extends Panel implements ModelChangeListener
+{
+
+   private FormPanel detailsForm;
+
+   private ProcessInstanceRef selectedInstance;
+
+   private ModelModificationCallback callback;
+
+   private MainView mainView;
+
+   private Button suspendButton;
+   private Button resumeButton;
+
+   public ProcessInstanceDetailForm(MainView view, ModelModificationCallback callback)
+   {
+      super();
+
+      this.mainView = mainView;
+      this.callback = callback;
+
+      setTitle("Instance Details");
+      setBorder(false);
+      setFrame(false);
+
+      // ---------------
+
+      detailsForm = FormWidgets.createBaseFormPanel();
+
+      // ---------------
+
+      TextField idField = new TextField("Id", "instanceId", 230);
+      idField.setReadOnly(true);
+      detailsForm.add(idField);
+      TextField keyField = new TextField("Key", "key", 230);
+      keyField.setReadOnly(true);
+      detailsForm.add(keyField);
+      TextField stateField = new TextField("State", "state", 230);
+      stateField.setReadOnly(true);
+      detailsForm.add(stateField);
+      DateField startDateField = new DateField("Start Date", "startDate", 230);
+      startDateField.setReadOnly(true);
+      detailsForm.add(startDateField);
+      //detailsForm.add(new DateField("End Date", "endDate", 230));
+
+      suspendButton = new Button("Suspend",
+            new ButtonListenerAdapter()
+            {
+               public void onClick(Button button, EventObject eventObject)
+               {
+                  selectedInstance.setState(ProcessInstanceRef.STATE.SUSPENDED);
+                  persistStateChange();
+               }
+            }
+      );
+
+      resumeButton = new Button("Resume",
+            new ButtonListenerAdapter()
+            {
+
+               public void onClick(Button button, EventObject eventObject)
+               {
+                  selectedInstance.setState(ProcessInstanceRef.STATE.RUNNING);
+                  persistStateChange();
+               }
+            }
+      );
+
+      detailsForm.addButton(suspendButton);
+      detailsForm.addButton(resumeButton);
+
+      this.add(detailsForm);
+            
+   }
+
+   private void persistStateChange()
+      {
+         String url = mainView.getUrlBuilder().getStateChangeURL(
+               selectedInstance.getInstanceId(), selectedInstance.getState()
+         );
+
+         RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
+
+         try
+         {
+            rb.sendRequest(null,
+                  new RequestCallback() {
+
+                     public void onResponseReceived(Request request, Response response)
+                     {
+                        if(response.getStatusCode()!=200)
+                           Log.error("Failed to change state: " +response.getStatusText());
+                        else
+                           callback.onStaleModel();
+                     }
+
+                     public void onError(Request request, Throwable t)
+                     {
+                        // Unknown error
+                        Log.error("Unknown error", t);
+                     }
+                  });
+         }
+         catch (RequestException e1)
+         {
+            Log.error("Request failed", e1);
+         }
+      }
+
+
+   public void onModelChange(ModelListenerRegistry parent, Object changeEvent)
+   {
+      // not used
+   }
+
+   public void onRecordChange(ModelListenerRegistry parent, Record record)
+   {
+      selectedInstance = ProcessInstanceList.transform(record);
+
+      if(selectedInstance.isSuspended())
+      {
+         suspendButton.disable();
+         resumeButton.enable();
+      }
+      else
+      {
+         resumeButton.disable();
+         suspendButton.enable();
+      }
+
+      detailsForm.getForm().loadRecord(record);
+      detailsForm.doLayout();
+
+   }
+}

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceListEditor.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceListEditor.java	2008-11-21 11:31:29 UTC (rev 3026)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessInstanceListEditor.java	2008-11-21 11:42:46 UTC (rev 3027)
@@ -21,18 +21,10 @@
  */
 package org.jboss.bpm.console.client.process;
 
-import com.allen_sauer.gwt.log.client.Log;
-import com.google.gwt.http.client.*;
-import com.gwtext.client.core.EventObject;
 import com.gwtext.client.data.Record;
-import com.gwtext.client.widgets.Button;
 import com.gwtext.client.widgets.PaddedPanel;
 import com.gwtext.client.widgets.Panel;
 import com.gwtext.client.widgets.TabPanel;
-import com.gwtext.client.widgets.event.ButtonListenerAdapter;
-import com.gwtext.client.widgets.form.DateField;
-import com.gwtext.client.widgets.form.FormPanel;
-import com.gwtext.client.widgets.form.TextField;
 import com.gwtext.client.widgets.grid.RowSelectionModel;
 import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
 import com.gwtext.client.widgets.layout.ColumnLayout;
@@ -42,7 +34,6 @@
 import org.jboss.bpm.console.client.UIConstants;
 import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
 import org.jboss.bpm.console.client.model.ProcessInstanceRef;
-import org.jboss.bpm.console.client.model.jbpm3.TokenReference;
 import org.jboss.bpm.console.client.widgets.*;
 
 /**
@@ -56,14 +47,17 @@
    private ProcessDefinitionRef parent;
    private ProcessInstanceList instanceList;
 
-   private FormPanel detailsForm;
    private Panel tokenEditorPanel;
    private ProcessInstanceRef selectedInstance;
    private TokenEditor currentTokenEditor;
 
    private TabPanel tabPanel;
-   
-   public ProcessInstanceListEditor(ProcessDefinitionRef proc, MainView view)
+
+   private ModelListenerRegistry modelListeners;
+
+   private ModelModificationCallback modelModificationCallback;
+
+   public ProcessInstanceListEditor(ProcessDefinitionRef proc, final MainView view)
    {
       super();
 
@@ -78,14 +72,16 @@
 
       // ---------------
 
+      this.modelListeners = new ModelListenerRegistry(this);
+
+      // ---------------
+
       Panel leftHand = new Panel();
       leftHand.setFrame(false);
       leftHand.setHeader(false);
-      leftHand.setBorder(false);      
+      leftHand.setBorder(false);
 
-      instanceList = new ProcessInstanceList(
-            proc, "Process Instances", view
-      );
+      instanceList = new ProcessInstanceList(proc, "Process Instances", view);
 
       // ---------------
 
@@ -99,87 +95,21 @@
 
       // ----------------------------------------
 
-      Panel detailsForm = assembleDetailsForm();
-      tokenEditorPanel = new Panel("Tokens");
-      tokenEditorPanel.setIconCls("bpm-tools-icon");
-
-      tabPanel.add( detailsForm );
-      tabPanel.add(tokenEditorPanel);
-
-      // ----------------------------------
-
-      HelpPanel help = new HelpPanel(UIConstants.TEASER_PANEL_WIDTH, 200, "Managing process instances");
-
-      TeaserPanel teaserPanel = new TeaserPanel();
-      teaserPanel.add(help);
-
-      // ----------------------------------
-
-      leftHand.add(instanceList);
-      leftHand.add(tabPadding);
-
-      this.add(leftHand, new ColumnLayoutData(0.7) );
-      this.add(teaserPanel , new ColumnLayoutData(0.3) );
-
-   }
-
-   private Panel assembleDetailsForm()
-   {
-      // ---------------
-
-      Panel outerFormPanel = new Panel();
-      outerFormPanel.setTitle("Instance Details");
-      outerFormPanel.setBorder(false);
-      outerFormPanel.setFrame(false);
-
-      // ---------------
-
-      detailsForm = FormWidgets.createBaseFormPanel();
-
-      // ---------------
-
-      TextField idField = new TextField("Id", "instanceId", 230);
-      idField.setReadOnly(true);
-      detailsForm.add(idField);
-      TextField keyField = new TextField("Key", "key", 230);
-      keyField.setReadOnly(true);
-      detailsForm.add(keyField);
-      TextField stateField = new TextField("State", "state", 230);
-      stateField.setReadOnly(true);
-      detailsForm.add(stateField);
-      DateField startDateField = new DateField("Start Date", "startDate", 230);
-      startDateField.setReadOnly(true);
-      detailsForm.add(startDateField);
-      //detailsForm.add(new DateField("End Date", "endDate", 230)); 
-
-      final Button suspendButton = new Button("Suspend",
-            new ButtonListenerAdapter()
-            {
-               public void onClick(Button button, EventObject eventObject)
-               {
-                  selectedInstance.setState(ProcessInstanceRef.STATE.SUSPENDED);
-                  persistStateChange();
-               }
-            }
+      modelModificationCallback = new ModelModificationCallback()
+      {
+         public void onStaleModel()
+         {
+            resetEditor();
+         }
+      };
+      Panel detailsForm = new ProcessInstanceDetailForm(view,
+            modelModificationCallback
       );
+      modelListeners.addListener( (ModelChangeListener) detailsForm);
 
-      final Button resumeButton = new Button("Resume",
-            new ButtonListenerAdapter()
-            {
-
-               public void onClick(Button button, EventObject eventObject)
-               {
-                  selectedInstance.setState(ProcessInstanceRef.STATE.RUNNING);
-                  persistStateChange();
-               }
-            }
-      );
-
-      detailsForm.addButton(suspendButton);
-      detailsForm.addButton(resumeButton);
-
       // ----------------
 
+
       final RowSelectionModel sm = new RowSelectionModel(true);
       sm.addListener(
             new RowSelectionListenerAdapter()
@@ -188,32 +118,15 @@
                {
                   selectedInstance = ProcessInstanceList.transform(record);
 
-                  if(selectedInstance.isSuspended())
-                  {
-                     suspendButton.disable();
-                     resumeButton.enable();
-                  }
-                  else
-                  {
-                     resumeButton.disable();
-                     suspendButton.enable();
-                  }
+                  modelListeners.fireRecordChangeEvent(record);
+                  modelListeners.fireModelChangeEvent(selectedInstance);
 
-                  detailsForm.getForm().loadRecord(record);
-                  detailsForm.doLayout();
-
-                  final TokenEditor.SignalCallback callback = new TokenEditor.SignalCallback()
-                  {
-                     public void onSignalToken(TokenReference tok, String signal)
-                     {
-                        Log.debug("signal -> " +signal );
-                        remoteSignal(tok, signal);
-                     }
-                  };
-
+                  // --------------------
+                  
                   // token form update
+                  // TODO: can't this use ModelChangeListener callbacks as well?
                   tokenEditorPanel.clear();
-                  currentTokenEditor = new TokenEditor(selectedInstance, callback);
+                  currentTokenEditor = new TokenEditor(view, selectedInstance, modelModificationCallback);
                   tokenEditorPanel.add(   // TODO: LRU caching (i.e. last 5)
                         currentTokenEditor
                   );
@@ -223,80 +136,30 @@
       );
       instanceList.setRowSelectionModel(sm);
 
-      outerFormPanel.add(detailsForm);
-      return outerFormPanel;
-   }
 
+      tokenEditorPanel = new Panel("Tokens");
+      tokenEditorPanel.setIconCls("bpm-tools-icon");
 
-   
-   private void remoteSignal(TokenReference tok, String signal)
-   {
+      tabPanel.add( detailsForm );
+      tabPanel.add(tokenEditorPanel);
 
-      String url = signal.equals(UIConstants.DEFAULT_TRANSITION) ?
-            view.getUrlBuilder().getTokenSignalUrl(tok) :
-            view.getUrlBuilder().getTokenSignalUrl(tok, signal);
-      
-      RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
+      // ----------------------------------
 
-      try
-      {
-         rb.sendRequest(null,
-               new RequestCallback() {
+      HelpPanel help = new HelpPanel(UIConstants.TEASER_PANEL_WIDTH, 200, "Managing process instances");
 
-                  public void onResponseReceived(Request request, Response response)
-                  {
-                     if(response.getStatusCode()!=200)
-                        Log.error("Signaling failed: " +response.getText());
-                     else
-                        resetEditor();
-                  }
+      TeaserPanel teaserPanel = new TeaserPanel();
+      teaserPanel.add(help);
 
-                  public void onError(Request request, Throwable t)
-                  {
-                     // Unknown error
-                     Log.error("Unknown error", t);
-                  }
-               });
-      }
-      catch (RequestException e1)
-      {
-         Log.error("Request failed", e1);
-      }
-   }
+      // ----------------------------------
 
-   private void persistStateChange()
-   {
-      RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, view.getUrlBuilder().getStateChangeURL(
-            selectedInstance.getInstanceId(), selectedInstance.getState())
-      );
+      leftHand.add(instanceList);
+      leftHand.add(tabPadding);
 
-      try
-      {
-         rb.sendRequest(null,
-               new RequestCallback() {
+      this.add(leftHand, new ColumnLayoutData(0.7) );
+      this.add(teaserPanel , new ColumnLayoutData(0.3) );
 
-                  public void onResponseReceived(Request request, Response response)
-                  {
-                     if(response.getStatusCode()!=200)
-                        Log.error("Failed to change state: " +response.getStatusText());
-                     else
-                        resetEditor();
-                  }
-
-                  public void onError(Request request, Throwable t)
-                  {
-                     // Unknown error
-                     Log.error("Unknown error", t);
-                  }
-               });
-      }
-      catch (RequestException e1)
-      {
-         Log.error("Request failed", e1);
-      }
    }
 
-
    public String getEditorId()
    {
       return getId();
@@ -318,14 +181,12 @@
       instanceList.reloadStore();
       selectedInstance = null;
 
-      detailsForm.getForm().reset();
-      
       if(currentTokenEditor!=null)
          currentTokenEditor.resetEditor();
 
       tokenEditorPanel.clear();
       tokenEditorPanel.doLayout();
-      
+
       //tabPanel.setActiveTab(0);
    }
 }

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/TokenEditor.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/TokenEditor.java	2008-11-21 11:31:29 UTC (rev 3026)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/TokenEditor.java	2008-11-21 11:42:46 UTC (rev 3027)
@@ -21,6 +21,8 @@
  */
 package org.jboss.bpm.console.client.process;
 
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.http.client.*;
 import com.gwtext.client.core.EventObject;
 import com.gwtext.client.data.Node;
 import com.gwtext.client.widgets.Panel;
@@ -29,6 +31,9 @@
 import com.gwtext.client.widgets.tree.TreeNode;
 import com.gwtext.client.widgets.tree.TreePanel;
 import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
+import org.jboss.bpm.console.client.MainView;
+import org.jboss.bpm.console.client.UIConstants;
+import org.jboss.bpm.console.client.widgets.ModelModificationCallback;
 import org.jboss.bpm.console.client.model.ProcessInstanceRef;
 import org.jboss.bpm.console.client.model.jbpm3.TokenReference;
 
@@ -40,11 +45,19 @@
 
    private TokenForm tokenForm;
    private TokenTree tokenTree;
+   private MainView mainView;
+   private ModelModificationCallback callback;
 
-   public TokenEditor(final ProcessInstanceRef instance, final SignalCallback callback)
+   public TokenEditor(
+         MainView mainView, final ProcessInstanceRef instance,
+         ModelModificationCallback callback
+   )
    {
       super();
 
+      this.mainView = mainView;
+      this.callback = callback;
+
       this.setHeader(false);
       this.setBorder(false);
       this.setFrame(false);
@@ -68,8 +81,17 @@
 
       // ----------------
 
-      tokenForm = new TokenForm(callback);      
+      tokenForm = new TokenForm(
+            new SignalCallback()
+            {
 
+               public void onSignalToken(TokenReference tok, String signal)
+               {
+                  remoteSignal(tok, signal);
+               }
+            }
+      );
+
       // ----------------
 
       this.add(tokenTree, new ColumnLayoutData(0.3));
@@ -142,5 +164,43 @@
    {
       void onSignalToken(TokenReference tok, String signal);
    }
+
+   private void remoteSignal(TokenReference tok, String signal)
+   {
+
+      String url = signal.equals(UIConstants.DEFAULT_TRANSITION) ?
+            mainView.getUrlBuilder().getTokenSignalUrl(tok) :
+            mainView.getUrlBuilder().getTokenSignalUrl(tok, signal);
+
+      RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
+
+      try
+      {
+         rb.sendRequest(null,
+               new RequestCallback() {
+
+                  public void onResponseReceived(Request request, Response response)
+                  {
+                     if(response.getStatusCode()!=200)
+                        Log.error("Signaling failed: " +response.getText());
+                     else
+                     {
+                        resetEditor();
+                        callback.onStaleModel();
+                     }
+                  }
+
+                  public void onError(Request request, Throwable t)
+                  {
+                     // Unknown error
+                     Log.error("Unknown error", t);
+                  }
+               });
+      }
+      catch (RequestException e1)
+      {
+         Log.error("Request failed", e1);
+      }
+   }
 }
 

Added: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/widgets/ModelModificationCallback.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/widgets/ModelModificationCallback.java	                        (rev 0)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/widgets/ModelModificationCallback.java	2008-11-21 11:42:46 UTC (rev 3027)
@@ -0,0 +1,32 @@
+/*
+ * 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.widgets;
+
+import org.jboss.bpm.console.client.model.ProcessInstanceRef;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ModelModificationCallback
+{
+   void onStaleModel();
+}




More information about the jbpm-commits mailing list