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

Diff of /cashews/src/nongnu/cashews/eclipse/composer/commands/ConnectionCreateCommand.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  /* ConnectionCreateCommand.java -- Command for creating connections.  /* ConnectionCreateCommand.java -- Command for creating connections.
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 java.util.List;  import java.util.List;
42    
43  import nongnu.cashews.eclipse.composer.model.Connection;  import nongnu.cashews.eclipse.composer.model.ConnectionElement;
44  import nongnu.cashews.eclipse.composer.model.Node;  import nongnu.cashews.eclipse.composer.model.Node;
45    import nongnu.cashews.eclipse.composer.ui.ConnectionWindow;
46    
47  import org.eclipse.gef.commands.Command;  import org.eclipse.gef.commands.Command;
48    
49  public class ConnectionCreateCommand  public class ConnectionCreateCommand extends Command
   extends Command  
50  {  {
51    
52    protected Connection connection;    protected ConnectionElement connection;
53    
54    protected Node source;    protected Node source;
55    
# Line 61  public class ConnectionCreateCommand Line 62  public class ConnectionCreateCommand
62      this.source = source;      this.source = source;
63    }    }
64    
65    public void setConnection(Connection connection)    public void setConnection(ConnectionElement connection)
66    {    {
67      this.connection = connection;      this.connection = connection;
68    }    }
# Line 82  public class ConnectionCreateCommand Line 83  public class ConnectionCreateCommand
83    public boolean canExecute()    public boolean canExecute()
84    {    {
85      if (source.equals(target))      if (source.equals(target))
86        return false;        {
87            return false;
88          }
89    
90      // Check for existence of connection already      // Check for existence of connection already
91      List connections = this.source.getOutgoingConnections();      if (source.getOutgoingConnections() != null)
     for (int i = 0; i < connections.size(); i++)  
92        {        {
93          if (((Connection) connections.get(i)).getTarget().equals(target))          List connections = this.source.getOutgoingConnections();
94            return false;          if (connections.size() != 0)
95              {
96                for (int i = 0; i < connections.size(); i++)
97                  {
98                    if (((ConnectionElement) connections.get(i)).getTarget().equals(target))
99                      return false;
100                  }
101              }
102        }        }
103      return true;      return true;
104    }    }
105    
106    public void execute()    public void execute()
107    {    {
108      this.connection = new Connection(source, target);        this.connection = new ConnectionElement(source, target);
109          ConnectionWindow cw = new ConnectionWindow(null, connection);
110          cw.open();
111    }    }
112    
113    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