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

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

[CASHeW-s-editor-patches] Added Error Dialogue


From: X F Liu
Subject: [CASHeW-s-editor-patches] Added Error Dialogue
Date: Mon, 14 Mar 2005 15:20:33 +0000
User-agent: Internet Messaging Program (IMP) 3.2.2


Index: src/nongnu/cashews/eclipse/composer/commands/CreateNodeCommand.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/commands/CreateNodeCommand.java,v
retrieving revision 1.3
diff -u -r1.3 CreateNodeCommand.java
---
src/nongnu/cashews/eclipse/composer/commands/CreateNodeCommand.java     
2005/02/24
20:13:33        1.3
+++
src/nongnu/cashews/eclipse/composer/commands/CreateNodeCommand.java     
2005/03/14
15:16:01
@@ -2,6 +2,7 @@
 
 import nongnu.cashews.eclipse.composer.model.Diagram;
 import nongnu.cashews.eclipse.composer.model.Node;
+import nongnu.cashews.eclipse.composer.model.RectangleNode;
 
 import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.gef.commands.Command;
@@ -14,6 +15,10 @@
    private Point location;
 
 
+   public CreateNodeCommand()
+   {
+     node = new RectangleNode("Fred");
+   }
    // setters
    
    public void setDiagram(Diagram diagram) {
@@ -35,19 +40,19 @@
    public String getLabel() {
       return "Create Node";
    }
-
+   
    public void execute() {
-      if (this.location != null) {
-         this.node.setLocation(this.location);
+      if (location != null) {
+         node.setLocation(location);
       }
-      this.diagram.addNode(this.node);
+      diagram.addNode(node);
    }
 
    public void undo() {
-      this.diagram.removeNode(this.node);
+      diagram.removeNode(node);
    }
 
    public void redo() {
-      this.execute();
+      execute();
    }
 }
Index: src/nongnu/cashews/eclipse/composer/commands/RenameNodeCommand.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/commands/RenameNodeCommand.java,v
retrieving revision 1.3
diff -u -r1.3 RenameNodeCommand.java
---
src/nongnu/cashews/eclipse/composer/commands/RenameNodeCommand.java     
2005/02/24
20:13:33        1.3
+++
src/nongnu/cashews/eclipse/composer/commands/RenameNodeCommand.java     
2005/03/14
15:16:01
@@ -1,6 +1,8 @@
 package nongnu.cashews.eclipse.composer.commands;
 
 import nongnu.cashews.eclipse.composer.model.Node;
+import nongnu.cashews.eclipse.composer.model.NodeRegistrar;
+import nongnu.cashews.eclipse.composer.util.Dialogs;
 
 import org.eclipse.gef.commands.Command;
 
@@ -30,7 +32,13 @@
       return "Rename Node";
    }
 
