-
Notifications
You must be signed in to change notification settings - Fork 85
/
CsServices.java
6971 lines (6071 loc) · 255 KB
/
CsServices.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, 2020 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.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.query.DRepresentationQuery;
import org.eclipse.sirius.business.api.session.Session;
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.DiagramPackage;
import org.eclipse.sirius.diagram.DragAndDropTarget;
import org.eclipse.sirius.diagram.EdgeTarget;
import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.ContainerMapping;
import org.eclipse.sirius.diagram.description.DiagramElementMapping;
import org.eclipse.sirius.diagram.description.EdgeMapping;
import org.eclipse.sirius.diagram.description.IEdgeMapping;
import org.eclipse.sirius.diagram.description.NodeMapping;
import org.eclipse.sirius.diagram.description.filter.FilterDescription;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.polarsys.capella.common.data.activity.Pin;
import org.polarsys.capella.common.data.behavior.AbstractEvent;
import org.polarsys.capella.common.data.modellingcore.AbstractExchangeItem;
import org.polarsys.capella.common.data.modellingcore.AbstractNamedElement;
import org.polarsys.capella.common.data.modellingcore.AbstractType;
import org.polarsys.capella.common.data.modellingcore.FinalizableElement;
import org.polarsys.capella.common.data.modellingcore.InformationsExchanger;
import org.polarsys.capella.common.data.modellingcore.ModelElement;
import org.polarsys.capella.common.helpers.EObjectExt;
import org.polarsys.capella.common.mdsofa.common.constant.ICommonConstants;
import org.polarsys.capella.common.mdsofa.common.misc.Couple;
import org.polarsys.capella.common.menu.dynamic.util.INamePrefixService;
import org.polarsys.capella.common.queries.interpretor.QueryInterpretor;
import org.polarsys.capella.common.tools.report.util.IReportManagerDefaultComponents;
import org.polarsys.capella.core.data.capellacommon.ChangeEvent;
import org.polarsys.capella.core.data.capellacommon.State;
import org.polarsys.capella.core.data.capellacommon.StateEvent;
import org.polarsys.capella.core.data.capellacommon.StateTransition;
import org.polarsys.capella.core.data.capellacommon.TimeEvent;
import org.polarsys.capella.core.data.capellacore.AbstractDependenciesPkg;
import org.polarsys.capella.core.data.capellacore.AbstractPropertyValue;
import org.polarsys.capella.core.data.capellacore.Allocation;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
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.ModellingArchitecture;
import org.polarsys.capella.core.data.capellacore.ModellingBlock;
import org.polarsys.capella.core.data.capellacore.NamedElement;
import org.polarsys.capella.core.data.capellacore.PropertyValueGroup;
import org.polarsys.capella.core.data.capellacore.Relationship;
import org.polarsys.capella.core.data.capellacore.Type;
import org.polarsys.capella.core.data.cs.AbstractDeploymentLink;
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.CsFactory;
import org.polarsys.capella.core.data.cs.CsPackage;
import org.polarsys.capella.core.data.cs.DeployableElement;
import org.polarsys.capella.core.data.cs.DeploymentTarget;
import org.polarsys.capella.core.data.cs.Interface;
import org.polarsys.capella.core.data.cs.InterfaceImplementation;
import org.polarsys.capella.core.data.cs.InterfaceUse;
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.cs.PhysicalPort;
import org.polarsys.capella.core.data.ctx.CtxFactory;
import org.polarsys.capella.core.data.ctx.CtxPackage;
import org.polarsys.capella.core.data.ctx.SystemAnalysis;
import org.polarsys.capella.core.data.ctx.SystemComponent;
import org.polarsys.capella.core.data.ctx.SystemComponentPkg;
import org.polarsys.capella.core.data.epbs.ConfigurationItem;
import org.polarsys.capella.core.data.epbs.ConfigurationItemPkg;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.fa.ComponentExchangeCategory;
import org.polarsys.capella.core.data.fa.ComponentExchangeKind;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.data.fa.ComponentPort;
import org.polarsys.capella.core.data.fa.ComponentPortAllocation;
import org.polarsys.capella.core.data.fa.ComponentPortAllocationEnd;
import org.polarsys.capella.core.data.fa.ComponentPortKind;
import org.polarsys.capella.core.data.fa.ControlNode;
import org.polarsys.capella.core.data.fa.FaPackage;
import org.polarsys.capella.core.data.fa.FunctionalChain;
import org.polarsys.capella.core.data.fa.FunctionalChainInvolvement;
import org.polarsys.capella.core.data.fa.FunctionalChainInvolvementFunction;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.fa.SequenceLink;
import org.polarsys.capella.core.data.fa.SequenceLinkEnd;
import org.polarsys.capella.core.data.helpers.cs.services.PhysicalLinkExt;
import org.polarsys.capella.core.data.helpers.information.services.CommunicationLinkExt;
import org.polarsys.capella.core.data.helpers.information.services.ExchangeItemExt;
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.Port;
import org.polarsys.capella.core.data.information.PortAllocation;
import org.polarsys.capella.core.data.information.Property;
import org.polarsys.capella.core.data.information.communication.CommunicationLink;
import org.polarsys.capella.core.data.information.communication.CommunicationLinkExchanger;
import org.polarsys.capella.core.data.information.communication.CommunicationLinkKind;
import org.polarsys.capella.core.data.information.datatype.NumericType;
import org.polarsys.capella.core.data.information.datatype.PhysicalQuantity;
import org.polarsys.capella.core.data.information.datavalue.DataValue;
import org.polarsys.capella.core.data.information.datavalue.NumericValue;
import org.polarsys.capella.core.data.information.util.PropertyNamingHelper;
import org.polarsys.capella.core.data.interaction.AbstractCapability;
import org.polarsys.capella.core.data.interaction.Scenario;
import org.polarsys.capella.core.data.la.CapabilityRealization;
import org.polarsys.capella.core.data.la.LaFactory;
import org.polarsys.capella.core.data.la.LaPackage;
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.Entity;
import org.polarsys.capella.core.data.oa.EntityPkg;
import org.polarsys.capella.core.data.oa.OaFactory;
import org.polarsys.capella.core.data.oa.OaPackage;
import org.polarsys.capella.core.data.oa.OperationalAnalysis;
import org.polarsys.capella.core.data.pa.PaFactory;
import org.polarsys.capella.core.data.pa.PaPackage;
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.data.pa.deployment.PartDeploymentLink;
import org.polarsys.capella.core.diagram.helpers.ContextualDiagramHelper;
import org.polarsys.capella.core.diagram.helpers.DiagramHelper;
import org.polarsys.capella.core.diagram.helpers.traceability.DiagramTraceabilityHelper;
import org.polarsys.capella.core.diagram.helpers.traceability.IDiagramTraceability;
import org.polarsys.capella.core.model.handler.helpers.CapellaProjectHelper;
import org.polarsys.capella.core.model.handler.helpers.CapellaProjectHelper.TriStateBoolean;
import org.polarsys.capella.core.model.handler.helpers.RepresentationHelper;
import org.polarsys.capella.core.model.helpers.AbstractDependenciesPkgExt;
import org.polarsys.capella.core.model.helpers.AssociationExt;
import org.polarsys.capella.core.model.helpers.BlockArchitectureExt;
import org.polarsys.capella.core.model.helpers.CapabilityRealizationExt;
import org.polarsys.capella.core.model.helpers.CapellaElementExt;
import org.polarsys.capella.core.model.helpers.ComponentExchangeCategoryExt;
import org.polarsys.capella.core.model.helpers.ComponentExchangeExt;
import org.polarsys.capella.core.model.helpers.ComponentExt;
import org.polarsys.capella.core.model.helpers.ComponentPkgExt;
import org.polarsys.capella.core.model.helpers.FunctionalChainExt;
import org.polarsys.capella.core.model.helpers.InterfaceExt;
import org.polarsys.capella.core.model.helpers.InterfacePkgExt;
import org.polarsys.capella.core.model.helpers.PartExt;
import org.polarsys.capella.core.model.helpers.PhysicalComponentExt;
import org.polarsys.capella.core.model.helpers.PhysicalLinkCategoryExt;
import org.polarsys.capella.core.model.helpers.PortExt;
import org.polarsys.capella.core.model.helpers.SystemEngineeringExt;
import org.polarsys.capella.core.model.preferences.CapellaModelPreferencesPlugin;
import org.polarsys.capella.core.model.utils.CapellaLayerCheckingExt;
import org.polarsys.capella.core.sirius.analysis.constants.IFilterNameConstants;
import org.polarsys.capella.core.sirius.analysis.constants.MappingConstantsHelper;
import org.polarsys.capella.core.sirius.analysis.helpers.FilterHelper;
import org.polarsys.capella.core.sirius.analysis.queries.QueryIdentifierConstants;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Streams;
/**
* Provides services for all interfaces diagram.
*/
public class CsServices {
private static CsServices service = null;
private static final String TRANSITION_TRACEABILITY = "org.polarsys.capella.core.transition.diagram"; //$NON-NLS-1$
private static final String TRANSITION_TRACEABILITY_COMMAND = TRANSITION_TRACEABILITY;
public static CsServices getService() {
if (service == null) {
service = new CsServices();
}
return service;
}
public boolean isValidInitializeDiagramFromExistingDiagram(DSemanticDecorator diagram) {
if (!(diagram instanceof DRepresentation)) {
return false;
}
return true;
}
/**
* Returns whether the Initialization tool must be show in palette
*
* @param diagram
* @return true if hidden
*/
public boolean isFilterInitializeDiagramFromExistingDiagram(DSemanticDecorator diagram) {
if (!(diagram instanceof DRepresentation)) {
return true;
}
IDiagramTraceability handler = DiagramTraceabilityHelper.getService()
.getTraceabilityHandler((DRepresentation) diagram, TRANSITION_TRACEABILITY);
if (handler == null) {
return true;
}
DRepresentationDescriptor descriptor = RepresentationHelper.getRepresentationDescriptor((DRepresentation) diagram);
if (handler.isRealizingable(descriptor)) {
handler.dispose();
if (diagram instanceof DDiagram) {
// Disable initialization on non-empty diagram
if (DiagramHelper.getService().isA((DDiagram) diagram,
IDiagramNameConstants.SYSTEM_ARCHITECTURE_BLANK_DIAGRAM_NAME)) {
if (((DDiagram) diagram).getOwnedDiagramElements().size() > 1) {
return true;
}
} else if (DiagramHelper.getService().isA((DDiagram) diagram,
IDiagramNameConstants.LOGICAL_ARCHITECTURE_BLANK_DIAGRAM_NAME)) {
if (((DDiagram) diagram).getOwnedDiagramElements().size() > 1) {
return true;
}
} else {
// Disable initialization on non-empty diagram
if (!((DDiagram) diagram).getOwnedDiagramElements().isEmpty()) {
return true;
}
}
}
return false;
}
return true;
}
public EObject initializeDiagramFromExistingDiagram(DSemanticDecorator diagram, DSemanticDecorator sourceDiagram) {
Logger logger = Logger.getLogger(IReportManagerDefaultComponents.DIAGRAM);
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (handlerService == null || commandService == null) {
logger.error("Cannot access to diagram initialization tool");
return diagram;
}
if (sourceDiagram == null) {
logger.error("Cannot retrieve source diagram for diagram initialization");
return diagram;
}
Command command = commandService.getCommand(TRANSITION_TRACEABILITY_COMMAND);
// Create a ParameterizedCommand with no parameter
ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
EvaluationContext context = new EvaluationContext(null, Collections.singleton(sourceDiagram));
context.addVariable("TARGET_DIAGRAM", diagram);
try {
handlerService.executeCommandInContext(parameterizedCommand, null, context);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException exception) {
logger.error("Errors occured while diagram initialization", exception);
}
return diagram;
}
/**
* @param diagram
* @return
*/
public List<DRepresentation> getScopeInitializeDiagramFromExistingDiagram(DRepresentation diagram) {
List<DRepresentation> scope = new ArrayList<>();
IDiagramTraceability handler = DiagramTraceabilityHelper.getService().getTraceabilityHandler(diagram,
TRANSITION_TRACEABILITY);
Session session = DiagramHelper.getService().getSession(diagram);
DRepresentationDescriptor descriptor = RepresentationHelper.getRepresentationDescriptor(diagram);
for (DRepresentationDescriptor representationDescriptor : DialectManager.INSTANCE
.getAllRepresentationDescriptors(session)) {
if (handler.isRealizable(representationDescriptor, descriptor)
&& !scope.contains(representationDescriptor.getRepresentation())) {
scope.add(representationDescriptor.getRepresentation());
}
}
handler.dispose();
return scope;
}
/**
* Returns whether object is contextual element and filter is active
*
* @param object
* @param diagram
* @return
*/
public boolean isFilterContextualElement(EObject object, DDiagram diagram) {
DRepresentationDescriptor descriptor = new DRepresentationQuery(diagram).getRepresentationDescriptor();
if (ContextualDiagramHelper.getService().hasContextualElements(descriptor)) {
for (FilterDescription filter : diagram.getActivatedFilters()) {
if (IMappingNameConstants.SHOW_CONTEXTUAL_ELEMENTS.equals(filter.getName())
&& ContextualDiagramHelper.getService().getContextualElements(descriptor).contains(object)) {
return true;
}
}
}
return false;
}
/**
* Allows to set variable on the interpreter Should be replaced odesign by
* org.polarsys.capella.core.sirius.analysis.actions.extensions.SetVariable
*
* @param context
* the context
* @param name
* the name
* @param value
* the value
* @return the EObject
*/
public EObject setInterpreterVariable(EObject context, String name, EObject value) {
InterpreterUtil.getInterpreter(context).setVariable(name, value);
return context;
}
public EObject setInterpreterVariable(EObject context, String name, Collection<EObject> values) {
InterpreterUtil.getInterpreter(context).setVariable(name, values);
return context;
}
/**
* Allows to retrieve variable on the interpreter
*
* @param context
* the context
* @param name
* the name
* @param value
* the value
* @return the EObject
*/
public Object getInterpreterVariable(EObject context, String name) {
return InterpreterUtil.getInterpreter(context).getVariable(name);
}
/**
* Support for old odesign definition
*/
@Deprecated
public EObject setVariableA(EObject context, String name, EObject value) {
return setInterpreterVariable(context, name, value);
}
/**
* Checks if user has enabled the preference.
*
* @param object
* useful only in sirius
* @return whether if is preference is enabled
*/
@Deprecated
public boolean isPreferenceEnabled(EObject object, String preference) {
if (object instanceof DSemanticDecorator) {
DSemanticDecorator decorator = (DSemanticDecorator) object;
if (decorator.getTarget() instanceof ModelElement) {
return isMultipartMode((ModelElement) decorator.getTarget());
}
}
return true;
}
/**
* Used in sirius to check if multipart mode is enabled
*
* @param object
* , any eobject
* @return whether if is preference is enabled
*/
public boolean isMultipartMode(ModelElement object) {
return TriStateBoolean.True.equals(CapellaProjectHelper.isReusableComponentsDriven(object));
}
@Deprecated
public static final String PREFERENCE_LISTENER_ID = "org.polarsys.capella.core.preferences.Listener"; //$NON-NLS-1$
@Deprecated
public static final String PREFERENCE_LISTENER_ID_PREFERENCE_MULTIPART = "multipart.allowed"; //$NON-NLS-1$
@Deprecated
public static final String[] PREFERENCE_LISTENER_ID_PREFERENCES = new String[] {
PREFERENCE_LISTENER_ID_PREFERENCE_MULTIPART, };
@Deprecated
public EObject preferenceListener = null;
/**
* Create a wrapper EObject which will be send a notification when the preference change
*
* @param object
* @return
*/
@Deprecated
public EObject getPreferenceListener(final EObject object) {
return object;
}
/**
* Debug purpose only. display a popup message with informations about the given object
*
* @param object
* the object
* @return true, if successful
*/
public boolean myDebug(EObject object) {
MessageDialog.openInformation(null, object.getClass().getName(), object.toString());
return true;
}
/**
* Returns all related capability which are associated to the interface.
*
* @param itf
* the given interface
* @return the related components
*/
public Collection<Component> getRelatedComponents(Interface itf) {
return InterfaceExt.getRelatedComponents(itf);
}
public DSemanticDecorator getRelatedFunctionView(DSemanticDecorator element) {
if (element.getTarget() instanceof AbstractFunction) {
return element;
}
if (element.eContainer() instanceof DSemanticDecorator) {
return getRelatedFunctionView((DSemanticDecorator) element.eContainer());
}
return null;
}
public DSemanticDecorator getRelatedPartView(DSemanticDecorator element) {
if ((element.getTarget() != null)
&& ((element.getTarget() instanceof Part) || (element.getTarget() instanceof Entity))) {
return element;
}
if (element.eContainer() instanceof DSemanticDecorator) {
return getRelatedPartView((DSemanticDecorator) element.eContainer());
}
return null;
}
public InformationsExchanger getRelatedPart(DSemanticDecorator element) {
if ((element.getTarget() != null)
&& ((element.getTarget() instanceof Part) || (element.getTarget() instanceof Entity))) {
return (InformationsExchanger) element.getTarget();
}
if (element.eContainer() instanceof DSemanticDecorator) {
return getRelatedPart((DSemanticDecorator) element.eContainer());
}
return null;
}
/**
* Returns all related capability which are associated to the interface.
*
* @param itf
* the given interface
* @return the related components
*/
public Collection<CommunicationLinkExchanger> getRelatedExchangers(AbstractExchangeItem item) {
return ExchangeItemExt.getRelatedExchangers(item);
}
/**
* Returns all interfaces related to the component.
*
* @param root
* the component of the TID table
* @return interfaces related to the given component for the TID table
*/
public Collection<Interface> getTIDInterfaces(Component root) {
return getAllRelatedInterfaces(root);
}
/**
* Returns label displayed instead of interface name.
*
* @param itf
* the given interface
* @return label of the given interface for the TID table
*/
public String getTIDInterfaceLabel(Interface itf) {
return itf.getName();
}
/**
* Returns label displayed in a cell of the TID.
*
* @param itf
* the interface
* @param line
* the line of the cell
* @param column
* the column of the cell
* @return the label which will be display in the cell
*/
public String getTIDLabel(EObject itf, EObject line, EObject column) {
Component component = (Component) ((DSemanticDecorator) column).getTarget();
Interface relatedItf = (Interface) ((DSemanticDecorator) line).getTarget();
StringBuilder res = new StringBuilder();
if (ComponentExt.getAllImplementedInterfaces(component).contains(relatedItf)) {
res.append(Messages.Diagram_TID_Implemented);
res.append("\n"); //$NON-NLS-1$
}
if (ComponentExt.getAllUsedInterfaces(component).contains(relatedItf)) {
res.append(Messages.Diagram_TID_Used);
res.append("\n"); //$NON-NLS-1$
}
if (ComponentExt.getAllProvidedInterfaces(component).contains(relatedItf)) {
res.append(Messages.Diagram_TID_Provided);
res.append("\n"); //$NON-NLS-1$
}
if (ComponentExt.getAllRequiredInterfaces(component).contains(relatedItf)) {
res.append(Messages.Diagram_TID_Required);
res.append("\n"); //$NON-NLS-1$
}
if (res.length() > 0) {
res.deleteCharAt(res.length() - 1);
}
return res.toString();
}
/**
* Returns whether the given parent is a parent of current element.
*
* @param current
* the current EObject
* @param parent
* the parent EObject
* @return true, if parent is an ancestor of the current element
*/
public boolean isAnAncestor(EObject current, EObject parent) {
EObject object = current;
for (object = object.eContainer(); object != null; object = object.eContainer()) {
if (object == parent) {
return true;
}
}
return false;
}
/**
* Returns true if e1 is an ancestor of e2 and vice versa
*
* @param e1
* @param e2
* @return
*/
public boolean oneIsAncestorAnother(EObject current, EObject e1, EObject e2) {
return EcoreUtil.isAncestor(e1, e2) || EcoreUtil.isAncestor(e1, e2);
}
/**
* Returns the parent component of the element or the blockarchitecture based on what's displayed on the diagram.
*
* @param current
* the current element
* @return the parent component or block architecture
*/
public EObject getParentContainer(EObject current) {
EObject object = current;
for (object = current.eContainer(); object != null; object = object.eContainer()) {
if ((object instanceof Component) || (object instanceof BlockArchitecture)) {
return object;
}
}
return null;
}
/**
* Returns the nearest semantic parent component of the element
*
* @param current
* the current element isActorContext whether we are looking the parent of an actor
* @return the parent component or block architecture
*/
public EObject getSemanticParentContainer(EObject current, boolean isActorContext) {
EObject object = current;
for (object = current.eContainer(); object != null; object = object.eContainer()) {
if (object instanceof BlockArchitecture) {
return object;
}
if (isActorContext) {
if (ComponentExt.canCreateABActor(object)) {
return object;
}
} else {
if (ComponentExt.canCreateABComponent(object)) {
return object;
}
}
}
return null;
}
/**
* Returns the list of parent component or block architecture of the element.
*
* @param current
* the current element
* @return the parent component or block architecture
*/
public Collection<EObject> getParentContainers(EObject current) {
LinkedList<EObject> elements = new LinkedList<>();
elements.add(current);
return getParentContainers(elements);
}
/**
* Returns all parents of currents elements
*
* @param currents
* the list of elements
* @return parents component or block architecture
*/
protected Collection<EObject> getParentContainers(Collection<EObject> currents) {
LinkedList<EObject> toVisits = new LinkedList<>(currents);
Collection<EObject> parents = new java.util.HashSet<>();
// Access all hierarchy of components and blockarchitectures
while (!toVisits.isEmpty()) {
EObject owner = toVisits.removeFirst();
EObject parent = getParentContainer(owner);
if ((parent != null) && !parents.contains(parent)) {
parents.add(parent);
toVisits.addLast(parent);
}
}
return parents;
}
/**
* Returns the parent component of the element or the blockarchitecture. If current is a component or a
* blockarchitecture, returns the given element itself
*
* @param current
* the given EObject
* @return the first parent component or blockarchitecture
*/
public EObject getFirstParentContainer(EObject current) {
EObject object = current;
for (; object != null; object = object.eContainer()) {
if ((object instanceof Component) || (object instanceof BlockArchitecture)) {
return current;
}
}
return null;
}
/**
* Returns all components which contains parts of the given component.
*
* @param component
* the component
* @return all components which contains a part of the given component.
*/
public Collection<Component> getContainersOfParts(Component component) {
Collection<Component> containers = new java.util.HashSet<>();
// Access to all container of parts
for (Part part : component.getRepresentingParts()) {
EObject parent = getParentContainer(part);
if (parent instanceof Component) {
containers.add((Component) parent);
}
for (DeploymentTarget deploment : getCache(PartExt::getDeployingElements, part)) {
if (deploment instanceof Part) {
AbstractType type = (((Part) deploment)).getAbstractType();
if (type instanceof Component) {
containers.add((Component) type);
}
}
}
}
return containers;
}
/**
* Returns all components which contains parts of the given component.
*
* @param component
* the component
* @return all components which contains a part of the given component.
*/
public Collection<Component> getContainersOfPart(Part part) {
Collection<Component> containers = new java.util.HashSet<>();
// Access to all container of parts
EObject parent = getParentContainer(part);
if (parent instanceof Component) {
containers.add((Component) parent);
}
for (DeploymentTarget deploment : getCache(PartExt::getDeployingElements, part)) {
if (deploment instanceof Part) {
AbstractType type = (((Part) deploment)).getAbstractType();
if (type instanceof Component) {
containers.add((Component) type);
}
}
}
return containers;
}
/**
* Returns whether the given interface can be linked to the current component (interfaces from parents) (requires,
* implements, uses or provides).
*
* @param component
* the given component
* @param inter
* the given interface
* @return true, if the interface can be linked to the current component
*/
public boolean isAvailableInterface(Component component, Interface inter) {
return getCCEIInsertInterface(component).contains(inter);
}
/**
* Returns parents components of parts of the given component.
*
* @param component
* the given component
* @return the parent components by parts of the given component
*/
public Collection<EObject> getParentContainersByParts(Component component) {
LinkedList<Component> elements = new LinkedList<>();
elements.add(component);
return getParentContainersByParts(elements);
}
/**
* Returns parents components of parts of given objects.
*
* @param currents
* the collection of EObject
* @return the parent components by parts of the given objects.
*/
public Collection<EObject> getParentContainersByParts(Collection<Component> currents) {
LinkedList<EObject> toVisits = new LinkedList<>(currents);
Collection<EObject> parents = new java.util.HashSet<>();
// Access all hierarchy of components and blockarchitectures
while (!toVisits.isEmpty()) {
EObject owner = toVisits.removeFirst();
if (owner instanceof Component) {
EObject parent = getParentContainer(owner);
if ((parent != null) && !parents.contains(parent)) {
parents.add(parent);
toVisits.addLast(parent);
}
for (EObject i : getContainersOfParts((Component) owner)) {
if ((i != null) && !parents.contains(i)) {
parents.add(i);
toVisits.addLast(i);
}
}
}
}
return parents;
}
/**
* Returns parents and brothers of parents components of parts of the given object
*/
public Collection<EObject> getAvailableComponentsByNamespaceOfParts(Component component) {
LinkedList<EObject> ownerParts = new LinkedList<>();
ownerParts.addAll(getContainersOfParts(component));
return ComponentExt.getAvailableComponentsByNamespaceOfParts(ownerParts);
}
/**
* Returns interfaces available on the Show/Hide interface of the CCII diagram.
*/
public Collection<Interface> getCCIIInsertInterface(EObject object) {
Collection<Interface> res = getCCEIInsertInterface(object);
if (object instanceof Component) {
res.addAll(getSubDefinedInterfaces((Component) object));
res.addAll(getRelatedInterfaces((Component) object));
} else if (object instanceof BlockArchitecture) {
res.addAll(getSubDefinedInterfaces((BlockArchitecture) object));
}
return res;
}
/**
* Returns interfaces available on the Show/Hide interface of the IB diagram.
*/
public Collection<Interface> getIBInsertInterface(EObject object) {
return getCCIIInsertInterface(object);
}
/**
* Returns available interfaces which can be added into an external diagram (all interfaces from parents-hierarchy of
* all part of a component) CCEI-Insert-Interface CCII-Insert-Interface with getSubInterfaces added For an EPBS,
* returns interfaces related of parents and sub-components and their allocated components For others, returns
* interfaces of parents components and their allocated components (recursively).
*/
public Collection<Interface> getCCEIInsertInterface(EObject context) {
return QueryInterpretor.executeQuery(QueryIdentifierConstants.GET_CCE_INSERT_INTERFACE_FOR_LIB, context);
}
/**
* Returns related interfaces of components (implements, uses, provides, requires).
*/
public Collection<CommunicationLink> getRelatedCommunicationLinks(Component component) {
return CommunicationLinkExt.getAllCommunicationLinks(component);
}
/**
* Returns related interfaces of components (implements, uses, provides, requires).
*/
public Collection<Interface> getRelatedInterfaces(Component component) {
Collection<Interface> interfaces = new ArrayList<>();
if (component != null) {
interfaces.addAll(ComponentExt.getImplementedAndProvidedInterfaces(component));
interfaces.addAll(ComponentExt.getUsedAndRequiredInterfaces(component));
}
return interfaces;
}
/**
* Returns related interfaces of components (implements, uses, provides, requires).
*/
public Collection<Interface> getAllRelatedInterfaces(Component component) {
Collection<Interface> interfaces = new ArrayList<>();
if (component != null) {
interfaces.addAll(ComponentExt.getAllImplementedAndProvidedInterfaces(component));
interfaces.addAll(ComponentExt.getAllUsedAndRequiredInterfaces(component));
}
return interfaces;
}
/**
* Remove into the given collection all allocated interfaces.
*/
public void removeAllAllocatedInterfaces(Collection<Interface> interfaces) {
// Remove all allocated interfaces
Collection<Interface> toRemove = new java.util.HashSet<>();
for (Interface inter : interfaces) {
if (inter.getAllocatedInterfaces() != null) {
for (Interface allocated : inter.getAllocatedInterfaces()) {
toRemove.add(allocated);
}
}
}
interfaces.removeAll(toRemove);
}
/**
* Returns the list with all interfaces which are in allocated components.
*/
public Collection<Interface> getInterfacesFromAllocatedComponent(Component subComponent) {
Collection<Interface> interfaces = new ArrayList<>();
// Add interfaces from allocated components
if (subComponent.getRealizedComponents() != null) {
LinkedList<Component> allocateds = new LinkedList<>();
for (Component allocated : subComponent.getRealizedComponents()) {
allocateds.add(allocated); // addAll can throw an exception
}
while (!allocateds.isEmpty()) {
Component allocated = allocateds.removeFirst();
interfaces.addAll(getSubDefinedInterfaces(allocated));
if (allocated.getRealizedComponents() != null) {
for (Component suballocated : allocated.getRealizedComponents()) {
allocateds.add(suballocated);
}
}
}
}
return interfaces;
}
/**
* Fills the list with all interfaces which are in allocated components.
*/
public Collection<Interface> getRelatedInterfacesFromAllocatedComponent(Component subComponent) {
Collection<Interface> interfaces = new ArrayList<>();
// Add interfaces from allocated components
if (subComponent.getRealizedComponents() != null) {
LinkedList<Component> allocateds = new LinkedList<>();
for (Component allocated : subComponent.getRealizedComponents()) {
allocateds.add(allocated); // addAll can throw an exception
}
while (!allocateds.isEmpty()) {
Component allocated = allocateds.removeFirst();
interfaces.addAll(getRelatedInterfaces(allocated));
}
}
return interfaces;
}
/**
* Fills the list with all interfaces which are in allocated architectures.
*/
public Collection<Interface> getInterfacesFromAllocatedArchitecture(BlockArchitecture architecture) {
Collection<Interface> interfaces = new ArrayList<>();
// Add interfaces from allocated components
if (architecture.getAllocatedArchitectures() != null) {
LinkedList<BlockArchitecture> allocateds = new LinkedList<>();
for (BlockArchitecture allocated : architecture.getAllocatedArchitectures()) {
allocateds.add(allocated); // addAll can throw an exception
}
while (!allocateds.isEmpty()) {
BlockArchitecture allocated = allocateds.removeFirst();
interfaces.addAll(getSubDefinedInterfaces(allocated));
if (allocated.getAllocatedArchitectures() != null) {
for (BlockArchitecture suballocated : allocated.getAllocatedArchitectures()) {
allocateds.add(suballocated);