cashew-s-editor-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[CASHeW-s-editor-patches] Nodes number bugs solved!


From: Xianfeng Liu
Subject: [CASHeW-s-editor-patches] Nodes number bugs solved!
Date: Mon, 11 Apr 2005 21:59:38 +0100

Dear all,
I Just solved the autoid bugs in the codes. I deleted the list and iterator in 
the NodeRegistrar.java which is useless and slow. the autoid will +1 when 
create a node manually or from the parser!

Roger    address@hidden

Index: resource/plugin.xml
===================================================================
RCS file: plugin.xml
diff -N plugin.xml
--- /tmp/cvsAAACWaive Mon Apr 11 21:54:47 2005
+++ /dev/null Mon Apr 11 21:45:29 2005
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin id="nongnu.cashews.eclipse.composer"
-   name="CASheW-s"
-   version="0.0.0"
-   provider-name="The CASheW-s Project"
-   class="nongnu.cashews.eclipse.composer.Plugin">
-
-   <runtime>
-      <library name="composer.jar"/>
-   </runtime>
-   <requires>
-      <import plugin="org.eclipse.core.runtime"/>
-      <import plugin="org.eclipse.gef"/>
-      <import plugin="org.eclipse.core.resources"/>
-      <import plugin="org.eclipse.ui.views"/>
-      <import plugin="org.eclipse.jface"/>
-      <import plugin="org.eclipse.ui"/>
-      <import plugin="org.eclipse.ui.workbench"/>
-      <import plugin="org.eclipse.ui.cheatsheets"/>
-      <import plugin="org.eclipse.ui.console"/>
-      <import plugin="org.eclipse.ui.editors"/>
-      <import plugin="org.eclipse.ui.externaltools"/>
-      <import plugin="org.eclipse.ui.forms"/>
-      <import plugin="org.eclipse.ui.ide"/>
-      <import plugin="org.eclipse.ui.intro"/>
-   </requires>
-
-   <extension point="org.eclipse.ui.editors">
-      <editor id="nongnu.cashews.eclipse.composer.editor"
-            name="Cashews Editor"
-            default="true"
-            icon=""
-            extensions="composer"
-            
contributorClass="nongnu.cashews.eclipse.composer.actions.DiagramActionBarContributor"
-            class="nongnu.cashews.eclipse.composer.ui.DiagramEditor">
-      </editor>
-   </extension>
-
-   <extension point="org.eclipse.ui.newWizards">
-      <category id="nongnu.cashews.eclipse.composer" name="Composer"/>
-      <wizard id="nongnu.cashews.eclipse.composer.wizard.new.file"
-            name="Composer Model"
-            category="nongnu.cashews.eclipse.composer"
-            class="nongnu.cashews.eclipse.composer.ui.DiagramCreationWizard">
-         <description>Wizard for creating a new CASheW-s process 
diagram.</description>
-         <selection class="org.eclipse.core.resources.IResource">
-         </selection>
-      </wizard>
-   </extension>
-
-</plugin>
\ No newline at end of file
Index: src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java
===================================================================
RCS file: 
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java,v
retrieving revision 1.7
diff -u -r1.7 DeleteNodeCommand.java
--- src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java 
2005/03/28 04:28:51 1.7
+++ src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java 
2005/04/11 20:54:45
@@ -37,6 +37,7 @@
 
 package nongnu.cashews.eclipse.composer.commands;
 
+import nongnu.cashews.eclipse.composer.model.Connection;
 import nongnu.cashews.eclipse.composer.model.Diagram;
 import nongnu.cashews.eclipse.composer.model.Node;
 import nongnu.cashews.eclipse.composer.model.NodeRegistrar;
@@ -51,6 +52,7 @@
 
   private Node node;
 
+  private Connection connection;
   // setters
 
   public void setDiagram(Diagram diagram)
@@ -62,7 +64,10 @@
   {
     this.node = node;
   }
-
+  
+  public void setConnection (Connection connection){
+   this.connection = connection;   
+  }
   // ------------------------------------------------------------------------
   // Overridden from Command
 
