Skip to main content
summaryrefslogtreecommitdiffstats
blob: 166aa4ccc801a8449d7ec55eb909b0ce4ac736e3 (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
/*******************************************************************************
 * Copyright (c) 2013 Obeo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram;

import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.or;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueIs;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.command.impl.CopyCommand;
import org.eclipse.emf.compare.diagram.ide.ui.internal.accessor.IDiagramDiffAccessor;
import org.eclipse.emf.compare.diagram.ide.ui.internal.accessor.IDiagramNodeAccessor;
import org.eclipse.emf.compare.diagram.internal.extensions.DiagramDiff;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.ide.EMFCompareIDEPlugin;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.tree.TreeContentMergeViewerContentProvider;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoAction;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer;
import org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide;
import org.eclipse.emf.compare.utils.DiffUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editparts.LayerManager;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;

/**
 * Specialized {@link org.eclipse.compare.contentmergeviewer.ContentMergeViewer} that uses
 * {@link org.eclipse.jface.viewers.TreeViewer} to display left, right and ancestor {@link EObject}.
 * 
 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
 */
public class DiagramContentMergeViewer extends EMFCompareContentMergeViewer {

	/**
	 * Interface for the management of decorators.
	 * 
	 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
	 */
	private interface IDecoratorManager {

		/**
		 * It hides the revealed decorators.
		 */
		void hideAll();

		/**
		 * From a given difference, it hides the related decorators.
		 * 
		 * @param difference
		 *            The difference.
		 */
		void hideDecorators(Diff difference);

		/**
		 * From a given difference, it reveals the related decorators.
		 * 
		 * @param difference
		 *            The difference.
		 */
		void revealDecorators(Diff difference);
	}

	/**
	 * Decorator manager to create, hide or reveal decorator figures related to deleted or added graphical
	 * objects.
	 * 
	 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
	 */
	private abstract class AbstractDecoratorManager implements IDecoratorManager {

		/**
		 * Decorator represented by a <code>figure</code> on a <code>layer</code>, from the given
		 * <code>side</code> of the merge viewer. An edit part may be linked to the <code>figure</code> in
		 * some cases.<br>
		 * The decorator is related to a <code>difference</code> and it is binded with the reference view and
		 * figure.
		 * 
		 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
		 */
		protected abstract class AbstractDecorator {

			/** The reference <code>View</code> for this decorator. */
			protected View fOriginView;

			/** The reference <code>IFigure</code> for this phantom. */
			protected IFigure fOriginFigure;

			/** The <code>IFigure</code> representing this phantom. */
			protected IFigure fFigure;

			/** The layer on which the <code>figure</code> has to be drawn. */
			protected IFigure fLayer;

			/** The side of the merge viewer on which the <code>figure</code> has to be drawn. */
			protected MergeViewerSide fSide;

			/** The difference related to this phantom. */
			protected Diff fDifference;

			/** The edit part of the figure representing this phantom. May be null. */
			protected EditPart fEditPart;

			/**
			 * Getter.
			 * 
			 * @return the originView {@link Phantom#fOriginView}.
			 */
			public View getOriginView() {
				return fOriginView;
			}

			/**
			 * Setter.
			 * 
			 * @param originView
			 *            {@link Phantom#fOriginView}.
			 */
			public void setOriginView(View originView) {
				this.fOriginView = originView;
			}

			/**
			 * Getter.
			 * 
			 * @return the originFigure {@link Phantom#fOriginFigure}.
			 */
			public IFigure getOriginFigure() {
				return fOriginFigure;
			}

			/**
			 * Setter.
			 * 
			 * @param originFigure
			 *            {@link Phantom#fOriginFigure}.
			 */
			public void setOriginFigure(IFigure originFigure) {
				this.fOriginFigure = originFigure;
			}

			/**
			 * Getter.
			 * 
			 * @return the figure {@link Phantom#fFigure}.
			 */
			public IFigure getFigure() {
				return fFigure;
			}

			/**
			 * Setter.
			 * 
			 * @param figure
			 *            {@link Phantom#fFigure}.
			 */
			public void setFigure(IFigure figure) {
				this.fFigure = figure;
			}

			/**
			 * Getter.
			 * 
			 * @return the layer {@link Phantom#fLayer}.
			 */
			public IFigure getLayer() {
				return fLayer;
			}

			/**
			 * Setter.
			 * 
			 * @param layer
			 *            {@link Phantom#fLayer}.
			 */
			public void setLayer(IFigure layer) {
				this.fLayer = layer;
			}

			/**
			 * Getter.
			 * 
			 * @return the side {@link Phantom#fSide}.
			 */
			public MergeViewerSide getSide() {
				return fSide;
			}

			/**
			 * Setter.
			 * 
			 * @param side
			 *            {@link Phantom#fSide}.
			 */
			public void setSide(MergeViewerSide side) {
				this.fSide = side;
			}

			/**
			 * Getter.
			 * 
			 * @return the difference {@link Phantom#fDifference}.
			 */
			public Diff getDifference() {
				return fDifference;
			}

			/**
			 * Setter.
			 * 
			 * @param difference
			 *            {@link Phantom#fDifference}.
			 */
			public void setDifference(Diff difference) {
				this.fDifference = difference;
			}

			/**
			 * Getter.
			 * 
			 * @return the editPart {@link Phantom#fEditPart}.
			 */
			public EditPart getEditPart() {
				return fEditPart;
			}

			/**
			 * Setter.
			 * 
			 * @param editPart
			 *            {@link Phantom#fEditPart}.
			 */
			public void setEditPart(EditPart editPart) {
				this.fEditPart = editPart;
			}

		}

		/**
		 * From a given difference, it hides the related decorators.
		 * 
		 * @param difference
		 *            The difference.
		 */
		public void hideDecorators(Diff difference) {
			List<? extends AbstractDecorator> oldDecorators = getDecorators(difference);
			if (oldDecorators != null && !oldDecorators.isEmpty() && getComparison() != null) {
				handleDecorators(oldDecorators, false, true);
			}
		}

		/**
		 * From a given difference, it reveals the related decorators.
		 * 
		 * @param difference
		 *            The difference.
		 */
		public void revealDecorators(Diff difference) {

			List<? super AbstractDecorator> decorators = (List<? super AbstractDecorator>)getDecorators(difference);

			// Create phantoms only if they do not already exist and if the related difference is an ADD or
			// DELETE
			if ((decorators == null || decorators.isEmpty()) && isGoodCandidate(difference)) {

				DiagramDiff diagramDiff = (DiagramDiff)difference;

				List<View> referenveViews = getReferenceViews(diagramDiff);

				for (View referenceView : referenveViews) {
					IFigure referenceFigure = getFigure(referenceView);

					if (referenceFigure != null) {
						MergeViewerSide targetSide = getTargetSide(getComparison().getMatch(referenceView),
								referenceView);

						if (decorators == null) {
							decorators = new ArrayList();
						}

						decorators.add(createAndRegisterDecorator(difference, referenceView, referenceFigure,
								targetSide));
					}

				}

			}

			// The selected difference is an ADD or DELETE and decorators exist for it
			if (decorators != null && !decorators.isEmpty()) {
				revealDecorators((List<? extends AbstractDecorator>)decorators);
			}
		}

		/**
		 * It reveals the given decorators.
		 * 
		 * @param decorators
		 *            The main decorators.
		 */
		protected void revealDecorators(List<? extends AbstractDecorator> decorators) {
			handleDecorators(decorators, true, true);
		}

		/**
		 * Get the figure related to the given view.
		 * 
		 * @param view
		 *            The view.
		 * @return the figure.
		 */
		protected IFigure getFigure(View view) {
			MergeViewerSide side = getSide(view);
			GraphicalEditPart originEditPart = (GraphicalEditPart)getViewer(side).getEditPart(view);
			if (originEditPart != null) {
				return originEditPart.getFigure();
			}
			return null;
		}

		/**
		 * It manages the display of the given decorators.
		 * 
		 * @param decorators
		 *            The decorators to handle.
		 * @param isAdd
		 *            True if it has to be revealed, False otherwise.
		 * @param areMain
		 *            It indicates if the given decorators to handle are considered as the main ones (the ones
		 *            directly linked to the selected difference).
		 */
		protected void handleDecorators(List<? extends AbstractDecorator> decorators, boolean isAdd,
				boolean areMain) {
			for (AbstractDecorator decorator : decorators) {
				handleDecorator(decorator, isAdd, areMain);
			}
		}

		/**
		 * It manages the display of the given decorator.
		 * 
		 * @param decorator
		 *            The decorator to handle.
		 * @param isAdd
		 *            True if it has to be revealed, False otherwise.
		 * @param isMain
		 *            It indicates if the given decorator to handle is considered as the main one (the one
		 *            directly linked to the selected difference).
		 */
		protected void handleDecorator(AbstractDecorator decorator, boolean isAdd, boolean isMain) {
			IFigure layer = decorator.getLayer();
			IFigure figure = decorator.getFigure();
			EditPart editpart = decorator.getEditPart();
			if (editpart == null) {
				if (isAdd && !layer.getChildren().contains(figure)) {
					handleAddDecorator(decorator, layer, figure, isMain);
				} else if (layer.getChildren().contains(figure)) {
					handleDeleteDecorator(decorator, layer, figure, isMain);
				}
			} else {
				if (isAdd && !editpart.isActive()) {
					editpart.activate();
					handleAddDecorator(decorator, layer, figure, isMain);
				} else if (editpart.isActive()) {
					editpart.deactivate();
					handleDeleteDecorator(decorator, layer, figure, isMain);
				}
			}

		}

		/**
		 * It manages the reveal of the given decorator.
		 * 
		 * @param decorator
		 *            The decorator.
		 * @param parent
		 *            The parent figure which has to get the figure to reveal (<code>toAdd</code>)
		 * @param toAdd
		 *            The figure to reveal.
		 * @param isMain
		 *            It indicates if the given decorator to reveal is considered as the main one (the one
		 *            directly linked to the selected difference).
		 */
		protected void handleAddDecorator(AbstractDecorator decorator, IFigure parent, IFigure toAdd,
				boolean isMain) {
			parent.add(toAdd);
		}

		/**
		 * It manages the hiding of the given decorator.
		 * 
		 * @param decorator
		 *            The decorator.
		 * @param parent
		 *            The parent figure which has to get the figure to hide (<code>toDelete</code>)
		 * @param toDelete
		 *            The figure to hide.
		 * @param isMain
		 *            It indicates if the given decorator to hide is considered as the main one (the one
		 *            directly linked to the selected difference).
		 */
		protected void handleDeleteDecorator(AbstractDecorator decorator, IFigure parent, IFigure toDelete,
				boolean isMain) {
			parent.remove(toDelete);
		}

		/**
		 * It checks if the given difference is a good candidate to manage decorators.<br>
		 * 
		 * @see {@link PhantomManager#goodCandidate()}.
		 * @param difference
		 *            The difference.
		 * @return True if it is a good candidate, False otherwise.
		 */
		private boolean isGoodCandidate(Diff difference) {
			return goodCandidate().apply(difference);
		}

		/**
		 * Get the layer on the given side, from the reference view.<br>
		 * 
		 * @see @ link PhantomManager#getIDLayer(View)} .
		 * @param referenceView
		 *            The reference view.
		 * @param side
		 *            The side where the layer has to be found.
		 * @return The layer figure.
		 */
		protected IFigure getLayer(View referenceView, MergeViewerSide side) {
			Diagram referenceDiagram = referenceView.getDiagram();
			Diagram targetDiagram = (Diagram)getMatchView(referenceDiagram, side);
			DiagramMergeViewer targetViewer = getViewer(side);
			IFigure targetLayer = LayerManager.Helper.find(targetViewer.getEditPart(targetDiagram)).getLayer(
					getIDLayer(referenceView));
			return targetLayer;
		}

		/**
		 * Get the layer ID to use from the reference view.<br>
		 * If the reference view is an edge, it is the {@link LayerConstants.CONNECTION_LAYER} which is used,
		 * {@link LayerConstants.SCALABLE_LAYERS} otherwise.
		 * 
		 * @param referenceView
		 *            The reference view.
		 * @return The ID of te layer.
		 */
		protected Object getIDLayer(View referenceView) {
			if (referenceView instanceof Edge) {
				return LayerConstants.CONNECTION_LAYER;
			} else {
				return LayerConstants.SCALABLE_LAYERS;
			}
		}

		/**
		 * It translates the coordinates of the given bounds, from the reference figure and the root of this
		 * one, to absolute coordinates.
		 * 
		 * @param referenceFigure
		 *            The reference figure.
		 * @param rootReferenceFigure
		 *            The root of the reference figure.
		 * @param boundsToTranslate
		 *            The bounds to translate.
		 */
		protected void translateCoordinates(IFigure referenceFigure, IFigure rootReferenceFigure,
				Rectangle boundsToTranslate) {
			IFigure referenceParentFigure = referenceFigure.getParent();
			if (referenceParentFigure != null && referenceFigure != rootReferenceFigure) {
				if (referenceParentFigure.isCoordinateSystem()) {
					boundsToTranslate.x += referenceParentFigure.getBounds().x;
					boundsToTranslate.y += referenceParentFigure.getBounds().y;
				}
				translateCoordinates(referenceParentFigure, rootReferenceFigure, boundsToTranslate);
			}
		}

		/**
		 * Get the predicate to know the differences concerned by the display of decorators.
		 * 
		 * @return The predicate.
		 */
		protected abstract Predicate<Diff> goodCandidate();

		/**
		 * Get the views which have to be used as reference to build the related decorators from the given
		 * difference of the value concerned by the difference.<br>
		 * 
		 * @param difference
		 *            The difference.
		 * @return The list of reference views.
		 */
		protected abstract List<View> getReferenceViews(DiagramDiff difference);

		/**
		 * Get the side where decorators have to be drawn, according to the given reference view and its
		 * match.<br>
		 * 
		 * @param match
		 *            The match of the reference view.
		 * @param referenceView
		 *            The reference view.
		 * @return The side for phantoms.
		 */
		protected abstract MergeViewerSide getTargetSide(Match match, View referenceView);

		/**
		 * It creates new decorators and registers them.
		 * 
		 * @param diff
		 *            The related difference used as index for the main decorator.
		 * @param referenceView
		 *            The reference view as base for creation of the decorator.
		 * @param referenceFigure
		 *            The reference figure as base for creation of the decorator.
		 * @param targetSide
		 *            The side where the decorator has to be created.
		 * @return The list of main decorators.
		 */
		protected abstract AbstractDecorator createAndRegisterDecorator(Diff diff, View referenceView,
				IFigure referenceFigure, MergeViewerSide targetSide);

		/**
		 * Get the main decorators related to the given difference.
		 * 
		 * @param difference
		 *            The difference.
		 * @return The list of main decorators.
		 */
		protected abstract List<? extends AbstractDecorator> getDecorators(Diff difference);

	}

	/**
	 * Phantom manager to create, hide or reveal phantom figures related to deleted or added graphical
	 * objects.
	 * 
	 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
	 */
	private class PhantomManager extends AbstractDecoratorManager {

		/**
		 * Phantom represented by a <code>figure</code> on a <code>layer</code>, from the given
		 * <code>side</code> of the merge viewer. An edit part may be linked to the <code>figure</code> in
		 * some cases.<br>
		 * The phantom is related to a <code>difference</code> and it is binded with the reference view and
		 * figure.
		 * 
		 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
		 */
		private class Phantom extends AbstractDecorator {

			/**
			 * Constructor.
			 * 
			 * @param layer
			 *            {@link Phantom#fLayer}.
			 * @param side
			 *            {@link Phantom#fSide}.
			 * @param originView
			 *            {@link Phantom#fOriginView}.
			 * @param originFigure
			 *            {@link Phantom#fOriginFigure}.
			 * @param diff
			 *            {@link Phantom#fDifference}.
			 */
			public Phantom(IFigure layer, MergeViewerSide side, View originView, IFigure originFigure,
					Diff diff) {
				setLayer(layer);
				setSide(side);
				setOriginView(originView);
				setOriginFigure(originFigure);
				setDifference(diff);
			}

			/**
			 * Get the decorator dependencies of this one. The dependencies are the decorator ancestors plus
			 * the extremities of an edge decorator.
			 * 
			 * @return The list of found decorators.
			 */
			public List<? extends AbstractDecorator> getDependencies() {
				List<AbstractDecorator> result = new ArrayList<AbstractDecorator>();
				result.addAll(getAncestors());
				if (fOriginView instanceof Edge) {
					View source = ((Edge)fOriginView).getSource();
					View target = ((Edge)fOriginView).getTarget();
					result.addAll(getOrCreateRelatedDecorators(source));
					result.addAll(getOrCreateRelatedDecorators(target));
				}
				return result;
			}

			/**
			 * From the given view, get or create the related phantoms.
			 * 
			 * @param referenceView
			 *            The given view.
			 * @return The list of phantoms.
			 */
			private List<Phantom> getOrCreateRelatedDecorators(EObject referenceView) {
				List<Phantom> result = new ArrayList<Phantom>();
				Collection<Diff> changes = Collections2.filter(getComparison().getDifferences(referenceView),
						goodCandidate());
				for (Diff change : changes) {
					Phantom phantom = fPhantomRegistry.get(change);
					if (phantom == null) {
						IFigure referenceFigure = PhantomManager.this.getFigure((View)referenceView);
						if (referenceFigure != null) {
							phantom = createAndRegisterDecorator(change, (View)referenceView,
									referenceFigure, fSide);
						}
					}
					if (phantom != null) {
						result.add(phantom);
					}
				}
				return result;
			}

			/**
			 * Get the ancestor decorators of this one.
			 * 
			 * @return The list of the ancestors.
			 */
			private List<? extends AbstractDecorator> getAncestors() {
				List<AbstractDecorator> result = new ArrayList<AbstractDecorator>();
				EObject parentOriginView = fOriginView.eContainer();
				while (parentOriginView != null) {
					result.addAll(getOrCreateRelatedDecorators(parentOriginView));
					parentOriginView = parentOriginView.eContainer();
				}
				return result;
			}
		}

		/** Registry of created phantoms, indexed by difference. */
		private final Map<Diff, Phantom> fPhantomRegistry = new HashMap<Diff, Phantom>();

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#goodCandidate()<br>
		 *      Only the diagram differences ADD or DELETE are concerned by this display.
		 */
		@Override
		protected Predicate<Diff> goodCandidate() {
			return new Predicate<Diff>() {
				public boolean apply(Diff difference) {
					return and(instanceOf(DiagramDiff.class),
							or(ofKind(DifferenceKind.ADD), ofKind(DifferenceKind.DELETE))).apply(difference);
				}
			};
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getReferenceViews(org.eclipse.emf.compare.diagram.DiagramDiff)
		 */
		@Override
		protected List<View> getReferenceViews(DiagramDiff difference) {
			List<View> result = new ArrayList<View>();

			Match match = getComparison().getMatch(difference.getView());

			EObject originObj = match.getOrigin();
			EObject leftObj = match.getLeft();
			EObject rightObj = match.getRight();

			if (leftObj instanceof View || rightObj instanceof View) {
				result.add(getReferenceView((View)originObj, (View)leftObj, (View)rightObj));
			}

			return result;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getTargetSide(org.eclipse.emf.compare.Match,
		 *      org.eclipse.gmf.runtime.notation.View)<br>
		 *      If the left object is null, a phantom should be drawn instead. Else, it means that the right
		 *      object is null and a phantom should be displayed on the right side.
		 */
		@Override
		protected MergeViewerSide getTargetSide(Match match, View referenceView) {
			MergeViewerSide targetSide = null;
			if (match.getLeft() == null) {
				targetSide = MergeViewerSide.LEFT;
			} else {
				targetSide = MergeViewerSide.RIGHT;
			}
			return targetSide;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#createAndRegisterDecorator(org.eclipse.emf.compare.Diff,
		 *      org.eclipse.gmf.runtime.notation.View, org.eclipse.draw2d.IFigure,
		 *      org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide)
		 */
		@Override
		protected Phantom createAndRegisterDecorator(Diff diff, View referenceView, IFigure referenceFigure,
				MergeViewerSide targetSide) {
			Phantom phantom = createPhantom(diff, referenceView, referenceFigure, targetSide);
			fPhantomRegistry.put(diff, phantom);
			return phantom;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getDecorators(org.eclipse.emf.compare.Diff)
		 */
		@Override
		protected List<Phantom> getDecorators(Diff difference) {
			List<Phantom> result = new ArrayList<DiagramContentMergeViewer.PhantomManager.Phantom>();
			Phantom phantom = fPhantomRegistry.get(difference);
			if (phantom != null) {
				result.add(phantom);
			}
			return result;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#handleDecorator(org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager.AbstractDecorator,
		 *      boolean)
		 */
		@Override
		protected void handleDecorator(AbstractDecorator decorator, boolean isAdd, boolean isMain) {
			super.handleDecorator(decorator, isAdd, isMain);
			// Display the dependencies (context) of this decorator
			for (AbstractDecorator ancestor : ((Phantom)decorator).getDependencies()) {
				super.handleDecorator(ancestor, isAdd, false);
			}
		}

		@Override
		protected void handleAddDecorator(AbstractDecorator decorator, IFigure parent, IFigure toAdd,
				boolean isMain) {
			super.handleAddDecorator(decorator, parent, toAdd, isMain);
			// Set the highlight of the figure
			Color strokeColor = null;
			if (isMain) {
				((Shape)toAdd).setLineWidth(((Shape)toAdd).getLineWidth() + 1);
				strokeColor = getCompareColor().getStrokeColor(decorator.getDifference(), isThreeWay(),
						false, true);
				// figure.setBorder(new FocusBorder());

				// FIXME: Find a way to set the focus on this figure.
				getViewer(decorator.getSide()).getGraphicalViewer().reveal(toAdd);
			} else {
				strokeColor = getCompareColor().getStrokeColor(decorator.getDifference(), isThreeWay(),
						false, false);

			}
			toAdd.setForegroundColor(strokeColor);
		}

		@Override
		protected void handleDeleteDecorator(AbstractDecorator decorator, IFigure parent, IFigure toDelete,
				boolean isMain) {
			super.handleDeleteDecorator(decorator, parent, toDelete, isMain);
			// Re-initialize the highlight of the figure
			if (isMain) {
				((Shape)toDelete).setLineWidth(((Shape)toDelete).getLineWidth() - 1);
				Color strokeColor = getCompareColor().getStrokeColor(decorator.getDifference(), isThreeWay(),
						false, false);
				toDelete.setForegroundColor(strokeColor);
				// figure.setBorder(null);
			}
		}

		/**
		 * Get the view which has to be used as reference to build a phantom.<br>
		 * The reference is the non null object among the given objects. In case of delete object, in the
		 * context of three-way comparison, the reference will be the ancestor one (<code>originObj</code>).
		 * 
		 * @param originObj
		 *            The ancestor object.
		 * @param leftView
		 *            The left object.
		 * @param rightView
		 *            The right object.
		 * @return The reference object.
		 */
		private View getReferenceView(View originObj, View leftView, View rightView) {
			View referenceView;
			if (originObj != null) {
				referenceView = originObj;
			} else if (leftView != null) {
				referenceView = leftView;
			} else {
				referenceView = rightView;
			}
			return referenceView;
		}

		/**
		 * It creates a new phantom from the given difference, view and figure.
		 * 
		 * @param diff
		 *            The related difference used as index for the main phantom.
		 * @param referenceView
		 *            The reference view as base for creation of the phantom.
		 * @param referenceFigure
		 *            The reference figure as base for creation of the phantom.
		 * @param side
		 *            The side where the phantom has to be created.
		 * @return The phantom.
		 */
		private Phantom createPhantom(Diff diff, View referenceView, IFigure referenceFigure,
				MergeViewerSide side) {

			MergeViewerSide referenceSide = getSide(referenceView);

			Rectangle rect = referenceFigure.getBounds().getCopy();

			IFigure referenceLayer = getLayer(referenceView, referenceSide);
			translateCoordinates(referenceFigure, referenceLayer, rect);

			IFigure ghost = null;

			IFigure targetLayer = getLayer(referenceView, side);
			Phantom phantom = new Phantom(targetLayer, side, referenceView, referenceFigure, diff);

			// Container "list" case
			if (referenceView.eContainer() instanceof BasicCompartment) {
				ghost = new Polyline();

				Diff refiningDiff = Iterators.find(diff.getRefinedBy().iterator(), and(
						valueIs(referenceView), onFeature(NotationPackage.Literals.VIEW__PERSISTED_CHILDREN
								.getName())));

				// FIXME:
				// - It has to manage visible views.
				// - What about transient children ?
				int index = DiffUtil.findInsertionIndex(getComparison(), refiningDiff,
						side == MergeViewerSide.LEFT);

				IFigure referenceParentFigure = referenceFigure.getParent();
				Rectangle referenceParentBounds = referenceParentFigure.getBounds().getCopy();
				translateCoordinates(referenceParentFigure, referenceLayer, referenceParentBounds);

				View parentView = (View)getMatchView(referenceView.eContainer(), side);
				if (parentView != null) {
					int nbElements = getVisibleViews(parentView).size();
					if (index > nbElements) {
						index = nbElements;
					}
				}

				// FIXME: The add of decorators modifies the physical coordinates of elements
				// FIXME: Compute position from the y position of the first child + sum of height of the
				// children.
				int pos = rect.height * index + referenceParentBounds.y + 1;

				((Polyline)ghost).setEndpoints(new Point(rect.x, pos), new Point(rect.x + rect.width, pos));

				// Edge case
			} else if (referenceView instanceof Edge) {
				// If the edge phantom ties shapes where their coordinates changed
				if (hasAnExtremityChange((Edge)referenceView, side)) {
					EditPart edgeEditPart = createEdgeEditPart((Edge)referenceView, referenceSide, side);
					if (edgeEditPart instanceof GraphicalEditPart) {
						phantom.setEditPart(edgeEditPart);
						ghost = ((GraphicalEditPart)edgeEditPart).getFigure();
						ghost.getChildren().clear();
					}
					// Else, it creates only a polyline connection figure with the same properties as the
					// reference
				} else {
					if (referenceFigure instanceof PolylineConnection) {
						ghost = new PolylineConnection();
						ghost.setBounds(rect);
						((PolylineConnection)ghost).setPoints(((PolylineConnection)referenceFigure)
								.getPoints().getCopy());
					}
				}
			}

			// Default case: Nodes
			if (ghost == null) {
				ghost = new RectangleFigure();
				ghost.setBounds(rect);
			}

			if (ghost instanceof Shape) {
				((Shape)ghost).setFill(false);
			}

			phantom.setFigure(ghost);

			translateWhenInsideContainerChange(phantom);

			return phantom;
		}

		/**
		 * Get the visible view under the given parent view.
		 * 
		 * @param parent
		 *            The parent view.
		 * @return The list of views.
		 */
		private List<View> getVisibleViews(View parent) {
			return (List<View>)Lists.newArrayList(Iterators.filter(parent.getChildren().iterator(),
					new Predicate<Object>() {
						public boolean apply(Object input) {
							return input instanceof View && ((View)input).isVisible();
						}
					}));
		}

		/**
		 * It translates and resizes the figure of the given phantom when this one is nested in a container
		 * which is subjected to a coordinates change.
		 * 
		 * @param phantom
		 *            The phantom.
		 */
		private void translateWhenInsideContainerChange(Phantom phantom) {
			// FIXME: It was "phantom.getDifference().getMatch()" replaced by
			// "getDiffAncestors(phantom.getDifference())" to fix a regression due to an other regression
			// about
			// the location of the extensions under matches.
			Collection<Diff> changes = Collections2.filter(getDiffAncestors(phantom.getDifference()),
					new Predicate<Diff>() {

						public boolean apply(Diff difference) {
							// FIXME: it will be changed to CHANGE (change coordinates (or dimension))
							return difference.getKind() == DifferenceKind.MOVE;
						}

					});
			if (changes.size() > 0) {
				View referenceView = phantom.getOriginView();
				View parentReferenceView = (View)referenceView.eContainer();
				if (parentReferenceView != null) {
					View parentView = (View)getMatchView(parentReferenceView, phantom.getSide());
					IFigure parentFigure = getFigure(parentView);
					if (parentFigure != null) {
						Rectangle parentRect = parentFigure.getBounds().getCopy();
						translateCoordinates(parentFigure,
								getLayer(parentReferenceView, getSide(parentView)), parentRect);

						IFigure parentReferenceFigure = getFigure(parentReferenceView);
						// CHECKSTYLE:OFF
						if (parentReferenceFigure != null) {
							Rectangle parentReferenceRect = parentReferenceFigure.getBounds().getCopy();
							translateCoordinates(parentReferenceFigure, getLayer(parentReferenceView,
									getSide(parentReferenceView)), parentReferenceRect);

							int deltaX = parentRect.x - parentReferenceRect.x;
							int deltaY = parentRect.y - parentReferenceRect.y;
							int deltaWidth = parentRect.width - parentReferenceRect.width;
							int deltaHeight = parentRect.height - parentReferenceRect.height;

							IFigure figure = phantom.getFigure();

							Rectangle rect = figure.getBounds().getCopy();
							rect.x += deltaX;
							rect.y += deltaY;
							rect.width += deltaWidth;
							if (!(figure instanceof Polyline)) {
								rect.height += deltaHeight;
							}
							figure.setBounds(rect);

							if (figure instanceof Polyline) {

								Point firstPoint = ((Polyline)figure).getPoints().getFirstPoint().getCopy();
								Point lastPoint = ((Polyline)figure).getPoints().getLastPoint().getCopy();

								firstPoint.x += deltaX;
								firstPoint.y += deltaY;

								lastPoint.x += deltaX + deltaWidth;
								lastPoint.y += deltaY;

								((Polyline)figure).setEndpoints(firstPoint, lastPoint);

							}
						}
						// CHECKSTYLE:ON
					}
				}
			}
		}

		/**
		 * Get all the ancestor matches from the given difference.
		 * 
		 * @param difference
		 *            The difference.
		 * @return the list of ancestor matches.
		 */
		private List<Match> getMatchAncestors(Diff difference) {
			List<Match> result = new ArrayList<Match>();
			EObject match = difference.getMatch();
			while (match != null) {
				if (match instanceof Match) {
					result.add((Match)match);
				}
				match = match.eContainer();
			}
			return result;
		}

		/**
		 * Get all the differences above the given one.
		 * 
		 * @param difference
		 *            The difference.
		 * @return the list of parent differences.
		 */
		private List<Diff> getDiffAncestors(Diff difference) {
			List<Diff> result = new ArrayList<Diff>();
			Iterator<Match> matches = getMatchAncestors(difference).iterator();
			while (matches.hasNext()) {
				Match match = matches.next();
				result.addAll(match.getDifferences());
			}
			return result;
		}

		/**
		 * It checks that the given edge is linked to graphical objects subjected to coordinate changes, on
		 * the given side.
		 * 
		 * @param edge
		 *            The edge to check.
		 * @param targetSide
		 *            The side to check extremities (side of the phantom).
		 * @return True if an extremity at least changed its location, False otherwise.
		 */
		private boolean hasAnExtremityChange(Edge edge, MergeViewerSide targetSide) {
			View referenceSource = edge.getSource();
			View referenceTarget = edge.getTarget();
			return hasChange(referenceSource, targetSide) || hasChange(referenceTarget, targetSide);
		}

		/**
		 * It checks that the coordinates of the given view changed between left and right, from the given
		 * side.
		 * 
		 * @param referenceView
		 *            The view to check.
		 * @param targetSide
		 *            The side to focus.
		 * @return True if the view changed its location, False otherwise.
		 */
		private boolean hasChange(View referenceView, MergeViewerSide targetSide) {
			DifferenceKind lookup = DifferenceKind.MOVE; // FIXME: it will be change to CHANGE (change
															// coordinates)
			View extremity = (View)getMatchView(referenceView, targetSide);
			// Look for a related change coordinates on the extremity of the edge reference.
			Collection<Diff> diffs = Collections2.filter(getComparison().getDifferences(referenceView), and(
					instanceOf(DiagramDiff.class), ofKind(lookup)));
			if (diffs.isEmpty()) {
				// Look for a related change coordinates on the matching extremity (other side) of the edge
				// reference.
				diffs = Collections2.filter(getComparison().getDifferences(extremity), and(
						instanceOf(DiagramDiff.class), ofKind(lookup)));
			}
			return !diffs.isEmpty();
		}

		/**
		 * It creates and returns a new edit part from the given edge. This edit part listens the reference
		 * edge but is attached to the controllers of the target (phantom) side.
		 * 
		 * @param referenceEdge
		 *            The edge as base of the edit part.
		 * @param referenceSide
		 *            The side of this edge.
		 * @param targetSide
		 *            The side where the edit part has to be created to draw the related phantom.
		 * @return The new edit part.
		 */
		private EditPart createEdgeEditPart(Edge referenceEdge, MergeViewerSide referenceSide,
				MergeViewerSide targetSide) {
			EditPart edgeEditPartReference = getViewer(referenceSide).getEditPart(referenceEdge);
			EditPart edgeEditPart = null;
			if (edgeEditPartReference instanceof ConnectionEditPart) {
				edgeEditPart = createEditPartForPhantoms(referenceEdge, referenceSide, targetSide);
				if (edgeEditPart instanceof ConnectionEditPart) {
					View source = (View)((ConnectionEditPart)edgeEditPartReference).getSource().getModel();
					if (source == null) {
						source = referenceEdge.getSource();
					}
					View target = (View)((ConnectionEditPart)edgeEditPartReference).getTarget().getModel();
					if (target == null) {
						target = referenceEdge.getTarget();
					}
					EditPart sourceEp = createEditPartForPhantoms(source, referenceSide, targetSide);
					((AbstractGraphicalEditPart)sourceEp).activate();
					((AbstractGraphicalEditPart)sourceEp).getFigure();
					((ConnectionEditPart)edgeEditPart).setSource(sourceEp);
					EditPart targetEp = createEditPartForPhantoms(target, referenceSide, targetSide);
					((AbstractGraphicalEditPart)targetEp).activate();
					((AbstractGraphicalEditPart)targetEp).getFigure();
					((ConnectionEditPart)edgeEditPart).setTarget(targetEp);
				}
			}
			return edgeEditPart;
		}

		/**
		 * It creates and returns a new edit part from the given view. This edit part listens the reference
		 * view but is attached to the controllers of the target (phantom) side.
		 * 
		 * @param referenceView
		 *            The view as base of the edit part.
		 * @param referenceSide
		 *            The side of this view.
		 * @param targetSide
		 *            The side where the edit part has to be created to draw the related phantom.
		 * @return The new edit part.
		 */
		private EditPart createEditPartForPhantoms(EObject referenceView, MergeViewerSide referenceSide,
				MergeViewerSide targetSide) {
			EditPart editPartParent = null;
			EditPart editPart = null;
			EditPart editPartReference = getViewer(referenceSide).getEditPart(referenceView);
			EditPart editPartReferenceParent = editPartReference.getParent();
			Object referenceViewParent = editPartReferenceParent.getModel();
			if (!(referenceViewParent instanceof EObject)) {
				referenceViewParent = referenceView.eContainer();
			}
			View viewParent = (View)getMatchView((EObject)referenceViewParent, targetSide);
			if (viewParent != null) {
				editPartParent = getViewer(targetSide).getEditPart(viewParent);
			}
			if (editPartParent == null) {
				editPartParent = createEditPartForPhantoms((EObject)referenceViewParent, referenceSide,
						targetSide);

			}
			if (editPartParent != null) {
				View view = (View)getMatchView(referenceView, targetSide);
				if (view != null) {
					editPart = getViewer(targetSide).getEditPart(view);
				}
				if (editPart == null) {
					editPart = getViewer(targetSide).getGraphicalViewer().getEditPartFactory()
							.createEditPart(editPartParent, referenceView);
					editPart.setParent(editPartParent);
					getViewer(targetSide).getGraphicalViewer().getEditPartRegistry().put(referenceView,
							editPart);
				}

			}
			return editPart;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.IDecoratorManager#hideAll()
		 */
		public void hideAll() {
			Iterator<Phantom> visiblePhantoms = Iterators.filter(fPhantomRegistry.values().iterator(),
					new Predicate<Phantom>() {
						public boolean apply(Phantom phantom) {
							return phantom.getFigure().getParent() != null;
						}
					});
			while (visiblePhantoms.hasNext()) {
				Phantom phantom = (Phantom)visiblePhantoms.next();
				handleDecorator(phantom, false, true);
			}
		}
	}

	/**
	 * Marker manager to create, hide or reveal marker figures related to deleted or added graphical objects.
	 * 
	 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
	 */
	private class MarkerManager extends AbstractDecoratorManager {

		/**
		 * Marker represented by a <code>figure</code> on a <code>layer</code>, from the given
		 * <code>side</code> of the merge viewer. An edit part may be linked to the <code>figure</code> in
		 * some cases.<br>
		 * The marker is related to a <code>difference</code> and it is binded with the reference view and
		 * figure.
		 * 
		 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
		 */
		private class Marker extends AbstractDecorator {

			/** Thickness of the marker. */
			public static final int THICKNESS = 6;

			/** The alpha number for the figure. */
			public static final int ALPHA = 30;

			/**
			 * Constructor.
			 * 
			 * @param layer
			 *            {@link Marker#fLayer}.
			 * @param side
			 *            {@link Marker#fSide}.
			 * @param originView
			 *            {@link Marker#fOriginView}.
			 * @param originFigure
			 *            {@link Marker#fOriginFigure}.
			 * @param diff
			 *            {@link Marker#fDifference}.
			 */
			public Marker(IFigure layer, MergeViewerSide side, View originView, IFigure originFigure,
					Diff diff) {
				setLayer(layer);
				setSide(side);
				setOriginView(originView);
				setOriginFigure(originFigure);
				setDifference(diff);
			}
		}

		/** Registry of created markers, indexed by difference. */
		private Map<Diff, List<Marker>> fMarkerRegistry = new HashMap<Diff, List<Marker>>();

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getReferenceViews(org.eclipse.emf.compare.diagram.DiagramDiff)
		 */
		@Override
		protected List<View> getReferenceViews(DiagramDiff difference) {
			List<View> result = new ArrayList<View>();
			Match matchValue = getComparison().getMatch(difference.getView());
			if (matchValue != null) {
				if (matchValue.getLeft() != null) {
					result.add((View)matchValue.getLeft());
				}
				if (matchValue.getRight() != null) {
					result.add((View)matchValue.getRight());
				}
				if (getComparison().isThreeWay()) {
					switch (difference.getKind()) {
						case DELETE:
						case CHANGE:
						case MOVE:
							result.add((View)matchValue.getOrigin());
							break;
						default:
							break;
					}
				}
			}
			return result;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getTargetSide(org.eclipse.emf.compare.Match,
		 *      org.eclipse.gmf.runtime.notation.View)
		 */
		@Override
		protected MergeViewerSide getTargetSide(Match match, View referenceView) {
			return getSide(referenceView);
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#createAndRegisterDecorator(org.eclipse.emf.compare.Diff,
		 *      org.eclipse.gmf.runtime.notation.View, org.eclipse.draw2d.IFigure,
		 *      org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide)
		 */
		@Override
		protected Marker createAndRegisterDecorator(Diff diff, View referenceView, IFigure referenceFigure,
				MergeViewerSide targetSide) {
			Marker marker = createMarker(diff, referenceView, referenceFigure, targetSide);
			List<Marker> markers = fMarkerRegistry.get(diff);
			if (markers == null) {
				markers = new ArrayList<Marker>();
				fMarkerRegistry.put(diff, markers);
			}
			markers.add(marker);
			return marker;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#getDecorators(org.eclipse.emf.compare.Diff)
		 */
		@Override
		protected List<Marker> getDecorators(Diff difference) {
			return fMarkerRegistry.get(difference);
		}

		@Override
		protected void handleAddDecorator(AbstractDecorator decorator, IFigure parent, IFigure toAdd,
				boolean isMain) {
			super.handleAddDecorator(decorator, parent, toAdd, isMain);
			DiagramMergeViewer viewer = getViewer(decorator.getSide());
			viewer.getGraphicalViewer().reveal(viewer.getEditPart(decorator.getOriginView()));
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.AbstractDecoratorManager#goodCandidate()<br>
		 *      All graphical differences are concerned.
		 */
		@Override
		protected Predicate<Diff> goodCandidate() {
			return new Predicate<Diff>() {
				public boolean apply(Diff difference) {
					return instanceOf(DiagramDiff.class).apply(difference);
				}
			};
		}

		/**
		 * It creates a new marker from the given difference, view and figure.
		 * 
		 * @param diff
		 *            The related difference used as index for the main marker.
		 * @param referenceView
		 *            The reference view as base for creation of the marker.
		 * @param referenceFigure
		 *            The reference figure as base for creation of the marker.
		 * @param side
		 *            The side where the marker has to be created.
		 * @return The phantom.
		 */
		private Marker createMarker(Diff diff, View referenceView, IFigure referenceFigure,
				MergeViewerSide side) {

			Rectangle referenceBounds = referenceFigure.getBounds().getCopy();
			IFigure referenceLayer = getLayer(referenceView, side);
			translateCoordinates(referenceFigure, referenceLayer, referenceBounds);

			IFigure markerFigure = null;

			IFigure targetLayer = getLayer(referenceView, side);
			Marker marker = new Marker(targetLayer, side, referenceView, referenceFigure, diff);

			if (referenceView.eContainer() instanceof BasicCompartment) {

				markerFigure = new RectangleFigure();
				markerFigure.setBounds(referenceBounds);

			} else if (referenceView instanceof Edge) {

				if (referenceFigure instanceof PolylineConnection) {

					markerFigure = new PolylineConnection();

					markerFigure.setBounds(referenceBounds);

					((PolylineConnection)markerFigure).setPoints(((PolylineConnection)referenceFigure)
							.getPoints().getCopy());

					int oldWidth = ((Shape)referenceFigure).getLineWidth();
					int newWidth = oldWidth + Marker.THICKNESS * 2;
					((PolylineConnection)markerFigure).setLineWidth(newWidth);
				}

			}

			// Default case: Nodes
			if (markerFigure == null) {

				markerFigure = new RectangleFigure();

				referenceBounds.x -= Marker.THICKNESS;
				referenceBounds.y -= Marker.THICKNESS;
				referenceBounds.width += Marker.THICKNESS * 2;
				referenceBounds.height += Marker.THICKNESS * 2;

				markerFigure.setBounds(referenceBounds);
			}

			Color strokeColor = getCompareColor().getStrokeColor(diff, isThreeWay(), false, true);
			markerFigure.setForegroundColor(strokeColor);
			markerFigure.setBackgroundColor(strokeColor);
			// markerFigure.setBorder(new FocusBorder());
			((Shape)markerFigure).setAlpha(Marker.ALPHA);

			marker.setFigure(markerFigure);

			return marker;
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.IDecoratorManager#hideAll()
		 */
		public void hideAll() {
			Iterator<Marker> visibleMarkers = Iterators.filter(Iterables.concat(fMarkerRegistry.values())
					.iterator(), new Predicate<Marker>() {
				public boolean apply(Marker marker) {
					return marker.getFigure().getParent() != null;
				}
			});
			while (visibleMarkers.hasNext()) {
				Marker marker = (Marker)visibleMarkers.next();
				handleDecorator(marker, false, true);
			}
		}

	}

	/**
	 * Decorator manager to create, hide or reveal all decorator figures related to graphical changes.
	 * 
	 * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
	 */
	private class DecoratorsManager implements IDecoratorManager {
		/** Phantoms manager. */
		private IDecoratorManager fPhantomManager = new PhantomManager();

		/** Markers manager. */
		private IDecoratorManager fMarkerManager = new MarkerManager();

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.IDecoratorManager#hideDecorators(org.eclipse.emf.compare.Diff)
		 */
		public void hideDecorators(Diff difference) {
			fMarkerManager.hideDecorators(difference);
			fPhantomManager.hideDecorators(difference);
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.IDecoratorManager#revealDecorators(org.eclipse.emf.compare.Diff)
		 */
		public void revealDecorators(Diff difference) {
			fMarkerManager.revealDecorators(difference);
			fPhantomManager.revealDecorators(difference);
		}

		/**
		 * {@inheritDoc}
		 * 
		 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagram.DiagramContentMergeViewer.IDecoratorManager#hideAll()
		 */
		public void hideAll() {
			fMarkerManager.hideAll();
			fPhantomManager.hideAll();
		}

	}

	/**
	 * Bundle name of the property file containing all displayed strings.
	 */
	private static final String BUNDLE_NAME = DiagramContentMergeViewer.class.getName();

	/** The editing domain. */
	private ICompareEditingDomain fEditingDomain;

	/** Listener to manage the update of the decorators on events about the command stack. */
	private CommandStackListener fDecoratorsCommandStackListener;

	/** The phantom manager to use in the context of this viewer. */
	private final DecoratorsManager fDecoratorsManager = new DecoratorsManager();

	/** The current "opened" difference. */
	private Diff fCurrentSelectedDiff;

	/**
	 * The adapter factory used to create the content and label provider for ancestor, left and right
	 * {@link DiagramMergeViewer}.
	 */
	private final ComposedAdapterFactory fAdapterFactory;

	/**
	 * Creates a new {@link DiagramContentMergeViewer} by calling the super constructor with the given
	 * parameters.
	 * <p>
	 * It calls {@link #buildControl(Composite)} as stated in its javadoc.
	 * <p>
	 * {@link #setContentProvider(org.eclipse.jface.viewers.IContentProvider) content provider} to properly
	 * display ancestor, left and right parts.
	 * 
	 * @param parent
	 *            the parent composite to build the UI in
	 * @param config
	 *            the {@link CompareConfiguration}
	 */
	public DiagramContentMergeViewer(Composite parent, CompareConfiguration config) {
		super(SWT.NONE, ResourceBundle.getBundle(BUNDLE_NAME), config);

		fAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		fAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
		fAdapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());

		buildControl(parent);
		setContentProvider(new TreeContentMergeViewerContentProvider(config, getComparison()));
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
	 */
	@Override
	protected void handleDispose(DisposeEvent event) {
		fEditingDomain.getCommandStack().removeCommandStackListener(fDecoratorsCommandStackListener);
		fAdapterFactory.dispose();
		super.handleDispose(event);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#getAncestorMergeViewer()
	 */
	@SuppressWarnings("unchecked")
	// see createMergeViewer() to see it is safe
	@Override
	public DiagramMergeViewer getAncestorMergeViewer() {
		return (DiagramMergeViewer)super.getAncestorMergeViewer();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#getLeftMergeViewer()
	 */
	@SuppressWarnings("unchecked")
	// see createMergeViewer() to see it is safe
	@Override
	public DiagramMergeViewer getLeftMergeViewer() {
		return (DiagramMergeViewer)super.getLeftMergeViewer();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#getRightMergeViewer()
	 */
	@SuppressWarnings("unchecked")
	// see createMergeViewer() to see it is safe
	@Override
	public DiagramMergeViewer getRightMergeViewer() {
		return (DiagramMergeViewer)super.getRightMergeViewer();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#copyDiff(boolean)
	 */
	@Override
	protected void copyDiff(boolean leftToRight) {
		/*
		 * FIXME change this! For the moment we always do a new setInput() on the content viewer whenever we
		 * select a Diagram Difference. This is meant to change so that we use selection synchronization
		 * instead. This code will break whenever we implement that change.
		 */
		if (fCurrentSelectedDiff != null) {
			final Command command = getEditingDomain().createCopyCommand(
					Collections.singletonList(fCurrentSelectedDiff), leftToRight,
					EMFCompareRCPPlugin.getDefault().getMergerRegistry());
			getEditingDomain().getCommandStack().execute(command);

			if (leftToRight) {
				setRightDirty(true);
			} else {
				setLeftDirty(true);
			}
			// refresh();
		}

	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getContents(boolean)
	 */
	@Override
	protected byte[] getContents(boolean left) {
		return null;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.DiagramCompareContentMergeViewer#createMergeViewer(org.eclipse.swt.widgets.Composite,
	 *      org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide)
	 */
	@Override
	protected IMergeViewer createMergeViewer(Composite parent, MergeViewerSide side) {
		final DiagramMergeViewer diagramMergeViewer = new DiagramMergeViewer(parent, side);
		return diagramMergeViewer;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.DiagramCompareContentMergeViewer#paintCenter(org.eclipse.swt.graphics.GC)
	 */
	@Override
	protected void paintCenter(GC g) {

	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.DiagramCompareContentMergeViewer#updateContent(java.lang.Object,
	 *      java.lang.Object, java.lang.Object)
	 */
	@Override
	protected void updateContent(Object ancestor, Object left, Object right) {
		initStackListenerAndUpdateContent(ancestor, left, right);

		getLeftMergeViewer().getGraphicalViewer().flush();
		getRightMergeViewer().getGraphicalViewer().flush();
		getAncestorMergeViewer().getGraphicalViewer().flush();

		if (left instanceof IDiagramDiffAccessor) {
			IDiagramDiffAccessor input = (IDiagramDiffAccessor)left;

			// initialization: reset the current difference selection hiding potential visible phantoms
			if (fCurrentSelectedDiff != null && fCurrentSelectedDiff.getState() != DifferenceState.MERGED) {
				fDecoratorsManager.hideDecorators(fCurrentSelectedDiff);
			}

			Diff diff = input.getDiff(); // equivalent to getInput().getTarget()
			fCurrentSelectedDiff = diff;

			if (diff.getState() != DifferenceState.MERGED) {
				fDecoratorsManager.revealDecorators(diff);
			}

			// FIXME use the decorator manager to refresh decorators after a merge and using undo/redo
			// actions.
		} else if (left instanceof IDiagramNodeAccessor) {
			if (fCurrentSelectedDiff != null && fCurrentSelectedDiff.getState() != DifferenceState.MERGED) {
				fDecoratorsManager.hideDecorators(fCurrentSelectedDiff);
			}
			fCurrentSelectedDiff = null;
		}

		updateToolItems();

	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#installCommandStackListener(org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction,
	 *      org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoAction)
	 */
	@Override
	protected CommandStackListener installCommandStackListener(UndoAction undoAction, RedoAction redoAction) {
		CommandStackListener cmdStackListener = super.installCommandStackListener(undoAction, redoAction);
		fEditingDomain = getEditingDomain();
		fDecoratorsCommandStackListener = new CommandStackListener() {

			public void commandStackChanged(EventObject event) {
				Object source = event.getSource();
				if (source instanceof TransactionalCommandStack) {
					Command command = ((TransactionalCommandStack)source).getMostRecentCommand();
					if (command instanceof CopyCommand) {
						Iterator<DiagramDiff> diffs = Iterators.filter(command.getAffectedObjects()
								.iterator(), DiagramDiff.class);
						while (diffs.hasNext()) {
							DiagramDiff diagramDiff = diffs.next();
							if (diagramDiff.getState() != DifferenceState.UNRESOLVED) {
								fDecoratorsManager.hideDecorators(diagramDiff);
							}
						}
					}
				}
			}
		};
		fEditingDomain.getCommandStack().addCommandStackListener(fDecoratorsCommandStackListener);
		return cmdStackListener;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
	 */
	@Override
	public void selectionChanged(SelectionChangedEvent event) {
		// No selection synchronization (content to structure merge viewer).
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#getDiffFrom(org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer)
	 */
	@Override
	protected Diff getDiffFrom(IMergeViewer viewer) {
		return fCurrentSelectedDiff;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#createControls(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	protected void createControls(Composite composite) {
		super.createControls(composite);
		getAncestorMergeViewer().removeSelectionChangedListener(this);
		getLeftMergeViewer().removeSelectionChangedListener(this);
		getRightMergeViewer().removeSelectionChangedListener(this);
	}

	/**
	 * Utility method to retrieve the {@link DiagramMergeViewer} from the given side.
	 * 
	 * @param side
	 *            The side to focus.
	 * @return The viewer.
	 */
	private DiagramMergeViewer getViewer(MergeViewerSide side) {
		DiagramMergeViewer result = null;
		switch (side) {
			case LEFT:
				result = getLeftMergeViewer();
				break;
			case RIGHT:
				result = getRightMergeViewer();
				break;
			case ANCESTOR:
				result = getAncestorMergeViewer();
				break;
			default:
		}
		return result;
	}

	/**
	 * Utility method to know the side where is located the given view.
	 * 
	 * @param view
	 *            The view.
	 * @return The side of the view.
	 */
	private MergeViewerSide getSide(View view) {
		MergeViewerSide result = null;
		Match match = getComparison().getMatch(view);
		if (match.getLeft() == view) {
			result = MergeViewerSide.LEFT;
		} else if (match.getRight() == view) {
			result = MergeViewerSide.RIGHT;
		} else if (match.getOrigin() == view) {
			result = MergeViewerSide.ANCESTOR;
		}
		return result;
	}

	/**
	 * Utility method to get the object matching with the given one, to the given side.
	 * 
	 * @param object
	 *            The object as base of the lookup.
	 * @param side
	 *            The side where the potential matching object has to be retrieved.
	 * @return The matching object.
	 */
	private EObject getMatchView(EObject object, MergeViewerSide side) {
		Match match = getComparison().getMatch(object);
		return getMatchView(match, side);
	}

	/**
	 * Utility method to get the object in the given side from the given match.
	 * 
	 * @param match
	 *            The match.
	 * @param side
	 *            The side where the potential matching object has to be retrieved.
	 * @return The matching object.
	 */
	private EObject getMatchView(Match match, MergeViewerSide side) {
		EObject result = null;
		switch (side) {
			case LEFT:
				result = match.getLeft();
				break;
			case RIGHT:
				result = match.getRight();
				break;
			case ANCESTOR:
				result = match.getOrigin();
				break;
			default:
		}
		return result;
	}

}

Back to the top