summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.ui/src/main/java/net/wotonomy/ui/EODisplayGroup.java
blob: ed65b1c4072e9f1a7ca3dfed96bb70c0ce46d9ac (plain)
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
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
/*
Wotonomy: OpenStep design patterns for pure Java applications.
Copyright (C) 2000 Michael Powers

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see http://www.gnu.org
*/

package net.wotonomy.ui;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Observable;

import javax.swing.JOptionPane;

import net.wotonomy.control.EODataSource;
import net.wotonomy.control.EODelayedObserver;
import net.wotonomy.control.EOEditingContext;
import net.wotonomy.control.EOKeyValueCoding;
import net.wotonomy.control.EOKeyValueCodingSupport;
import net.wotonomy.control.EOObjectStore;
import net.wotonomy.control.EOObserverCenter;
import net.wotonomy.control.EOObserving;
import net.wotonomy.control.EOQualifier;
import net.wotonomy.control.EOSortOrdering;
import net.wotonomy.control.OrderedDataSource;
import net.wotonomy.foundation.NSArray;
import net.wotonomy.foundation.NSDictionary;
import net.wotonomy.foundation.NSMutableArray;
import net.wotonomy.foundation.NSNotification;
import net.wotonomy.foundation.NSNotificationCenter;
import net.wotonomy.foundation.NSSelector;
import net.wotonomy.foundation.internal.Duplicator;
import net.wotonomy.foundation.internal.WotonomyException;

