Revision 525

View differences:

branches/modelio3.7.x/src/main/java/org/modelio/module/sysml/properties/SysMLPropertyPage.java
1
/**
2
 * Java Class : SysML.java
3
 *
4
 * Description :
5
 *
6
 * Licensed to the Apache Software Foundation (ASF) under one
7
 * or more contributor license agreements.  See the NOTICE file
8
 * distributed with this work for additional information
9
 * regarding copyright ownership.  The ASF licenses this file
10
 * to you under the Apache License, Version 2.0 (the
11
 * "License"); you may not use this file except in compliance
12
 * with the License.  You may obtain a copy of the License at
13
 *
14
 *    http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 *    Unless required by applicable law or agreed to in writing,
17
 *    software distributed under the License is distributed on an
18
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
 *    KIND, either express or implied.  See the License for the
20
 *    specific language governing permissions and limitations
21
 *    under the License.
22
 *
23
 * @category   Modelio Impl
24
 * @package    com.modeliosoft.modelio.sysml.properties
25
 * @author     Modelio
26
 * @license    http://www.apache.org/licenses/LICENSE-2.0
27
 * @version    2.0.08
28
 **/
29
package org.modelio.module.sysml.properties;
30

  
31
import java.util.List;
32
import com.modeliosoft.modelio.javadesigner.annotations.objid;
33
import org.modelio.api.module.IModule;
34
import org.modelio.api.module.propertiesPage.AbstractModulePropertyPage;
35
import org.modelio.api.module.propertiesPage.IModulePropertyTable;
36
import org.modelio.metamodel.uml.infrastructure.ModelElement;
37
import org.modelio.module.sysml.propertypage.SysMLPropertyManager;
38
import org.modelio.vcore.smkernel.mapi.MObject;
39

  
40
/**
41
 * This class extends
42
 */
43
@objid ("1a63c204-c285-4918-b7c6-37ecb2161836")
44
public class SysMLPropertyPage extends AbstractModulePropertyPage {
45
    /**
46
     * Constructor
47
     * @author ebrosse
48
     * @param module : the associated IModule
49
     * @param name : the name of the property page
50
     * @param label : the label of the property page
51
     * @param bitmap : the bitmap of the property page
52
     */
53
    @objid ("f96f6803-d702-4bb6-8cab-f51cd2cc8902")
54
    public SysMLPropertyPage(IModule module, String name, String label, String bitmap) {
55
        super (module, name, label, bitmap);
56
    }
57

  
58
    /**
59
     * This method is called when the current selection changes and that the property box contents requires an update.
60
     * The ?selectedElements? parameter contains the list of the newly selected elements. The ?table? parameter is the
61
     * table that must be filled with the updated contents of the property box before returning.
62
     */
63
    @objid ("76f28a18-41e1-4272-8c3c-1231fab0ae94")
64
    @Override
65
    public void update(List<MObject> selectedElements, IModulePropertyTable table) {
66
        if ((selectedElements != null) && (selectedElements.size() > 0)
67
                && (selectedElements.get(0) != null)
68
                && (selectedElements.get(0) instanceof ModelElement)){
69
        
70
            ModelElement element = ((ModelElement) selectedElements.get(0));
71
            
72
            SysMLPropertyManager sysMLPage = new SysMLPropertyManager();
73
            sysMLPage.update(element, table);
74
        
75
        }
76
    }
77

  
78
    /**
79
     * This method is called when a value has been edited in the property box in the row ?row?. The ?selectedElements?
80
     * parameter contains the list of the currently selected elements. The ?row? parameter is the row number of the
81
     * modified value. The ?value? parameter is the new value the user has set to the given row.
82
     */
83
    @objid ("412872bf-6a0f-44b6-b070-1fa2db4fde78")
84
    @Override
85
    public void changeProperty(List<MObject> selectedElements, int row, String value) {
86
        if ((selectedElements != null) && (selectedElements.size() > 0) && (selectedElements.get(0) instanceof ModelElement)){
87
        
88
            ModelElement element = ((ModelElement) selectedElements.get (0));
89
        
90
            SysMLPropertyManager sysMLPage = new SysMLPropertyManager();
91
            sysMLPage.changeProperty(element, row, value);
92
            
93
        }
94
    }
95

  
96
}
0 97

  
branches/modelio3.7.x/src/main/java/org/modelio/module/sysml/i18n/I18nMessageService.java
1
package org.modelio.module.sysml.i18n;
2

  
3
import java.text.MessageFormat;
4
import java.util.Locale;
5
import java.util.MissingResourceException;
6
import java.util.ResourceBundle;
7
import com.modeliosoft.modelio.javadesigner.annotations.objid;
8

  
9
/**
10
 * Message service
11
 * <br>Use of "i18n/messages"
12
 */
