Statistics
| Revision:

root / branches / modelio3.7.x / src / main / java / org / modelio / togaf / profile / businessentities / commande / explorer / diagram / wizard / TogafDataLifeCycleDiagramWizardContributor.java @ 237

History | View | Annotate | Download (5.31 KB)

1
/**
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *        Unless required by applicable law or agreed to in writing,
13
 *        software distributed under the License is distributed on an
14
 *        "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 *        KIND, either express or implied.  See the License for the
16
 *        specific language governing permissions and limitations
17
 *        under the License.
18
 *
19
 *
20
 * @package    org.modelio.togaf.
21
 * @author     Modelio
22
 * @license    http://www.apache.org/licenses/LICENSE-2.0
23
 * @version  1.0.00
24
 **/
25
package org.modelio.togaf.profile.businessentities.commande.explorer.diagram.wizard;
26

    
27
import org.modelio.api.modelio.diagram.IDiagramService;
28
import org.modelio.api.modelio.diagram.style.IStyleHandle;
29
import org.modelio.api.modelio.model.IMetamodelExtensions;
30
import org.modelio.api.modelio.model.IModelingSession;
31
import org.modelio.api.modelio.model.ITransaction;
32
import org.modelio.api.module.context.IModuleContext;
33
import org.modelio.api.module.contributor.ElementDescriptor;
34
import org.modelio.metamodel.diagrams.AbstractDiagram;
35
import org.modelio.metamodel.diagrams.StateMachineDiagram;
36
import org.modelio.metamodel.uml.behavior.stateMachineModel.StateMachine;
37
import org.modelio.metamodel.uml.infrastructure.ModelElement;
38
import org.modelio.metamodel.uml.infrastructure.Stereotype;
39
import org.modelio.metamodel.uml.statik.NameSpace;
40
import org.modelio.metamodel.uml.statik.Package;
41
import org.modelio.togaf.api.ITogafArchitectPeerModule;
42
import org.modelio.togaf.impl.TogafArchitectModule;
43
import org.modelio.togaf.profile.businessentities.model.BusinessEntity;
44
import org.modelio.togaf.profile.businessentities.model.EntityLifeCycle;
45
import org.modelio.togaf.profile.businessentities.model.TogafDataLifeCycleDiagram;
46
import org.modelio.togaf.profile.utils.TogafDiagramWizardContributor;
47
import org.modelio.vcore.smkernel.mapi.MClass;
48
import org.modelio.vcore.smkernel.mapi.MMetamodel;
49
import org.modelio.vcore.smkernel.mapi.MObject;
50

    
51
public class TogafDataLifeCycleDiagramWizardContributor extends TogafDiagramWizardContributor {
52

    
53
        @Override
54
        public boolean accept(MObject ielement) {
55

    
56
                ModelElement element = (ModelElement) ielement;
57
                if (element instanceof NameSpace) {
58
                        if (element.isStereotyped("TogafArchitect", "EntityLifeCycle")) {
59
                                return true;
60
                        }
61

    
62
                        if (element.isStereotyped("TogafArchitect", "BusinessEntities")) {
63
                                return true;
64
                        }
65
                        if (element.isStereotyped("TogafArchitect", "BusinessEntity")) {
66
                                return true;
67
                        }
68
                } else {
69
                        ModelElement owner = (ModelElement) element.getCompositionOwner();
70
                        if (owner != null && owner.isStereotyped("TogafArchitect", "TogafProduct")) {
71
                                return true;
72
                        }
73
                }
74
                return false;
75
        }
76

    
77
        @Override
78
        public AbstractDiagram actionPerformed(ModelElement diagramOwner, String diagramName, String diagramDescription) {
79
                IModelingSession session = TogafArchitectModule.getInstance().getModuleContext().getModelingSession();
80
                IDiagramService diagramService = TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getDiagramService();
81
                try (ITransaction transaction = session.createTransaction("");) {
82
                        IStyleHandle style = diagramService.getStyle(getStyle());
83
                        TogafDataLifeCycleDiagram proxy = null;
84
                        if (diagramOwner instanceof Package) {
85
                                BusinessEntity entity = new BusinessEntity();
86
                                entity.setParent((Package) diagramOwner);
87

    
88
                                EntityLifeCycle element = new EntityLifeCycle();
89
                                element.setParent(entity.getElement());
90
                                diagramOwner = element.getElement();
91
                                proxy = new TogafDataLifeCycleDiagram((StateMachine) diagramOwner,style);
92
                                TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getEditionService().openEditor(proxy.getElement());
93
                        } else if (diagramOwner instanceof NameSpace) {
94
                                EntityLifeCycle element = new EntityLifeCycle();
95
                                element.setParent((NameSpace) diagramOwner);
96
                                diagramOwner = element.getElement();
97
                                proxy = new TogafDataLifeCycleDiagram((StateMachine) diagramOwner,style);
98
                                TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getEditionService().openEditor(proxy.getElement());
99
                        } else if (diagramOwner instanceof StateMachine) {
100
                                proxy = new TogafDataLifeCycleDiagram((StateMachine) diagramOwner,style);
101
                        } else {
102
                                return null;
103
                        }
104
                        transaction.commit();
105
                        return proxy.getElement();
106
                } catch (Exception e) {
107
                        e.printStackTrace();
108
                }
109

    
110
                return null;
111
        }
112

    
113
        @Override
114
        public ElementDescriptor getCreatedElementType() {
115
                IModuleContext moduleContext = getModule().getModuleContext();
116
                MMetamodel metamodel = moduleContext.getModelioServices().getMetamodelService().getMetamodel();
117
                MClass mClass = metamodel.getMClass(StateMachineDiagram.class);
118
                IMetamodelExtensions extensions = moduleContext.getModelingSession().getMetamodelExtensions();
119
                Stereotype stereotype = extensions.getStereotype(ITogafArchitectPeerModule.MODULE_NAME, "TogafDataLifeCycleDiagram", mClass);
120
                return stereotype != null ? new ElementDescriptor(mClass, stereotype) : null;
121
        }
122

    
123
}