/**
* EODisplayGroup provides an abstraction of a user interface,
* comprising of an ordered collection of data objects, some
* of which are displayed, and of those some are selected.
*
* @author michael@mpowers.net
* @author $Author: cgruber $
* @version $Revision: 904 $
*/
public class EODisplayGroup extends Observable
                         implements EOObserving, EOEditingContext.Editor
{
    /**
    * Notification sent when the display group is about to fetch.
    */ 
    public static final String DisplayGroupWillFetchNotification
        = "DisplayGroupWillFetchNotification";
    
    private static boolean
        globalDefaultForValidatesChangesImmediately = true;
    private static String
        globalDefaultStringMatchFormat = "caseInsensitiveLike";
    private static String
        globalDefaultStringMatchOperator = "%@*";

    protected NSMutableArray allObjects;
    protected NSArray allObjectsProxy;
    protected NSMutableArray displayedObjects;
    protected NSArray displayedObjectsProxy;
    protected NSMutableArray selectedObjects;
    protected NSArray selectedObjectsProxy;
    protected NSMutableArray selectedIndexes;

    private String defaultStringMatchOperator;
    private String defaultStringMatchFormat;

    private boolean validatesChangesImmediately;
    private Object delegate;
    private EODataSource dataSource;
    private EOAssociation editingAssociation;
    private EOQualifier qualifier;
    private NSMutableArray sortOrderings;
    private NSArray sortOrderingsProxy;

    private NSArray localKeys;
    private NSDictionary insertedObjectDefaultValues;
    private boolean fetchesOnLoad;
    private boolean selectsFirstObjectAfterFetch;
    private boolean usesOptimisticRefresh;
    private boolean inQueryMode;

    // change detection: package access for helper classes
    boolean contentsChanged;
    boolean selectionChanged;
    int updatedObjectIndex;

    // this property is not in the spec
    private boolean compareByReference = false;

    private EOObserving lastGroupObserver;
    
    /**
    * Creates a new display group.
    */
    public EODisplayGroup ()
    {
        validatesChangesImmediately =
            globalDefaultForValidatesChangesImmediately();
        defaultStringMatchOperator =
            globalDefaultStringMatchFormat();
        defaultStringMatchFormat =
            globalDefaultStringMatchOperator();

        allObjects = new ObservableArray( this );
        allObjectsProxy = NSArray.arrayBackedByList( allObjects );
        displayedObjects = new NSMutableArray();
        displayedObjectsProxy = NSArray.arrayBackedByList( displayedObjects );
        selectedObjects = new NSMutableArray();
        selectedObjectsProxy = NSArray.arrayBackedByList( selectedObjects );
        sortOrderings = new NSMutableArray();
        sortOrderingsProxy = NSArray.arrayBackedByList( sortOrderings );
        selectedIndexes = new NSMutableArray();

        delegate = null;
        dataSource = null;
        editingAssociation = null;
        qualifier = null;

        localKeys = new NSArray(); // not implemented
        insertedObjectDefaultValues = new NSDictionary();
        fetchesOnLoad = false; // not implemented
        selectsFirstObjectAfterFetch = false;
        usesOptimisticRefresh = false;
        inQueryMode = false; // not implemented

        contentsChanged = false;
        selectionChanged = false;
        updatedObjectIndex = -1;

        // create our private delayed observer
        lastGroupObserver = new LastGroupObserver( this );
        EOObserverCenter.addObserver( lastGroupObserver, this );
    }



    // specify optional data source

    /**
    * Sets the data source that will be used by
    * this display group.
    */
    public void setDataSource ( EODataSource aDataSource )
    {
        if ( ( dataSource != null )
        &&   ( dataSource.editingContext() != null ) )
        {
            // un-register for notifications from existing parent store
            NSNotificationCenter.defaultCenter().removeObserver(
                this, null, dataSource.editingContext() );
            dataSource.editingContext().removeEditor( this );
            if ( dataSource.editingContext().messageHandler() == this )
            {
                dataSource.editingContext().setMessageHandler( null );
            }
            
        }

        dataSource = aDataSource;

        if ( ( dataSource != null )
        &&   ( dataSource.editingContext() != null ) )
        {
            // register for notifications from parent store
            NSNotificationCenter.defaultCenter().addObserver(
                this, new NSSelector( "objectsInvalidatedInEditingContext",
                    new Class[] { NSNotification.class } ),
                null, dataSource.editingContext() );
            
            // add ourselves as editor
            dataSource.editingContext().addEditor( this );
            
            // add ourselves as message handler if no such handler exists
            if ( dataSource.editingContext().messageHandler() == null )
            {
                dataSource.editingContext().setMessageHandler( this );
            }
        }
    }
    
    /**
    * Returns the current data source backing this display group,
    * or null if no dataSource is currently used.
    */
    public EODataSource dataSource ()
    {
        return dataSource;
    }



    // specify optional delegate

    /**
    * Sets the display group delegate that
    * will be used by this display group.
    */
    public void setDelegate ( Object aDelegate )
    {
        delegate = aDelegate;
    }

   /**
    * Returns the current delegate for this display group,
    * or null if no delegate is currently set.
    */
    public Object delegate ()
    {
        return delegate;
    }



    // display group configuration

    /**
    * Returns the current string matching format.
    * If not set, defaults to "%@*".
    */
    public String defaultStringMatchFormat ()
    {
        return defaultStringMatchFormat;
    }

    /**
    * Returns the current string matching operator.
    * If not set, defaults to "caseInsensitiveLike".
    */
    public String defaultStringMatchOperator ()
    {
        return defaultStringMatchOperator;
    }

    /**
    * Sets the display group and associations to edit a
    * "query by example" query object.  This method is
    * used for target/action connections.
    */
    public void enterQueryMode ( Object aSender )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Returns whether this display group should immediate
    * fetch when loaded.
    */
    public boolean fetchesOnLoad ()
    {
        return fetchesOnLoad;
    }

    /**
    * Returns whether this display group is in "query by
    * example" mode.
    */
    public boolean inQueryMode ()
    {
        return inQueryMode;
    }

    /**
    * Returns a Map of default values that are applied
    * to new objects that are inserted into the list.
    */
    public NSDictionary insertedObjectDefaultValues ()
    {
        return insertedObjectDefaultValues;
    }

    /**
    * Returns the keys that were declared when read from
    * an external resource file.
    */
    public NSArray localKeys ()
    {
        return localKeys;
    }

    /**
    * Sets whether this display group will select the
    * first object in the list after a fetch.
    */
    public boolean selectsFirstObjectAfterFetch ()
    {
        return selectsFirstObjectAfterFetch;
    }

    /**
    * Sets the default string matching format that
    * will be used by this display group.
    */
    public void setDefaultStringMatchFormat ( String aFormat )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the default string matching operator that
    * will be used by this display group.
    */
    public void setDefaultStringMatchOperator ( String anOperator )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets whether this display group will fetch objects
    * from its data source on load.
    */
    public void setFetchesOnLoad ( boolean willFetch )
    {
        fetchesOnLoad = willFetch;
    }

    /**
    * Sets whether this display group is in "query by example"
    * mode.  If true, all associations will bind to a special
    * "example" object.
    */
    public void setInQueryMode ( boolean isInQueryMode )
    {
        inQueryMode = isInQueryMode;
    }

    /**
    * Sets the mapping that contains the values that will
    * be applied to new objects inserted into the display group.
    */
    public void setInsertedObjectDefaultValues ( Map aMap )
    {
        insertedObjectDefaultValues = new NSDictionary( aMap );
    }

    /**
    * Sets the keys that are declared when instantiated from
    * an external resource file.
    */
    public void setLocalKeys ( List aKeyList )
    {
        localKeys = new NSArray( (Collection) aKeyList );
    }

    /**
    * Sets whether the first object in the list will be
    * selected after a fetch.
    */
    public void setSelectsFirstObjectAfterFetch (
        boolean selectsFirst )
    {
        selectsFirstObjectAfterFetch = selectsFirst;
    }

    /**
    * Sets the order of the keys by which this display group
    * will be ordered after a fetch or after a call to
    * updateDisplayedObjects().  The elements in the display
    * group will be sorted first by the first key, within
    * the first key, by the second key, and so on.
    */
    public void setSortOrderings ( List aList )
    {
        sortOrderings.removeAllObjects();

        Object o;
        Iterator it = aList.iterator();
        while ( it.hasNext() )
        {
            o = it.next();
            // handle the convenience of specifying just a key
            if ( ! ( o instanceof EOSortOrdering ) )
            {
                o = new EOSortOrdering(
                    o.toString(), EOSortOrdering.CompareAscending );
            }
            sortOrderings.add( o );
        }
    }

    /**
    * Sets whether only changed objects are refreshed (optimistic),
    * or whether all objects are refreshed (pessimistic, default).
    * By default, when the display group receives notification that
    * one of its objects has changed, updateDisplayedObjects is called.
    */
    public void setUsesOptimisticRefresh ( boolean isOptimistic )
    {
        usesOptimisticRefresh = isOptimistic;
    }

    /**
    * Sets whether changes made by associations are validated
    * immediately, or when changes are saved.
    */
    public void setValidatesChangesImmediately (
        boolean validatesImmediately )
    {
        validatesChangesImmediately = validatesImmediately;
    }

    /**
    * Returns a read-only List of sort orderings for this display group.
    */
    public NSArray sortOrderings ()
    {
        return sortOrderingsProxy;
    }

    /**
    * Returns whether this display group refreshes only
    * the changed objects or all objects on refresh.
    */
    public boolean usesOptimisticRefresh ()
    {
        return usesOptimisticRefresh;
    }

    /**
    * Returns whether this display group validates changes
    * immediately.  Otherwise, validation should occur when
    * changes are saved.  Default is the global default,
    * which is initially true.
    */
    public boolean validatesChangesImmediately ()
    {
        return validatesChangesImmediately;
    }


    // qualification

    /**
    * Returns a qualifier that will be applied all the objects
    * in this display group to determine which objects will
    * be displayed.
    */
    public EOQualifier qualifier ()
    {
        return qualifier;
    }

    /**
    * Returns a new qualifier built from the three query
    * value maps: greater than, equal to, and less than.
    */
    public EOQualifier qualifierFromQueryValues ()
    {
        //TODO: assemble qualifier from query values

        return new EOQualifier()
        {
            // use inner class until we actually implement one
            public EOQualifier qualifierWithBindings(
                Map aMap,
                boolean requireAll )
            {
                return null;
            }
            public Throwable
            validateKeysWithRootClassDescription( Class aClass )
            {
                return null;
            }
                        public boolean evaluateWithObject(Object o)
                        {
                          return false;
                        }
        };
    }

    /**
    * Calls qualifierFromQueryValues(), applies the result
    * to the data source, and calls fetch().
    */
    public void qualifyDataSource ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Calls qualifierFromQueryValues(), sets the qualifier
    * with setQualifier(), and calls updateDisplayedObjects().
    */
    public void qualifyDisplayGroup ()
    {
        setQualifier( qualifierFromQueryValues() );
        updateDisplayedObjects();
    }

    /**
    * Returns a Map containing the mappings of keys
    * to binding query values.
    */
    public NSDictionary queryBindingValues ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Returns a Map containing the mappings of keys
    * to operator values.
    */
    public NSDictionary queryOperatorValues ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the qualifier that will be used by
    * updateDisplayedObjects() to filter displayed objects.
    */
    public void setQualifier ( EOQualifier aQualifier )
    {
        qualifier = aQualifier;
    }

    /**
    * Sets the mapping that contains the mappings of keys
    * to binding values.
    */
    public void setQueryBindingValues ( Map aMap )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the mapping that contains the mappings of keys
    * to operator values.
    */
    public void setQueryOperatorValues ( Map aMap )
    {
        throw new RuntimeException( "Not implemented yet." );
    }



    // qualifier query values

    /**
    * Returns a Map containing the mappings of keys
    * to query values that will be used to test for equality.
    */
    public NSDictionary equalToQueryValues ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Returns a Map containing the mappings of keys
    * to query values that will be used to test for greater value.
    */
    public NSDictionary greaterThanQueryValues ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Returns a Map containing the mappings of keys
    * to query values that will be used to test for lesser value.
    */
    public NSDictionary lessThanQueryValues ()
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the Map that contains the mappings of keys
    * to query values that will be used to test for equality.
    */
    public void setEqualToQueryValues ( Map aMap )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the mapping that contains the mappings of keys
    * to query values that will be used to test for greater value.
    */
    public void setGreaterThanQueryValues ( Map aMap )
    {
        throw new RuntimeException( "Not implemented yet." );
    }

    /**
    * Sets the mapping that contains the mappings of keys
    * to query values that will be used to test for lesser value.
    */
    public void setLessThanQueryValues ( Map aMap )
    {
        throw new RuntimeException( "Not implemented yet." );
    }


    // interface to associations

    /**
    * Called by an association when it begins editing.
    */
    public void associationDidBeginEditing ( EOAssociation anAssociation )
    { // System.out.println( "EODisplayGroup.associationDidBeginEditing: " + anAssociation );        
        if ( dataSource != null )
        {
            if ( dataSource.editingContext() != null )
            {
                dataSource.editingContext().setMessageHandler( this );
            }
        }
        editingAssociation = anAssociation;
    }

    /**
    * Called by an association when it is finished editing.
    */
    public void associationDidEndEditing ( EOAssociation anAssociation )
    { // System.out.println( "EODisplayGroup.associationDidEndEditing: " + anAssociation );        
        editingAssociation = null;
    }

    /**
    * Called by associations to determine whether the contents
    * of any objects have been changed.  Returns true if the
    * contents have changed and not all observers have been
    * notified.
    */
    public boolean contentsChanged ()
    {
        return contentsChanged;
    }

    /**
    * Called by associations to determine whether the
    * selection has been changed.  Returns true if the
    * selection has changed and not all observers have
    * been notified.
    */
    public boolean selectionChanged ()
    {
        return selectionChanged;
    }

    /**
    * Called by an association when a user-specified value fails the association's
    * validation rules.  This implementation returns true, unless the delegate
    * prevents this.
    * @return True to allow the association to handle user notification,
    * otherwise return false to let the association know that the
    * display group notified the user.
    */
    public boolean associationFailedToValidateValue (
        EOAssociation anAssociation,
        String aValue,
        String aKey,
        Object anObject,
        String anErrorDescription )
    {
        Object result = notifyDelegate(
            "displayGroupShouldDisplayAlert",
            new Class[] { EODisplayGroup.class, String.class, String.class },
            new Object[] { this, "Validation Failed", anErrorDescription } );
        if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
        {
            return true;
        }
        return false;
    }

    /**
    * Called by an association to determine whether it should enable
    * a component that displayes a value for the specified key.
    * @return true if an object is selected, or if
    * the specified key is a query key.  Otherwise false.
    */
    public boolean enabledToSetSelectedObjectValueForKey ( String aKey )
    {
        if ( ( aKey != null ) && ( aKey.startsWith( "@" ) ) ) return true;
        return ( selectedObject() != null );
    }

    
    // association management

    /**
    * Returns the association that is currently being edited,
    * or null if no editing is taking place.
    */
    public EOAssociation editingAssociation ()
    {
        return editingAssociation;
    }

    /**
    * Asks the association currently editing to stop editing.
    * @returns true if editing was stopped, false if the
    * association refused to stop editing (if a modal dialog
    * is displayed or a value failed to validate).
    */
    public boolean endEditing ()
    {
        if ( editingAssociation == null ) return true;
        return editingAssociation.endEditing();
    }

    /**
    * Returns a read-only List of associations that are observing
    * this display group.
    */
    public NSArray observingAssociations ()
    {
        NSArray observers =
            EOObserverCenter.observersForObject( this );
        NSMutableArray result = new NSMutableArray();

        Object o;
        Enumeration e = observers.objectEnumerator();
        while ( e.hasMoreElements() )
        {
            o = e.nextElement();
            if ( o instanceof EOAssociation )
            {
                result.addObject( o );
            }
        }
        return result;
    }



    // object management

    /**
    * Returns a read-only List containing all objects managed by the display group.
    * This includes those objects not visible due to disqualification.
    */
    public NSArray allObjects ()
    { //System.out.println( "avoided allocation: allObjects" );
        return allObjectsProxy;
    }

    /**
    * Clears the current selection.
    * @return True is the selection was cleared,
    * False if the selection could not be cleared
    * @see #setSelectionIndexes
    */
    public boolean clearSelection ()
    {
        Object result = notifyDelegate(
            "displayGroupShouldChangeSelection",
            new Class[] { EODisplayGroup.class, List.class },
            new Object[] { this, new NSArray( selectedObjects ) } );
        if ( ( result != null ) && ( Boolean.FALSE.equals( result ) ) )
        {
            return false;
        }

        selectionChanged = true;
        willChange();

        selectedObjects.removeAllObjects();
        selectedIndexes.removeAllObjects();

        notifyDelegate(
            "displayGroupDidChangeSelection",
            new Class[] { EODisplayGroup.class },
            new Object[] { this } );
        notifyDelegate(
            "displayGroupDidChangeSelectedObjects",
            new Class[] { EODisplayGroup.class },
            new Object[] { this } );

        return true;
    }

    /**
    * Deletes the object at the specified index,
    * notifying the delegate before and after the operation,
    * and then updating the selection if needed.
    * @return True if delete was successful, false if the
    * object was not deleted.
    */
    public boolean deleteObjectAtIndex ( int anIndex )
    {
        Object target = displayedObjects.objectAtIndex( anIndex );

        Object result = notifyDelegate(
            "displayGroupShouldDeleteObject",
            new Class[] { EODisplayGroup.class, Object.class },
            new Object[] { this, target } );
        if ( ( result != null ) && ( Boolean.FALSE.equals( result ) ) )
        {
            return false;
        }

        contentsChanged = true;

        deleteObjectAtIndexNoNotify( anIndex );

        if ( dataSource != null )
        {
            dataSource.deleteObject( target );
        }

        notifyDelegate(
            "displayGroupDidDeleteObject",
            new Class[] { EODisplayGroup.class, Object.class },
            new Object[] { this, target } );

        return true;
    }

    private void deleteObjectAtIndexNoNotify ( int anIndex )
    {
        Object target = displayedObjects.objectAtIndex( anIndex );

        int i;

        // remove from selected objects if necessary
        i = indexOf( selectedObjects, target );
        if ( i != NSArray.NotFound )
        {
            selectionChanged = true;
            willChange(); // notify before removing
            selectedObjects.removeObjectAtIndex( i );
            selectedIndexes.remove( new Integer( i ) ); // comps by value
        }
        else // notify - no selection change needed
        {
            willChange();
        }

        // remove from all objects
        i = indexOf( allObjects, target );
        if ( i != NSArray.NotFound )
        {
            allObjects.removeObjectAtIndex( i );
        }
        else // otherwise should never happen
        {
//          throw new WotonomyException(
//              "Displayed object not found in allObjects" );
        }

        // remove from displayed objects
        displayedObjects.removeObjectAtIndex( anIndex );
    }

    /**
    * Deletes the currently selected objects.
    * This implementation calls deleteObjectAtIndex() for
    * each index in the selection list, immediately returning
    * false if any delete operation fails.
    * @return True if all selected objects were deleted,
    * false if any deletion failed.
    */
    public boolean deleteSelection ()
    {
        int i;
        boolean result = true;

        Enumeration e = new NSArray( selectedObjects ).objectEnumerator();
        while ( e.hasMoreElements() )
        {
            i = indexOf( displayedObjects, e.nextElement() );
            if ( i == NSArray.NotFound )
            {
                // should never happen
                throw new WotonomyException(
                    "Selected object not found in displayedObjects" );
            }
            result = result && deleteObjectAtIndex( i );
        }

        return result;
    }

    /**
    * Returns a read-only List of all objects in the display group
    * that are currently displayed by the associations.
    */
    public NSArray displayedObjects ()
    { // System.out.println( "avoided allocation: displayedObjects" );
        return displayedObjectsProxy;
    }

    /**
    * Requests a list of objects from the DataSource
    * and calls setObjectArray to populate the list.
    * More specifically, calls endEditing(), asks the
    * delegate, fetches the objects, notifies the delegate,
    * and populates the list.
    */
    public boolean fetch ()
    {
        endEditing();

        if ( dataSource == null )
        {
            return false;
        }

        Object result = notifyDelegate(
            "displayGroupShouldFetch",
            new Class[] { EODisplayGroup.class },
            new Object[] { this } );
        if ( ( result != null ) && ( Boolean.FALSE.equals( result ) ) )
        {
            return false;
        }

        NSNotificationCenter.defaultCenter().postNotification(
            DisplayGroupWillFetchNotification, this, new NSDictionary() );
        
        NSArray objectList = dataSource.fetchObjects();

        notifyDelegate(
            "displayGroupDidFetchObjects",
            new Class[] { EODisplayGroup.class, List.class },
            new Object[] { this, objectList } );
            
        if ( selectsFirstObjectAfterFetch ) 
        {
            //note: there's a good chance this logic ought to be in master-detail assoc:
            // we're doing this because changes in the master object trigger a refetch
            // on the child display group which annoyingly changes the selection.
            NSArray original = new NSArray( allObjects );
            setObjectArray( objectList );
            if ( displayedObjects.size() > 0
                && !original.equals( allObjects ) ) // don't change if no change
            {
                setSelectionIndexes( new NSArray( new Integer( 0 ) ) );
            }
        }
        else
        {
            setObjectArray( objectList );
        }

        return true;
   }

    /**
    * Creates a new object at the specified index.
    * Calls insertObjectAtIndex() with the result
    * from sending createObject() to the data source.
    * Presents a JOptionPane if the create fails, unless
    * the delegate implements displayGroupCreateObjectFailed.
    * @return the newly created object.
    */
    public Object insertNewObjectAtIndex ( int anIndex )
    {
        Object result = null;
        if ( dataSource != null )
        {
            result = dataSource.createObject();
        }
        if ( result != null )
        {
            if ( insertedObjectDefaultValues != null )
            {
                Duplicator.writePropertiesForObject(
                    insertedObjectDefaultValues, result );
            }
            insertObjectAtIndex( result, anIndex );
        }
        else // create failed
        {
            if ( delegate() != null )
            {
                NSSelector selector = new NSSelector(
                    "displayGroupCreateObjectFailed",
                    new Class[] { EODisplayGroup.class, EODataSource.class } );
                if ( selector.implementedByObject( delegate() ) )
                {
                    try
                    {
                        selector.invoke( delegate(), new Object[] { this, dataSource } );
                        return result;
                    }
                    catch ( Exception exc )
                    {
                        System.err.println( "Error notifying delegate: displayGroupCreateObjectFailed" );
                        exc.printStackTrace();
                    }
                }                    
            }
            
            // no delegate or delegate does not implement displayGroupCreateObjectFailed
            
            String message = "Data source could not create new object";
            Object delegateResult = notifyDelegate(
                "displayGroupShouldDisplayAlert",
                new Class[] { EODisplayGroup.class, String.class, String.class },
                new Object[] { this, "Error", message } );
            if ( ( delegateResult == null ) || ( Boolean.TRUE.equals( delegateResult ) ) )
            {
                JOptionPane.showMessageDialog( null, message );
            }
        }
        return result;
    }

    /**
    * Inserts the specified object into the list at
    * the specified index.
    */
    public void insertObjectAtIndex ( Object anObject, int anIndex )
    {
        Object result = notifyDelegate(
            "displayGroupShouldInsertObject",
            new Class[] { EODisplayGroup.class, Object.class, int.class },
            new Object[] { this, anObject, new Integer(anIndex) } );
        if ( ( result != null ) && ( Boolean.FALSE.equals( result ) ) )
        {
            return;
        }

        contentsChanged = true;
        updatedObjectIndex = anIndex;
        willChange();


        // add to all objects
        if ( anIndex == displayedObjects.size() )
        {
            allObjects.addObject( anObject );
        }
        else // insert before same object
        {
            Object target = displayedObjects.objectAtIndex( anIndex );
            int targetIndex = indexOf( allObjects, target );
            if ( targetIndex != NSArray.NotFound )
            {
                allObjects.insertObjectAtIndex( anObject, targetIndex );
            }
            else // should never happen
            {
                throw new WotonomyException(
                    "Could not find displayed object in all objects list: "
                    + target );
            }
        }

        // add to displayed objects
        displayedObjects.insertObjectAtIndex( anObject, anIndex );

        if ( dataSource != null )
        {
            if ( dataSource instanceof OrderedDataSource )
            {
                ((OrderedDataSource)dataSource).insertObjectAtIndex(
                    anObject, anIndex );
            }
            else
            {
                dataSource.insertObject( anObject );
            }
        }

        notifyDelegate(
            "displayGroupDidInsertObject",
            new Class[] { EODisplayGroup.class, Object.class },
            new Object[] { this, anObject } );
    }

    /**
    * Sets contentsChanged to true and notifies all observers.
    */
    public void redisplay ()
    {
        contentsChanged = true;
        willChange();
    }

    /**
    * Sets the selection to the next displayed object after the current
    * selection.  If the last object is selected, or if no object
    * is selected, then the first object becomes selected.
    * If multiple items are selected, the first selected item is
    * considered the selected item for the purposes of this method.
    * Does not call redisplay().
    * @return true if an object was selected.
    */
    public boolean selectNext ()
    {
        int count = displayedObjects.count();
        if ( count == 0 ) return false;
        if ( count == 1 )
        {
            selectObject( displayedObjects.objectAtIndex( 0 ) );
            return true;
        }

        int i = -1;
        Object selectedObject = selectedObject();
        if ( selectedObject != null )
        {
            i = indexOf( displayedObjects, selectedObject );
        }
        if ( i == NSArray.NotFound ) i = -1;

        // select next object
        i++;
        if ( i != displayedObjects.count() )
        {
            // set to next object
            selectedObject = displayedObjects.objectAtIndex( i );
        }
        else // out of range
        {
            // set to null
            selectedObject = displayedObjects.objectAtIndex( 0 );
        }

        return selectObject( selectedObject );
    }

    /**
    * Sets the selection to the specified object.
    * If the specified object is null or does not exist
    * in the list of displayed objects, the selection
    * will be cleared.
    * @return true if the object was selected.
    */
    public boolean selectObject ( Object anObject )
    {
        if ( ( anObject == null ) ||
             ( indexOf( displayedObjects, anObject )
               == NSArray.NotFound ) )
        {
            clearSelection();
            return false;
        }

        selectObjectsIdenticalTo( new NSArray( new Object[] { anObject } ) );
        return true;
    }

    /**
    * Sets the selection to the specified objects.
    * If the specified list is null or if none of the objects
    * in the list exist in the list of displayed objects, the
    * selection will be cleared.
    * @return true if all specified objects were selected.
    */
    public boolean selectObjectsIdenticalTo ( List anObjectList )
    {
        // optimization: check for resetting of selection
        if ( ( anObjectList != null ) && ( selectedObjects.size() == anObjectList.size() ) )
        {
            boolean identical = true;
            int size = selectedObjects.size();
            for ( int i = 0; ( i < size ) && identical; i++ )
            {
                // compare by reference
                if ( anObjectList.get( i ) != selectedObjects.get( i ) )
                {
                    identical = false;
                }
                else if ( displayedObjects.indexOfIdenticalObject(
                      anObjectList.get( i ) ) == NSArray.NotFound )
                {
                    identical = false;
                }
            }
            if ( identical )
            {
                return true;
            }
        }

        Object result = notifyDelegate(
            "displayGroupShouldChangeSelection",
            new Class[] { EODisplayGroup.class, List.class },
            new Object[] { this, anObjectList } );
        if ( ( result != null ) && ( Boolean.FALSE.equals( result ) ) )
        {
            // need to notify the calling component
            //   to revert back to the previous selection
            selectionChanged = true;
            willChange();
            return false;
        }

        int i;
        selectionChanged = true;
        willChange();
        Object o;
        selectedObjects.removeAllObjects();
        selectedIndexes.removeAllObjects();
        Iterator it = anObjectList.iterator();
        while ( it.hasNext() )
        {
            o = it.next();
            if ( ( i = displayedObjects.indexOfIdenticalObject( o ) )
                != NSArray.NotFound )
            {
                selectedObjects.addObject( o );
                selectedIndexes.addObject( new Integer( i ) );
            }
        }
        
        notifyDelegate(
            "displayGroupDidChangeSelection",
            new Class[] { EODisplayGroup.class },
            new Object[] { this } );
        notifyDelegate(
            "displayGroupDidChangeSelectedObjects",
            new Class[] { EODisplayGroup.class },
            new Object[] { this } );

        return true;
    }

    /**
    * Sets the selection to the previous displayed object before the current
    * selection.  If the first object is selected, or if no object
    * is selected, then the last object becomes selected.
    * If multiple items are selected, the first selected item is
    * considered the selected item for the purposes of this method.
    * Does not call redisplay().
    * @return true if an object was selected.
    */
    public boolean selectPrevious ()
    {
        int i = displayedObjects.count();
        if ( i == 0 ) return false;
        if ( i == 1 )
        {
            selectObject( displayedObjects.objectAtIndex( 0 ) );
            return true;
        }

        Object selectedObject = selectedObject();
        if ( selectedObject != null )
        {
            i = indexOf( displayedObjects, selectedObject );
        }
        if ( i == NSArray.NotFound ) i = displayedObjects.count();

        // select next object
        i--;
        if ( i < 0 )
        {
            // out of range - select last object
            i = displayedObjects.count() - 1;
        }

        return selectObject( displayedObjects.objectAtIndex( i ) );
    }

    /**
    * Returns the currently selected object, or null if
    * there is no selection.
    */
    public Object selectedObject ()
    {
        if ( selectedObjects.count() == 0 )
        {
            return null;
        }
        return selectedObjects.objectAtIndex( 0 );
    }

    /**
    * Returns a read-only List containing all selected objects, if any.
    * Returns an empty list if no objects are selected.
    */
    public NSArray selectedObjects ()
    { // System.out.println( "avoided allocation: selectedObjects" );
        return selectedObjectsProxy;
    }

    /**
    * Returns a read-only List containing the indexes of all selected
    * objects, if any.  The list contains instances of
    * java.lang.Number; call intValue() to retrieve the index.
    */
    public NSArray selectionIndexes ()
    {
//        return selectedIndexes;
        int i;
        NSMutableArray result = new NSMutableArray();
        Enumeration e = selectedObjects.objectEnumerator();
        while ( e.hasMoreElements() )
        {
            i = indexOf( displayedObjects, e.nextElement() );
            if ( i != NSArray.NotFound )
            {
                result.addObject( new Integer( i ) );
            }
            else
            {
              System.err.println( 
                  "Should never happen: selected objects not in displayed objects" );
              new RuntimeException().printStackTrace( System.err );
            }
        }
        return result;
    }

    /**
    * Sets the objects managed by this display group.
    * updateDisplayedObjects() is called to filter the
    * display objects.  The previous selection will be
    * maintained if possible.  The data source is not
    * notified.
    */
    public void setObjectArray ( List anObjectList )
    {
        if ( anObjectList == null ) anObjectList = new NSArray();

        Object result = notifyDelegate(
            "displayGroupDisplayArrayForObjects",
            new Class[] { EODisplayGroup.class, List.class },
            new Object[] { this, anObjectList } );
        if ( result != null )
        {
            anObjectList = (List) result;
        }

        contentsChanged = true;
        willChange();

        NSArray oldSelectedObjects = new NSArray( selectedObjects ); // copy

        // reset allObjects to new list
        allObjects.removeAllObjects();
        allObjects.addObjectsFromArray( anObjectList );

        // update the displayed object list
        updateDisplayedObjects();
        
        // restore the selection if possible
        selectObjectsIdenticalTo( oldSelectedObjects );
    }

    /**
    * Sets the currently selected object, or clears the
    * selection if the object is not found or is null.
    * Note: it's not clear how this differs from
    * selectObject in the spec.  It is recommended that
    * you call selectObject for now.
    */
    public void setSelectedObject ( Object anObject )
    {
        selectObject( anObject );
    }

    /**
    * Sets the current selection to the specified objects.
    * The previous selection is cleared, and any objects
    * in the display group that are in the specified list
    * are then selected.  If no items in the specified list
    * are found in the display group, then the selection is
    * effectively cleared.
    * Note: it's not clear how this differs from
    * selectObjectsIdenticalTo in the spec.
    * It is recommended that you call that method for now.
    */
    public void setSelectedObjects ( List aList )
    {
        selectObjectsIdenticalTo( aList );
    }

    /**
    * Sets the current selection to the objects at the
    * specified indexes.  Items in the list are assumed
    * to be instances of java.lang.Number.
    * The previous selection is cleared, and any objects
    * in the display group that are in the specified list
    * are then selected.  If no items in the specified list
    * are found in the display group, then the selection is
    * effectively cleared.
    */
    public boolean setSelectionIndexes ( List aList )
    {
        Object o;
        int index;
        NSMutableArray objects = new NSMutableArray();
        Iterator it = aList.iterator();
        while ( it.hasNext() )
        {
            index = ((Number)it.next()).intValue();
            if ( index < displayedObjects.count() )
            {
                o = displayedObjects.objectAtIndex( index );
                if ( o != null )
                {
                    objects.add( o );
                }
            }
        }
        return selectObjectsIdenticalTo( objects );
    }

    /**
    * Applies the qualifier to all objects and sorts
    * the results to update the list of displayed objects.
    * Observing associations are notified to reflect the changes.
    */
    public void updateDisplayedObjects ()
    {
        contentsChanged = true;
        updatedObjectIndex = -1;
        willChange();

        displayedObjects.removeAllObjects();

        displayedObjects.addObjectsFromArray( allObjects );

        // apply qualifier, if any
        if ( qualifier() != null )
        {
            EOQualifier.filterArrayWithQualifier(
                displayedObjects, qualifier() );
        }

        // apply sort orderings, if any
        NSArray orderings = sortOrderings();
        if ( orderings != null )
        {
            if ( orderings.count() > 0 )
            {
                selectionChanged = true;
                willChange();
                EOSortOrdering.sortArrayUsingKeyOrderArray(
                    displayedObjects, orderings );
            }
        }

          // make sure the selectedObjects is a subset of displayedObjects
          int i;
          Object o;
          Iterator it = new LinkedList( selectedObjects ).iterator();
          boolean removeflag = false;
          selectedIndexes.removeAllObjects();
          while ( it.hasNext() )
          {
              o = it.next();
              if ( ( i = displayedObjects.indexOfIdenticalObject( o ) )
                      == NSArray.NotFound )
              {
                  selectedObjects.removeIdenticalObject( o );
                  removeflag = true;
              }
              else
              {
                  selectedIndexes.addObject( new Integer( i ) );
              }
          }

          //Note: it is important to put the
          //selectionChanged = true line below remove.
          if (removeflag)
          {
            selectionChanged = true;
            willChange();

            notifyDelegate(
                "displayGroupDidChangeSelection",
                new Class[] { EODisplayGroup.class },
                new Object[] { this } );
            notifyDelegate(
                "displayGroupDidChangeSelectedObjects",
                new Class[] { EODisplayGroup.class },
                new Object[] { this } );
          }
    }

    /**
    * Returns the index of the changed object.  If more than
    * one object has changed, -1 is returned.
    */
    public int updatedObjectIndex ()
    {
        return updatedObjectIndex;
    }

    // getting and setting values in objects

    /**
    * Returns a value on the selected object for the specified key.
    */
    public Object selectedObjectValueForKey ( String aKey )
    {
        Object selectedObject = selectedObject();
        if ( selectedObject == null ) return null;
        return valueForObject( selectedObject, aKey );
    }

    /**
    * Sets the specified value for the specified key on
    * all selected objects.
    */
    public boolean setSelectedObjectValue (
        Object aValue, String aKey )
    {
        Object selectedObject = selectedObject();
        if ( selectedObject == null ) return false;
        return setValueForObject( aValue, selectedObject, aKey );
    }

    /**
    * Sets the specified value for the specified key on
    * the specified object.  Validations may be triggered,
    * and error dialogs may appear to the user.
    * @return True if the value was set successfully,
    * false if the value could not be set and the update
    * operation should not continue.
    */
    public boolean setValueForObject (
        Object aValue, Object anObject, String aKey )
    {
        // notify object's observers:
        //   this includes us, and will notify our observers
        EOObserverCenter.notifyObserversObjectWillChange( anObject );

        //TODO: if key is null, need to remove old object
        // and add new object instead of simply replacing it.

        try
        {
            if ( anObject instanceof EOKeyValueCoding )
            {
                ((EOKeyValueCoding)anObject).takeValueForKey( aValue, aKey );
            }
            else
            {
                EOKeyValueCodingSupport.takeValueForKey( anObject, aValue, aKey );
            }
        }
        catch ( RuntimeException exc )
        {
            Object result = notifyDelegate(
                "displayGroupShouldDisplayAlert",
                new Class[] { EODisplayGroup.class, String.class, String.class },
                new Object[] { this, "Error", exc.getMessage() } );
            if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
            {
                throw exc;
            }
            return false;
        }

        notifyDelegate(
            "displayGroupDidSetValueForObject",
            new Class[] { EODisplayGroup.class, Object.class, Object.class, String.class },
            new Object[] { this, aValue, anObject, aKey } );

        return true;
    }

    /**
    * Calls setValueForObject() for the object at
    * the specified index.
    */
    public boolean setValueForObjectAtIndex (
        Object aValue, int anIndex, String aKey )
    {
        return setValueForObject(
            aValue, displayedObjects.objectAtIndex( anIndex ), aKey );
    }

    /**
    * Returns the value for the specified key on the specified object.
    */
    public Object valueForObject ( Object anObject, String aKey )
    {
        // empty string is considered the identity property
        if ( aKey == null ) return anObject;
        if ( aKey.equals( "" ) ) return anObject;

        try
        {
            if ( anObject instanceof EOKeyValueCoding )
            {
                return ((EOKeyValueCoding)anObject).valueForKey( aKey );
            }
            else
            {
                return EOKeyValueCodingSupport.valueForKey( anObject, aKey );
            }
        }
        catch ( RuntimeException exc )
        {
            Object result = notifyDelegate(
                "displayGroupShouldDisplayAlert",
                new Class[] { EODisplayGroup.class, String.class, String.class },
                new Object[] { this, "Error", exc.getMessage() } );
            if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
            {
                throw exc;
            }
            return null;
        }
    }

    /**
    * Calls valueForObject() for the object at the specified index.
    */
    public Object valueForObjectAtIndex ( int anIndex, String aKey )
    {
        Object o = displayedObjects.objectAtIndex( anIndex );
        return valueForObject( o, aKey );
    }

    /**
    * Prints out the list of displayed objects.
    */
    public String toString()
    {
        return displayedObjects.toString();
    }


    /**
    * Handles notifications from the data source's editing context,
    * looking for InvalidatedAllObjectsInStoreNotification and
    * ObjectsChangedInEditingContextNotification, refetching in
    * the former case and updating displayed objects in the latter.
    * Note: This method is not in the public specification.
    */
    public void objectsInvalidatedInEditingContext( NSNotification aNotification )
    {
        if ( EOObjectStore.InvalidatedAllObjectsInStoreNotification
            .equals( aNotification.name() ) )
        {
            Object result = notifyDelegate(
                "displayGroupShouldRefetch",
                new Class[] { EODisplayGroup.class, NSNotification.class },
                new Object[] { this, aNotification } );
            if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
            {
                fetch();
            }
        }
        else
        if ( EOEditingContext.ObjectsChangedInEditingContextNotification
            .equals( aNotification.name() ) )
        {
            Object result = notifyDelegate(
                "displayGroupShouldRedisplay",
                new Class[] { EODisplayGroup.class, NSNotification.class },
                new Object[] { this, aNotification } );
            if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
            {
                int index;
                Enumeration e;
                boolean didChange = false;
                NSDictionary userInfo = aNotification.userInfo();
    
                // inserts are ignored
    
                // mark updated objects as updated
                NSArray updates = (NSArray) userInfo.objectForKey(
                    EOObjectStore.UpdatedKey );
                e = updates.objectEnumerator();
                while ( e.hasMoreElements() )
                {
                    index = indexOf( displayedObjects, e.nextElement() );
                    if ( index != NSArray.NotFound )
                    {
                        //System.out.println( "EODisplayGroup: updated: " + index );
                        if ( ! didChange )
                        {
                            didChange = true;
                            contentsChanged = true;
                            willChange();
                            updatedObjectIndex = index;
                        }
                        else
                        {
                            updatedObjectIndex = -1;
                        }
                    }
                }
    
                // treat invalidated objects as updated
                NSArray invalidates = (NSArray) userInfo.objectForKey(
                    EOObjectStore.InvalidatedKey );
                e = invalidates.objectEnumerator();
                while ( e.hasMoreElements() )
                {
                    index = indexOf( displayedObjects, e.nextElement() );
                    if ( index != NSArray.NotFound )
                    {
                        //System.out.println( "EODisplayGroup: invalidated: " + index );
                        if ( ! didChange )
                        {
                            didChange = true;
                            contentsChanged = true;
                            willChange();
                            updatedObjectIndex = index;
                        }
                        else
                        {
                            updatedObjectIndex = -1;
                        }
                    }
                }
    
                // remove deletes from display group if they exist
                NSArray deletes = (NSArray) userInfo.objectForKey(
                    EOObjectStore.DeletedKey );
                e = deletes.objectEnumerator();
                Object o;
                while ( e.hasMoreElements() )
                {
                    o = e.nextElement();
                    index = indexOf( displayedObjects, o );
                    if ( index != NSArray.NotFound )
                    {
                        //System.out.println( "EODisplayGroup: deleted: " + o );
                        deleteObjectAtIndexNoNotify( index );
                    }
                }
                
                if ( !usesOptimisticRefresh() )
                {
                    updateDisplayedObjects();
                }
            }
        }

    }

    // static methods

    /**
    * Specifies the default behavior for whether changes
    * should be validated immediately for all display groups.
    */
    public static boolean
        globalDefaultForValidatesChangesImmediately ()
    {
        return globalDefaultForValidatesChangesImmediately;
    }

    /**
    * Specifies the default string matching format for all
    * display groups.
    */
    public static String globalDefaultStringMatchFormat ()
    {
        return globalDefaultStringMatchFormat;
    }

    /**
    * Specifies the default string matching operator for all
    * display groups.
    */
    public static String globalDefaultStringMatchOperator ()
    {
        return globalDefaultStringMatchOperator;
    }

    /**
    * Sets the default behavior for validating changes
    * for all display groups.
    */
    public static void
    setGlobalDefaultForValidatesChangesImmediately (
        boolean validatesImmediately )
    {
        globalDefaultForValidatesChangesImmediately =
            validatesImmediately;
    }

    /**
    * Sets the default string matching format that
    * will be used by all display groups.
    */
    public static void
    setGlobalDefaultStringMatchFormat ( String aFormat )
    {
        globalDefaultStringMatchFormat = aFormat;
    }

    /**
    * Sets the default string matching operator that
    * will be used by all display groups.
    */
    public static void
    setGlobalDefaultStringMatchOperator ( String anOperator )
    {
        globalDefaultStringMatchOperator = anOperator;
    }

    /**
    * Needed because we don't inherit from NSObject.
    * Calls EOObserverCenter.notifyObserversObjectWillChange.
    */
    protected void willChange()
    {
        EOObserverCenter.notifyObserversObjectWillChange( this );
    }

    /**
    * Called by LastGroupObserver to clear flags.
    */
    protected void processRecentChanges()
    {
        contentsChanged = false;
        selectionChanged = false;
    }

    /**
    * Returns the index of the specified object in the
    * specified NSArray, comparing by value or by reference
    * as determined by the private instance variable
    * compareByReference.  If not found, returns NSArray.NotFound.
    */
    private int indexOf( NSArray anArray, Object anObject )
    {
        if ( compareByReference )
        {
            return anArray.indexOfIdenticalObject( anObject );
        }
        else
        {
            return anArray.indexOf( anObject );
        }
    }

    // interface EOObserving

    /**
    * Receives notifications of changes from objects that
    * are managed by this display group.  This implementation
    * sets updatedObjectIndex and contentsChanged as appropriate.
    */
    public void objectWillChange(Object anObject)
    {
        int index = indexOf( displayedObjects, anObject );
        if ( index != NSArray.NotFound )
        {
            updatedObjectIndex = index;
            contentsChanged = true;
            willChange();
        }
    }

    // interface EOEditingContext.Editor
    
    /**
    * Called before the editing context begins to save changes.
    * This implementation calls endEditing().
    */
    public void editingContextWillSaveChanges( 
        EOEditingContext anEditingContext )
    {
        endEditing();
    }

    /**
    * Called to determine whether this editor has changes
    * that have not been committed to the object in the context.
    */
    public boolean editorHasChangesForEditingContext(
        EOEditingContext anEditingContext )
    {
        return ( editingAssociation() != null );
    }

    // interface EOEditingContext.MessageHandler
    
    /**
    * Called to display a message for an error that occurred
    * in the specified editing context.  If the delegate allows,
    * this implementation presents an informational JOptionPane.
    * Override to customize.
    */
    public void editingContextPresentErrorMessage( 
        EOEditingContext anEditingContext,
        String aMessage )
    {
        Object result = notifyDelegate(
            "displayGroupShouldDisplayAlert",
            new Class[] { EODisplayGroup.class, String.class, String.class },
            new Object[] { this, "Error", aMessage } );
        if ( ( result == null ) || ( Boolean.TRUE.equals( result ) ) )
        {
            JOptionPane.showMessageDialog( null, aMessage );
        }
    }

    /**
    * Called by the specified object store to determine whether
    * fetching should continue, where count is the current count
    * and limit is the limit as specified by the fetch specification.
    * This implementation presents an JOptionPane allowing the user
    * to specify whether to continue.  Override to customize.
    */
    public boolean editingContextShouldContinueFetching(
        EOEditingContext anEditingContext,
        int count,
        int limit,
        EOObjectStore anObjectStore )
    {
        return ( JOptionPane.showConfirmDialog( null, 
            "Fetch limit reached: do you wish to continue?", 
            "Continue?", 
            JOptionPane.YES_NO_OPTION ) == JOptionPane.YES_OPTION );
    }

    /**
     * Sends the specified message to the delegate.
     * Returns the return value of the method,
     * or null if no return value or no delegate
     * or no implementation.
     */
    private Object notifyDelegate( 
        String aMethodName, Class[] types, Object[] params )
    {
        try
        {
            Object delegate = delegate();
            if ( delegate == null ) return null;
            return NSSelector.invoke( 
                aMethodName, types, delegate, params );
        }
        catch ( NoSuchMethodException e )
        {
            // ignore: not implemented
        }
        catch ( Exception exc )
        {
            // log to standard error
            System.err.println( 
                "Error while messaging delegate: " + 
                    delegate + " : " + aMethodName );
            exc.printStackTrace();
        }
        
        return null;
    }
    
    /**
    * DisplayGroups can delegate important decisions to a Delegate.  
    * Note that DisplayGroup doesn't require its delegates to implement
    * this interface: rather, this interface defines the methods that
    * DisplayGroup will attempt to invoke dynamically on its delegate.
    * The delegate may choose to implement only a subset of the methods
    * on the interface.
    */
    public interface Delegate
    {
        /**
        * Called when the specified data source fails
        * to create an object for the specified display group.
        */
        void displayGroupCreateObjectFailed (
            EODisplayGroup aDisplayGroup,
            EODataSource aDataSource );

        /**
        * Called after the specified display group's
        * data source is changed.
        */
        void displayGroupDidChangeDataSource (
            EODisplayGroup aDisplayGroup );

        /**
        * Called after a change occurs in the specified 
        * display group's selected objects.
        */
        void displayGroupDidChangeSelectedObjects (
            EODisplayGroup aDisplayGroup );

        /**
        * Called after the specified display group's
        * selection has changed.
        */
        void displayGroupDidChangeSelection (
            EODisplayGroup aDisplayGroup );

        /**
        * Called after the specified display group has
        * deleted the specified object.
        */
        void displayGroupDidDeleteObject (
            EODisplayGroup aDisplayGroup,
            Object anObject );

        /**
        * Called after the specified display group
        * has fetched the specified object list.
        */
        void displayGroupDidFetchObjects (
            EODisplayGroup aDisplayGroup,
            List anObjectList );

        /**
        * Called after the specified display group
        * has inserted the specified object into
        * its internal object list.
        */
        void displayGroupDidInsertObject (
            EODisplayGroup aDisplayGroup,
            Object anObject );

        /**
        * Called after the specified display group
        * has set the specified value for the specified
        * object and key.
        */
        void displayGroupDidSetValueForObject (
            EODisplayGroup aDisplayGroup,
            Object aValue,
            Object anObject,
            String aKey );

        /**
        * Called by the specified display group to
        * determine what objects should be displayed
        * for the objects in the specified list.
        * @return An NSArray containing the objects
        * to be displayed for the objects in the
        * specified list.
        */
        NSArray displayGroupDisplayArrayForObjects (
            EODisplayGroup aDisplayGroup,
            List aList );

        /**
        * Called by the specified display group before
        * it attempts to change the selection.
        * @return True to allow the selection to change,
        * false otherwise.
        */
        boolean displayGroupShouldChangeSelection (
            EODisplayGroup aDisplayGroup,
            List aSelectionList );

        /**
        * Called by the specified display group before
        * it attempts to delete the specified object.
        * @return True to allow the object to be deleted
        * false to prevent the deletion.
        */
        boolean displayGroupShouldDeleteObject (
            EODisplayGroup aDisplayGroup,
            Object anObject );

        /**
        * Called by the specified display group before
        * it attempts display the specified alert to
        * the user.
        * @return True to allow the message to be
        * displayed, false if you want to handle the
        * alert yourself and suppress the display group's
        * notification.
        */
        boolean displayGroupShouldDisplayAlert (
            EODisplayGroup aDisplayGroup,
            String aTitle,
            String aMessage );

        /**
        * Called by the specified display group before
        * it attempts fetch objects.
        * @return True to allow the fetch to take place,
        * false to prevent the fetch.
        */
        boolean displayGroupShouldFetch (
            EODisplayGroup aDisplayGroup );

        /**
        * Called by the specified display group before
        * it attempts to insert the specified object.
        * @return True to allow the object to be inserted
        * false to prevent the insertion.
        */
        boolean displayGroupShouldInsertObject (
            EODisplayGroup aDisplayGroup,
            Object anObject,
            int anIndex );

        /**
        * Called by the specified display group when
        * it receives the specified 
        * ObjectsChangedInEditingContextNotification.
        * @return True to allow the display group to
        * update the display (recommended), false
        * to prevent the update.
        */
        boolean displayGroupShouldRedisplay (
            EODisplayGroup aDisplayGroup,
            NSNotification aNotification );

        /**
        * Called by the specified display group when
        * it receives the specified 
        * InvalidatedAllObjectsInStoreNotification.
        * @return True to allow the display group to
        * refetch (recommended), false to prevent the 
        * refetch.
        */
        boolean displayGroupShouldRefetch (
            EODisplayGroup aDisplayGroup,
            NSNotification aNotification );

    }

}

    /**
    * A private class that will serve to clear the contentsChanged
    * and selectionChanged flags after all Associations have been
    * notified.
    */
    class LastGroupObserver extends EODelayedObserver
    {
        Reference ref;

        public LastGroupObserver( EODisplayGroup aDisplayGroup )
        {
            ref = new WeakReference( aDisplayGroup );
        }

        /**
        * We want to be informed last, after all Associations
        * have been notified to changes in the DisplayGroup.
        */
        public int priority()
        {
            return ObserverPrioritySixth;
        }

        /**
        * After all Associations have been notified,
        * clear the contentsChanged and selectionChanged flags.
        */
        public void subjectChanged ()
        {
            EODisplayGroup group = (EODisplayGroup) ref.get();
            if ( group != null )
            {
                group.processRecentChanges();
            }
        }
    }