13
@objid ("463ead25-4cde-4d69-98da-8bb1d69ab2e5")
14
public class I18nMessageService {
15
    @objid ("97374cab-78ac-4562-a6c4-a49a3869a7b4")
16
    private static final String FILE_NAME_MESSAGES = "org.modelio.module.sysml.i18n.messages";
17

  
18
    @objid ("aab38df2-69e5-4a7d-bf73-30e44411dac6")
19
    private static I18nMessageService instance;
20

  
21
    @objid ("278e1bb6-71a0-41e8-bead-81e79a26bad7")
22
    private ResourceBundle messageResource;
23

  
24
    /**
25
     * Private constructor.
26
     */
27
    @objid ("cd46e10c-e9e0-48a4-b96b-80e1d4631204")
28
    private I18nMessageService() {
29
        Locale locale = Locale.getDefault();
30
        this.messageResource = ResourceBundle.getBundle(FILE_NAME_MESSAGES, locale);
31
    }
32

  
33
    /**
34
     * Singleton creation.
35
     */
36
    @objid ("b28ccc9f-0a98-4b21-8f44-d216db2efa96")
37
    private static I18nMessageService getInstance() {
38
        if (null == instance) { // Premier appel
39
            instance = new I18nMessageService();
40
        }
41
        return instance;
42
    }
43

  
44
    /**
45
     * @return the messageResource
46
     */
47
    @objid ("e721ad78-9cf0-45a8-be66-46b9255bc591")
48
    private ResourceBundle getMessageResource() {
49
        return this.messageResource;
50
    }
51

  
52
    /**
53
     * Get message value from key.
54
     * @param key the key for the desired string.
55
     * @return the string for the given key.
56
     */
57
    @objid ("1aaa6349-375a-4dd4-b2b5-da987ccb1e8f")
58
    public static String getString(String key) {
59
        String message = null;
60
        try {
61
            message = getInstance().getMessageResource().getString(key);
62
        } catch (@SuppressWarnings ("unused") MissingResourceException e) {
63
            message = '!' + key + '!';
64
        }
65
        return message;
66
    }
67

  
68
    /**
69
     * Get list of messages values from key with parameters.
70
     * @param key the key for the desired string.
71
     * @param params an array of objects to be formatted and substituted.
72
     * @return the string for the given key.
73
     */
74
    @objid ("0e3d1b43-4456-4b94-9e36-69400402ad17")
75
    public static String getString(String key, String... params) {
76
        String message = null;
77
        try {
78
            String value = getString(key);
79
            message = MessageFormat.format(value, (Object[]) params);
80
        } catch (@SuppressWarnings ("unused") MissingResourceException e) {
81
            message = '!' + key + '!';
82
        }
83
        return message;
84
    }
85

  
86
}
0 87

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

  
31
import java.util.ArrayList;
32
import java.util.Collection;
33
import java.util.Iterator;
34
import java.util.List;
35
import com.modeliosoft.modelio.javadesigner.annotations.objid;
36
import org.modelio.api.modelio.model.IUmlModel;
37
import org.modelio.metamodel.uml.behavior.activityModel.ActivityEdge;
38
import org.modelio.metamodel.uml.behavior.activityModel.ActivityNode;
39
import org.modelio.metamodel.uml.behavior.activityModel.ObjectNode;
40
import org.modelio.metamodel.uml.informationFlow.InformationFlow;
41
import org.modelio.metamodel.uml.infrastructure.Dependency;
42
import org.modelio.metamodel.uml.infrastructure.ModelElement;
43
import org.modelio.metamodel.uml.infrastructure.Stereotype;
44
import org.modelio.metamodel.uml.infrastructure.TagParameter;
45
import org.modelio.metamodel.uml.infrastructure.TagType;
46
import org.modelio.metamodel.uml.infrastructure.TaggedValue;
47
import org.modelio.metamodel.uml.statik.Association;
48
import org.modelio.metamodel.uml.statik.AssociationEnd;
49
import org.modelio.metamodel.uml.statik.BindableInstance;
50
import org.modelio.metamodel.uml.statik.Class;
51
import org.modelio.metamodel.uml.statik.ClassAssociation;
52
import org.modelio.metamodel.uml.statik.Classifier;
53
import org.modelio.metamodel.uml.statik.DataType;
54
import org.modelio.metamodel.uml.statik.Instance;
55
import org.modelio.metamodel.uml.statik.Link;
56
import org.modelio.metamodel.uml.statik.LinkEnd;
57
import org.modelio.metamodel.uml.statik.NameSpace;
58
import org.modelio.module.sysml.api.ISysMLPeerModule;
59
import org.modelio.module.sysml.api.SysMLStereotypes;
60
import org.modelio.module.sysml.api.SysMLTagTypes;
61
import org.modelio.module.sysml.impl.SysMLModule;
62
import org.modelio.vcore.smkernel.mapi.MObject;
63

  
64
/**
65
 * @author Tony Marchand This class provides services on model. At the moment, services are about tagged values.
66
 */