Index: src/nongnu/cashews/eclipse/composer/commands/DiagramSingleton.java
===================================================================
RCS file: 
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/commands/DiagramSingleton.java,v
retrieving revision 1.1
diff -u -r1.1 DiagramSingleton.java
--- src/nongnu/cashews/eclipse/composer/commands/DiagramSingleton.java 
2005/04/03 14:11:50 1.1
+++ src/nongnu/cashews/eclipse/composer/commands/DiagramSingleton.java 
2005/04/11 20:54:45
@@ -45,7 +45,7 @@
 */
 public class DiagramSingleton
 {
- private Diagram diagram;
+ private Diagram diagram = new Diagram();
 
  private static DiagramSingleton ds;
  static
Index: src/nongnu/cashews/eclipse/composer/model/DiagramParser.java
===================================================================
RCS file: 
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/DiagramParser.java,v
retrieving revision 1.11
diff -u -r1.11 DiagramParser.java
--- src/nongnu/cashews/eclipse/composer/model/DiagramParser.java 2005/04/11 
00:11:25 1.11
+++ src/nongnu/cashews/eclipse/composer/model/DiagramParser.java 2005/04/11 
20:54:45
@@ -73,6 +73,7 @@
     d = new Diagram();
     sourceList = new ArrayList<String>();
     targetList = new ArrayList<String>();
+    
   }
 
   public void endDocument()
@@ -173,6 +174,17 @@
             diagramNodeCount++;
           }
       }
