1 |
/* NodeFactory.java -- Factory for creating nodes. |
/* NodeFactory.java -- Factory for creating 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.model; |
package nongnu.cashews.eclipse.composer.model; |
40 |
|
|
41 |
import java.util.regex.Matcher; |
import java.util.regex.Matcher; |
42 |
import java.util.regex.Pattern; |
import java.util.regex.Pattern; |
43 |
|
|
44 |
|
import nongnu.cashews.eclipse.composer.commands.DiagramSingleton; |
45 |
|
import nongnu.cashews.eclipse.composer.wizards.ProcessData; |
46 |
|
import nongnu.cashews.eclipse.composer.wizards.ProcessDefine; |
47 |
|
|
48 |
import org.eclipse.gef.requests.SimpleFactory; |
import org.eclipse.gef.requests.SimpleFactory; |
49 |
|
|
50 |
public abstract class NodeFactory |
public abstract class NodeFactory extends SimpleFactory |
|
extends SimpleFactory |
|
51 |
{ |
{ |
52 |
|
|
53 |
static int autoId; |
int autoId; |
54 |
|
|
55 |
private Node node; |
private Node node; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
/** |
/** |
60 |
* @param aClass |
* @param aClass |
67 |
|
|
68 |
public Node getNewObject() |
public Node getNewObject() |
69 |
{ |
{ |
70 |
|
|
71 |
do |
do |
72 |
{ |
{ |
73 |
node = createNode("Untitled" + autoId); |
node = createNode("Untitled" + autoId); |
74 |
++autoId; |
++autoId; |
75 |
} |
} |
76 |
while (!NodeRegistrar.registerNewNode(node.getName())); |
while (!NodeRegistrar.registerNewNode( |
77 |
|
node.getName(), |
78 |
|
(Diagram) DiagramSingleton.getInstance().getDiagram())); |
79 |
|
|
80 |
|
/*ProcessDefine pd = new ProcessDefine(null); |
81 |
|
pd.run(); |
82 |
|
|
83 |
|
String name = null; |
84 |
|
name = pd.getName(); |
85 |
|
NodeRegistrar.registerNewNode( |
86 |
|
name, |
87 |
|
(Diagram) DiagramSingleton.getInstance().getDiagram()); |
88 |
|
node = createNode(name);*/ |
89 |
return node; |
return node; |
90 |
} |
} |
91 |
|
|
95 |
Matcher matcher = untitled.matcher(name); |
Matcher matcher = untitled.matcher(name); |
96 |
if (matcher.matches()) |
if (matcher.matches()) |
97 |
{ |
{ |
98 |
int serializedId = Integer.parseInt(matcher.group()); |
int serializedId = Integer.parseInt(matcher.group(1)); |
99 |
autoId = serializedId + 1; |
autoId = serializedId + 1; |
100 |
} |
} |
101 |
|
|
102 |
|
NodeRegistrar.registerNewNode( |
103 |
|
name, |
104 |
|
(Diagram) DiagramSingleton.getInstance().getDiagram()); |
105 |
node = createNode(name); |
node = createNode(name); |
|
if (!NodeRegistrar.registerNewNode(node.getName())) |
|
|
{ |
|
|
throw new IllegalStateException("A node with one of the " |
|
|
+ "deserialized names already " |
|
|
+ "exists."); |
|
|
} |
|
106 |
return node; |
return node; |
107 |
} |
} |
108 |
|
|