67
@objid ("c98c4981-c6fe-4a06-89ca-6e7daa7678e8")
68
public class ModelUtils {
69
    /**
70
     * This operation returns the first tagged value with the &lt;tagName&gt; name on the &lt;element&gt; ModelElement.
71
     * @param MObject
72
     * ModelElement on which the tagged value is search for.
73
     * @param tagName String containing the tagged value name
74
     * @return The TaggedValue
75
     */
76
    @objid ("7e417d2c-009d-4c63-86cc-49020a7442cd")
77
    public static TaggedValue getFirstTaggedValue(ModelElement element, String tagName) {
78
        TaggedValue tag = null;
79
        int i;
80
        List<TaggedValue> tags = element.getTag();
81
        for (i = 0; (i < tags.size()) && (tag == null); i++) {
82
            TaggedValue localTag = tags.get(i);
83
            if (localTag.getDefinition().getName().contentEquals(tagName)) {
84
                tag = localTag;
85
            }
86
        }
87
        return tag;
88
    }
89

  
90
    /**
91
     * This operation returns the parameter values of the first tagged value with the &lt;tagName&gt; name on the &lt;element&gt;
92
     * ModelElement. The tagged value must have a parameter.
93
     * @param MObject
94
     * ModelElement on which the tagged value is search for.
95
     * @param tagName String containing the tagged value name
96
     * @return The parameter values
97
     */
98
    @objid ("4e584430-2e49-467e-a3e9-1c5cd79280c3")
99
    public static ArrayList<String> getParametersOfTag(ModelElement element, String tagName) {
100
        List<TaggedValue> tags = element.getTag();
101
        ArrayList<String> parameters = null;
102
        
103
        for (TaggedValue tag : tags) {
104
            if (tag.getDefinition().getName().contentEquals(tagName)) {
105
                parameters = new ArrayList<>(tag.getActual().size());
106
                for (TagParameter parameter : tag.getActual()) {
107
                    parameters.add(parameter.getValue());
108
                }
109
            }
110
        }
111
        return parameters;
112
    }
113

  
114
    /**
115
     * This operation returns the content of the first parameter of the first tagged value with the &lt;tagName&gt; name on the
116
     * &lt;element&gt; ModelElement. The tagged value must have a parameter.
117
     * @param MObject
118
     * ModelElement on which the tagged value is search for.
119
     * @param tagName String containing the tagged value name
120
     * @return The value of the first tag parameter
121
     */
122
    @objid ("a53e4797-81d4-482f-a764-b9804fac92ff")
123
    public static String getProperty(ModelElement element, String tagName) {
124
        TaggedValue tag = getFirstTaggedValue(element, tagName);
125
        String value;
126
        if (tag != null) {
127
            value = tag.getActual().get(0).getValue();
128
        } else {
129
            value = "";
130
        }
131
        return value;
132
    }
133

  
134
    /**
135
     * Method getNearestClassifier
136
     * @author ebrosse
137
     * @param source @return
138
     */
139
    @objid ("60e5b461-b630-462e-b447-34f48619077b")
140
    public static NameSpace getNearestNameSpace(ModelElement source) {
141
        ModelElement owner = source;
142
        
143
        while (!(owner instanceof NameSpace)) {
144
        
145
            if (owner instanceof BindableInstance) {
146
                if (((BindableInstance) owner).getInternalOwner() != null)
147
                    owner = ((BindableInstance) owner).getInternalOwner();
148
                else
149
                    owner = ((BindableInstance) owner).getCluster();
150
            } else if (owner instanceof Instance) {
151
                owner = ((Instance) owner).getOwner();
152
            }
153
        
154
        }
155
        return (NameSpace) owner;
156
    }
157

  
158
    /**
159
     * Method addValue
160
     * @author ebrosse
161
     * @param name
162
     * @param values
163
     * @param MObject
164
     * @return
165
     */
166
    @objid ("19fd6e45-4698-4507-91a1-ea202c42d180")
167
    public static void addValue(String modulename, String name, String values, ModelElement element) {
168
        // DON'T place Transition HERE
169
        boolean exist = false;
170
        List<TaggedValue> tagElements = element.getTag();
171
        TaggedValue tvFound = null;
172
        
173
        // existing verification
174
        if (!tagElements.isEmpty()) {
175
            for (TaggedValue tag : tagElements) {
176
        
177
                TagType type = tag.getDefinition();
178
                String tagname = type.getName();
179
        
180
                if (tagname.equals(name)) {
181
                    exist = true;
182
                    // Modelio.out.println("tvFound FOUND");
183
                    tvFound = tag;
184
                }
185
            }
186
        }
187
        
188
        // if the tagged value doesn't exist yet, we create this
189
        if (!exist) {
190
            try {
191
                // Modelio.out.println("tvFound does not exist");
192
                TaggedValue v = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel().createTaggedValue(modulename, name, element);
193
                element.getTag().add(v);
194
                if (!v.getDefinition().getParamNumber().equals("0")) {
195
                    setTaggedValue(name, element, values);
196
                }
197
            } catch (Exception e) {
198
                SysMLModule.logService.error(e);
199
            }
200
        }
201
        // if the tagged value already exists
202
        else {
203
            if ((tvFound != null ) && (tvFound.getDefinition().getParamNumber().equals("0"))) {
204
                // Modelio.out.println("tvFound.getDefinition().getParamNumber().equals(0), the tv is deleted");
205
                tvFound.delete();
206
            } else {
207
                setTaggedValue(name, element, values);
208
            }
209
        }
210
    }
211

  
212
    /**
213
     * Method getTaggedValue
214
     * @author ebrosse
215
     * @param tagtype
216
     * @param MObject
217
     * @return
218
     */
219
    @objid ("2859dbba-2d61-4628-904d-b5c554645b8f")
220
    public static String getTaggedValue(String tagtype, ModelElement element) {
221
        for (TaggedValue tag : element.getTag()) {
222
            TagType type = tag.getDefinition();
223
            String tagname = type.getName();
224
        
225
            if (tagname.equals(tagtype)) {
226
        
227
                List<TagParameter> actuals = tag.getActual();
228
                if ((actuals != null) && (actuals.size() > 0)) {
229
                    return actuals.get(0).getValue();
230
                } else
231
                    return "";
232
        
233
            }
234
        }
235
        return "";
236
    }
237

  
238
    /**
239
     * Method addValue
240
     * @author ebrosse
241
     * @param name
242
     * @param value
243
     * @param element
244
     * @param related
245
     * @param stereotypeLink @return
246
     */
247
    @objid ("6e44f1b3-b1cb-4ffa-8b1a-53601a8099be")
248
    public static void addValue(String modulename, String name, String value, ModelElement element, ModelElement related, String modulelink, String stereotypeLink) {
249
        // DON'T place Transition HERE
250
        
251
        boolean exist = false;
252
        
253
        TaggedValue tag = null;
254
        List<TaggedValue> tagElements = element.getTag();
255
        IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
256
        
257
        if (!tagElements.isEmpty()) {
258
            for (TaggedValue currentTag : tagElements) {
259
                TagType type = currentTag.getDefinition();
260
                String tagname = type.getName();
261
        
262
                if (tagname.equals(name)) {
263
                    exist = true;
264
                    tag = currentTag;
265
                    break;
266
        
267
                }
268
            }
269
        }
270
        
271
        if (!exist) {
272
            try {
273
                tag = model.createTaggedValue(modulename, name, element);
274
        
275
            } catch (Exception e) {
276
                SysMLModule.logService.error(e);
277
            }
278
        
279
        }
280
        
281
        setTaggedValue(tag, element, value, related,modulelink, stereotypeLink);
282
    }
283

  
284
    /**
285
     * Method hasTaggedValue
286
     * @author ebrosse
287
     * @param tagtype
288
     * @param _element @return
289
     */
290
    @objid ("522b4d73-046f-44e3-9cee-35d8d7af605b")
291
    public static boolean hasTaggedValue(String tagtype, ModelElement _element) {
292
        List<TaggedValue> tagElements = _element.getTag();
293
        Iterator<TaggedValue> itChildren = tagElements.iterator();
294
        
295
        while (itChildren.hasNext()) {
296
            TaggedValue tag = itChildren.next();
297
            TagType type = tag.getDefinition();
298
            String tagname = type.getName();
299
            if (tagname.equals(tagtype)) {
300
        
301
                return true;
302
            }
303
        
304
        }
305
        return false;
306
    }
307

  
308
    /**
309
     * Method setTaggedValue
310
     * @author ebrosse
311
     * @param name
312
     * @param elt
313
     * @param value @return
314
     */
315
    @objid ("cfe4f93a-f764-414f-913d-c00134b467e6")
316
    public static void setTaggedValue(String name, ModelElement elt, String value) {
317
        List<TaggedValue> tagElements = elt.getTag();
318
        IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
319
        
320
        if (!tagElements.isEmpty()) {
321
        
322
            for (TaggedValue tag : tagElements) {
323
                String tagname = tag.getDefinition().getName();
324
                if (tagname.equals(name)) {
325
        
326
                    TagParameter firstElt = null;
327
                    List<TagParameter> actuals = tag.getActual();
328
                    if ((actuals != null) && (actuals.size() > 0)) {
329
                        firstElt = actuals.get(0);
330
                    } else {
331
                        firstElt = model.createTagParameter();
332
                        tag.getActual().add(firstElt);
333
                    }
334
        
335
                    if (((value.equals("false")) && (tag.getDefinition().getParamNumber().equals("0")))
336
                            || ((value.equals("")) && (tag.getDefinition().getParamNumber().equals("1")))) {
337
                        tag.delete();
338
                    } else {
339
                        firstElt.setValue(value);
340
                    }
341
                }
342
            }
343
        }
344
    }
345

  
346
    /**
347
     * Method setTaggedValue
348
     * @author ebrosse
349
     * @param tvFound
350
     * @param elt
351
     * @param value
352
     * @param related
353
     * @param stereotypeLink @return
354
     */
355
    @objid ("7464086c-3b04-4192-b676-defd0632a1b3")
356
    public static void setTaggedValue(TaggedValue tvFound, ModelElement elt, String value, ModelElement related, String modulelink, String stereotypeLink) {
357
        IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
358
        
359
        for (Dependency existingLinks : new ArrayList<>(elt.getDependsOnDependency())) {
360
            if (existingLinks.isStereotyped(modulelink,stereotypeLink)) {
361
                existingLinks.delete();
362
            }
363
        }
364
        
365
        TagParameter firstElt = null;
366
        List<TagParameter> actuals = tvFound.getActual();
367
        if ((actuals != null) && (actuals.size() > 0)) {
368
            firstElt = actuals.get(0);
369
        } else {
370
            firstElt = model.createTagParameter();
371
            tvFound.getActual().add(firstElt);
372
        }
373
        
374
        if (value.equals("false")) {
375
            tvFound.delete();
376
        } else {
377
            firstElt.setValue(value);
378
            try {
379
                model.createDependency(elt, related,modulelink, stereotypeLink);
380
            } catch (Exception e) {
381
                SysMLModule.logService.error(e);
382
            }
383
        }
384
    }
385

  
386
    /**
387
     * Method searchElement
388
     * @author ebrosse
389
     * @param extendedClass
390
     * @param stereotype @return
391
     */
392
    @objid ("8499bc6d-983a-4435-b989-428f9509c8aa")
393
    public static ArrayList<MObject> searchElement(java.lang.Class<? extends MObject> extendedClass, String modulename, String stereotype) {
394
        // initialize the result
395
        ArrayList<MObject> result = new ArrayList<>();
396
        
397
        // dynamic elements list creating
398
        Collection<? extends MObject> listElements =  SysMLModule.getInstance().getModuleContext().getModelingSession()
399
                .findByClass(extendedClass);
400
        
401
        // vector initialization
402
        for (MObject elt : listElements) {
403
            if ((elt instanceof ModelElement)
404
                    && (((ModelElement)elt).isStereotyped(modulename,stereotype))) {
405
                result.add(elt);
406
            }
407
        }
408
        return result;
409
    }
410

  
411
    /**
412
     * Method updateSource
413
     * @author ebrosse
414
     * @param element
415
     * @param tagtypeName
416
     * @param linkName
417
     */
418
    @objid ("165e7abd-efda-4e2f-9813-f3a862840ff5")
419
    public static void updateSource(ModelElement element, String tagtypeName, String modulename, String linkName) {
420
        try {
421
        
422
            ArrayList<Dependency> linkList = new ArrayList<>();
423
            for (Dependency existingLinks : element.getDependsOnDependency()) {
424
                if (existingLinks.isStereotyped(modulename,linkName)) {
425
                    linkList.add(existingLinks);
426
                }
427
            }
428
        
429
            // search for taggedValue
430
            TaggedValue tag = null;
431
            List<TaggedValue> taglist = element.getTag();
432
            for (TaggedValue taggedValue : taglist) {
433
                if (taggedValue.getDefinition().getName().equals(tagtypeName)) {
434
                    tag = taggedValue;
435
                    break;
436
                }
437
            }
438
        
439
            IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
440
            if (linkList.size() > 0) {
441
        
442
                // if not exist the tagged value is created
443
                if (tag == null) {
444
                    tag = model.createTaggedValue(modulename,tagtypeName, element);
445
                }
446
                List<TagParameter> actuals = tag.getActual();
447
        
448
                for (TagParameter actual : actuals) {
449
                    actual.delete();
450
                }
451
        
452
                for (Dependency link : linkList) {
453
                    TagParameter currentTag = model.createTagParameter();
454
                    tag.getActual().add(currentTag);
455
                    currentTag.setValue(link.getDependsOn().getName());
456
                }
457
        
458
            } else {
459
        
460
                if (tag != null) {
461
                    tag.delete();
462
                }
463
            }
464
        } catch (Exception e) {
465
            SysMLModule.logService.error(e);
466
        }
467
    }
468

  
469
    /**
470
     * Method addValue
471
     * @author ebrosse
472
     * @param name
473
     * @param values
474
     * @param MObject
475
     */
476
    @objid ("c22b7dc9-854b-451f-a8fe-b21ac054053b")
477
    public static void addValue(String modulename, String name, boolean values, ModelElement element) {
478
        boolean exist = false;
479
        
480
        List<TaggedValue> tagElements = element.getTag();
481
        Iterator<TaggedValue> itChildren = tagElements.iterator();
482
        while (itChildren.hasNext()) {
483
            TaggedValue tag = itChildren.next();
484
            TagType type = tag.getDefinition();
485
            String tagname = type.getName();
486
        
487
            if (tagname.equals(name)) {
488
                exist = true;
489
            }
490
        }
491
        
492
        if (!exist) {
493
            IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
494
            try {
495
                model.createTaggedValue(modulename,name, element);
496
            } catch (Exception e) {
497
                SysMLModule.logService.error(e);
498
            }
499
        }
500
    }
501

  
502
    /**
503
     * Method clean
504
     * @author ebrosse
505
     * @param element
506
     * @param tagtypeName
507
     * @param stereotypelink @return
508
     */
509
    @objid ("e4e8268c-b53d-48ed-92a0-9f3067927dda")
510
    public static void clean(ModelElement element, String tagtypeName, String stereotypelink) {
511
        for (Dependency existingLinks : element.getDependsOnDependency()) {
512
            if (existingLinks.isStereotyped(ISysMLPeerModule.MODULE_NAME, stereotypelink)) {
513
                existingLinks.delete();
514
            }
515
        }
516
        
517
        List<TaggedValue> taglist = element.getTag();
518
        for (TaggedValue taggedValue : taglist) {
519
            if (taggedValue.getDefinition().getName().equals(tagtypeName)) {
520
                taggedValue.delete();
521
                break;
522
            }
523
        }
524
    }
525

  
526
    /**
527
     * Method createActivityEdge
528
     * @author ebrosse
529
     * @param source
530
     * @param target @return
531
     */
532
    @objid ("54139665-8d18-4952-bf15-39552cb382a0")
533
    public static ActivityEdge createActivityEdge(ActivityNode source, ActivityNode target) {
534
        IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
535
        ActivityEdge result = null;
536
        if ((source instanceof ObjectNode) || (target instanceof ObjectNode))
537
            result = model.createObjectFlow();
538
        else
539
            result = model.createControlFlow();
540
        
541
        result.setSource(source);
542
        result.setTarget(target);
543
        return result;
544
    }
545

  
546
    /**
547
     * Method updateTarget
548
     * @author ebrosse
549
     * @param element
550
     * @param tagtypeName
551
     * @param linkName @return
552
     */
553
    @objid ("1274094e-4920-47a4-84fd-e0395e6ddf3e")
554
    public static void updateTarget(ModelElement element, String modulename, String tagtypeName, String modulelinkname, String linkName) {
555
        if (element.getStatus().isModifiable()){
556
        
557
            try {
558
        
559
                // search stereotyped dependency
560
                ArrayList<Dependency> linkList = new ArrayList<>();
561
                for (Dependency existingLinks : element.getImpactedDependency()) {
562
                    if (existingLinks.isStereotyped(modulelinkname, linkName)) {
563
                        linkList.add(existingLinks);
564
                    }
565
                }
566
        
567
                // search for taggedValue
568
                TaggedValue tag = null;
569
                List<TaggedValue> taglist = element.getTag();
570
                for (TaggedValue taggedValue : taglist) {
571
                    if (taggedValue.getDefinition().getName().equals(tagtypeName)) {
572
                        tag = taggedValue;
573
                        break;
574
                    }
575
                }
576
        
577
                IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
578
                if (linkList.size() > 0) {
579
        
580
                    // if not exist the tagged value is created
581
                    if (tag == null) {
582
                        tag = model.createTaggedValue(modulename,tagtypeName, element);
583
                    }
584
        
585
                    List<TagParameter> actuals = tag.getActual();
586
        
587
                    for (TagParameter actual : actuals) {
588
                        actual.delete();
589
                    }
590
        
591
                    for (Dependency link : linkList) {
592
                        TagParameter currentTag = model.createTagParameter();
593
                        tag.getActual().add(currentTag);
594
                        currentTag.setValue(link.getImpacted().getName());
595
                    }
596
        
597
                } else {
598
                    if (tag != null) {
599
                        tag.delete();
600
                    }
601
        
602
                }
603
            } catch (Exception e) {
604
                SysMLModule.logService.error(e);
605
            }
606
        }
607
    }
608

  
609
    /**
610
     * Method synchronizeSysMLModel
611
     * @author ebrosse
612
     * @return
613
     */
614
    @objid ("7845c348-7657-4f39-9e5a-18463d5dee52")
615
    public static void synchronizeSysMLModel() {
616
        synchronizeUnit();
617
        synchronizeValueType();
618
        synchronizeView();
619
    }
620

  
621
    /**
622
     * Method synchronizeView
623
     * @author ebrosse
624
     * @return
625
     */
626
    @objid ("213168ef-3a36-4016-9b5c-04e3b961f336")
627
    private static void synchronizeView() {
628
        Collection<Class> listElements =  SysMLModule.getInstance().getModuleContext().getModelingSession().findByClass(Class.class);
629
        
630
        for (Class temp : listElements) {
631
            if (temp.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.VIEW))
632
                updateSource(temp,ISysMLPeerModule.MODULE_NAME, SysMLTagTypes.VIEW_VIEW_VIEWPOINT, SysMLStereotypes.CONFORM);
633
        }
634
    }