+    int max = 0; 
+    for (int k = 0; k < d.nodes.size(); k++) { 
+          Node cur = (Node) d.nodes.get(k); 
+          int tmp = Integer.parseInt(cur.getName().substring(8));
+          if (cur.getName().startsWith("Untitled") && tmp > max)
+          { max = tmp; } 
+        }
+        System.out.println("Max autoId node is: " + max);
+        NodeRegistrar.setMax(max);
+        
+
   }
 
   public void startElement(String uri, String name, String qName,
Index: src/nongnu/cashews/eclipse/composer/model/NodeFactory.java
===================================================================
RCS file: 
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/NodeFactory.java,v
retrieving revision 1.8
diff -u -r1.8 NodeFactory.java
--- src/nongnu/cashews/eclipse/composer/model/NodeFactory.java 2005/04/10 
17:29:03 1.8
+++ src/nongnu/cashews/eclipse/composer/model/NodeFactory.java 2005/04/11 
20:54:46
@@ -63,10 +63,16 @@
 
   public Node getNewObject()
   {
+    NodeRegistrar nr = new NodeRegistrar();
+    autoId = nr.getMax()+1;
     do
       {
+        System.out.println("Create node autoId is: " + autoId);
         node = createNode("Untitled" + autoId);
-        ++autoId;
+        nr.setMax(autoId);
+        autoId++;
+        
+        System.out.println("Creating node: Untitled" + autoId);
       }
     while (!NodeRegistrar.registerNewNode(
                                           node.getName(),
@@ -80,25 +86,22 @@
     Matcher matcher = untitled.matcher(name);
     if (matcher.matches())
       {
-        int serializedId = Integer.parseInt(matcher.group().substring(8));
+        int serializedId = Integer.parseInt(matcher.group(1));
         System.out.println("Parsing the: " + serializedId + " node");
         autoId = serializedId + 1;
-
+        System.out.println("Auto id is " + autoId);
       }
-     System.out.println("Finish parsing " + name);
-   NodeRegistrar.registerNewNode(
-     name,
-     DiagramSingleton.getInstance().getDiagram());
+    System.out.println("Finish parsing " + name);
+    NodeRegistrar.registerNewNode(name,
+                                  DiagramSingleton.getInstance().getDiagram());
     node = createNode(name);
-   
-    /*if (!NodeRegistrar.registerNewNode(
-                                       node.getName(),
-                                       
DiagramSingleton.getInstance().getDiagram()))
-      {
-        throw new IllegalStateException("A node with one of the "
-                                        + "deserialized names already "
-                                        + "exists.");
-      }*/
+
+    /*
+     * if (!NodeRegistrar.registerNewNode( node.getName(),
+     * DiagramSingleton.getInstance().getDiagram())) { throw new
+     * IllegalStateException("A node with one of the " + "deserialized names
+     * already " + "exists."); }
+     */
     return node;
   }
 
Index: src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java
===================================================================
RCS file: 
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java,v
retrieving revision 1.8
diff -u -r1.8 NodeRegistrar.java
--- src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java 2005/04/08 
02:07:17 1.8
+++ src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java 2005/04/11 
20:54:46
@@ -38,52 +38,77 @@
 
 package nongnu.cashews.eclipse.composer.model;
 
+import java.util.ArrayList;
 import java.util.HashSet;
-
+import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
+
+
 /**
  * @author Andrew John Hughes (address@hidden)
  * @author Xianfeng Liu (address@hidden)
  */
+
 public class NodeRegistrar
 {
 
   private static Set<String> names;
-  // private static List<String> temps;
-  // private static int max;
+
+  private static List<String> temps;
+
+  private static int max;
 
   static
     {
       names = new HashSet<String>();
-      // temps = new ArrayList<String>();
+      temps = new ArrayList<String>();
     }
 
   public static boolean registerNewNode(String name, Diagram d)
   {
-    /*
-     * Iterator i = d.nodes.iterator(); names.clear(); int m=0; max = 0; String
-     * curName;
-     * 
-     * while(i.hasNext()) { curName = ((Node)i.next()).getName(); m =
-     * Integer.parseInt(curName.substring(8)); if( max < m) { max = m; }
-     * names.add(curName); }
-     */
-    /*
-     * Iterator it = names.iterator(); while (it.hasNext()){ temps.add((String)
-     * it.next()); } System.out.println("There are: " + temps.size() + 
"nodes");
-     */
 
+    /*Iterator i = d.nodes.iterator();
+     //names.clear();
+    int m = 0;
+    String curName;
+
+    while (i.hasNext())
+      {
+        curName = ((Node) i.next()).getName();
+        
+            m = Integer.parseInt(curName.substring(8));
+            if (max < m)
+              {
+                max = m;
+              }
+          
+      }*/
+   // System.out.println("New Max is:" + max);
     if (names.contains(name))
-      return false;
-    names.add(name);
-    return true;
+      {
+        return false;
+      }
+    else
+      {
+        names.add(name);
+        return true;
+      }
+
   }
+
+  public static void setMax(int x)
+  {
+    max = x;
 
-  /*
-   * public static void setMax(int x) { max = x; } public static int getMax() {
-   * return max; }
-   */
+  }
+
+  public int getMax()
+  {
+    return max;
+
+  }
 
   public static boolean renameNode(String oldName, String newName, Diagram d)
   {
@@ -99,6 +124,7 @@
   public static void removeNode(String name)
   {
     names.remove(name);
+    
   }
 
 }
Index: plugin.xml
===================================================================
RCS file: plugin.xml
diff -N plugin.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ plugin.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin id="nongnu.cashews.eclipse.composer"
+   name="CASheW-s"
+   version="0.0.0"
+   provider-name="The CASheW-s Project"
+   class="nongnu.cashews.eclipse.composer.Plugin">
+
+   <runtime>
+      <library name="composer.jar"/>
+   </runtime>
+   <requires>
+      <import plugin="org.eclipse.core.runtime"/>
+      <import plugin="org.eclipse.gef"/>
+      <import plugin="org.eclipse.core.resources"/>
+      <import plugin="org.eclipse.ui.views"/>
+      <import plugin="org.eclipse.jface"/>
+      <import plugin="org.eclipse.ui"/>
+      <import plugin="org.eclipse.ui.workbench"/>
+      <import plugin="org.eclipse.ui.cheatsheets"/>
+      <import plugin="org.eclipse.ui.console"/>
+      <import plugin="org.eclipse.ui.editors"/>
+      <import plugin="org.eclipse.ui.externaltools"/>
+      <import plugin="org.eclipse.ui.forms"/>
+      <import plugin="org.eclipse.ui.ide"/>
+      <import plugin="org.eclipse.ui.intro"/>
+   </requires>
+
+   <extension point="org.eclipse.ui.editors">
+      <editor id="nongnu.cashews.eclipse.composer.editor"
+            name="Cashews Editor"
+            default="true"
+            icon=""
+            extensions="composer"
+            
contributorClass="nongnu.cashews.eclipse.composer.actions.DiagramActionBarContributor"
+            class="nongnu.cashews.eclipse.composer.ui.DiagramEditor">
+      </editor>
+   </extension>
+
+   <extension point="org.eclipse.ui.newWizards">
+      <category id="nongnu.cashews.eclipse.composer" name="Composer"/>
+      <wizard id="nongnu.cashews.eclipse.composer.wizard.new.file"
+            name="Composer Model"
+            category="nongnu.cashews.eclipse.composer"
+            class="nongnu.cashews.eclipse.composer.ui.DiagramCreationWizard">
+         <description>Wizard for creating a new CASheW-s process 
diagram.</description>
+         <selection class="org.eclipse.core.resources.IResource">
+         </selection>
+      </wizard>
+   </extension>
+
+</plugin>

Attachment: NodesNumBugsSolved.diff
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]