-
Notifications
You must be signed in to change notification settings - Fork 85
/
CapellaServices.java
3079 lines (2781 loc) · 113 KB
/
CapellaServices.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2006, 2022 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.sirius.analysis;
import static org.polarsys.capella.common.helpers.cache.ModelCache.getCache;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
import java.util.stream.Collectors;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.helper.task.DeleteEObjectTask;
import org.eclipse.sirius.business.api.query.DRepresentationQuery;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterSiriusVariables;
import org.eclipse.sirius.diagram.AbstractDNode;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.DDiagramElementContainer;
import org.eclipse.sirius.diagram.DEdge;
import org.eclipse.sirius.diagram.DNode;
import org.eclipse.sirius.diagram.DNodeContainer;
import org.eclipse.sirius.diagram.DSemanticDiagram;
import org.eclipse.sirius.diagram.EdgeTarget;
import org.eclipse.sirius.diagram.business.api.helper.display.DisplayServiceManager;
import org.eclipse.sirius.diagram.business.api.helper.graphicalfilters.HideFilterHelper;
import org.eclipse.sirius.diagram.business.api.query.DiagramElementMappingQuery;
import org.eclipse.sirius.diagram.business.internal.sync.DDiagramElementSynchronizer;
import org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer;
import org.eclipse.sirius.diagram.description.DiagramElementMapping;
import org.eclipse.sirius.diagram.description.Layer;
import org.eclipse.sirius.diagram.ui.business.api.helper.graphicalfilters.CompositeFilterApplicationBuilder;
import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.ecore.extender.business.api.accessor.exception.FeatureNotFoundException;
import org.eclipse.sirius.ecore.extender.business.api.accessor.exception.MetaClassNotFoundException;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.tools.api.SiriusPlugin;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.polarsys.capella.common.data.activity.ActivityEdge;
import org.polarsys.capella.common.data.activity.ActivityNode;
import org.polarsys.capella.common.data.activity.Pin;
import org.polarsys.capella.common.data.modellingcore.AbstractConstraint;
import org.polarsys.capella.common.data.modellingcore.AbstractExchangeItem;
import org.polarsys.capella.common.data.modellingcore.AbstractNamedElement;
import org.polarsys.capella.common.data.modellingcore.AbstractTrace;
import org.polarsys.capella.common.data.modellingcore.AbstractType;
import org.polarsys.capella.common.data.modellingcore.AbstractTypedElement;
import org.polarsys.capella.common.data.modellingcore.ModelElement;
import org.polarsys.capella.common.data.modellingcore.ModellingcorePackage;
import org.polarsys.capella.common.data.modellingcore.TraceableElement;
import org.polarsys.capella.common.helpers.EObjectExt;
import org.polarsys.capella.common.helpers.EcoreUtil2;
import org.polarsys.capella.common.helpers.TransactionHelper;
import org.polarsys.capella.common.libraries.ILibraryManager;
import org.polarsys.capella.common.libraries.IModel;
import org.polarsys.capella.common.libraries.manager.LibraryManager;
import org.polarsys.capella.common.platform.sirius.ted.SemanticEditingDomainFactory.SemanticEditingDomain;
import org.polarsys.capella.common.queries.interpretor.QueryInterpretor;
import org.polarsys.capella.core.business.queries.IBusinessQuery;
import org.polarsys.capella.core.business.queries.capellacore.BusinessQueriesProvider;
import org.polarsys.capella.core.commands.preferences.initializers.CapellaDiagramPreferencesInitializer;
import org.polarsys.capella.core.commands.preferences.preferences.CapellaDiagramPreferences;
import org.polarsys.capella.core.data.capellacommon.CapabilityRealizationInvolvedElement;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
import org.polarsys.capella.core.data.capellacore.Classifier;
import org.polarsys.capella.core.data.capellacore.Constraint;
import org.polarsys.capella.core.data.capellacore.Feature;
import org.polarsys.capella.core.data.capellacore.GeneralizableElement;
import org.polarsys.capella.core.data.capellacore.Generalization;
import org.polarsys.capella.core.data.capellacore.Involvement;
import org.polarsys.capella.core.data.capellacore.ModellingArchitecture;
import org.polarsys.capella.core.data.capellacore.Structure;
import org.polarsys.capella.core.data.capellacore.TypedElement;
import org.polarsys.capella.core.data.cs.AbstractDeploymentLink;
import org.polarsys.capella.core.data.cs.Block;
import org.polarsys.capella.core.data.cs.BlockArchitecture;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.ComponentPkg;
import org.polarsys.capella.core.data.cs.CsPackage;
import org.polarsys.capella.core.data.cs.DeployableElement;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.cs.PhysicalLinkCategory;
import org.polarsys.capella.core.data.ctx.Capability;
import org.polarsys.capella.core.data.ctx.CapabilityExploitation;
import org.polarsys.capella.core.data.ctx.CapabilityInvolvement;
import org.polarsys.capella.core.data.ctx.CtxPackage;
import org.polarsys.capella.core.data.ctx.Mission;
import org.polarsys.capella.core.data.ctx.MissionInvolvement;
import org.polarsys.capella.core.data.ctx.MissionPkg;
import org.polarsys.capella.core.data.ctx.SystemAnalysis;
import org.polarsys.capella.core.data.ctx.SystemComponent;
import org.polarsys.capella.core.data.epbs.EPBSArchitecture;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.fa.ComponentExchangeCategory;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.data.fa.ExchangeCategory;
import org.polarsys.capella.core.data.fa.FaPackage;
import org.polarsys.capella.core.data.fa.FunctionInputPort;
import org.polarsys.capella.core.data.fa.FunctionOutputPort;
import org.polarsys.capella.core.data.fa.FunctionPkg;
import org.polarsys.capella.core.data.fa.FunctionalChain;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.helpers.cs.services.PhysicalLinkExt;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionExt;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionPkgExt;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionalExt;
import org.polarsys.capella.core.data.information.AbstractInstance;
import org.polarsys.capella.core.data.information.AggregationKind;
import org.polarsys.capella.core.data.information.Association;
import org.polarsys.capella.core.data.information.Class;
import org.polarsys.capella.core.data.information.ExchangeItem;
import org.polarsys.capella.core.data.information.ExchangeItemElement;
import org.polarsys.capella.core.data.information.Port;
import org.polarsys.capella.core.data.information.PortAllocation;
import org.polarsys.capella.core.data.information.PortRealization;
import org.polarsys.capella.core.data.information.Property;
import org.polarsys.capella.core.data.information.datatype.DataType;
import org.polarsys.capella.core.data.information.datatype.NumericType;
import org.polarsys.capella.core.data.information.datatype.PhysicalQuantity;
import org.polarsys.capella.core.data.interaction.AbstractCapability;
import org.polarsys.capella.core.data.interaction.AbstractEnd;
import org.polarsys.capella.core.data.interaction.EventReceiptOperation;
import org.polarsys.capella.core.data.interaction.EventSentOperation;
import org.polarsys.capella.core.data.interaction.Execution;
import org.polarsys.capella.core.data.interaction.InstanceRole;
import org.polarsys.capella.core.data.interaction.RefinementLink;
import org.polarsys.capella.core.data.interaction.Scenario;
import org.polarsys.capella.core.data.interaction.SequenceMessage;
import org.polarsys.capella.core.data.interaction.StateFragment;
import org.polarsys.capella.core.data.la.CapabilityRealization;
import org.polarsys.capella.core.data.la.LogicalArchitecture;
import org.polarsys.capella.core.data.la.LogicalComponent;
import org.polarsys.capella.core.data.la.LogicalComponentPkg;
import org.polarsys.capella.core.data.oa.ActivityAllocation;
import org.polarsys.capella.core.data.oa.Entity;
import org.polarsys.capella.core.data.oa.OperationalActivity;
import org.polarsys.capella.core.data.oa.OperationalAnalysis;
import org.polarsys.capella.core.data.oa.Role;
import org.polarsys.capella.core.data.pa.PhysicalArchitecture;
import org.polarsys.capella.core.data.pa.PhysicalComponent;
import org.polarsys.capella.core.data.pa.PhysicalComponentNature;
import org.polarsys.capella.core.data.pa.PhysicalComponentPkg;
import org.polarsys.capella.core.diagram.helpers.DiagramHelper;
import org.polarsys.capella.core.libraries.queries.QueryIdentifierConstants;
import org.polarsys.capella.core.linkedtext.ui.CapellaEmbeddedLinkedTextEditorInput;
import org.polarsys.capella.core.model.helpers.AbstractFunctionExt;
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.model.helpers.CapellaElementExt;
import org.polarsys.capella.core.model.helpers.ComponentExchangeExt;
import org.polarsys.capella.core.model.helpers.ComponentExt;
import org.polarsys.capella.core.model.helpers.FunctionalChainExt;
import org.polarsys.capella.core.model.helpers.FunctionalExchangeExt;
import org.polarsys.capella.core.model.helpers.PartExt;
import org.polarsys.capella.core.model.helpers.ScenarioExt;
import org.polarsys.capella.core.model.preferences.CapellaModelPreferencesPlugin;
import org.polarsys.capella.core.platform.sirius.ui.commands.CapellaDeleteCommand;
import org.polarsys.capella.core.sirius.analysis.tool.StringUtil;
/**
* Basic Services For Capella models.
*/
public class CapellaServices {
/**
* A specific prefix to add for message of {@link OperationCanceledException} that must be rethrown to rollback all
* the corresponding command.
*/
public static final String RE_THROW_OCE_PREFIX = "-RT-"; //$NON-NLS-1$
public EObject getRootContainer(EObject eObject) {
return EcoreUtil.getRootContainer(eObject);
}
/** used by aql queries */
public List<DDiagramElementContainer> getAllContainersNew(EObject container) {
return getAllContainers(container);
}
// equivalent de <%
// (((current+current.~).ancestor[eClass.name=="DAnalysis"].nMinimize().put("aird")
// + (get("aird")+get("aird").~+get("aird").~.~+get("aird").~.~.~).put("airds")
// +
// get("airds")+get("airds").referencedAnalysis+get("airds").referencedAnalysis.referencedAnalysis+get("airds").referencedAnalysis.referencedAnalysis.referencedAnalysis).nMinimize()[eClass.name=="DAnalysis"])
// %>
public static Collection<EObject> getAllDAnalysis(EObject eObject) {
Collection<EObject> result = new ArrayList<>();
EObject source = eObject;
if (source instanceof DSemanticDecorator) {
source = ((DSemanticDecorator) source).getTarget();
}
if (source instanceof DRepresentationDescriptor) {
source = ((DRepresentationDescriptor) source).getTarget();
}
Session session = SessionManager.INSTANCE.getSession(source);
if (session instanceof DAnalysisSession) {
result.addAll(((DAnalysisSession) session).allAnalyses());
}
return result;
}
/** used by aql queries */
public Object void2Null(EObject eObject, Object object) {
if (object instanceof Collection && ((Collection<?>) object).isEmpty()) {
return null;
}
return object;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
/** used by aql queries */
public Object makeIntersection(EObject eObject, Object obj1, Object obj2) {
try {
List<Object> result = new ArrayList<>();
if (obj1 instanceof Collection) {
result.addAll((Collection) obj1);
} else if (obj1 != null) {
result.add(obj1);
}
if (obj2 instanceof Collection) {
result.retainAll((Collection) obj2);
} else if (obj2 != null && !result.contains(obj2)) {
result.remove(obj2);
}
return result;
} catch (Exception e) {
throw new UnsupportedOperationException();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
/** used by aql queries */
public Object makeDiff(EObject eObject, Object obj1, Object obj2) {
try {
List<Object> result = new ArrayList<Object>();
if (obj1 instanceof Collection) {
result.addAll((Collection) obj1);
} else if (obj1 != null) {
result.add(obj1);
}
if (obj2 instanceof Collection) {
result.removeAll((Collection) obj2);
} else if (obj2 instanceof Object[]) {
for (Object o : (Object[]) obj2) {
result.remove(o);
}
} else if (obj2 != null) {
result.remove(obj2);
}
// if (result.size() == 1)
// return result.get(0);
return result;
} catch (Exception e) {
throw new UnsupportedOperationException();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
/** used by aql queries */
public Object makeUnion(EObject eObject, Object obj1, Object obj2) {
try {
List<Object> result = new ArrayList<>();
if (obj1 instanceof Collection) {
result.addAll((Collection) obj1);
} else if (obj1 != null) {
result.add(obj1);
}
if (obj2 instanceof Collection) {
result.addAll((Collection) obj2);
} else if (obj2 != null) {
result.add(obj2);
}
return result;
} catch (Exception e) {
throw new UnsupportedOperationException();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
/** used by aql queries */
public Object makeUnion(EObject eObject, Object obj1, Object obj2, Object obj3) {
try {
List<Object> result = new ArrayList<>();
if (obj1 instanceof Collection) {
result.addAll((Collection) obj1);
} else if (obj1 != null) {
result.add(obj1);
}
if (obj2 instanceof Collection) {
result.addAll((Collection) obj2);
} else if (obj2 != null) {
result.add(obj2);
}
if (obj3 instanceof Collection) {
result.addAll((Collection) obj3);
} else if (obj3 != null) {
result.add(obj3);
}
return result;
} catch (Exception e) {
throw new UnsupportedOperationException();
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
/** used by aql queries */
public Object makeUnion(EObject eObject, Object obj1, Object obj2, Object obj3, Object obj4) {
try {
List<Object> result = new ArrayList<>();
if (obj1 instanceof Collection) {
result.addAll((Collection) obj1);
} else if (obj1 != null) {
result.add(obj1);
}
if (obj2 instanceof Collection) {
result.addAll((Collection) obj2);
} else if (obj2 != null) {
result.add(obj2);
}
if (obj3 instanceof Collection) {
result.addAll((Collection) obj3);
} else if (obj3 != null) {
result.add(obj3);
}
if (obj4 instanceof Collection) {
result.addAll((Collection) obj4);
} else if (obj4 != null) {
result.add(obj4);
}
return result;
} catch (Exception e) {
throw new UnsupportedOperationException();
}
}
public List<EObject> selectOnlyCreatedView(EObject eObject) {
return Collections.singletonList((EObject) InterpreterUtil.getInterpreter(eObject).getVariable("view"));
}
public boolean isInLib(EObject context) {
Session session = SessionManager.INSTANCE.getSession(context);
IModel sessionModel = ILibraryManager.INSTANCE.getModel(TransactionHelper.getEditingDomain(session));
IModel currentElementModel = ILibraryManager.INSTANCE.getModel(context);
return sessionModel.equals(currentElementModel); // forbidden if the element's IModel is not the session's one
// (ie
// is a Library)
}
public List<EObject> ancestor(EObject object) {
List<EObject> result = new ArrayList<>();
if (object != null) {
for (object = object.eContainer(); object != null; object = object.eContainer()) {
result.add(object);
}
}
return result;
}
/** A shared instance. */
private static CapellaServices service;
protected void addInAvailableFunctionList(AbstractFunction function, AbstractFunction functionToAdd,
List<AbstractFunction> functionInDiagram) {
if (EcoreUtil.isAncestor(functionToAdd, function) || EcoreUtil.isAncestor(function, functionToAdd)
|| functionInDiagram.contains(functionToAdd)) {
return;
}
AbstractFunction toRemove = null;
boolean toAdd = true;
for (AbstractFunction aFunction : functionInDiagram) {
// if a descendant of the actual function is in diagram
// we must remove the descendant and add the actual function
if (EcoreUtil.isAncestor(functionToAdd, aFunction)) {
toRemove = aFunction;
toAdd = true;
break;
}
// if a parent of the actual function is in diagram
// do nothing
if (EcoreUtil.isAncestor(aFunction, functionToAdd)) {
toAdd = false;
}
}
if ((toRemove != null) && (functionInDiagram.contains(toRemove))) {
functionInDiagram.remove(toRemove);
}
if (toAdd && !functionInDiagram.contains(toRemove)) {
functionInDiagram.add(functionToAdd);
}
}
public EObject creationService(EObject context) {
return CapellaElementExt.creationService(context);
}
public EObject creationService(EObject context, String namingPrefix) {
return CapellaElementExt.creationService(context, namingPrefix);
}
/**
* @param element
*/
public void deleteView(DDiagramElement element) {
DeleteEObjectTask task = new DeleteEObjectTask(element,
SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(element));
try {
task.execute();
} catch (FeatureNotFoundException | MetaClassNotFoundException ex) {
// Do nothing
}
}
public void filter(Collection<? extends EObject> collection, EClass type) {
Iterator<? extends EObject> iterContents = collection.iterator();
while (iterContents.hasNext()) {
final EObject next = iterContents.next();
if (!type.isSuperTypeOf(next.eClass())) {
iterContents.remove();
}
}
}
public EObject forceRefresh(DDiagram diagram) {
if (null != diagram && !new DRepresentationQuery(diagram).isAutoRefresh()) {
if (!diagram.getActivatedFilters().isEmpty()) {
CompositeFilterApplicationBuilder builder = new CompositeFilterApplicationBuilder(diagram);
builder.computeCompositeFilterApplications();
}
// Refreshes the diagram
DialectManager.INSTANCE.refresh(diagram, new NullProgressMonitor());
}
return diagram;
}
/**
* Retrieve name of navigation menu from the given containerView to the named diagramName
*
* @param containerView
* @param diagramName
* @return
*/
public String getNavigationName(DSemanticDecorator containerView, String diagramName) {
// low-reference to private method
// org.eclipse.sirius.diagram.tools.internal.menu.NavigateToMenuContribution.buildOpenRepresentationAction
String result = diagramName;
if (StringUtil.isEmpty(result)) {
result = Messages.CapellaServices_NavigateUnnamed;
}
return Messages.CapellaServices_NavigateOpen + result;
}
/**
* Get scope for others navigable elements
*
* @param current
* @return
*/
public List<EObject> getNavigationScope(EObject current) {
ArrayList<EObject> scope = new ArrayList<>();
if (current instanceof AbstractTypedElement) {
scope.add(((AbstractTypedElement) current).getAbstractType());
} else if (current instanceof AbstractType) {
scope.addAll(((AbstractType) current).getAbstractTypedElements());
}
return scope;
}
public List<Component> getAllActors(ComponentPkg actorPkg) {
return ScenarioExt.getAllActors(actorPkg);
}
/**
* TODO check duplicate used everywhere
*
* @param eObject
* @return
*/
public List<EObject> getAllAncestor(EObject eObject) {
EObject obj = eObject;
List<EObject> list = new ArrayList<>();
if (obj == null) {
return list;
}
while (obj.eContainer() != null) {
EObject container = obj.eContainer();
list.add(container);
obj = container;
}
return list;
}
/**
* used
*
* @param current
* @return
*/
public List<Component> getAllAncestors(final EObject context, Component current) {
return getAllAncestors(current);
}
List<Component> getAllAncestors(Component current) {
return ComponentExt.getAllPartitionableElementAncestors(current);
}
/**
* used in context
*
* @param context
* @return
*/
public EList<CapabilityExploitation> getAllCapabilityExploitation(final EObject context) {
// Missions Capabilities Blank : CapExploitation4
// Contextual Capability: CapExploitation3
EList<CapabilityExploitation> list = new BasicEList<>();
SystemAnalysis ca = (SystemAnalysis) getAncestor(context, CtxPackage.Literals.SYSTEM_ANALYSIS);
// get all recursive missionpkgs : private service
EList<MissionPkg> allMissionPkg = getAllRecursiveMissionPkg(ca);
EList<Mission> ownedMissions = new BasicEList<>();
for (MissionPkg missionPkg : allMissionPkg) {
// get all missions
ownedMissions.addAll(missionPkg.getOwnedMissions());
}
for (Mission mission : ownedMissions) {
// add all capability exploitation
list.addAll(mission.getOwnedCapabilityExploitations());
}
return list;
}
private Collection<Constraint> getAllConstraints(final EObject context) {
Collection<Constraint> returnedClasses = new ArrayList<>();
for (BlockArchitecture aBlockArchitecture : getAvailableArchitectures(context)) {
TreeIterator<EObject> it = aBlockArchitecture.eAllContents();
while (it.hasNext()) {
EObject currentObject = it.next();
if (currentObject instanceof Constraint) {
returnedClasses.add((Constraint) currentObject);
}
}
}
return returnedClasses;
}
/**
* Recursively get all ports on current function and its children functions.
*/
private List<Pin> getAllContainedPins(AbstractFunction function) {
List<Pin> result = new LinkedList<>();
for (EObject child : FaServices.getFaServices().getAllAbstractFunctions(function)) {
if (child instanceof AbstractFunction) {
result.addAll(getContainedPins((AbstractFunction) child));
}
}
return result;
}
/**
* used in context, logical, physical
*
* @param container
* @return container + recursively all the containers of container
*/
public List<DDiagramElementContainer> getAllContainers(EObject container) {
List<DDiagramElementContainer> returnedList = new ArrayList<>();
if (container instanceof DDiagram) {
returnedList = ((DDiagram) container).getContainers();
} else if (container instanceof DDiagramElementContainer) {
returnedList.add((DDiagramElementContainer) container);
for (DDiagramElementContainer aContainer : ((DDiagramElementContainer) container).getContainers()) {
returnedList.addAll(getAllContainers(aContainer));
}
}
return returnedList;
}
/**
* used everywhere
*
* @param current
* @return
*/
public List<Component> getAllDescendants(Component current) {
List<Component> result = new ArrayList<>();
List<Part> ownedPartitions = ComponentExt.getSubParts(current);
List<Component> children = new ArrayList<>();
for (Part partition : ownedPartitions) {
if (partition.getAbstractType() instanceof Component) {
Component pa = (Component) partition.getAbstractType();
children.add(pa);
}
}
result.addAll(children);
for (Component partitionableElement : children) {
result.addAll(getAllDescendants(partitionableElement));
}
return result;
}
/**
* used in context, logical, physical
*
* @param context
* @return
*/
public EList<ExchangeCategory> getAllExchangeCategory(final EObject context) {
EList<ExchangeCategory> result = new BasicEList<>();
BlockArchitecture architecture = BlockArchitectureExt.getRootBlockArchitecture(context);
result.addAll(FunctionPkgExt.getAllExchangeCategories(architecture.getOwnedFunctionPkg()));
return result;
}
public Collection<AbstractExchangeItem> getAllExchangeItems(final EObject context) {
Collection<AbstractExchangeItem> returnedInformationItems = new ArrayList<>();
List<BlockArchitecture> blocks = QueryInterpretor
.executeQuery(QueryIdentifierConstants.GET_AVAILABLE_ARCHITECTURES_FOR_LIB, context);
for (BlockArchitecture aBlockArchitecture : blocks) {
TreeIterator<EObject> it = aBlockArchitecture.eAllContents();
while (it.hasNext()) {
EObject currentObject = it.next();
if (currentObject instanceof AbstractExchangeItem) {
returnedInformationItems.add((AbstractExchangeItem) currentObject);
}
if (!((currentObject instanceof Block) || (currentObject instanceof Structure))) {
it.prune();
}
}
}
return returnedInformationItems;
}
/**
* used partout
*
* @param context
* @return
*/
public List<FunctionalChain> getAllFunctionalChain(final ModelElement context) {
BlockArchitecture architecture = ComponentExt.getRootBlockArchitecture(context);
return FunctionalChainExt.getAllFunctionalChains(architecture);
}
/**
* Recursively get all graphical container nodes which are contained within a diagram or a container node.
*/
private List<DNodeContainer> getAllGraphicalContainers(DDiagram diagram) {
List<DNodeContainer> returnedList = new ArrayList<>();
for (AbstractDNode aContainer : diagram.getContainers()) {
if (aContainer instanceof DNodeContainer) {
returnedList.add((DNodeContainer) aContainer);
}
}
return returnedList;
}
private List<DNodeContainer> getAllGraphicalContainers(DNodeContainer container) {
List<DNodeContainer> result = new LinkedList<>();
result.add(container);
for (AbstractDNode aContainer : container.getContainers()) {
if (aContainer instanceof DNodeContainer) {
result.add((DNodeContainer) aContainer);
}
}
return result;
}
public List<LogicalComponent> getAllLogicalActors(LogicalComponentPkg logicalActorPkg) {
return (List) ScenarioExt.getAllActors(logicalActorPkg);
}
public List<PhysicalComponent> getAllphysicalActors(PhysicalComponentPkg physicalActorPkg) {
return (List) ScenarioExt.getAllActors(physicalActorPkg);
}
/**
* used in common logical physical
*
* @param context
* @return
*/
@Deprecated
public EList<PortAllocation> getAllPortAllocation(final EObject context) {
EList<PortAllocation> result = new BasicEList<>();
Collection<Component> subLCsFromRoot = BlockArchitectureExt
.getAllComponents(BlockArchitectureExt.getRootBlockArchitecture(context));
for (Component partitionableElement : subLCsFromRoot) {
EList<Feature> ownedFeatures = partitionableElement.getOwnedFeatures();
for (Feature feature : ownedFeatures) {
if (feature instanceof Port) {
Port fp = (Port) feature;
result.addAll(fp.getOwnedPortAllocations());
}
}
}
return result;
}
/**
* used in context, logical, physical
*
* @param context
* @return
*/
@Deprecated
public EList<PortRealization> getAllPortRealisation(final EObject context) {
// //System Architecture Blank : CA PortRealization Flow Port to
// Standard Port + CA PortRealization FlowPort to FlowPort
EList<PortRealization> result = new BasicEList<>();
Collection<Component> enclosedComponents = BlockArchitectureExt
.getAllComponents(BlockArchitectureExt.getRootBlockArchitecture(context));
for (Component partitionableElement : enclosedComponents) {
EList<Feature> ownedFeatures = partitionableElement.getOwnedFeatures();
for (Feature feature : ownedFeatures) {
if (feature instanceof Port) {
Port fp = (Port) feature;
result.addAll(fp.getOwnedPortRealizations());
}
}
}
return result;
}
/**
* used by refreshExtension
*
* @param context
* @return
*/
public EList<Mission> getAllPurposeMission(final Capability context) {
// Contextual Capability : MissionNode3
EList<Mission> list = new BasicEList<>();
list.addAll(context.getPurposeMissions());
/*
* EList<CapabilityExploitation> purposes = context.getPurposes(); for (CapabilityExploitation
* capabilityExploitation : purposes) { Mission mission = capabilityExploitation.getMission(); list.add(mission); }
*/
SystemAnalysis ca = (SystemAnalysis) getAncestor(context, CtxPackage.Literals.SYSTEM_ANALYSIS);
// get all missionpkgs : private service
EList<MissionPkg> allMissionPkg = getAllRecursiveMissionPkg(ca);
EList<Mission> ownedMissions = new BasicEList<>();
for (MissionPkg missionPkg : allMissionPkg) {
// get all missions
ownedMissions.addAll(missionPkg.getOwnedMissions());
}
for (Mission mission : ownedMissions) {
EList<Capability> exploitedCapabilities = mission.getExploitedCapabilities();
if (exploitedCapabilities.contains(context)) {
list.add(mission);
}
}
return list;
}
private EList<MissionPkg> getAllRecursiveMissionPkg(MissionPkg missionPkg) {
EList<MissionPkg> list = new BasicEList<>();
EList<MissionPkg> subMissionPkgs = missionPkg.getOwnedMissionPkgs();
list.addAll(subMissionPkgs);
for (MissionPkg pkg : subMissionPkgs) {
list.addAll(getAllRecursiveMissionPkg(pkg));
}
return list;
}
private EList<MissionPkg> getAllRecursiveMissionPkg(SystemAnalysis contextArchi) {
EList<MissionPkg> list = new BasicEList<>();
MissionPkg ownedMissionPkg = contextArchi.getOwnedMissionPkg();
// add the root missionpkg
list.add(ownedMissionPkg);
// add all the owned missionpkgs
list.addAll(getAllRecursiveMissionPkg(ownedMissionPkg));
return list;
}
/**
* used in context.odesign
*
* @param context
* @param target
* @return
*/
public List<AbstractCapability> getAllSuperCapabilities(final EObject context, AbstractCapability target) {
List<AbstractCapability> result = new LinkedList<>();
result.add(target);
if (target.getSuper() == null) {
return result;
}
for (AbstractCapability current : target.getSuper()) {
result.addAll(getAllSuperCapabilities(context, current));
}
return result;
}
/**
* Finds an unique name for the given capella element. Suffixes the <code>prefix</code> string with a number to get an
* unique name for the namespace of <code>namedElement</code>.
*
* @param namedElement
* the named element.
* @param prefix
* the prefix of the name.
* @return an unique name for the given capella element. Suffixes the <code>prefix</code> string with a number to get
* an unique name for the namespace of <code>namedElement</code>.
*/
public String getAllUniqueName(AbstractNamedElement namedElement, String prefix) {
return EcoreUtil2.getUniqueName(namedElement, ModellingcorePackage.Literals.ABSTRACT_NAMED_ELEMENT__NAME, prefix,
false, true);
}
/**
* Gets the first ancestor of the given type.
*
* @param context
* the context.
* @param type
* the type.
* @return the first ancestor of the given type.
*/
public EObject getAncestor(final EObject context, EClass eclass) {
EObject current = context.eContainer();
while ((current != null) && !eclass.isInstance(current)) {
current = current.eContainer();
}
return current;
}
public List<BlockArchitecture> getAvailableArchitectures(final EObject context) {
return QueryInterpretor.executeQuery(
org.polarsys.capella.core.sirius.analysis.queries.QueryIdentifierConstants.GET_AVAILABLE_ARCHITECTURES,
context);
}
public Collection<EObject> getRelatedAssociations(Classifier clazz) {
Collection<EObject> result = new ArrayList<>();
// retrieve all the association of the target
for (TypedElement typedElement : clazz.getTypedElements()) {
if ((typedElement instanceof Property)
&& (((Property) typedElement).getAggregationKind() != AggregationKind.UNSET)) {
Property property = (Property) typedElement;
SemanticEditingDomain semEditDomain = (SemanticEditingDomain) TransactionHelper.getEditingDomain(property);
if (semEditDomain != null) {
ECrossReferenceAdapter crossReferencer = semEditDomain.getCrossReferencer();
if (crossReferencer != null) {
for (Setting setting : crossReferencer.getInverseReferences(property)) {
EObject eObject = setting.getEObject();
if (eObject instanceof Association) {
result.add(eObject);
}
}
}
}
}
}
return result;
}
/**
* used in common.odesign
*
* @param context
* : '$containerView' - veiw of Element in Diagram
* @return return the all the association not in Diagram of the target value of '$containerVeiw'.
*/
public List<EObject> getAvailableAssociationToInsert(EObject context) {
// collect all association of the context target not in Diagram
List<EObject> result = new ArrayList<>();
// filter 'context' as 'DDiagramElementContainer'
if (context instanceof AbstractDNode) {
AbstractDNode currentContainer = (AbstractDNode) context;
// retrieve Diagram
DDiagram currentDiagram = getDiagramContainer(currentContainer);
// collect all the elements from the Diagram
List<EObject> elementsIndiagram = new ArrayList<>();
for (AbstractDNode aContainer : currentDiagram.getContainers()) {
elementsIndiagram.add(aContainer.getTarget());
}
// filter 'context' target element as 'Classifier'
if (currentContainer.getTarget() instanceof Classifier) {
Classifier target = (Classifier) currentContainer.getTarget();
result.addAll(getRelatedAssociations(target));
}
// filter existing Association from the result list.
for (DEdge anEdge : currentDiagram.getEdges()) {
if (result.contains(anEdge.getTarget())) {
result.remove(anEdge.getTarget());
}
}
}
return result;
}
/**
* Returns the semantic context for the given context. If the given context is a DSemanticDecorator, retrieve the
* target of this DSemanticDecorator. (it is used if sirius change its default variables from semantic to view)
*/
public EObject getSemanticContext(EObject context) {
EObject semanticContext = context;
if (semanticContext instanceof DSemanticDecorator) {
semanticContext = ((DSemanticDecorator) semanticContext).getTarget();
}
return semanticContext;
}
public Collection<Constraint> getAvailableConstraintToInsert(final EObject context, EObject containerView) {
EObject semanticContext = getSemanticContext(context);
if (containerView instanceof DDiagram) {
return getAllConstraints(semanticContext);
}
if (semanticContext instanceof Structure) {
List<Constraint> list = new ArrayList<>();
EList<AbstractConstraint> constraints = ((Structure) semanticContext).getOwnedConstraints();
for (AbstractConstraint abstractConstraint : constraints) {
if (abstractConstraint instanceof Constraint) {
list.add((Constraint) abstractConstraint);
}
}
return list;
}
return new ArrayList<>();
}
public List<AbstractFunction> getCDFSemanticAbstractFunctions(AbstractFunction function) {
// previously named getAvailableContextualFunctions
List<AbstractFunction> returnedFunctions = new ArrayList<>();