635

  
636
    /**
637
     * Method update
638
     * @author ebrosse
639
     * @param updatedElement
640
     * @param linkStereotype
641
     * @param tagSource
642
     * @param tagTarget @return
643
     */
644
    @objid ("fd777d3f-7aa7-4913-bbc8-2ff48a5c1777")
645
    private static void update(Dependency updatedElement, String modulename, String linkStereotype, String tagSource, String tagTarget) {
646
        updateSource(updatedElement.getDependsOn(),modulename, tagSource, linkStereotype);
647
        updateTarget(updatedElement.getImpacted(),modulename, tagTarget,modulename, linkStereotype);
648
    }
649

  
650
    /**
651
     * Method synchronizeValueType
652
     * @author ebrosse
653
     * @return
654
     */
655
    @objid ("bf95a1b5-4bd4-487b-bec2-e19a80578585")
656
    private static void synchronizeValueType() {
657
        Collection<DataType> listElements =  SysMLModule.getInstance().getModuleContext().getModelingSession().findByClass(DataType.class);
658
        
659
        for (DataType temp : listElements) {
660
            if (temp.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.VALUETYPE)) {
661
                updateSource(temp, ISysMLPeerModule.MODULE_NAME, SysMLTagTypes.VALUETYPE_VALUETYPE_UNIT, SysMLStereotypes.VALUETYPEUNIT);
662
                updateTarget(temp, ISysMLPeerModule.MODULE_NAME, SysMLTagTypes.VALUETYPE_VALUETYPE_QUANTITYKIND, ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.VALUETYPEQUANTITYKIND);
663
            }
664
        }