-   public void execute() {
+   public void execute() 
+   {
+      if (!NodeRegistrar.renameNode(oldName, newName))
+        {
+          Dialogs.displayErrorDialog("This node already exists.");
+          return;
+        }
       oldName = this.node.getName();
       this.node.setName(newName);
    }
Index: src/nongnu/cashews/eclipse/composer/model/Diagram.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/Diagram.java,v
retrieving revision 1.4
diff -u -r1.4 Diagram.java
--- src/nongnu/cashews/eclipse/composer/model/Diagram.java      2005/02/24
20:13:33        1.4
+++ src/nongnu/cashews/eclipse/composer/model/Diagram.java      2005/03/14 
15:16:01
@@ -18,7 +18,7 @@
    public static String NODES = "nodes";
 
    // actual fields
-   protected List nodes = new ArrayList();
+   protected List<Node> nodes = new ArrayList<Node>();
 
    public void addNode(Node node) {
       nodes.add(node);
Index: src/nongnu/cashews/eclipse/composer/model/Element.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/Element.java,v
retrieving revision 1.3
diff -u -r1.3 Element.java
--- src/nongnu/cashews/eclipse/composer/model/Element.java      2005/02/24
20:13:33        1.3
+++ src/nongnu/cashews/eclipse/composer/model/Element.java      2005/03/14 
15:16:04
@@ -8,7 +8,8 @@
 
 // abstract base class of elements in the model
 
-abstract public class Element implements Cloneable, Serializable {
+public abstract class Element
+  implements Cloneable, Serializable {
 
    // serialization version
    static final long serialVersionUID = 1;
Index: src/nongnu/cashews/eclipse/composer/model/Node.java
===================================================================
RCS file:
/share/darwin/darwin4/cvs/java/src/nongnu/cashews/eclipse/composer/model/Node.java,v
retrieving revision 1.6
diff -u -r1.6 Node.java
--- src/nongnu/cashews/eclipse/composer/model/Node.java 2005/03/14 12:41:13     
1.6
+++ src/nongnu/cashews/eclipse/composer/model/Node.java 2005/03/14 15:16:07
@@ -1,3 +1,5 @@
+
+
 package nongnu.cashews.eclipse.composer.model;
 
 import java.util.ArrayList;
@@ -7,129 +9,158 @@
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertySource;
 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
+
+public class Node extends Element implements IPropertySource
+{
+
+  // serialization version
+  static final long serialVersionUID = 4;
+
+  // properties
+  public static final String LOCATION = "location";
+
+  public static final String NAME = "name";
+
+  public static final String INPUTS = "inputs";
+
+  public static final String OUTPUTS = "outputs";
 
-public class Node extends Element implements IPropertySource {
+  // descriptors for property sheet
+  protected static IPropertyDescriptor[] descriptors;
+  static
+    {
+      descriptors = new IPropertyDescriptor[] { new TextPropertyDescriptor(
+                                                                          
NAME,
+                                                                          
"Name") };
+    }
 
-   // serialization version
-   static final long serialVersionUID = 4;
+  // actual fields
+  protected Point location = new Point(0, 0);
 
-   // properties
-   public static final String LOCATION = "location";
-   public static final String NAME = "name";
-   public static final String INPUTS = "inputs";
-   public static final String OUTPUTS = "outputs";
-
-   // descriptors for property sheet
-   protected static IPropertyDescriptor[] descriptors;
-   static {
-      descriptors = new IPropertyDescriptor[] {
-         new TextPropertyDescriptor(NAME, "Name")};
-   }
-
-   // actual fields
-   protected Point location = new Point(0, 0);
-   protected String name = "Node";
-   protected List outputs = new ArrayList(5);
-   protected List inputs = new ArrayList(5);
-
-
-   public void setLocation(Point p) {
-      if (this.location.equals(p)) {
-         return;
-      } 
-      this.location = p;
-      firePropertyChange(LOCATION, null, p);
-   }
-
-   public Point getLocation() {
-      return location;
-   }
-   
-   public void setName(String name) {
-      if (this.name.equals(name)) {
-         return;
-      }
-      this.name = name;
-      firePropertyChange(NAME, null, name);
-   }
-   
-   public String getName() {
-      return name;
-   }
-
-   public void addInput(Connection connection) {
-      this.inputs.add(connection);
-      fireStructureChange(INPUTS, connection);
-   }
-
-   public void addOutput(Connection connection) {
-      this.outputs.add(connection);
-      fireStructureChange(OUTPUTS, connection);
-   }
-
-   public List getIncomingConnections() {
-      return this.inputs;
-   }
-
-   public List getOutgoingConnections() {
-      return this.outputs;
-   }
-
-   public void removeInput(Connection connection) {
-      this.inputs.remove(connection);
-      fireStructureChange(INPUTS, connection);
-   }
-
-   public void removeOutput(Connection connection) {
-      this.outputs.remove(connection);
-      fireStructureChange(OUTPUTS, connection);
-   }
-
-
-   //------------------------------------------------------------------------
-   // Abstract methods from IPropertySource
-
-   public Object getEditableValue() {
-      return this;
-   }
-
-   public IPropertyDescriptor[] getPropertyDescriptors() {
-      return descriptors;
-   }
-
-   public Object getPropertyValue(Object id) {
-      if (NAME.equals(id)) {
-         return getName();
+  protected String name = "Node";
+
+  protected List outputs = new ArrayList(5);
+
+  protected List inputs = new ArrayList(5);
+
+  public void setLocation(Point p)
+  {
+    if (this.location.equals(p))
+      {
+        return;
+      }
+    this.location = p;
+    firePropertyChange(LOCATION, null, p);
+  }
+
+  public Point getLocation()
+  {
+    return location;
+  }
+
+  public void setName(String name)
+  {
+    if (this.name.equals(name))
+      {
+        return;
       }
-      else {
-         return null;
+    this.name = name;
+    firePropertyChange(NAME, null, name);
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public void addInput(Connection connection)
+  {
+    this.inputs.add(connection);
+    fireStructureChange(INPUTS, connection);
+  }
+
+  public void addOutput(Connection connection)
+  {
+    this.outputs.add(connection);
+    fireStructureChange(OUTPUTS, connection);
+  }
+
+  public List getIncomingConnections()
+  {
+    return this.inputs;
+  }
+
+  public List getOutgoingConnections()
+  {
+    return this.outputs;
+  }
+
+  public void removeInput(Connection connection)
+  {
+    this.inputs.remove(connection);
+    fireStructureChange(INPUTS, connection);
+  }
+
+  public void removeOutput(Connection connection)
+  {
+    this.outputs.remove(connection);
+    fireStructureChange(OUTPUTS, connection);
+  }
+
+  // ------------------------------------------------------------------------
+  // Abstract methods from IPropertySource
+
+  public Object getEditableValue()
+  {
+    return this;
+  }
+
+  public IPropertyDescriptor[] getPropertyDescriptors()
+  {
+    return descriptors;
+  }
+
+  public Object getPropertyValue(Object id)
+  {
+    if (NAME.equals(id))
+      {
+        return getName();
       }
-   }
+    else
+      {
+        return null;
+      }
+  }
+
+  public boolean isPropertySet(Object id)
+  {
+    return true;
+  }
+
+  public void resetPropertyValue(Object id)
+  {
+    // do nothing
+  }
+
+  public void setPropertyValue(Object id, Object value)
+  {
+    if (id == NAME)
+      {
+        setName((String) value);
+      }
+  }
 
-   public boolean isPropertySet(Object id) {
+  public boolean equals(Object obj)
+  {
+    if (obj == this)
       return true;
-   }
+    if (obj instanceof Node)
+      {
+        Node cmpNode = (Node) obj;
+        return getName().equals(cmpNode.getName());
+      }
+    else
+      return false;
+  }
 
-   public void resetPropertyValue(Object id) {
-      // do nothing
-   }
-
-   public void setPropertyValue(Object id, Object value) {
-      if (id == NAME) {
-         setName((String)value);
-      }
-   }
-   
-   public boolean equals(Object obj)
-   {
-     if (obj == this)
-       return true;
-     if (obj instanceof Node)
-       {
-         Node cmpNode = (Node) obj;
-         return getName().equals(cmpNode.getName());
-       }
-     else
-       return false;
-   }
 }
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.1
diff -u -r1.1 NodeFactory.java
--- src/nongnu/cashews/eclipse/composer/model/NodeFactory.java  2005/03/14
12:41:13        1.1
+++ src/nongnu/cashews/eclipse/composer/model/NodeFactory.java  2005/03/14
15:16:15
@@ -27,7 +27,7 @@
       {
         node = createNode("Untitled" + autoId);
         ++autoId;
-      } while (!NodeRegistrar.registerNewNode(node));
+      } while (!NodeRegistrar.registerNewNode(node.getName()));
     return node;
   }
   
@@ -41,7 +41,7 @@
         autoId = serializedId + 1;
       }
     node = createNode(name);
-    if (!NodeRegistrar.registerNewNode(node))
+    if (!NodeRegistrar.registerNewNode(node.getName()))
       {
         throw new IllegalStateException("A node with one of the " +
                                         "deserialized names already " +
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.1
diff -u -r1.1 NodeRegistrar.java
--- src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java        
2005/03/14
12:41:13        1.1
+++ src/nongnu/cashews/eclipse/composer/model/NodeRegistrar.java        
2005/03/14
15:16:15
@@ -7,8 +7,8 @@
 package nongnu.cashews.eclipse.composer.model;
 
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * @author Roger Liu
@@ -19,19 +19,30 @@
 public class NodeRegistrar
 {
 
-  private static List<Node> nodes;
+  private static Set<String> names;
   
   static
   {
-      nodes = new ArrayList<Node>();
+      names = new HashSet<String>();
   }
   
-  public static boolean registerNewNode(Node node)
+  public static boolean registerNewNode(String name)
   {
-    if (nodes.contains(node))
+    if (names.contains(name))
       return false;
-    nodes.add(node);
+    names.add(name);
     return true;
+  }
+  
+  public static boolean renameNode(String oldName, String newName)
+  {
+    if (registerNewNode(newName))
+      {
+        names.remove(oldName);
+        return true;
+      }
+    else
+      return false;
   }
   
 }
Index: src/nongnu/cashews/eclipse/composer/util/Dialogs.java
===================================================================
RCS file: src/nongnu/cashews/eclipse/composer/util/Dialogs.java
diff -N src/nongnu/cashews/eclipse/composer/util/Dialogs.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/eclipse/composer/util/Dialogs.java       1 Jan 1970 
00:00:00
-0000
@@ -0,0 +1,35 @@
+/*
+ * Created on 2005-3-14
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package nongnu.cashews.eclipse.composer.util;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Roger Liu
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class Dialogs
+{
+  public static void displayErrorDialog(String message)
+  {
+    IWorkbenchWindow window =
+      PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+    if (window != null)
+      {
+        Shell shell = window.getShell();
+        shell.setMinimized(false);
+        shell.forceActive();
+        MessageDialog.openError(shell,"CASheW-s Composer Error",
+                                message);
+      }
+  }
+}




reply via email to

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