/[cashew-s-editor]/cashews/src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java
ViewVC logotype

Diff of /cashews/src/nongnu/cashews/eclipse/composer/commands/DeleteNodeCommand.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by gnu_andrew, Thu Mar 31 17:35:21 2005 UTC revision 1.2 by gnu_andrew, Thu May 5 23:47:58 2005 UTC
# Line 1  Line 1 
1  /* DeleteNodeCommand.java -- Command for deleting nodes.  /* DeleteNodeCommand.java -- Command for deleting nodes.
2     Copyright (C) 2005  The University of Sheffield.   Copyright (C) 2005  The University of Sheffield.
3    
4  This file is part of the CASheW-s editor Eclipse plug-in.   This file is part of the CASheW-s editor Eclipse plug-in.
5    
6  The CASheW-s editor Eclipse plug-in is free software; you may copy, modify,   The CASheW-s editor Eclipse plug-in is free software; you may copy, modify,
7  and redistribute it under the terms of the GNU General Public License   and redistribute it under the terms of the GNU General Public License
8  version 2 (or, at your option, any later version), and/or the Eclipse   version 2 (or, at your option, any later version), and/or the Eclipse
9  Public License version 1.0.   Public License version 1.0.
10    
11  The CASheW-s editor is distributed in the hope that it will be useful, but   The CASheW-s editor is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of   WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  General Public License for more details.   General Public License for more details.
15    
16  You should have received a copy of the GNU General Public License   You should have received a copy of the GNU General Public License
17  along with The CASheW-s editor; see the file COPYING.  If not, write to the   along with The CASheW-s editor; see the file COPYING.  If not, write to the
18  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  02111-1307 USA.   02111-1307 USA.
20    
21  The University of Sheffield makes available all content in this plug-in   The University of Sheffield makes available all content in this plug-in
22  ("Content"). Unless otherwise indicated below, the Content is provided to   ("Content"). Unless otherwise indicated below, the Content is provided to
23  you under the terms and conditions of the Eclipse Public License Version   you under the terms and conditions of the Eclipse Public License Version
24  1.0 ("EPL"). A copy of the EPL is available at   1.0 ("EPL"). A copy of the EPL is available at
25  http://www.eclipse.org/legal/epl-v10.html. For purposes of the EPL,   http://www.eclipse.org/legal/epl-v10.html. For purposes of the EPL,
26  "Program" will mean the Content.   "Program" will mean the Content.
27    
28  If you did not receive this Content directly from the University of Sheffield,   If you did not receive this Content directly from the University of Sheffield,
29  the Content is being redistributed by another party ("Redistributor") and   the Content is being redistributed by another party ("Redistributor") and
30  different terms and conditions may apply to your use of any object code in   different terms and conditions may apply to your use of any object code in
31  the Content. Check the Redistributor's license that was provided with the   the Content. Check the Redistributor's license that was provided with the
32  Content. If no such license exists, contact the Redistributor. Unless   Content. If no such license exists, contact the Redistributor. Unless
33  otherwise indicated below, the terms and conditions of the EPL still apply   otherwise indicated below, the terms and conditions of the EPL still apply
34  to any source code in the Content.   to any source code in the Content.
35    
36     */
37    
 */  
38    
39  package nongnu.cashews.eclipse.composer.commands;  package nongnu.cashews.eclipse.composer.commands;
40    
41    import nongnu.cashews.eclipse.composer.model.ConnectionElement;
42  import nongnu.cashews.eclipse.composer.model.Diagram;  import nongnu.cashews.eclipse.composer.model.Diagram;
43  import nongnu.cashews.eclipse.composer.model.Node;  import nongnu.cashews.eclipse.composer.model.Node;
44  import nongnu.cashews.eclipse.composer.model.NodeRegistrar;  import nongnu.cashews.eclipse.composer.model.NodeRegistrar;
   
45  import org.eclipse.gef.commands.Command;  import org.eclipse.gef.commands.Command;
46    
47  public class DeleteNodeCommand  public class DeleteNodeCommand extends Command
   extends Command  
48  {  {
49    
50    private Diagram diagram;    private Diagram diagram;
51    
52    private Node node;    private Node node;
53    
54      private ConnectionElement connection;
55    
56    
57    // setters    // setters
58    
59    public void setDiagram(Diagram diagram)    public void setDiagram(Diagram diagram)
# Line 63  public class DeleteNodeCommand Line 66  public class DeleteNodeCommand
66      this.node = node;      this.node = node;
67    }    }
68    
69      public void setConnection(ConnectionElement connection)
70      {
71        this.connection = connection;
72      }
73    
74    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------
75    // Overridden from Command    // Overridden from Command
76    
# Line 73  public class DeleteNodeCommand Line 81  public class DeleteNodeCommand
81    
82    public void execute()    public void execute()
83    {    {
84         if(diagram.getNodes() == null)
85            return;
86        int nodeSize = diagram.getNodes().size();
87        for (int i = 0; i < nodeSize; i++)
88          {
89    
90            Node temp = (Node) diagram.getNodes().get(i);
91            if (temp.getOutgoingConnections() != null)
92              {
93    
94                if (temp.getOutgoingConnections().size() != 0)
95                  {
96                    for (int j = 0; j < temp.getOutgoingConnections().size(); j++)
97                      {
98    
99                        ConnectionElement outgoing = (ConnectionElement) temp.getOutgoingConnections().get(
100                                                                                             j);
101                        if (node.getName().equals(outgoing.getTarget().getName()))
102                          {// temp.removeOutput(cn);
103                            if (temp.getOutgoingConnections().remove(outgoing))
104                              {
105                                outgoing.getSource().removeOutput(outgoing);
106                                System.out.println("Outgoing Connection Deleted");
107                                j--;
108                              }
109                            else
110                              {
111                                System.out.println("Outgoing Connection Delete Failed");
112                              }
113    
114                          }
115    
116                      }
117                  }
118              }
119            if (temp.getIncomingConnections() != null)
120              {
121                if (temp.getIncomingConnections().size() != 0)
122                  {
123                    for (int k = 0; k < temp.getIncomingConnections().size(); k++)
124                      {
125    
126                        ConnectionElement incoming = (ConnectionElement) temp.getIncomingConnections().get(
127                                                                                             k);
128    
129                        if (node.getName().equals(incoming.getSource().getName()))
130                          {
131                            if (temp.getIncomingConnections().remove(incoming))
132                              {
133                                incoming.getTarget().removeInput(incoming);
134                                System.out.println("Incoming Connection Deleted");
135                                k--;
136                              }
137                            else
138                              {
139                                System.out.println("Incoming Delete Failed");
140                              }
141                          }
142    
143                      }
144                  }
145    
146              }
147          }
148        if(node.getOutgoingConnections() != null)
149          node.getOutgoingConnections().clear();
150        if(node.getIncomingConnections()!=null)
151          node.getIncomingConnections().clear();
152        
153      diagram.removeNode(node);      diagram.removeNode(node);
154      NodeRegistrar.removeNode(node.getName());      NodeRegistrar.removeNode(node.getName());
155        
156        //dp.refreshVisuals();
157    }    }
158    
159    public void undo()    public void undo()

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26