665
    }
666

  
667
    /**
668
     * Method synchronizeUnit
669
     * @author ebrosse
670
     * @return
671
     */
672
    @objid ("fbe35d91-dfcf-4069-8d23-20ec53f2c0d7")
673
    private static void synchronizeUnit() {
674
        Collection<Instance> listElements =  SysMLModule.getInstance().getModuleContext().getModelingSession().findByClass(Instance.class);
675
        
676
        for (Instance temp : listElements) {
677
            if (temp.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.UNIT)) {
678
                updateSource(temp,ISysMLPeerModule.MODULE_NAME, SysMLTagTypes.UNIT_UNIT_QUANTITYKIND, SysMLStereotypes.UNITQUANTITYKIND);
679
            }
680
        }
681
    }
682

  
683
    @objid ("62582fa6-432c-4c1f-8f37-b34c3c4478ff")
684
    public static boolean isAllocated(ModelElement element) {
685
        boolean isAllocated = false;
686
        
687
        
688
        for (Dependency existingLinks : element.getDependsOnDependency()) {
689
            if (existingLinks.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.ALLOCATE)) {
690
                isAllocated = true;
691
            }
692
        }
693
        
694
        for (Dependency existingLinks : element.getImpactedDependency()) {
695
            if (existingLinks.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.ALLOCATE)) {
696
                isAllocated = true;
697
            }
698
        
699
        }
700
        return isAllocated;
701
    }
702

  
703
    /**
704
     * Method isStereotypedSysML
705
     * @author ebrosse
706
     * @param eltToTest @return
707
     */
708
    @objid ("1f6b3812-619f-40b1-a0cd-d0e4a8d23641")
709
    public static boolean isStereotypedSysML(ModelElement eltToTest) {
710
        List<Stereotype> sterList = eltToTest.getExtension();
711
        for (Stereotype sterCurrent : sterList) {
712
            if (!(sterCurrent.getOwner().getOwnerModule().getUuid().toString().equals("00bc42d0-0000-19fb-0000-000000000000")))
713
                return false;
714
        }
715
        return true;
716
    }
717

  
718
    /**
719
     * Method searchConnector
720
     * @author ebrosse
721
     * @param owner @return
722
     */
723
    @objid ("e0a5d0a6-c52f-45c4-a17f-cd76227d3af7")
724
    public static ArrayList<MObject> searchConnector(NameSpace owner) {
725
        ArrayList<MObject> result = new ArrayList<>();
726
        if ((owner instanceof Classifier) && (owner.isStereotyped(ISysMLPeerModule.MODULE_NAME, SysMLStereotypes.BLOCK))) {
727
            for (BindableInstance binstance : ((Classifier) owner).getInternalStructure()) {
728
                for (LinkEnd linkEnd : binstance.getOwnedEnd()) {
729
                    Link link = linkEnd.getLink();
730
        
731
                    boolean isConnector = true;
732
                    for (LinkEnd end : link.getLinkEnd()) {
733
                        Instance endOwner = end.getOwner();
734
                        if ((endOwner.getCompositionOwner() == null) || (!(endOwner.getCompositionOwner().equals(owner)))) {
735
        
736
                            isConnector = false;
737
                        }
738
                    }
739
        
740
                    if ((isConnector) && (!(result.contains(link))))
741
                        result.add(link);
742
        
743
                }
744
            }
745
        }
746
        return result;
747
    }
748

  
749
    /**
750
     * Method getTaggedValueLink
751
     * @author ebrosse
752
     * @param stereotypeLink
753
     * @param MObject
754
     * @return
755
     */
756
    @objid ("f24d5be2-5b8e-42f9-8a79-b878efd5e950")
