Statistics
| Revision:

root / branches / modelio3.7.x / src / main / java / org / modelio / togaf / profile / businessarchitecture / model / TogafEventDiagram.java @ 237

History | View | Annotate | Download (4.16 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.businessarchitecture.model;
26

    
27
import org.eclipse.draw2d.geometry.Rectangle;
28
import org.modelio.api.modelio.diagram.IDiagramHandle;
29
import org.modelio.api.modelio.diagram.IDiagramNode;
30
import org.modelio.api.modelio.diagram.style.IStyleHandle;
31
import org.modelio.api.modelio.model.IModelingSession;
32
import org.modelio.api.module.IPeerModule;
33
import org.modelio.metamodel.diagrams.StaticDiagram;
34
import org.modelio.metamodel.uml.behavior.activityModel.Activity;
35
import org.modelio.metamodel.uml.infrastructure.ModelElement;
36
import org.modelio.metamodel.uml.infrastructure.Note;
37
import org.modelio.metamodel.uml.statik.Package;
38
import org.modelio.togaf.impl.TogafArchitectModule;
39
import org.modelio.togaf.profile.structure.model.BusinessArchitecture;
40
import org.modelio.togaf.profile.utils.Module;
41
import org.modelio.togaf.profile.utils.ResourceManager;
42

    
43
public class TogafEventDiagram {
44
        protected StaticDiagram element;
45

    
46
        public TogafEventDiagram(ModelElement owner, IStyleHandle style) {
47
                try {
48
                        this.element = TogafArchitectModule.getInstance().getModuleContext().getModelingSession().getModel().createStaticDiagram(owner.getName() + " " + ResourceManager.getName("TogafEventDiagram"), owner, TogafArchitectModule.getInstance().getModuleContext().getModelingSession().getMetamodelExtensions().getStereotype("TogafArchitect","TogafEventDiagram", TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getMetamodelService().getMetamodel().getMClass(StaticDiagram.class)));
49

    
50
                        try (IDiagramHandle diagramHandler = TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getDiagramService().getDiagramHandle(getElement())) {
51
                                diagramHandler.getDiagramNode().setStyle(style);
52
                                diagramHandler.save();
53
                                diagramHandler.close();
54
                        }
55

    
56
                        IModelingSession session = TogafArchitectModule.getInstance().getModuleContext().getModelingSession();
57
                        try (IDiagramHandle rep = TogafArchitectModule.getInstance().getModuleContext().getModelioServices().getDiagramService().getDiagramHandle(getElement())) {
58
                                if (owner instanceof Activity) {
59
                                        rep.unmask(owner, 0, 0);
60
                                        rep.save();
61
                                }
62

    
63
                                IPeerModule peer = Module.getPeer();
64
                                if (peer.getConfiguration().getParameterValue("DisplayNote").equals("TRUE")) {
65
                                        Note note = session.getModel().createNote(TogafArchitectModule.getInstance().getModuleContext().getModelingSession().getMetamodelExtensions().getNoteType("TogafArchitect","TOGAFModelingGuide", getElement().getMClass()), getElement(), org.modelio.togaf.i18n.Messages.getString("TogafEventDiagram_NOTE"));
66

    
67
                                        IDiagramNode node = (IDiagramNode) rep.unmask(note, 0, 0).get(0);
68
                                        node.setBounds(new Rectangle(0, 0, 500, 300));
69
                                        rep.save();
70
                                        rep.close();
71
                                }
72
                        }
73
                } catch (Exception e) {
74
                        e.printStackTrace();
75
                }
76
        }
77

    
78
        public TogafEventDiagram(StaticDiagram element) {
79
                this.element = element;
80
        }
81

    
82
        public StaticDiagram getElement() {
83
                return this.element;
84
        }
85

    
86
        public void setParent(ModelElement parent) {
87
                this.element.setOrigin(parent);
88
        }
89

    
90
        public BusinessArchitecture getBusinessArchitecture() {
91
                return new BusinessArchitecture((Package) this.element.getOrigin());
92
        }
93

    
94
        public void addBusinessArchitecture(BusinessArchitecture model) {
95
                this.element.setOrigin(model.getElement());
96
        }
97

    
98
}