phew, finally finished the WGC 'gui-demo'

gskc [2001-05-31 21:11:15]
phew, finally finished the WGC 'gui-demo'
Filename
PCM_Visual.java
PersonalCacheModuleImpl.java
WGCSienaRuleEngineImpl.java
WGC_Manager_Visual.java
WorkgroupManagerImpl.java
diff --git a/PCM_Visual.java b/PCM_Visual.java
index 8b81178..a081b6f 100644
--- a/PCM_Visual.java
+++ b/PCM_Visual.java
@@ -8,6 +8,8 @@ import java.awt.GridLayout;
 import java.awt.GridBagConstraints;

 import java.awt.Button;
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.Frame;
@@ -84,10 +86,13 @@ public class PCM_Visual {
  private static final int MAX_WIDTH = 500;
   private GridBagConstraints _botPanel1_3_1GBC = null;
   private Label       _botPanel1_3_WGLabel = null;
   private Label       _botPanel1_3_UsersLabel = null;
+  private Label       _botPanel1_3_TypeLabel = null;
   private TextField   _botPanel1_3_WGText = null;
   private TextField   _botPanel1_3_UsersText = null;
-  private Button      _botPanel1_3_CreateWG_But = null;
-  private Button      _botPanel1_3_JoinWG_But = null;
+  private CheckboxGroup _botPanel1_3_TypeCBoxGrp = null;
+  private Checkbox    _botPanel1_3_TypeCheckbox1 = null;
+  private Checkbox    _botPanel1_3_TypeCheckbox2 = null;
+  private Button      _botPanel1_3_AddWG_But = null;
   private Button      _botPanel1_3_ESCBut = null;
   private TextArea    _botPanel2_TextArea = null;
   // Personal Cache Module stuff ///////////////////////
@@ -230,20 +235,22 @@ public class PCM_Visual {
  private static final int MAX_WIDTH = 500;
     _botPanel1_3_WGLabel.setFont(_mediumFont);
     _botPanel1_3_UsersLabel = new Label("Users: ", Label.RIGHT);
     _botPanel1_3_UsersLabel.setFont(_mediumFont);
+    _botPanel1_3_TypeLabel = new Label("Type: ", Label.RIGHT);
+    _botPanel1_3_TypeLabel.setFont(_mediumFont);
     _botPanel1_3_WGText = new TextField();
     _botPanel1_3_WGText.setForeground(Color.white);
     _botPanel1_3_WGText.setBackground(_buttonColour);
     _botPanel1_3_UsersText = new TextField();
+    _botPanel1_3_UsersText.setEnabled(false);
     _botPanel1_3_UsersText.setForeground(Color.white);
     _botPanel1_3_UsersText.setBackground(_buttonColour);
-    _botPanel1_3_CreateWG_But = new Button("Create");
-    _botPanel1_3_CreateWG_But.setFont(_largeFont);
-    _botPanel1_3_CreateWG_But.setForeground(Color.white);
-    _botPanel1_3_CreateWG_But.setBackground(_buttonColour);
-    _botPanel1_3_JoinWG_But = new Button("Join");
-    _botPanel1_3_JoinWG_But.setFont(_largeFont);
-    _botPanel1_3_JoinWG_But.setForeground(Color.white);
-    _botPanel1_3_JoinWG_But.setBackground(_buttonColour);
+    _botPanel1_3_TypeCBoxGrp = new CheckboxGroup();
+    _botPanel1_3_TypeCheckbox1 = new Checkbox("Create", _botPanel1_3_TypeCBoxGrp, true);
+    _botPanel1_3_TypeCheckbox2 = new Checkbox("Join", _botPanel1_3_TypeCBoxGrp, false);
+    _botPanel1_3_AddWG_But = new Button("Add");
+    _botPanel1_3_AddWG_But.setFont(_largeFont);
+    _botPanel1_3_AddWG_But.setForeground(Color.white);
+    _botPanel1_3_AddWG_But.setBackground(_buttonColour);
     _botPanel1_3_ESCBut = new Button("Cancel");
     _botPanel1_3_ESCBut.setFont(_largeFont);
     _botPanel1_3_ESCBut.setForeground(Color.white);
@@ -261,35 +268,25 @@ public class PCM_Visual {
  private static final int MAX_WIDTH = 500;
     _botPanel1_3_1.add(_botPanel1_3_UsersLabel);
     _botPanel1_3_1GBL.setConstraints(_botPanel1_3_UsersText, _botPanel1_3_1GBC);
     _botPanel1_3_1.add(_botPanel1_3_UsersText);
+    _botPanel1_3_1.add(_botPanel1_3_TypeLabel);
+    _botPanel1_3_1.add(_botPanel1_3_TypeCheckbox1);
+    _botPanel1_3_1.add(_botPanel1_3_TypeCheckbox2);
     // ------------------------------------------------------------------------------- //
     _botPanel1_3.add(_botPanel1_3_2 = new Panel(new GridLayout(1, 3)));
-    _botPanel1_3_2.add(_botPanel1_3_CreateWG_But);
-    _botPanel1_3_CreateWG_But.addActionListener(new ActionListener() {
+    _botPanel1_3_2.add(_botPanel1_3_AddWG_But);
+    _botPanel1_3_AddWG_But.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
         String wgName = _botPanel1_3_WGText.getText();
         if (! wgName.equals("")) {
-          try {
-            _pcmi.createWorkgroup(wgName);
-            workgroupAdded(wgName);
-          } catch (WGCException wgce) { }
-        }
-        _botPanel1_3_WGText.setText("");
-        _botPanel1_3_UsersText.setText("");
-        ((CardLayout) _botPanel1.getLayout()).show(_botPanel1, "TOP");
-      }
-    });
-    _botPanel1_3_2.add(_botPanel1_3_JoinWG_But);
-    _botPanel1_3_JoinWG_But.addActionListener(new ActionListener() {
-      public void actionPerformed(ActionEvent ae) {
-        String wgName = _botPanel1_3_WGText.getText();
-        if (! wgName.equals("")) {
-          try {
-            _pcmi.joinWorkgroup(wgName);
-            workgroupAdded(wgName);
-          } catch (WGCException wgce) { }
+          try {
            if (_botPanel1_3_TypeCheckbox1.getState()) {
              _pcmi.createWorkgroup(wgName);
            } else {
              _pcmi.joinWorkgroup(wgName);
            }
+            // workgroupAdded(wgName);
+          } catch (WGCException wgce) {
+            wgce.printStackTrace();
+          }
         }
         _botPanel1_3_WGText.setText("");
         _botPanel1_3_UsersText.setText("");
+        _botPanel1_3_TypeCheckbox1.setState(true);
         ((CardLayout) _botPanel1.getLayout()).show(_botPanel1, "TOP");
       }
     });
@@ -298,6 +295,7 @@ public class PCM_Visual {
  private static final int MAX_WIDTH = 500;
       public void actionPerformed(ActionEvent ae) {
         _botPanel1_3_WGText.setText("");
         _botPanel1_3_UsersText.setText("");
+        _botPanel1_3_TypeCheckbox1.setState(true);
         ((CardLayout) _botPanel1.getLayout()).show(_botPanel1, "TOP");
       }
     });
diff --git a/PersonalCacheModuleImpl.java b/PersonalCacheModuleImpl.java
index 97872c5..9d9a147 100644
--- a/PersonalCacheModuleImpl.java
+++ b/PersonalCacheModuleImpl.java
@@ -307,6 +307,7 @@ public class PersonalCacheModuleImpl implements PersonalCacheModule {
     try {
       wgm.newWorkgroup(wgName);
       wgm.joinWorkgroup(wgName, url,roleName);
+      if (pcmv != null) pcmv.workgroupAdded(wgName);
       //wg.addmember(this);
       //wgm.setWorkgroup(wg);
       wgVec.addElement(wgName);
@@ -325,8 +326,8 @@ public class PersonalCacheModuleImpl implements PersonalCacheModule {

   public void joinWorkgroup(String wgName) throws WGCException  {
     try {
-      wgm.joinWorkgroup(wgName,url,roleName);
-    }catch (Exception e){
+      wgm.joinWorkgroup(wgName,url,roleName);
      if (pcmv != null) pcmv.workgroupAdded(wgName);
+    } catch (Exception e){
       System.out.println("ERROR: Server connection problem in joinWorkgroup");
       e.printStackTrace();
     }
diff --git a/WGCSienaRuleEngineImpl.java b/WGCSienaRuleEngineImpl.java
index f2b8305..0ced44d 100644
--- a/WGCSienaRuleEngineImpl.java
+++ b/WGCSienaRuleEngineImpl.java
@@ -99,7 +99,47 @@ public class WGCSienaRuleEngineImpl implements Runnable, Notifiable, WGCRuleEngi
       e.printStackTrace();
     }
   }
-
+  
  public void addRule(String instigator, String target, boolean isModule) {
+    log("Generating SmartEvent - addRule");    
    /*
+    Hashtable metaData = new Hashtable();
+    int SrcId = 235324;
+    metaData.put("type", new siena.AttributeValue("WGCRule"));
+    metaData.put("hostname", new siena.AttributeValue(hostname));
+    metaData.put("Instigator", new siena.AttributeValue(instigator));
+    metaData.put("DataHandle", new siena.AttributeValue((String) dataHandle.key));
+    */
    
    String WGC_RULE_TARGET_TYPE = isModule ? "Module" : "Workgroup";
+    String WGC_RULE_NAME = instigator + target + WGC_RULE_TARGET_TYPE;
+    String WGC_RULE_INSTIGATOR = instigator;
+    String WGC_RULE_TARGET = target;
+    
    String xmlRule = null;
+    Notification n = KXNotification.EDManagerAddRule(xmlRule =
+    "<rule name=\"" + WGC_RULE_NAME + "\">                                                                                         \n" +
+    "  <states>                                                                                                       \n" +
+    "    <state name=\"startState\" timebound=\"-1\" children=\"\" actions=\"ruleAction\" fail_actions=\"\">          \n" +
+    "      <attribute name=\"Instigator\" value=\"" + WGC_RULE_INSTIGATOR + "\"/>                                     \n" +
+    "      <attribute name=\"DataHandle\" value=\"*1\"/>                                                              \n" +
+    "    </state>                                                                                                     \n" +
+    "  </states>                                                                                                      \n" +
+    "  <actions>                                                                                                      \n" +
+    "    <notification name=\"ruleAction\">                                                                           \n" +
+    "      <attribute name=\"Instigator\" value=\"" + WGC_RULE_INSTIGATOR + "\"/>                                     \n" +
+    "      <attribute name=\"Action\" value=\"Push\"/>                                                                \n" +
+    "      <attribute name=\"Target\" value=\"" + WGC_RULE_TARGET_TYPE + "\"/>                                        \n" +
+    "      <attribute name=\"TargetName\" value=\"" + WGC_RULE_TARGET + "\"/>                                         \n" +
+    "      <attribute name=\"DataHandle\" value=\"*1\"/>                                                              \n" +
+    "    </notification>                                                                                              \n" +
+    "  </actions>                                                                                                     \n" +
+    "</rule>                                                                                                          \n");
+
+    try {
+      if (InternalED_RuleEngine != null) {
+        log("informing embedded ED-rule-engine of added rule");
+        InternalED_RuleEngine.notify(n);
      } else {
+        // send put-event to ED-rule-engine via Siena
+        si.publish(n);
      }
+    } catch (siena.SienaException se) {
+      se.printStackTrace();
    }
  }
+
   private void generatePutEvent(String instigator, String hostname, Cacheable dataHandle) {
     log("Generating SmartEvent");
     Hashtable metaData = new Hashtable();
diff --git a/WGC_Manager_Visual.java b/WGC_Manager_Visual.java
index c948b25..0e6f804 100644
--- a/WGC_Manager_Visual.java
+++ b/WGC_Manager_Visual.java
@@ -31,9 +31,9 @@ import javax.swing.SwingConstants;

 import java.util.Hashtable;

-import psl.wgcache.Cacheable;
-import psl.wgcache.PersonalCacheModuleImpl;
-import psl.wgcache.WGCException;
+// import psl.wgcache.Cacheable;
+// import psl.wgcache.PersonalCacheModuleImpl;
+// import psl.wgcache.WGCException;

 public class WGC_Manager_Visual {
   private static final int MAX_WIDTH = 600;
@@ -242,8 +242,8 @@ public class WGC_Manager_Visual {
         String target = _botPanel1_2_TargetText.getText();
         if (! instigator.equals("") && ! target.equals("")) {
           // _pcmi.put(new Cacheable(key, data, data.length()));
-          // create the new XML push rule in here
-          pushRuleAdded(instigator, target, _botPanel1_2_TypeCheckbox2.getState());
+          // create the new XML push rule in here
          WorkgroupServer.wgm.addRule(instigator, target, _botPanel1_2_TypeCheckbox1.getState());
          System.out.println("isModule: " + _botPanel1_2_TypeCheckbox1.getState());
+          // pushRuleAdded(instigator, target, _botPanel1_2_TypeCheckbox2.getState());
         }
         _botPanel1_2_InstigatorText.setText("");
         _botPanel1_2_TargetText.setText("");
@@ -396,17 +396,17 @@ public class WGC_Manager_Visual {

   private final static Color _moduleColour = new Color(129, 158, 193); // mauve
   private final static Color _groupColour = Color.green;
-  void pushRuleAdded(String instigator, String target, boolean targetIsGroup) {
+  void pushRuleAdded(String instigator, String target, boolean targetIsModule) {
     if (instigator.equals("") || target.equals("")) return;
     Panel p = new Panel(new GridLayout(1, 2));
     TextField tfInstigator, tfTarget;
     p.add(tfInstigator = new TextField(instigator));
     p.add(tfTarget = new TextField(target));
-    tfInstigator.setBackground(targetIsGroup ? _groupColour : _moduleColour);
-    tfTarget.setBackground(targetIsGroup ? _groupColour : _moduleColour);
+    tfInstigator.setBackground(targetIsModule ? _moduleColour : _groupColour);
+    tfTarget.setBackground(targetIsModule ? _moduleColour : _groupColour);
     _midPanel1_1.add(p);
     p.validate(); _midPanel1Scp.validate(); _midPanel1_1.validate();
-    System.out.println("Entered pushRuleAdded: " + instigator + ", " + target + ", " + targetIsGroup);
+    System.out.println("Entered pushRuleAdded: " + instigator + ", " + target + ", " + targetIsModule);
   }

   void memberJoined(String wgName, String memberName) {
diff --git a/WorkgroupManagerImpl.java b/WorkgroupManagerImpl.java
index 06c2482..be259af 100644
--- a/WorkgroupManagerImpl.java
+++ b/WorkgroupManagerImpl.java
@@ -226,6 +226,8 @@ public class WorkgroupManagerImpl extends UnicastRemoteObject implements java.io
       log("QueryTag provided is null");
     }
     return retVal;
+  }
  
  public void addRule(String instigator, String target, boolean isModule) {
+    wgRule.addRule(instigator, target, isModule);
    if (IS_VISUAL) wgcmv.pushRuleAdded(instigator, target, isModule);
   }

   private void log(String mesg)  {