757
    public static String getTaggedValueLink(String module, String stereotypeLink, ModelElement element) {
758
        for (Dependency depend : element.getDependsOnDependency()) {
759
            if (depend.isStereotyped(module,stereotypeLink)) {
760
                return depend.getDependsOn().getName();
761
            }
762
        }
763
        return "";
764
    }
765

  
766
    /**
767
     * Method searchEnds
768
     * @author ebrosse
769
     * @param MObject
770
     * @return
771
     */
772
    @objid ("2a179c90-346b-40d4-9bfb-fd95cef176a3")
773
    public static List<MObject> searchEnds(BindableInstance element) {
774
        NameSpace base = element.getBase();
775
        List<MObject> result = new ArrayList<>();
776
        if (base != null) {
777
            List<AssociationEnd> connection = new ArrayList<>();
778
        
779
            ClassAssociation classAssoc = ((Class) element.getInternalOwner()).getLinkToAssociation();
780
            connection.addAll(classAssoc.getAssociationPart().getEnd());
781
        
782
        
783
            for (AssociationEnd end : connection) {
784
                if ((end.getMultiplicityMax().equals("1")) && (end.getMultiplicityMin().equals("1"))
785
                        && (end.getTarget().equals(base)))
786
                    result.add(end);
787
            }
788
        }
789
        return result;
790
    }
791

  
792
    /**
793
     * Method createAssociation
794
     * @author ebrosse
795
     * @param c_source
796
     * @param c_destination @return
797
     */
798
    @objid ("e8f079dd-15a0-43e3-abdc-acd128109a42")
799
    public static Association createAssociation(Classifier c_source, Classifier c_destination) {
800
        Association association = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel()
801
                .createAssociation(c_source, c_destination, "");
802
        
803
        for (AssociationEnd end : association.getEnd()) {
804
            if (end.getOwner().equals(c_source)) {
805
                end.setName(c_destination.getName().toLowerCase());
806
                end.setMultiplicityMin("1");
807
                end.setMultiplicityMax("1");
808
            } else if (end.getOwner().equals(c_destination)) {
809
                end.setName(c_source.getName().toLowerCase());
810
            }
811
        }
812
        return association;
813
    }
814

  
815
    /**
816
     * Method createConnector
817
     * @author ebrosse
818
     * @param c_source
819
     * @param c_destination @return
820
     */
821
    @objid ("0d8ab673-38aa-4802-919c-81ed63c42bb4")
822
    public static Link createSmartLink(Instance c_source, Instance c_destination) {
823
        Link result = null;
824
        
825
        if (c_source instanceof BindableInstance)
826
            result = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel()
827
            .createConnector((BindableInstance) c_source, (BindableInstance) c_destination, "");
828
        else
829
            result = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel().createLink(c_source, c_destination, "");
830
        
831
        List<LinkEnd> ends = result.getLinkEnd();
832
        for (LinkEnd end : ends) {
833
            end.setName("");
834
            if (end.getOwner().equals(c_destination))
835
                end.setNavigable(true);
836
        }
837
        
838
        result.setName("");
839
        return result;
840
    }
841

  
842
    /**
843
     * Method getBindableInstance
844
     * @author ebrosse
845
     * @param MObject
846
     * @return
847
     */
848
    @objid ("517f339b-dc18-4574-9115-d66df6d41d83")
849
    public static ArrayList<MObject> getBindableInstance(InformationFlow element) {
850
        ArrayList<MObject> result = new ArrayList<>();
851
        
852
        if (element.getRealizingLink().size() > 0) {
853
        
854
            NameSpace nearestNamespace = getNearestNameSpace(element.getRealizingLink().get(0).getOwner());
855
        
856
            if (nearestNamespace instanceof Classifier){
857
                Classifier nearestClassifier = (Classifier) nearestNamespace;
858
                ArrayList<BindableInstance> temps = new ArrayList<>();
859
                ArrayList<BindableInstance> topInstances = new ArrayList<>();
860
        
861
                topInstances.addAll(nearestClassifier.getInternalStructure());
862
                temps.addAll(topInstances);
863
        
864
                ArrayList<BindableInstance> lowInstances = new ArrayList<>();
865
                for (BindableInstance instance : topInstances) {
866
                    lowInstances.addAll(instance.getPart());
867
                }
868
        
869
                while (lowInstances.size() > 0) {
870
                    topInstances = lowInstances;
871
                    temps.addAll(topInstances);
872
        
873
                    lowInstances = new ArrayList<>();
874
                    for (BindableInstance instance : topInstances) {
875
                        lowInstances.addAll(instance.getPart());
876
                    }
877
        
878
                }
879
        
880
                List<Classifier> convoyed = element.getConveyed();
881
        
882
                for (BindableInstance temp : temps) {
883
                    if (convoyed.contains(temp.getBase())) {
884
                        result.add(temp);
885
                    }
886
                }
887
            }
888
        }
889
        return result;
890
    }
891

  
892
}
0 893

  
branches/modelio3.7.x/src/main/java/org/modelio/module/sysml/utils/CommandExpert.java
1
package org.modelio.module.sysml.utils;
2

  
3
import com.modeliosoft.modelio.javadesigner.annotations.objid;
4
import org.modelio.api.modelio.model.IUmlModel;
5
import org.modelio.metamodel.uml.infrastructure.Profile;
6
import org.modelio.metamodel.uml.statik.Class;
7
import org.modelio.metamodel.uml.statik.Classifier;
8
import org.modelio.metamodel.uml.statik.Package;
9
import org.modelio.module.sysml.api.ISysMLPeerModule;
10
import org.modelio.module.sysml.api.SysMLStereotypes;
11
import org.modelio.module.sysml.filters.BlockFilter;
12
import org.modelio.module.sysml.filters.ConstraintBlockFilter;
13
import org.modelio.module.sysml.impl.SysMLModule;
14
import org.modelio.vcore.smkernel.mapi.MObject;
15

  
16
@objid ("323f1420-85a3-47ad-b8f7-df67cb8880b1")
17
public class CommandExpert {
18
    @objid ("8e989e6b-3447-49a9-856b-b56bc68ff9b4")
19
    public static boolean acceptBlock(MObject selectedElement) {
20
        return (accept(selectedElement))
21
                        && ((selectedElement instanceof Package))
22
                        || ((selectedElement instanceof Class) 
23
                                && (BlockFilter.isABlock(selectedElement)
24
                                        && (!ConstraintBlockFilter.isAConstraintBlock(selectedElement))));
25
    }
26

  
27
    @objid ("23dbff48-5df5-4006-8314-ad21d28ebc80")
28
    public static boolean acceptConnectorProperty(MObject selectedElement) {
29
        return (accept(selectedElement))
30
                        && (BlockFilter.isABlock (selectedElement))
31
                        && (!ConstraintBlockFilter.isAConstraintBlock(selectedElement));
32
    }
33

  
34
    @objid ("410794db-fb05-4a53-8969-606e1d849b9e")
35
    public static boolean acceptConstraintBlock(MObject selectedElement) {
36
        return (accept(selectedElement))
37
                        && (selectedElement instanceof Package)
38
                        && (!(selectedElement instanceof Profile));
39
    }
40

  
41
    @objid ("eaa3d2ce-de21-46ff-ab9e-35204e1aa38f")
42
    public static boolean acceptConstraintProperty(MObject selectedElement) {
43
        return (accept(selectedElement))
44
                        && (BlockFilter.isABlock (selectedElement))
45
                        || (ConstraintBlockFilter.isAConstraintBlock(selectedElement));
46
    }
47

  
48
    @objid ("ad7a4ecb-cea8-42fb-be62-910579d98932")
49
    public static boolean acceptDistributedProperty(MObject selectedElement) {
50
        return ((accept(selectedElement))
51
                        && ((selectedElement instanceof Classifier)
52
                                &&(BlockFilter.isABlock(selectedElement))
53
                                && (!ConstraintBlockFilter.isAConstraintBlock(selectedElement))
54
                                || (((Classifier) selectedElement).isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE))));
55
    }
