1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
2 | |
3 | import org.eclipse.core.runtime.Assert; |
4 | import org.eclipse.emf.transaction.RecordingCommand; |
5 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
6 | |
7 | import de.uka.ipd.sdq.pcm.repository.CollectionDataType; |
8 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
9 | import de.uka.ipd.sdq.pcm.repository.DataType; |
10 | import de.uka.ipd.sdq.pcm.repository.Repository; |
11 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
12 | |
13 | /** |
14 | * The class place the methods for the production of new DataType. |
15 | * |
16 | * @author Roman Andrej |
17 | */ |
18 | public class DataTypeCommand { |
19 | |
20 | /** The transactional editing domain which is used to get the commands */ |
21 | private TransactionalEditingDomain editingDomain; |
22 | |
23 | public DataTypeCommand(TransactionalEditingDomain editingDomain) { |
24 | this.editingDomain = editingDomain; |
25 | } |
26 | |
27 | /* (non-Javadoc) |
28 | * @see de.uka.ipd.sdq.pcmbench.tabs.dialogs.CreateDataTypeDialog#createCollectionDataType() |
29 | */ |
30 | public void createCollectionDataType(final Repository repository, |
31 | final DataType dataType, final DataType innerDataType, |
32 | final String entityName) { |
33 | |
34 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
35 | @Override |
36 | protected void doExecute() { |
37 | CollectionDataType collectionDataType; |
38 | |
39 | if (dataType != null) { |
40 | // Edite existet DataType |
41 | collectionDataType = (CollectionDataType) dataType; |
42 | String typeName = collectionDataType.getEntityName(); |
43 | DataType innerType = collectionDataType |
44 | .getInnerType_CollectionDataType(); |
45 | |
46 | if ((entityName != null) && (!typeName.equals(entityName))) |
47 | collectionDataType.setEntityName(entityName); |
48 | |
49 | if ((innerDataType != null) |
50 | && (!innerType.equals(innerDataType))) |
51 | collectionDataType |
52 | .setInnerType_CollectionDataType(innerDataType); |
53 | } else { |
54 | // Create new DataType |
55 | collectionDataType = RepositoryFactory.eINSTANCE |
56 | .createCollectionDataType(); |
57 | collectionDataType.setRepository__DataType(repository); |
58 | |
59 | Assert.isNotNull(collectionDataType); |
60 | Assert.isNotNull(innerDataType); |
61 | Assert.isNotNull(entityName); |
62 | |
63 | collectionDataType.setEntityName(entityName); |
64 | collectionDataType |
65 | .setInnerType_CollectionDataType(innerDataType); |
66 | } |
67 | } |
68 | }; |
69 | recCommand.setDescription("Add new/Edite CollectionDataType"); |
70 | editingDomain.getCommandStack().execute(recCommand); |
71 | } |
72 | |
73 | /* (non-Javadoc) |
74 | * @see de.uka.ipd.sdq.pcmbench.tabs.dialogs.CreateDataTypeDialog#createCompositeDataType() |
75 | */ |
76 | public void createCompositeDataType(final Repository repository, |
77 | final CompositeDataType compositeDataType, final String entityName) { |
78 | |
79 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
80 | @Override |
81 | protected void doExecute() { |
82 | Assert.isNotNull(compositeDataType); |
83 | |
84 | if ((entityName != null) |
85 | && (!compositeDataType.getEntityName().equals( |
86 | entityName))) |
87 | compositeDataType.setEntityName(entityName); |
88 | |
89 | if (repository != null) |
90 | compositeDataType.setRepository__DataType(repository); |
91 | } |
92 | }; |
93 | |
94 | recCommand.setDescription("Add new CompositeDataType"); |
95 | editingDomain.getCommandStack().execute(recCommand); |
96 | } |
97 | } |