/*
 * $Log$
 * Revision 1.2  2006/02/18 23:14:35  cgruber
 * Update imports and maven dependencies.
 *
 * Revision 1.1  2006/02/16 13:22:22  cgruber
 * Check in all sources in eclipse-friendly maven-enabled packages.
 *
 * Revision 1.51  2004/01/28 18:35:40  mpowers
 * Slight optimization: only comparing list in fetch if we have to.
 *
 * Revision 1.50  2004/01/27 20:42:30  mpowers
 * No longer reselecting first after fetch if contents are identical.
 *
 * Revision 1.49  2003/12/18 11:37:45  mpowers
 * Now calling qualifier internally.
 *
 * Revision 1.48  2003/08/06 23:07:52  chochos
 * general code cleanup (mostly, removing unused imports)
 *
 * Revision 1.47  2003/01/18 23:30:42  mpowers
 * WODisplayGroup now compiles.
 *
 * Revision 1.46  2002/10/24 21:15:36  mpowers
 * New implementations of NSArray and subclasses.
 *
 * Revision 1.45  2002/10/24 18:20:20  mpowers
 * Because NSArray is read-only, we are returning our internal representations
 * to callers of allObjects(), displayedObjects(), and selectedObjects().
 *
 * Revision 1.44  2002/08/06 18:20:25  mpowers
 * Now posting DisplayGroupWillFetch notifications before fetch.
 * Implemented support for usesOptimisticRefresh.
 * No longer supporting inserted/updated/deleted lists: not part of spec.
 *
 * Revision 1.43  2002/05/17 15:01:49  mpowers
 * Implemented dynamic lookup of delegate methods so delegates no longer
 * need to implement the DisplayGroup.Delegate interface.
 *
 * Revision 1.42  2002/03/26 21:46:06  mpowers
 * Contributing EditingContext as a java-friendly convenience.
 *
 * Revision 1.41  2002/03/11 03:17:56  mpowers
 * Provided control point for coalesced changes.
 *
 * Revision 1.40  2002/03/05 23:18:28  mpowers
 * Added documentation.
 * Added isSelectionPaintedImmediate and isSelectionTracking attributes
 * to TableAssociation.
 * Added getTableAssociation to TableColumnAssociation.
 *
 * Revision 1.39  2002/02/19 22:26:04  mpowers
 * Implemented EOEditingContext.MessageHandler support.
 *
 * Revision 1.38  2002/02/19 16:37:38  mpowers
 * Implemented support for EOEditingContext.Editor
 *
 * Revision 1.37  2001/12/11 22:17:48  mpowers
 * Now properly handling exceptions in valueForObject.
 * No longer trying to retain selection based only on index.
 *
 * Revision 1.36  2001/11/08 21:42:00  mpowers
 * Now we know what to do with shouldRefetch and shouldRedisplay.
 *
 * Revision 1.35  2001/11/04 18:26:58  mpowers
 * Fixed bug where exceptions were not properly reported when updating
 * a value and the display group did not have a delegate.
 *
 * Revision 1.34  2001/11/02 20:59:36  mpowers
 * Now correctly ensuring selected objects are a subset of displayed objects.
 *
 * Revision 1.33  2001/10/30 22:56:45  mpowers
 * Added support for EOQualifier.
 *
 * Revision 1.32  2001/10/23 22:27:53  mpowers
 * Now running at ObserverPrioritySixth.
 *
 * Revision 1.31  2001/10/23 18:45:05  mpowers
 * Rolling back changes.
 *
 * Revision 1.28  2001/08/22 19:23:41  mpowers
 * No longer asserting objects in all objects list.
 *
 * Revision 1.27  2001/07/30 16:17:01  mpowers
 * Minor code cleanup.
 *
 * Revision 1.26  2001/07/10 22:49:07  mpowers
 * Fixed bug in optimization for selectObjectsIdenticalTo (found by Dongzhi).
 *
 * Revision 1.25  2001/06/19 15:40:21  mpowers
 * Now only changing the selection if the new selection is different
 * from the old.
 *
 * Revision 1.24  2001/05/24 17:36:15  mpowers
 * Fixed problem with selectedObjectsIdenticalTo: it was using compare
 * by value instead of compare by reference.
 *
 * Revision 1.23  2001/05/18 21:09:19  mpowers
 * Now throwing exceptions if the delegate cannot handle error from update.
 *
 * Revision 1.22  2001/05/14 15:26:12  mpowers
 * Now checking for null delegate before and after selection change.
 *
 * Revision 1.21  2001/05/08 18:47:34  mpowers
 * Minor fixes for d3.
 *
 * Revision 1.20  2001/04/29 22:02:45  mpowers
 * Work on id transposing between editing contexts.
 *
 * Revision 1.19  2001/04/13 16:38:09  mpowers
 * Alpha3 release.
 *
 * Revision 1.18  2001/04/03 20:36:01  mpowers
 * Fixed refaulting/reverting/invalidating to be self-consistent.
 *
 * Revision 1.17  2001/03/29 03:31:13  mpowers
 * No longer using Introspector.
 *
 * Revision 1.16  2001/02/27 03:32:18  mpowers
 * Implemented default values for new objects.
 *
 * Revision 1.15  2001/02/27 02:11:17  mpowers
 * Now throwing exception when cloning fails.
 * Removed debugging printlns.
 *
 * Revision 1.14  2001/02/26 22:41:51  mpowers
 * Implemented null placeholder classes.
 * Duplicator now uses NSNull.
 * No longer catching base exception class.
 *
 * Revision 1.13  2001/02/26 15:53:22  mpowers
 * Fine-tuning notification firing.
 * Child display groups now update properly after parent save or invalidate.
 *
 * Revision 1.12  2001/02/22 20:55:06  mpowers
 * Implemented notification handling.
 *
 * Revision 1.11  2001/02/21 20:40:42  mpowers
 * setObjectArray now falls back to index when trying to retain the
 * same selection.
 *
 * Revision 1.10  2001/02/20 16:38:55  mpowers
 * MasterDetailAssociations now observe their controlled display group's
 * objects for changes to that the parent object will be marked as updated.
 * Before, only inserts and deletes to an object's items are registered.
 * Also, moved ObservableArray to package access.
 *
 * Revision 1.9  2001/02/17 17:23:49  mpowers
 * More changes to support compiling with jdk1.1 collections.
 *
 * Revision 1.8  2001/02/17 16:52:05  mpowers
 * Changes in imports to support building with jdk1.1 collections.
 *
 * Revision 1.7  2001/01/24 16:35:37  mpowers
 * Improved documentation on TreeAssociation.
 * SortOrderings are now inherited from parent nodes.
 * Updates after sorting are still lost on TreeController.
 *
 * Revision 1.6  2001/01/24 14:23:05  mpowers
 * Added support for OrderedDataSource.
 *
 * Revision 1.5  2001/01/12 17:21:37  mpowers
 * Implicit creation of EOSortOrderings now happens in setSortOrderings.
 *
 * Revision 1.4  2001/01/11 20:34:26  mpowers
 * Implemented EOSortOrdering and added support in framework.
 * Added header-click to sort table columns.
 *
 * Revision 1.3  2001/01/10 22:49:44  mpowers
 * Implemented similarly named selection methods instead of
 * throwing exceptions.
 *
 * Revision 1.2  2001/01/09 20:12:52  mpowers
 * Moved inner classes to package access.
 *
 * Revision 1.1.1.1  2000/12/21 15:48:20  mpowers
 * Contributing wotonomy.
 *
 * Revision 1.21  2000/12/20 16:25:39  michael
 * Added log to all files.
 *
 * Revision 1.20  2000/12/15 15:04:42  michael
 * Added doc.
 *
 * Revision 1.19  2000/12/11 13:32:48  michael
 * Finish the much better TreeAssociation implementation.
 * TreeAssociation now has no gui dependencies.
 *
 * Revision 1.18  2000/12/05 17:41:46  michael
 * Broadcasts selection change after delegate refuses selection change
 * so the initiating association gets refreshed.
 *
 */