56

  
57
    @objid ("0223c4cf-cf29-4009-b3c7-9b5058af0e9c")
58
    public static boolean acceptContinuousParameter(MObject selectedElement) {
59
        return  ((selectedElement != null) 
60
                        && (selectedElement.getStatus().isModifiable())
61
                        && acceptInternal(selectedElement));
62
    }
63

  
64
    @objid ("dfb3e281-2869-4aa5-923b-d7d2c9608537")
65
    public static boolean accept(MObject selectedElement) {
66
        return  ((selectedElement != null) 
67
                        && (selectedElement.getStatus().isModifiable())
68
                        && acceptInternal(selectedElement));
69
    }
70

  
71
    @objid ("0d66bbdf-0e6e-4aa0-ae74-8490c62020e7")
72
    private static boolean acceptInternal(MObject selectedElement) {
73
        IUmlModel model = SysMLModule.getInstance().getModuleContext().getModelingSession().getModel();
74
        
75
        for (MObject libRoot : model.getLibraryRoots()){
76
            if (selectedElement.equals(libRoot)){
77
                return false;
78
            }
79
        }
80
        
81
        for (MObject modelRoot : model.getModelRoots()){
82
            if (selectedElement.equals(modelRoot)){
83
                return false;
84
            }
85
        }
86
        return !((selectedElement.equals(model)));
87
    }
88

  
89
}
0 90

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

  
31
import com.modeliosoft.modelio.javadesigner.annotations.objid;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.swt.widgets.Display;
34
import org.modelio.api.modelio.model.IModelingSession;
35
import org.modelio.api.modelio.model.ITransaction;
36
import org.modelio.metamodel.uml.behavior.commonBehaviors.Signal;
37
import org.modelio.metamodel.uml.infrastructure.Element;
38
import org.modelio.metamodel.uml.statik.Attribute;
39
import org.modelio.metamodel.uml.statik.BindableInstance;
40
import org.modelio.metamodel.uml.statik.Classifier;
41
import org.modelio.metamodel.uml.statik.GeneralClass;
42
import org.modelio.metamodel.uml.statik.Interface;
43
import org.modelio.metamodel.uml.statik.NameSpace;
44
import org.modelio.metamodel.uml.statik.Operation;
45
import org.modelio.metamodel.uml.statik.Port;
46
import org.modelio.module.sysml.api.ISysMLPeerModule;
47
import org.modelio.module.sysml.api.SysMLStereotypes;
48
import org.modelio.module.sysml.i18n.I18nMessageService;
49
import org.modelio.module.sysml.impl.SysMLModule;
50

  
51
/**
52
 * This class provides services for checking SysML profile constraintes
53
 * @author ebrosse
54
 */
55
@objid ("85cb0457-feea-49e5-841d-3a95970a2cad")
56
public class ConstraintChecker {
57
    /**
58
     * Method CheckUpdatedElement
59
     * @author ebrosse
60
     * @param toCheck : the checked element
61
     */
62
    @objid ("d8570c36-cd07-47b3-a15c-cd62e5962930")
63
    public static void CheckUpdatedElement(Element toCheck) {
64
        IModelingSession session = SysMLModule.getInstance().getModuleContext().getModelingSession();
65
        try( ITransaction transaction = session.createTransaction (I18nMessageService.getString ("Info.Session.Create", "Check Update"))){
66
        
67
            if (toCheck instanceof Classifier){
68
                CheckUpdatedClassifier((Classifier) toCheck);
69
            }
70
        
71
            if (toCheck instanceof Port){
72
                CheckUpdatedPort((Port) toCheck);
73
            }
74
        
75
            if (toCheck instanceof Attribute){
76
                CheckUpdatedAttribute((Attribute) toCheck);
77
            }
78
        
79
            if (toCheck instanceof BindableInstance){
80
                CheckUpdatedBindableInstance((BindableInstance) toCheck);
81
            }
82
        
83
            if (toCheck instanceof Interface){
84
                CheckUpdatedInterface((Interface) toCheck);
85
            }
86
        
87
            transaction.commit();
88
        }
89
    }
90

  
91
    /**
92
     * Method CheckUpdatedInterface
93
     * @author ebrosse
94
     * @param toCheck
95
     */
96
    @objid ("11d1fae4-19af-4650-8a58-7ff59112a996")
97
    private static void CheckUpdatedInterface(Interface toCheck) {
98
        /**Flow specifications cannot own operations or receptions (they can only own FlowProperties).**/
99
        /**Every ?ownedAttribute? of a FlowSpecification must be a FlowProperty**/
100
        if (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWSPECIFICATION)){
101
            boolean ownedOperation = toCheck.getOwnedOperation().size() > 0;
102
            boolean ownedSimpleAttribute = false;
103
        
104
            for(Attribute current :toCheck.getOwnedAttribute() ){
105
                if ( !(current.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWPROPERTY)))
106
                    ownedSimpleAttribute = true;
107
            }
108
        
109
            if (ownedOperation)
110
                MessageDialog.openInformation(Display.getDefault().getActiveShell()
111
                        ,"SysML"
112
                        ,I18nMessageService.getString("Ui.I18nMessageService.FlowSpecificationCannotOwnOperations"));
113
        
114
        
115
            if (ownedSimpleAttribute)
116
                MessageDialog.openInformation(Display.getDefault().getActiveShell()
117
                        ,"SysML"
118
                        ,I18nMessageService.getString("Ui.I18nMessageService.FlowSpecificationCannotOwnSimpleAttribute"));
119
        
120
        }
121
    }
122

  
123
    /**
124
     * Method CheckCreatedElement
125
     * @author ebrosse
126
     * @param toCheck : the MObject to check
127
     */
128
    @objid ("689d874f-d939-4515-85ff-ffd182894570")
129
    public static void CheckCreatedElement(Element toCheck) {
130
        IModelingSession session = SysMLModule.getInstance().getModuleContext().getModelingSession();
131
        try( ITransaction transaction = session.createTransaction (I18nMessageService.getString ("Info.Session.Create", "Activity"))){
132
        
133
            if (toCheck instanceof Operation){
134
                CheckCreatedOperation((Operation) toCheck);
135
            }
136
        
137
            if (toCheck instanceof Attribute){
138
                CheckCreatedAttribute((Attribute) toCheck);
139
            }
140
        
141
            transaction.commit();
142
        }
143
    }
144

  
145
    /**
146
     * Method CheckCreatedOperation
147
     * @author ebrosse
148
     * @param toCheck
149
     */
150
    @objid ("8c87abde-1950-4f6e-b4e3-71f296d693d7")
151
    private static void CheckCreatedOperation(Operation toCheck) {
152
        /**Flow specifications cannot own operations or receptions (they can only own FlowProperties).**/
153
        Classifier owner = toCheck.getOwner();
154
        if (owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWSPECIFICATION)){
155
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
156
                    ,"SysML"
157
                    ,I18nMessageService.getString("Ui.I18nMessageService.FlowSpecificationCannotOwnOperations"));
158
        
159
        }
160
    }
161

  
162
    /**
163
     * Method CheckCreatedAttribute
164
     * @author ebrosse
165
     * @param toCheck
166
     */
167
    @objid ("ff7cdfe7-eb79-4b9c-a035-f8267d870c9f")
168
    private static void CheckCreatedAttribute(Attribute toCheck) {
169
        /**Flow specifications cannot own operations or receptions (they can only own FlowProperties).**/
170
        Classifier owner = toCheck.getOwner();
171
        if (owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWSPECIFICATION)){
172
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
173
                    ,"SysML"
174
                    ,I18nMessageService.getString("Ui.I18nMessageService.FlowSpecificationCannotOwnSimpleAttribute"));
175
        
176
        }
177
    }
178

  
179
    /**
180
     * Method CheckUpdatedClassifier
181
     * @author ebrosse
182
     * @param toCheck
183
     */
184
    @objid ("eb17ad2c-7331-43a6-b9be-48a1fa95a9e4")
185
    private static void CheckUpdatedClassifier(Classifier toCheck) {
186
        /**The name of a classifier to which a PropertySpecificType is applied must be missing. (The ?name? attribute of the NamedElement metaclass must be empty.)**/
187
        if  (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.PROPERTYSPECIFICTYPE)){
188
            toCheck.setName("");
189
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
190
                    ,"SysML"
191
                    ,I18nMessageService.getString("Ui.I18nMessageService.NameOfPropertySpecificTypeMustBeMissing"));
192
        
193
        }
194
    }
195

  
196
    /**
197
     * Method CheckUpdatedAttribute
198
     * @author ebrosse
199
     * @param toCheck
200
     */
201
    @objid ("9cb465cd-899f-4adb-b639-c62db1cff6fa")
202
    private static void CheckUpdatedAttribute(Attribute toCheck) {
203
        /**If a property owned by a SysML Block or SysML ValueType is typed by a SysML ValueType,
204
        then the aggregation attribute of the property must be ?composite.?**/
205
        Classifier owner = toCheck.getOwner();
206
        GeneralClass type = toCheck.getType();
207
        if ((owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK) || owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE))
208
                && ((type != null) && (type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE)))){
209
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
210
                    ,"SysML"
211
                    ,I18nMessageService.getString("Ui.I18nMessageService.ValueTypePropertyMustBeComposite"));
212
        
213
        }
214
        
215
        /**The DistributedProperty stereotype may be applied only to properties of classifiers stereotyped by Block or ValueType**/
216
        if ( (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.DISTRIBUTEDPROPERTY)) && 
217
                ( !    (owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK) || owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE))))
218
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
219
                    ,"SysML"
220
                    ,I18nMessageService.getString("Ui.I18nMessageService.DistributedPropertyOwnerMustBeBlockOrValueType"));
221
        
222
        
223
        /**A FlowProperty is typed by a ValueType, Block, or Signal.**/
224
        if ((type != null) && (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWPROPERTY)) && 
225
                ( !    (type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK) || type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE) 
226
                        || (type instanceof Signal))))
227
            MessageDialog.openInformation(Display.getDefault().getActiveShell()
228
                    ,"SysML"
229
                    ,I18nMessageService.getString("Ui.I18nMessageService.FlowPropertyTypeControl"));
230
    }
231

  
232
    /**
233
     * Method CheckUpdatedPort
234
     * @author ebrosse
235
     * @param toCheck
236
     */
237
    @objid ("a58a0d7b-252b-4a86-a661-47c06be25bca")
238
    private static void CheckUpdatedPort(Port toCheck) {
239
        /**A FlowPort must be typed by a FlowSpecification, Block, Signal, or ValueType.**/
240
        NameSpace type = toCheck.getBase();
241
        if (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWPORT) && (type != null) 
242
                && (!(type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.FLOWSPECIFICATION) 
243
                        || type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK)
244
                        || type.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE)
245
                        || (type instanceof Signal)))){
246
            MessageDialog.openInformation(Display.getDefault().getActiveShell(),
247
                    "SysML",
248
                    I18nMessageService.getString("Ui.I18nMessageService.FlowPropertyTypeControl"));
249
        
250
        }
251
    }
252

  
253
    /**
254
     * Method CheckUpdatedBindableInstance
255
     * @author ebrosse
256
     * @param toCheck
257
     */
258
    @objid ("d35a5873-765f-4c86-a56c-0eb78dbff2d6")
259
    private static void CheckUpdatedBindableInstance(BindableInstance toCheck) {
260
        /**ConnectorProperty may only be applied to properties of classes stereotyped by Block.**/
261
        Classifier owner = toCheck.getInternalOwner();
262
        if ((owner != null) && (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.CONNECTORPROPERTY)) && ( !owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK)))
263
            MessageDialog.openInformation(Display.getDefault().getActiveShell(),
264
                    "SysML",
265
                    I18nMessageService.getString("Ui.I18nMessageService.ConnectorPropertyOwnerMustBeBlock"));
266
        
267
        /**The DistributedProperty stereotype may be applied only to properties of classifiers stereotyped by Block or ValueType**/
268
        if ((owner != null) && (toCheck.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.DISTRIBUTEDPROPERTY)) && 
269
                ( !    (owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.BLOCK) || owner.isStereotyped(ISysMLPeerModule.MODULE_NAME,SysMLStereotypes.VALUETYPE))))
270
            MessageDialog.openInformation(Display.getDefault().getActiveShell(),
271
                    "SysML",
272
                    I18nMessageService.getString("Ui.I18nMessageService.DistributedPropertyOwnerMustBeBlockOrValueType"));
273
    }
274

  
275
}
0 276

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff