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
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
|
/*************************************************************************
*
* $RCSfile: unodatbr.cxx,v $
*
* $Revision: 1.50 $
*
* last change: $Author: fs $ $Date: 2001-04-03 14:15:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _SVX_GRIDCTRL_HXX
#include <svx/gridctrl.hxx>
#endif
#ifndef _SBA_UNODATBR_HXX_
#include "unodatbr.hxx"
#endif
#ifndef _SBA_GRID_HXX
#include "sbagrid.hxx"
#endif
#ifndef _SVTREEBOX_HXX
#include <svtools/svtreebx.hxx>
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/unohlp.hxx>
#endif
#ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
#include <com/sun/star/form/XLoadable.hpp>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SV_MULTISEL_HXX //autogen
#include <tools/multisel.hxx>
#endif
#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#endif
#ifndef _URLOBJ_HXX //autogen
#include <tools/urlobj.hxx>
#endif
#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif
#ifndef _SV_WAITOBJ_HXX
#include <vcl/waitobj.hxx>
#endif
#ifndef _SV_SVAPP_HXX //autogen
#include <vcl/svapp.hxx>
#endif
#ifndef _SFXAPP_HXX //autogen
#include <sfx2/app.hxx>
#endif
#ifndef _SV_WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
#include <com/sun/star/sdb/CommandType.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
#include <com/sun/star/sdbc/DataType.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XGRIDCOLUMNFACTORY_HPP_
#include <com/sun/star/form/XGridColumnFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XFORM_HPP_
#include <com/sun/star/form/XForm.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
#include <com/sun/star/awt/TextAlign.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
#include <com/sun/star/sdbcx/XDrop.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
#include <com/sun/star/sdb/XCompletedConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
#include <com/sun/star/container/XNameContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
#include <com/sun/star/sdbc/XDataSource.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XQUERYDEFINITIONSSUPPLIER_HPP_
#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_XEXECUTABLEDIALOG_HPP_
#include <com/sun/star/ui/XExecutableDialog.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
#endif
#ifndef _SVX_ALGITEM_HXX //autogen
#include <svx/algitem.hxx>
#endif
#ifndef _COM_SUN_STAR_SDB_XRESULTSETACCESS_HPP_
#include <com/sun/star/sdb/XResultSetAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
#include <com/sun/star/sdbc/SQLWarning.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
#include <com/sun/star/sdb/SQLContext.hpp>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef DBAUI_DBTREEMODEL_HXX
#include "dbtreemodel.hxx"
#endif
#ifndef DBACCESS_UI_DBTREEVIEW_HXX
#include "dbtreeview.hxx"
#endif
#ifndef _SVLBOXITM_HXX
#include <svtools/svlbitm.hxx>
#endif
#ifndef _SV_SPLIT_HXX
#include <vcl/split.hxx>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _DBU_RESOURCE_HRC_
#include "dbu_resource.hrc"
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef DBACCESS_SBA_GRID_HRC
#include "sbagrid.hrc"
#endif
#ifndef DBACCESS_UI_BROWSER_ID_HXX
#include "browserids.hxx"
#endif
#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif
#ifndef _VCL_STDTEXT_HXX
#include <vcl/stdtext.hxx>
#endif
#ifndef DBAUI_DBTREELISTBOX_HXX
#include "dbtreelistbox.hxx"
#endif
#ifndef _DBA_DBACCESS_HELPID_HRC_
#include "dbaccess_helpid.hrc"
#endif
#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
#include <com/sun/star/util/XFlushable.hpp>
#endif
#ifndef _DBAUI_QUERYDESIGNACCESS_HXX_
#include "querydesignaccess.hxx"
#endif
#ifndef _DBAUI_LISTVIEWITEMS_HXX_
#include "listviewitems.hxx"
#endif
#ifndef _CPPUHELPER_IMPLBASE2_HXX_
#include <cppuhelper/implbase2.hxx>
#endif
#ifndef DBAUI_TOKENWRITER_HXX
#include "TokenWriter.hxx"
#endif
#ifndef DBAUI_DBEXCHANGE_HXX
#include "dbexchange.hxx"
#endif
#ifndef DBAUI_WIZ_COPYTABLEDIALOG_HXX
#include "WCopyTable.hxx"
#endif
#ifndef DBAUI_WIZ_EXTENDPAGES_HXX
#include "WExtendPages.hxx"
#endif
#ifndef DBAUI_WIZ_NAMEMATCHING_HXX
#include "WNameMatch.hxx"
#endif
#ifndef DBAUI_WIZ_COLUMNSELECT_HXX
#include "WColumnSelect.hxx"
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif
#ifndef DBAUI_WIZARD_CPAGE_HXX
#include "WCPage.hxx"
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef DBAUI_RTFREADER_HXX
#include "RtfReader.hxx"
#endif
#ifndef DBAUI_HTMLREADER_HXX
#include "HtmlReader.hxx"
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef DBAUI_DLGSAVE_HXX
#include "dlgsave.hxx"
#endif
#ifndef _SOT_STORAGE_HXX
#include <sot/storage.hxx>
#endif
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::datatransfer;
using namespace ::dbtools;
// .........................................................................
namespace dbaui
{
// .........................................................................
//==================================================================
//= SbaTableQueryBrowser
//==================================================================
// -------------------------------------------------------------------------
extern "C" void SAL_CALL createRegistryInfo_OBrowser()
{
static OMultiInstanceAutoRegistration< SbaTableQueryBrowser > aAutoRegistration;
}
// -------------------------------------------------------------------------
void SafeAddPropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
{
Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
if (xInfo->hasPropertyByName(rPropName))
xSet->addPropertyChangeListener(rPropName, pListener);
}
// -------------------------------------------------------------------------
void SafeRemovePropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
{
Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
if (xInfo->hasPropertyByName(rPropName))
xSet->removePropertyChangeListener(rPropName, pListener);
}
//-------------------------------------------------------------------------
::rtl::OUString SAL_CALL SbaTableQueryBrowser::getImplementationName() throw(RuntimeException)
{
return getImplementationName_Static();
}
//-------------------------------------------------------------------------
::comphelper::StringSequence SAL_CALL SbaTableQueryBrowser::getSupportedServiceNames() throw(RuntimeException)
{
return getSupportedServiceNames_Static();
}
// -------------------------------------------------------------------------
::rtl::OUString SbaTableQueryBrowser::getImplementationName_Static() throw(RuntimeException)
{
return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ODatasourceBrowser");
}
//-------------------------------------------------------------------------
::comphelper::StringSequence SbaTableQueryBrowser::getSupportedServiceNames_Static() throw(RuntimeException)
{
::comphelper::StringSequence aSupported(1);
aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.DataSourceBrowser");
return aSupported;
}
//-------------------------------------------------------------------------
Reference< XInterface > SAL_CALL SbaTableQueryBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory)
{
::vos::OGuard aGuard(Application::GetSolarMutex());
return *(new SbaTableQueryBrowser(_rxFactory));
}
//------------------------------------------------------------------------------
SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XMultiServiceFactory >& _rM)
:SbaXDataBrowserController(_rM)
,m_pTreeModel(NULL)
,m_pTreeView(NULL)
,m_pSplitter(NULL)
,m_pCurrentlyDisplayed(NULL)
,m_nAsyncDrop(0)
{
// calc the title for the load stopper
// sal_uInt32 nTitleResId;
// switch (m_xDefinition->GetKind())
// {
// case dbTable : nTitleResId = STR_TBL_TITLE; break;
// case dbQuery : nTitleResId = STR_QRY_TITLE; break;
// default : DBG_ERROR("OpenDataObjectThread::run : invalid object !");
// }
// String sTemp = String(ModuleRes(nTitleResId));
// sTemp.SearchAndReplace('#', m_xDefinition->Name());
// m_sLoadStopperCaption = String(ModuleRes(RID_STR_OPEN_OBJECT));
// m_sLoadStopperCaption += ' ';
// m_sLoadStopperCaption += sTemp;
}
//------------------------------------------------------------------------------
SbaTableQueryBrowser::~SbaTableQueryBrowser()
{
}
//------------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::disposing()
{
::vos::OGuard aGuard(Application::GetSolarMutex());
// doin' a lot of VCL stuff here -> lock the SolarMutex
// reset the content's tree view: it holds a reference to our model which is to be deleted immediately,
// and it will live longer than we do.
if (getBrowserView())
getBrowserView()->setTreeView(NULL);
// clear the user data of the tree model
SvLBoxEntry* pEntryLoop = m_pTreeModel->First();
while (pEntryLoop)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pEntryLoop->GetUserData());
if(pData)
{
Reference<XConnection> xCon(pData->xObject,UNO_QUERY);
if(xCon.is())
{
Reference< XComponent > xComponent(xCon, UNO_QUERY);
if (xComponent.is())
{
Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
xComponent->removeEventListener(xEvtL);
}
::comphelper::disposeComponent(pData->xObject);
}
delete pData;
}
pEntryLoop = m_pTreeModel->Next(pEntryLoop);
}
m_pCurrentlyDisplayed = NULL;
// clear the tree model
delete m_pTreeModel;
m_pTreeModel = NULL;
// remove ourself as status listener
implRemoveStatusListeners();
// remove the container listener from the database context
Reference< XContainer > xDatasourceContainer(m_xDatabaseContext, UNO_QUERY);
if (xDatasourceContainer.is())
xDatasourceContainer->removeContainerListener(this);
SbaXDataBrowserController::disposing();
}
//------------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::Construct(Window* pParent)
{
if (!SbaXDataBrowserController::Construct(pParent))
return sal_False;
try
{
Reference< XContainer > xDatasourceContainer(m_xDatabaseContext, UNO_QUERY);
if (xDatasourceContainer.is())
xDatasourceContainer->addContainerListener(this);
else
DBG_ERROR("SbaTableQueryBrowser::Construct: the DatabaseContext should allow us to be a listener!");
// the collator for the string compares
m_xCollator = Reference< XCollator >(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.i18n.Collator")), UNO_QUERY);
if (m_xCollator.is())
m_xCollator->loadDefaultCollator(Application::GetSettings().GetLocale(), 0);
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::Construct: could not create (or start listening at) the database context!");
}
// some help ids
if (getBrowserView() && getBrowserView()->getVclControl())
{
// create controls and set sizes
const long nFrameWidth = getBrowserView()->LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
m_pSplitter = new Splitter(getBrowserView(),WB_HSCROLL);
m_pSplitter->SetPosSizePixel( Point(0,0), Size(nFrameWidth,0) );
m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
m_pSplitter->Show();
m_pTreeView = new DBTreeView(getBrowserView(),m_xMultiServiceFacatory, WB_TABSTOP);
m_pTreeView->Show();
m_pTreeView->SetPreExpandHandler(LINK(this, SbaTableQueryBrowser, OnExpandEntry));
m_pTreeView->getListBox()->setControlActionListener(this);
m_pTreeView->SetHelpId(HID_CTL_TREEVIEW);
// a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
m_pSplitter->SetSplitPosPixel( getBrowserView()->LogicToPixel( Size( 80, 0 ), MAP_APPFONT ).Width() );
getBrowserView()->setSplitter(m_pSplitter);
getBrowserView()->setTreeView(m_pTreeView);
// fill view with data
m_pTreeModel = new DBTreeListModel;
m_pTreeModel->SetSortMode(SortAscending);
m_pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare));
m_pTreeView->setModel(m_pTreeModel);
m_pTreeView->setSelectHdl(LINK(this, SbaTableQueryBrowser, OnSelectEntry));
initializeTreeModel();
// TODO
getBrowserView()->getVclControl()->GetDataWindow().SetUniqueId(UID_DATABROWSE_DATAWINDOW);
getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER);
getBrowserView()->SetUniqueId(UID_CTL_CONTENT);
if (getBrowserView()->getVclControl()->GetHeaderBar())
getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER);
InvalidateFeature(ID_BROWSER_EXPLORER);
}
return sal_True;
}
// -------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::InitializeForm(const Reference< ::com::sun::star::sdbc::XRowSet > & _rxForm)
{
if(!m_pCurrentlyDisplayed)
return sal_True;
// this method set all format settings from the orignal table or query
try
{
// we send all properties at once, maybe the implementation is clever enough to handle one big PropertiesChanged
// more effective than many small PropertyChanged ;)
Sequence< ::rtl::OUString> aProperties(3);
Sequence< Any> aValues(3);
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
OSL_ENSURE(pData,"No user data set at the currently displayed entry!");
Reference<XPropertySet> xTableProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xTableProp.is(),"No table available!");
// is the filter intially applied ?
aProperties.getArray()[0] = PROPERTY_APPLYFILTER;
aValues.getArray()[0] = xTableProp->getPropertyValue(PROPERTY_APPLYFILTER);
// the initial filter
aProperties.getArray()[1] = PROPERTY_FILTER;
aValues.getArray()[1] = xTableProp->getPropertyValue(PROPERTY_FILTER);
// the initial ordering
aProperties.getArray()[2] = PROPERTY_ORDER;
aValues.getArray()[2] = xTableProp->getPropertyValue(PROPERTY_ORDER);
Reference< XMultiPropertySet > xFormMultiSet(_rxForm, UNO_QUERY);
xFormMultiSet->setPropertyValues(aProperties, aValues);
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::InitializeForm : something went wrong !");
return sal_False;
}
return sal_True;
}
//------------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & xGrid)
{
try
{
Reference< ::com::sun::star::form::XGridColumnFactory > xColFactory(xGrid, UNO_QUERY);
Reference< XNameContainer > xColContainer(xGrid, UNO_QUERY);
// first we have to clear the grid
{
Sequence< ::rtl::OUString > aNames = xColContainer->getElementNames();
const ::rtl::OUString* pBegin = aNames.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
for (; pBegin != pEnd;++pBegin)
xColContainer->removeByName(*pBegin);
}
// set the formats from the table
if(m_pCurrentlyDisplayed)
{
Sequence< ::rtl::OUString> aProperties(3);
Sequence< Any> aValues(3);
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xTableProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xTableProp.is(),"No table available!");
aProperties.getArray()[0] = PROPERTY_FONT;
aValues.getArray()[0] = xTableProp->getPropertyValue(PROPERTY_FONT);
aProperties.getArray()[1] = PROPERTY_ROW_HEIGHT;
aValues.getArray()[1] = xTableProp->getPropertyValue(PROPERTY_ROW_HEIGHT);
aProperties.getArray()[2] = PROPERTY_TEXTCOLOR;
aValues.getArray()[2] = xTableProp->getPropertyValue(PROPERTY_TEXTCOLOR);
Reference< XMultiPropertySet > xFormMultiSet(xGrid, UNO_QUERY);
xFormMultiSet->setPropertyValues(aProperties, aValues);
}
// get the formats supplier of the database we're working with
Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = getNumberFormatter()->getNumberFormatsSupplier();
Reference<XConnection> xConnection;
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
::cppu::extractInterface(xConnection,xProp->getPropertyValue(PROPERTY_ACTIVECONNECTION));
OSL_ENSURE(xConnection.is(),"A ActiveConnection should normaly exists!");
Reference<XChild> xChild(xConnection,UNO_QUERY);
Reference<XPropertySet> xDataSourceProp(xChild->getParent(),UNO_QUERY);
sal_Bool bSupress = ::cppu::any2bool(xDataSourceProp->getPropertyValue(PROPERTY_SUPPRESSVERSIONCL));
// insert the column into the gridcontrol so that we see something :-)
::rtl::OUString aCurrentModelType;
Reference<XColumnsSupplier> xSupCols(getRowSet(),UNO_QUERY);
Reference<XNameAccess> xColumns = xSupCols->getColumns();
Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
const ::rtl::OUString* pBegin = aNames.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
Reference<XPropertySet> xColumn;
for (sal_uInt16 i=0; pBegin != pEnd; ++i,++pBegin)
{
// Typ
// first get type to determine wich control we need
::cppu::extractInterface(xColumn,xColumns->getByName(*pBegin));
// ignore the column when it is a rowversion one
if(bSupress && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISROWVERSION)
&& ::cppu::any2bool(xColumn->getPropertyValue(PROPERTY_ISROWVERSION)))
continue;
sal_Bool bIsFormatted = sal_False;
sal_Bool bFormattedIsNumeric = sal_True;
sal_Int32 nType = comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_TYPE));
switch(nType)
{
// TODO : die Strings fuer die Column-Typen irgendwo richtig platzieren
case DataType::BIT:
aCurrentModelType = ::rtl::OUString::createFromAscii("CheckBox");
break;
case DataType::BINARY:
case DataType::VARBINARY:
case DataType::LONGVARBINARY:
aCurrentModelType = ::rtl::OUString::createFromAscii("TextField");
break;
case DataType::VARCHAR:
case DataType::LONGVARCHAR:
case DataType::CHAR:
bFormattedIsNumeric = sal_False;
// _NO_ break !
default:
aCurrentModelType = ::rtl::OUString::createFromAscii("FormattedField");
bIsFormatted = sal_True;
break;
}
Reference< XPropertySet > xCurrentCol = xColFactory->createColumn(aCurrentModelType);
xCurrentCol->setPropertyValue(PROPERTY_CONTROLSOURCE, makeAny(*pBegin));
xCurrentCol->setPropertyValue(PROPERTY_LABEL, makeAny(*pBegin));
if (bIsFormatted)
{
if (xSupplier.is())
xCurrentCol->setPropertyValue(::rtl::OUString::createFromAscii("FormatsSupplier"), makeAny(xSupplier));
xCurrentCol->setPropertyValue(PROPERTY_FORMATKEY, xColumn->getPropertyValue(PROPERTY_FORMATKEY));
xCurrentCol->setPropertyValue(::rtl::OUString::createFromAscii("TreatAsNumber"), ::cppu::bool2any(bFormattedIsNumeric));
}
// default value
if (nType == DataType::BIT)
{
Any aDefault; aDefault <<= ((sal_Int16)STATE_DONTKNOW);
if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE))
aDefault <<= (comphelper::getString(xColumn->getPropertyValue(PROPERTY_DEFAULTVALUE)).toInt32() == 0) ? (sal_Int16)STATE_NOCHECK : (sal_Int16)STATE_CHECK;
xCurrentCol->setPropertyValue(PROPERTY_DEFAULTSTATE, aDefault);
}
// transfer properties from the definition to the UNO-model :
// ... the hidden flag
xCurrentCol->setPropertyValue(PROPERTY_HIDDEN, xColumn->getPropertyValue(PROPERTY_HIDDEN));
// ... the initial colum width
xCurrentCol->setPropertyValue(PROPERTY_WIDTH, xColumn->getPropertyValue(PROPERTY_WIDTH));
// ... horizontal justify
xCurrentCol->setPropertyValue(PROPERTY_ALIGN, makeAny(sal_Int16(::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_ALIGN)))));
// ... the 'comment' property as helptext (will usually be shown as header-tooltip)
Any aDescription; aDescription <<= ::rtl::OUString();
if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION))
aDescription <<= comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
xCurrentCol->setPropertyValue(PROPERTY_HELPTEXT, xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
xColContainer->insertByName(*pBegin, makeAny(xCurrentCol));
}
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::InitializeGridModel : something went wrong !");
return sal_False;
}
return sal_True;
}
//------------------------------------------------------------------------------
ToolBox* SbaTableQueryBrowser::CreateToolBox(Window* _pParent)
{
ToolBox* pTB = NULL;
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
if(xProp.is())
{
sal_Int32 nType;
xProp->getPropertyValue(::rtl::OUString::createFromAscii("CommandType")) >>= nType;
sal_uInt16 nResId = 0;
switch (nType)
{
case CommandType::TABLE : nResId = RID_BRW_TAB_TOOLBOX; break;
case CommandType::QUERY : nResId = RID_BRW_QRY_TOOLBOX; break;
case CommandType::COMMAND: nResId = RID_BRW_QRY_TOOLBOX; break;
default : return NULL;
}
pTB = new ToolBox(_pParent, ModuleRes(nResId));
if (!pTB)
return NULL;
}
return pTB;
}
// -----------------------------------------------------------------------------
Reference<XPropertySet> getColumnHelper(SvLBoxEntry* _pCurrentlyDisplayed,const Reference<XPropertySet>& _rxSource)
{
Reference<XPropertySet> xRet;
if(_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData());
Reference<XColumnsSupplier> xColumnsSup(pData->xObject,UNO_QUERY);
Reference<XNameAccess> xNames = xColumnsSup->getColumns();
::rtl::OUString aName;
_rxSource->getPropertyValue(PROPERTY_NAME) >>= aName;
if(xNames.is() && xNames->hasByName(aName))
::cppu::extractInterface(xRet,xNames->getByName(aName));
}
return xRet;
}
// -----------------------------------------------------------------------
void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt)
{
SbaXDataBrowserController::propertyChange(evt);
try
{
Reference< XPropertySet > xSource(evt.Source, UNO_QUERY);
if (!xSource.is())
return;
// one of the many properties which require us to update the definition ?
// a column's width ?
else if (evt.PropertyName.equals(PROPERTY_WIDTH))
{ // a column width has changed -> update the model
// (the update of the view is done elsewhere)
Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
if(xProp.is())
{
if(!evt.NewValue.hasValue())
xProp->setPropertyValue(PROPERTY_WIDTH,makeAny((sal_Int32)227));
else
xProp->setPropertyValue(PROPERTY_WIDTH,evt.NewValue);
}
}
// a column's 'visible' state ?
else if (evt.PropertyName.equals(PROPERTY_HIDDEN))
{
Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
if(xProp.is())
xProp->setPropertyValue(PROPERTY_HIDDEN,evt.NewValue);
}
// a columns alignment ?
else if (evt.PropertyName.equals(PROPERTY_ALIGN))
{
Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
try
{
if(xProp.is())
{
if(evt.NewValue.hasValue())
xProp->setPropertyValue(PROPERTY_ALIGN,evt.NewValue);
else
xProp->setPropertyValue(PROPERTY_ALIGN,makeAny((sal_Int32)0));
}
}
catch(Exception&)
{
OSL_ENSURE(sal_False, "SbaTableQueryBrowser::propertyChange: caught an exception!");
}
}
// a column's format ?
else if ( (evt.PropertyName.equals(PROPERTY_FORMATKEY))
&& (TypeClass_LONG == evt.NewValue.getValueTypeClass())
)
{
// update the model (means the definition object)
Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
if(xProp.is())
xProp->setPropertyValue(PROPERTY_FORMATKEY,evt.NewValue);
}
// some table definition properties ?
// the height of the rows in the grid ?
else if (evt.PropertyName.equals(PROPERTY_ROW_HEIGHT))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
sal_Bool bDefault = !evt.NewValue.hasValue();
if (bDefault)
xProp->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
else
xProp->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
}
}
// // the font of the grid ?
else if (evt.PropertyName.equals(PROPERTY_FONT))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
xProp->setPropertyValue(PROPERTY_FONT,evt.NewValue);
}
}
// // the text color of the grid ?
else if (evt.PropertyName.equals(PROPERTY_TEXTCOLOR))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
xProp->setPropertyValue(PROPERTY_TEXTCOLOR,evt.NewValue);
}
}
// // the filter ?
else if (evt.PropertyName.equals(PROPERTY_FILTER))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
xProp->setPropertyValue(PROPERTY_FILTER,evt.NewValue);
}
}
// the sort ?
else if (evt.PropertyName.equals(PROPERTY_ORDER))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
xProp->setPropertyValue(PROPERTY_ORDER,evt.NewValue);
}
}
// the appliance of the filter ?
else if (evt.PropertyName.equals(PROPERTY_APPLYFILTER))
{
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
Reference<XPropertySet> xProp(pData->xObject,UNO_QUERY);
OSL_ENSURE(xProp.is(),"No table available!");
xProp->setPropertyValue(PROPERTY_APPLYFILTER,evt.NewValue);
}
}
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::propertyChange: caught an exception!");
}
}
// -----------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::suspend(sal_Bool bSuspend) throw( RuntimeException )
{
if (!SbaXDataBrowserController::suspend(bSuspend))
return sal_False;
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
if(pData)
{
try
{
Reference<XFlushable> xFlush(pData->xObject,UNO_QUERY);
if(xFlush.is())
xFlush->flush();
}
catch(DisposedException&)
{
OSL_ENSURE(0,"Object already disposed!");
}
catch(Exception&)
{
}
}
}
return sal_True;
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::statusChanged( const FeatureStateEvent& _rEvent ) throw(RuntimeException)
{
// search the external dispatcher causing this call
Reference< XDispatch > xSource(_rEvent.Source, UNO_QUERY);
for ( SpecialSlotDispatchersIterator aLoop = m_aDispatchers.begin();
aLoop != m_aDispatchers.end();
++aLoop
)
{
if (_rEvent.FeatureURL.Complete == getURLForId(aLoop->first).Complete)
{
DBG_ASSERT(xSource.get() == aLoop->second.get(), "SbaTableQueryBrowser::statusChanged: inconsistent!");
m_aDispatchStates[aLoop->first] = _rEvent.IsEnabled;
implCheckExternalSlot(aLoop->first);
break;
}
}
DBG_ASSERT(aLoop != m_aDispatchers.end(), "SbaTableQueryBrowser::statusChanged: don't know who sent this!");
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::implCheckExternalSlot(sal_Int32 _nId)
{
// check if we have to hide this item from the toolbox
ToolBox* pTB = getBrowserView()->getToolBox();
if (pTB)
{
sal_Bool bHaveDispatcher = m_aDispatchers[_nId].is();
if (bHaveDispatcher != pTB->IsItemVisible((sal_uInt16)_nId))
bHaveDispatcher ? pTB->ShowItem((sal_uInt16)_nId) : pTB->HideItem((sal_uInt16)_nId);
}
// and invalidate this feature in general
InvalidateFeature((sal_uInt16)_nId);
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::disposing( const EventObject& _rSource ) throw(RuntimeException)
{
// search the external dispatcher causing this call in our map
Reference< XDispatch > xSource(_rSource.Source, UNO_QUERY);
if(xSource.is())
{
for ( SpecialSlotDispatchersIterator aLoop = m_aDispatchers.begin();
aLoop != m_aDispatchers.end();
++aLoop
)
{
if (aLoop->second.get() == xSource.get())
{
SpecialSlotDispatchersIterator aPrevious = aLoop;
--aPrevious;
// remove it
m_aDispatchers.erase(aLoop);
m_aDispatchStates.erase(aLoop->first);
// maybe update the UI
implCheckExternalSlot(aLoop->first);
// continue, the same XDispatch may be resposible for more than one URL
aLoop = aPrevious;
}
}
}
else
{
Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
if(xCon.is())
{ // our connection is in dispose so we have to find the entry equal with this connection
// and close it what means to collapse the entry
// get the top-level representing the removed data source
SvLBoxEntry* pDSLoop = m_pTreeView->getListBox()->FirstChild(NULL);
while (pDSLoop)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pDSLoop->GetUserData());
if(pData && pData->xObject == xCon)
{
// we set the conenction to null to avoid a second disposing of the connection
pData->xObject = NULL;
closeConnection(pDSLoop,sal_False);
break;
}
pDSLoop = m_pTreeView->getListBox()->NextSibling(pDSLoop);
}
}
else
SbaXDataBrowserController::disposing(_rSource);
}
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::implRemoveStatusListeners()
{
// clear all old dispatches
for ( ConstSpecialSlotDispatchersIterator aLoop = m_aDispatchers.begin();
aLoop != m_aDispatchers.end();
++aLoop
)
{
if (aLoop->second.is())
{
try
{
aLoop->second->removeStatusListener(this, getURLForId(aLoop->first));
}
catch (Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::attachFrame: could not remove a status listener!");
}
}
}
m_aDispatchers.clear();
m_aDispatchStates.clear();
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::attachFrame(const Reference< ::com::sun::star::frame::XFrame > & _xFrame) throw( RuntimeException )
{
implRemoveStatusListeners();
SbaXDataBrowserController::attachFrame(_xFrame);
// get the dispatchers for the external slots
Reference< XDispatchProvider > xProvider(m_xCurrentFrame, UNO_QUERY);
DBG_ASSERT(xProvider.is(), "SbaTableQueryBrowser::attachFrame: no DispatchPprovider !");
if (xProvider.is())
{
sal_Int32 nExternalIds[] = { ID_BROWSER_FORMLETTER, ID_BROWSER_INSERTCOLUMNS, ID_BROWSER_INSERTCONTENT };
for (sal_Int32 i=0; i<sizeof(nExternalIds)/sizeof(nExternalIds[0]); ++i)
{
URL aURL = getURLForId(nExternalIds[i]);
m_aDispatchers[nExternalIds[i]] = xProvider->queryDispatch(aURL, ::rtl::OUString::createFromAscii("_parent"), FrameSearchFlag::PARENT);
if (m_aDispatchers[nExternalIds[i]].get() == static_cast< XDispatch* >(this))
// as the URL is one of our "supported features", we may answer the request ourself if nobody out there
// is interested in.
m_aDispatchers[nExternalIds[i]].clear();
// assume te general availability of the feature. This is overruled if there is no dispatcher for the URL
m_aDispatchStates[nExternalIds[i]] = sal_True;
if (m_aDispatchers[nExternalIds[i]].is())
{
try
{
m_aDispatchers[nExternalIds[i]]->addStatusListener(this, aURL);
}
catch(DisposedException&)
{
OSL_ENSURE(0,"Object already disposed!");
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::attachFrame: could not attach a status listener!");
}
}
implCheckExternalSlot(nExternalIds[i]);
}
}
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
{
SbaXDataBrowserController::addModelListeners(_xGridControlModel);
Reference< XPropertySet > xCols(_xGridControlModel, UNO_QUERY);
if (xCols.is())
{
xCols->addPropertyChangeListener(PROPERTY_ROW_HEIGHT, (XPropertyChangeListener*)this);
xCols->addPropertyChangeListener(PROPERTY_FONT, (XPropertyChangeListener*)this);
xCols->addPropertyChangeListener(PROPERTY_TEXTCOLOR, (XPropertyChangeListener*)this);
}
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::removeModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
{
SbaXDataBrowserController::removeModelListeners(_xGridControlModel);
Reference< XPropertySet > xSourceSet(_xGridControlModel, UNO_QUERY);
if (xSourceSet.is())
{
xSourceSet->removePropertyChangeListener(PROPERTY_ROW_HEIGHT, (XPropertyChangeListener*)this);
xSourceSet->removePropertyChangeListener(PROPERTY_FONT, (XPropertyChangeListener*)this);
xSourceSet->removePropertyChangeListener(PROPERTY_TEXTCOLOR, (XPropertyChangeListener*)this);
}
}
// -------------------------------------------------------------------------
String SbaTableQueryBrowser::getURL() const
{
return String();
}
// -----------------------------------------------------------------------
void SbaTableQueryBrowser::InvalidateFeature(sal_uInt16 nId, const Reference< ::com::sun::star::frame::XStatusListener > & xListener)
{
SbaXDataBrowserController::InvalidateFeature(nId, xListener);
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::AddColumnListener(const Reference< XPropertySet > & xCol)
{
SbaXDataBrowserController::AddColumnListener(xCol);
SafeAddPropertyListener(xCol, PROPERTY_WIDTH, (XPropertyChangeListener*)this);
SafeAddPropertyListener(xCol, PROPERTY_HIDDEN, (XPropertyChangeListener*)this);
SafeAddPropertyListener(xCol, PROPERTY_ALIGN, (XPropertyChangeListener*)this);
SafeAddPropertyListener(xCol, PROPERTY_FORMATKEY, (XPropertyChangeListener*)this);
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::RemoveColumnListener(const Reference< XPropertySet > & xCol)
{
SbaXDataBrowserController::RemoveColumnListener(xCol);
SafeRemovePropertyListener(xCol, PROPERTY_WIDTH, (XPropertyChangeListener*)this);
SafeRemovePropertyListener(xCol, PROPERTY_HIDDEN, (XPropertyChangeListener*)this);
SafeRemovePropertyListener(xCol, PROPERTY_ALIGN, (XPropertyChangeListener*)this);
SafeRemovePropertyListener(xCol, PROPERTY_FORMATKEY, (XPropertyChangeListener*)this);
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::AddSupportedFeatures()
{
SbaXDataBrowserController::AddSupportedFeatures();
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:Title")] = ID_BROWSER_TITLE;
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:DataSourceBrowser/FormLetter")] = ID_BROWSER_FORMLETTER;
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:DataSourceBrowser/InsertColumns")] = ID_BROWSER_INSERTCOLUMNS;
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:DataSourceBrowser/InsertContent")] = ID_BROWSER_INSERTCONTENT;
m_aSupportedFeatures[ ::rtl::OUString::createFromAscii(".uno:DataSourceBrowser/ToggleExplore")] = ID_BROWSER_EXPLORER;
// TODO reenable our own code if we really have a handling for the formslots
// ControllerFeature( ::rtl::OUString::createFromAscii("private:FormSlot/moveToFirst"), SID_FM_RECORD_FIRST ),
// ControllerFeature( ::rtl::OUString::createFromAscii("private:FormSlot/moveToLast"), SID_FM_RECORD_LAST ),
// ControllerFeature( ::rtl::OUString::createFromAscii("private:FormSlot/moveToNew"), SID_FM_RECORD_NEW ),
// ControllerFeature( ::rtl::OUString::createFromAscii("private:FormSlot/moveToNext"), SID_FM_RECORD_NEXT ),
// ControllerFeature( ::rtl::OUString::createFromAscii("private:FormSlot/moveToPrev"), SID_FM_RECORD_PREV )
}
//------------------------------------------------------------------------------
FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId)
{
FeatureState aReturn;
// (disabled automatically)
if (ID_BROWSER_EXPLORER == nId)
{ // this slot is available even if no form is loaded
aReturn.bEnabled = sal_True;
aReturn.aState = ::cppu::bool2any(haveExplorer());
return aReturn;
}
try
{
// no chance without a view
if (!getBrowserView() || !getBrowserView()->getVclControl())
return aReturn;
// no chance without valid models
if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE) // the close button should always be enabled
return aReturn;
// no chance while loading the form
if (PendingLoad())
return aReturn;
switch (nId)
{
case ID_BROWSER_INSERTCOLUMNS:
case ID_BROWSER_INSERTCONTENT:
case ID_BROWSER_FORMLETTER:
{
// the slot is enabled if we have an external dispatcher able to handle it,
// and the dispatcher must have enabled the slot in general
if (m_aDispatchers[nId].is())
aReturn.bEnabled = m_aDispatchStates[nId];
else
aReturn.bEnabled = sal_False;
// for the Insert* slots, we need at least one selected row
if (ID_BROWSER_FORMLETTER != nId)
aReturn.bEnabled = aReturn.bEnabled && getBrowserView()->getVclControl()->GetSelectRowCount();
// disabled for native queries which are not saved within the database
// 67706 - 23.08.99 - FS
Reference< XPropertySet > xDataSource(getRowSet(), UNO_QUERY);
try
{
aReturn.bEnabled = aReturn.bEnabled && xDataSource.is();
if (xDataSource.is())
{
sal_Int32 nType = ::comphelper::getINT32(xDataSource->getPropertyValue(PROPERTY_COMMANDTYPE));
aReturn.bEnabled = aReturn.bEnabled && ((::comphelper::getBOOL(xDataSource->getPropertyValue(PROPERTY_USE_ESCAPE_PROCESSING)) || (nType == ::com::sun::star::sdb::CommandType::QUERY)));
}
}
catch(DisposedException&)
{
OSL_ENSURE(0,"Object already disposed!");
}
catch(Exception&)
{
}
}
break;
case ID_BROWSER_TITLE:
{
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
sal_Int32 nCommandType = CommandType::TABLE;
xProp->getPropertyValue(PROPERTY_COMMANDTYPE) >>= nCommandType;
String sTitle;
switch (nCommandType)
{
case CommandType::TABLE:
sTitle = String(ModuleRes(STR_TBL_TITLE)); break;
case CommandType::QUERY:
case CommandType::COMMAND:
sTitle = String(ModuleRes(STR_QRY_TITLE)); break;
default:
DBG_ASSERT(0,"Unbekannte DBDef Art");
}
::rtl::OUString aName;
xProp->getPropertyValue(PROPERTY_COMMAND) >>= aName;
String sObject(aName.getStr());
sTitle.SearchAndReplace('#',sObject);
aReturn.aState <<= ::rtl::OUString(sTitle);
aReturn.bEnabled = sal_True;
}
break;
case ID_BROWSER_TABLEATTR:
case ID_BROWSER_ROWHEIGHT:
case ID_BROWSER_COLATTRSET:
case ID_BROWSER_COLWIDTH:
aReturn.bEnabled = getBrowserView() && getBrowserView()->getVclControl() && isValid() && isValidCursor();
// aReturn.bEnabled &= getDefinition() && !getDefinition()->GetDatabase()->IsReadOnly();
break;
case ID_BROWSER_EDITDOC:
aReturn = SbaXDataBrowserController::GetState(nId);
// aReturn.bEnabled &= !getDefinition()->IsLocked();
// somebody is modifying the definition -> no edit mode
break;
case ID_BROWSER_CLOSE:
aReturn.bEnabled = sal_True;
break;
default:
return SbaXDataBrowserController::GetState(nId);
}
}
catch(Exception& e)
{
#if DBG_UTIL
String sMessage("SbaXDataBrowserController::GetState(", RTL_TEXTENCODING_ASCII_US);
sMessage += String::CreateFromInt32(nId);
sMessage.AppendAscii(") : catched an exception ! message : ");
sMessage += (const sal_Unicode*)e.Message;
DBG_ERROR(ByteString(sMessage, gsl_getSystemTextEncoding()).GetBuffer());
#else
e; // make compiler happy
#endif
}
;
return aReturn;
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::Execute(sal_uInt16 nId)
{
switch (nId)
{
case ID_BROWSER_EXPLORER:
toggleExplorer();
break;
case ID_BROWSER_EDITDOC:
SbaXDataBrowserController::Execute(nId);
break;
case ID_BROWSER_INSERTCOLUMNS:
case ID_BROWSER_INSERTCONTENT:
case ID_BROWSER_FORMLETTER:
if (getBrowserView() && isValidCursor())
{
// the URL the slot id is assigned to
URL aParentUrl = getURLForId(nId);
// let the dispatcher execute the slot
Reference< XDispatch > xDispatch(m_aDispatchers[nId]);
if (xDispatch.is())
{
// set the properties for the dispatch
// first fill the selection
SbaGridControl* pGrid = getBrowserView()->getVclControl();
MultiSelection* pSelection = (MultiSelection*)pGrid->GetSelection();
Sequence< sal_Int32 > aSelection;
if (pSelection != NULL)
{
aSelection.realloc(pSelection->GetSelectCount());
long nIdx = pSelection->FirstSelected();
sal_Int32 i = 0;
while (nIdx >= 0)
{
aSelection[i++] = nIdx+1;
nIdx = pSelection->NextSelected();
}
}
Reference< XResultSet > xCursorClone;
try
{
Reference< XResultSetAccess > xResultSetAccess(getRowSet(),UNO_QUERY);
if (xResultSetAccess.is())
xCursorClone = xResultSetAccess->createResultSet();
}
catch(DisposedException&)
{
OSL_ENSURE(0,"Object already disposed!");
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::Execute(ID_BROWSER_?): could not clone the cursor!");
}
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
try
{
Sequence< PropertyValue> aProps(5);
aProps[0] = PropertyValue(PROPERTY_DATASOURCENAME, -1, xProp->getPropertyValue(PROPERTY_DATASOURCENAME), PropertyState_DIRECT_VALUE);
aProps[1] = PropertyValue(PROPERTY_COMMAND, -1, xProp->getPropertyValue(PROPERTY_COMMAND), PropertyState_DIRECT_VALUE);
aProps[2] = PropertyValue(PROPERTY_COMMANDTYPE, -1, xProp->getPropertyValue(PROPERTY_COMMANDTYPE), PropertyState_DIRECT_VALUE);
aProps[3] = PropertyValue(::rtl::OUString::createFromAscii("Selection"), -1, makeAny(aSelection), PropertyState_DIRECT_VALUE);
aProps[4] = PropertyValue(::rtl::OUString::createFromAscii("Cursor"), -1, makeAny(xCursorClone), PropertyState_DIRECT_VALUE);
xDispatch->dispatch(aParentUrl, aProps);
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::Execute(ID_BROWSER_?): could not dispatch the slot (caught an exception)!");
}
}
}
break;
case ID_BROWSER_CLOSE:
{
Reference<XComponent> xComp(m_xCurrentFrame,UNO_QUERY);
::comphelper::disposeComponent(xComp);
}
break;
default:
SbaXDataBrowserController::Execute(nId);
break;
}
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::implAddDatasource(const String& _rDbName, Image& _rDbImage,
String& _rQueryName, Image& _rQueryImage, String& _rTableName, Image& _rTableImage)
{
// initialize the names/images if necessary
if (!_rQueryName.Len())
_rQueryName = String(ModuleRes(RID_STR_QUERIES_CONTAINER));
if (!_rTableName.Len())
_rTableName = String(ModuleRes(RID_STR_TABLES_CONTAINER));
if (!_rQueryImage)
_rQueryImage = Image(ModuleRes(QUERYFOLDER_TREE_ICON));
if (!_rTableImage)
_rTableImage = Image(ModuleRes(TABLEFOLDER_TREE_ICON));
if (!_rDbImage)
_rDbImage = Image(ModuleRes(IMG_DATABASE));
// add the entry for the data source
SvLBoxEntry* pDatasourceEntry = m_pTreeView->getListBox()->InsertEntry(_rDbName, _rDbImage, _rDbImage, NULL, sal_False);
pDatasourceEntry->SetUserData(new DBTreeListModel::DBTreeListUserData);
// the child for the queries container
SvLBoxEntry* pQueries = m_pTreeView->getListBox()->InsertEntry(_rQueryName, _rQueryImage, _rQueryImage, pDatasourceEntry, sal_True);
DBTreeListModel::DBTreeListUserData* pQueriesData = new DBTreeListModel::DBTreeListUserData;
pQueriesData->bTable = sal_False;
pQueries->SetUserData(pQueriesData);
// the child for the tables container
SvLBoxEntry* pTables = m_pTreeView->getListBox()->InsertEntry(_rTableName, _rTableImage, _rTableImage, pDatasourceEntry, sal_True);
DBTreeListModel::DBTreeListUserData* pTablesData = new DBTreeListModel::DBTreeListUserData;
pTablesData->bTable = sal_True;
pTables->SetUserData(pTablesData);
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::initializeTreeModel()
{
if (m_xDatabaseContext.is())
{
Image aDBImage, aQueriesImage, aTablesImage;
String sQueriesName, sTablesName;
// fill the model with the names of the registered datasources
Sequence< ::rtl::OUString > aDatasources = m_xDatabaseContext->getElementNames();
const ::rtl::OUString* pBegin = aDatasources.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aDatasources.getLength();
for (; pBegin != pEnd; ++pBegin)
implAddDatasource(*pBegin, aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage);
}
}
// -------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess, SvLBoxEntry* _pParent, const Image& _rImage)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(_pParent->GetUserData());
if(pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables
pData->xObject = _xNameAccess;
try
{
Sequence< ::rtl::OUString > aNames = _xNameAccess->getElementNames();
const ::rtl::OUString* pBegin = aNames.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
for (; pBegin != pEnd; ++pBegin)
if(!m_pTreeView->getListBox()->GetEntryPosByName(*pBegin,_pParent))
m_pTreeView->getListBox()->InsertEntry(*pBegin, _rImage, _rImage, _pParent, sal_False);
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree");
return sal_False;
}
return sal_True;
}
//------------------------------------------------------------------------------
IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvLBoxEntry*, _pParent)
{
if (_pParent->HasChilds())
// nothing to to ...
return 1L;
::osl::MutexGuard aGuard(m_aEntryMutex);
SvLBoxEntry* pFirstParent = m_pTreeView->getListBox()->GetRootLevelParent(_pParent);
OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!");
DBTreeListModel::DBTreeListUserData* pData = static_cast< DBTreeListModel::DBTreeListUserData* >(_pParent->GetUserData());
OSL_ENSURE(pData,"SbaTableQueryBrowser::OnExpandEntry: No user data!");
SvLBoxString* pString = static_cast<SvLBoxString*>(pFirstParent->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
OSL_ENSURE(pString,"SbaTableQueryBrowser::OnExpandEntry: No string item!");
if(pData->bTable)
{
// it could be that we already have a connection
DBTreeListModel::DBTreeListUserData* pFirstData = static_cast<DBTreeListModel::DBTreeListUserData*>(pFirstParent->GetUserData());
Reference<XConnection> xConnection(pFirstData->xObject,UNO_QUERY);
WaitObject aWaitCursor(getBrowserView());
if(!pFirstData->xObject.is())
{
UnoDataBrowserView* pView = static_cast<UnoDataBrowserView*>(getView());
if (pView)
{
String sConnecting(ModuleRes(STR_CONNECTING_DATASOURCE));
sConnecting.SearchAndReplaceAscii("$name$", pString->GetText());
pView->showStatus(sConnecting);
}
xConnection = connect(pString->GetText());
pFirstData->xObject = xConnection;
if (pView)
pView->hideStatus();
}
if(xConnection.is())
{
Reference< XWarningsSupplier > xWarnings(xConnection, UNO_QUERY);
if (xWarnings.is())
xWarnings->clearWarnings();
// first insert the views because the tables can also include
// views but that time the bitmap is the wrong one
// the nameaccess will be overwriten in populateTree
Reference<XViewsSupplier> xViewSup(xConnection,UNO_QUERY);
if(xViewSup.is())
{
Image aImage(ModuleRes(VIEW_TREE_ICON));
populateTree(xViewSup->getViews(),_pParent,aImage);
}
Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
if(xTabSup.is())
{
Image aImage(ModuleRes(TABLE_TREE_ICON));
populateTree(xTabSup->getTables(),_pParent,aImage);
Reference<XContainer> xCont(xTabSup->getTables(),UNO_QUERY);
if(xCont.is())
// add as listener to know when elements are inserted or removed
xCont->addContainerListener(this);
}
if (xWarnings.is())
{
SQLExceptionInfo aInfo(xWarnings->getWarnings());
if (aInfo.isValid() && sal_False)
{
SQLContext aContext;
aContext.Message = String(ModuleRes(STR_OPENTABLES_WARNINGS));
aContext.Details = String(ModuleRes(STR_OPENTABLES_WARNINGS_DETAILS));
aContext.NextException = aInfo.get();
aInfo = aContext;
showError(aInfo);
}
// TODO: we need a better concept for these warnings:
// something like "don't show any warnings for this datasource, again" would be nice
// But this requires an extension of the InteractionHandler and an additional property on the data source
}
}
else
return 0L;
// 0 indicates that an error occured
}
else
{ // we have to expand the queries
if (ensureEntryObject(_pParent))
{
Reference< XNameAccess > xQueries(static_cast< DBTreeListModel::DBTreeListUserData* >(_pParent->GetUserData())->xObject, UNO_QUERY);
populateTree(xQueries, _pParent, Image(ModuleRes(QUERY_TREE_ICON)));
}
}
return 1L;
}
//------------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvLBoxEntry* _pEntry )
{
DBG_ASSERT(_pEntry, "SbaTableQueryBrowser::ensureEntryObject: invalid argument!");
if (!_pEntry)
return sal_False;
EntryType eType = getEntryType( _pEntry );
// the user data of the entry
DBTreeListModel::DBTreeListUserData* pEntryData = static_cast<DBTreeListModel::DBTreeListUserData*>(_pEntry->GetUserData());
if (!pEntryData)
{ // create
pEntryData = new DBTreeListModel::DBTreeListUserData;
pEntryData->bTable = ET_TABLE == eType;
_pEntry->SetUserData(pEntryData);
}
if (pEntryData->xObject.is())
// nothing to do
return sal_True;
SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox()->GetRootLevelParent(_pEntry);
switch (eType)
{
case ET_QUERY_CONTAINER:
{
try
{
Reference< XQueryDefinitionsSupplier > xQuerySup;
m_xDatabaseContext->getByName( getEntryText( pDataSourceEntry ) ) >>= xQuerySup;
if (xQuerySup.is())
{
Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions();
Reference< XContainer > xCont(xQueryDefs, UNO_QUERY);
if (xCont.is())
// add as listener to get notified if elements are inserted or removed
xCont->addContainerListener(this);
pEntryData->xObject = xQueryDefs;
}
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: caught an exception while retrieving the queries container!");
}
}
break;
default:
DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: ooops ... missing some implementation here!");
// TODO ...
break;
}
return pEntryData->xObject.is();
}
//------------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::isSelected(SvLBoxEntry* _pEntry) const
{
SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
if (pTextItem)
return static_cast<OBoldListboxString*>(pTextItem)->isEmphasized();
else
DBG_ERROR("SbaTableQueryBrowser::isSelected: invalid entry!");
return sal_False;
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::select(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
{
SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
if (pTextItem)
{
static_cast<OBoldListboxString*>(pTextItem)->emphasize(_bSelect);
m_pTreeModel->InvalidateEntry(_pEntry);
}
else
DBG_ERROR("SbaTableQueryBrowser::select: invalid entry!");
}
//------------------------------------------------------------------------------
void SbaTableQueryBrowser::selectPath(SvLBoxEntry* _pEntry, sal_Bool _bSelect)
{
while (_pEntry)
{
select(_pEntry, _bSelect);
_pEntry = m_pTreeModel->GetParent(_pEntry);
}
}
//------------------------------------------------------------------------------
IMPL_LINK(SbaTableQueryBrowser, OnSelectEntry, SvLBoxEntry*, _pEntry)
{
::osl::MutexGuard aGuard(m_aEntryMutex);
// reinitialize the rowset
// but first check if it is necessary
// get all old properties
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
::rtl::OUString aOldName;
xProp->getPropertyValue(PROPERTY_COMMAND) >>= aOldName;
sal_Int32 nOldType;
xProp->getPropertyValue(PROPERTY_COMMANDTYPE) >>= nOldType;
Reference<XConnection> xOldConnection;
::cppu::extractInterface(xOldConnection,xProp->getPropertyValue(PROPERTY_ACTIVECONNECTION));
// the name of the table or query
SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
OSL_ENSURE(pString,"There must be a string item!");
::rtl::OUString aName(pString->GetText().GetBuffer());
// get the entry for the tables or queries
SvLBoxEntry* pTables = m_pTreeModel->GetParent(_pEntry);
DBTreeListModel::DBTreeListUserData* pTablesData = static_cast<DBTreeListModel::DBTreeListUserData*>(pTables->GetUserData());
// get the entry for the datasource
SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pTables);
DBTreeListModel::DBTreeListUserData* pConData = static_cast<DBTreeListModel::DBTreeListUserData*>(pConnection->GetUserData());
Reference<XConnection> xConnection(pConData->xObject,UNO_QUERY);
sal_Int32 nCommandType = pTablesData->bTable ? CommandType::TABLE : CommandType::QUERY;
// check if need to rebuild the rowset
sal_Bool bRebuild = xOldConnection != xConnection || nOldType != nCommandType || aName != aOldName;
Reference< ::com::sun::star::form::XLoadable > xLoadable(getRowSet(),UNO_QUERY);
bRebuild |= !xLoadable->isLoaded();
if(bRebuild)
{
try
{
// if table was selected before flush it
if(m_pCurrentlyDisplayed)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
if(pData) // can be null because the first load can be failed @see below
{
Reference<XFlushable> xFlush(pData->xObject,UNO_QUERY);
if(xFlush.is())
xFlush->flush();
}
}
}
catch(Exception&)
{
OSL_ENSURE(0,"Object can not be flushed!");
}
try
{
WaitObject aWaitCursor(getBrowserView());
// tell the old entry it has been deselected
selectPath(m_pCurrentlyDisplayed, sal_False);
m_pCurrentlyDisplayed = _pEntry;
// tell the new entry it has been selected
selectPath(m_pCurrentlyDisplayed, sal_True);
// get the name of the data source currently selected
::rtl::OUString sDataSourceName;
SvLBoxEntry* pEntry = m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed);
if (pEntry)
{
SvLBoxItem* pTextItem = pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
if (pTextItem)
sDataSourceName = static_cast<SvLBoxString*>(pTextItem)->GetText();
}
if(!xConnection.is())
{
xConnection = connect(sDataSourceName);
pConData->xObject = xConnection;
}
if(!xConnection.is())
{
unloadForm(sal_False,sal_False);
return 0L;
}
Reference<XNameAccess> xNameAccess;
switch(nCommandType)
{
case CommandType::TABLE:
{
// only for tables
if(!pTablesData->xObject.is())
{
Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
if(xSup.is())
xNameAccess = xSup->getTables();
pTablesData->xObject = xNameAccess;
}
else
xNameAccess = Reference<XNameAccess>(pTablesData->xObject,UNO_QUERY);
}
break;
case CommandType::QUERY:
{
Reference<XQueriesSupplier> xSup(xConnection,UNO_QUERY);
if(xSup.is())
xNameAccess = xSup->getQueries();
}
break;
}
if(xNameAccess.is() && xNameAccess->hasByName(aName))
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
if(!pData)
{
DBTreeListModel::DBTreeListUserData* pTableData = new DBTreeListModel::DBTreeListUserData;
pTableData->bTable = pTablesData->bTable;
if(xNameAccess->getByName(aName) >>= pTableData->xObject) // remember the table or query object
m_pCurrentlyDisplayed->SetUserData(pTableData);
else
delete pTableData; // do you see the data can be null or not set
}
}
// the values allowing the RowSet to re-execute
xProp->setPropertyValue(PROPERTY_DATASOURCENAME,makeAny(sDataSourceName));
// set this _before_ setting the connection, else the rowset would rebuild it ...
xProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,makeAny(xConnection));
xProp->setPropertyValue(PROPERTY_COMMANDTYPE,makeAny(nCommandType));
xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(aName));
// the formatter depends on the data source we're working on, so rebuild it here ...
initFormatter();
// switch the grid to design mode while loading
getBrowserView()->getGridControl()->setDesignMode(sal_True);
InitializeForm(getRowSet());
// load the row set
{
FormErrorHelper aNoticeErrors(this);
if (xLoadable->isLoaded())
// reload does not work if not already loaded
xLoadable->reload();
else
xLoadable->load();
sal_Bool bLoadSuccess = !errorOccured();
// initialize the model
InitializeGridModel(getFormComponent());
// reload ...
// TODO: why this reload ... me thinks the GridModel can't handle beeing initialized when the form
// is already loaded, but I'm not sure ...
// have to change this, reloading is much too expensive ...
if (xLoadable->isLoaded() && bLoadSuccess)
xLoadable->reload();
FormLoaded(sal_True);
}
}
catch(SQLException& e)
{
showError(SQLExceptionInfo(e));
// reset the values
xProp->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
xProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,Any());
}
catch(Exception&)
{
// reset the values
xProp->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
xProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,Any());
}
}
return 0L;
}
// -----------------------------------------------------------------------------
SvLBoxEntry* SbaTableQueryBrowser::getNameAccessFromEntry(const Reference<XNameAccess>& _rxNameAccess)
{
SvLBoxEntry* pDSLoop = m_pTreeView->getListBox()->FirstChild(NULL);
SvLBoxEntry* pContainer = NULL;
while (pDSLoop)
{
pContainer = m_pTreeView->getListBox()->GetEntry(pDSLoop, CONTAINER_QUERIES);
DBTreeListModel::DBTreeListUserData* pQueriesData = static_cast<DBTreeListModel::DBTreeListUserData*>(pContainer->GetUserData());
if(pQueriesData && pQueriesData->xObject.get() == _rxNameAccess.get())
break;
pContainer = m_pTreeView->getListBox()->GetEntry(pDSLoop, CONTAINER_TABLES);
DBTreeListModel::DBTreeListUserData* pTablesData = static_cast<DBTreeListModel::DBTreeListUserData*>(pContainer->GetUserData());
if(pTablesData && pTablesData->xObject.get() == _rxNameAccess.get())
break;
pDSLoop = m_pTreeView->getListBox()->NextSibling(pDSLoop);
pContainer = NULL;
}
return pContainer;
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
// first search for a definition container where we can insert this element
SvLBoxEntry* pEntry = getNameAccessFromEntry(xNames);
if(pEntry) // found one
{
// insert the new entry into the tree
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pEntry->GetUserData());
OSL_ENSURE(pData,"elementInserted: There must be user data for this type!");
Image aImage(ModuleRes(pData->bTable ? TABLE_TREE_ICON : QUERY_TREE_ICON));
SvLBoxEntry* pNewEntry = m_pTreeView->getListBox()->InsertEntry(::comphelper::getString(_rEvent.Accessor),
aImage, aImage, pEntry, sal_False);
if(pData->bTable)
{ // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
DBTreeListModel::DBTreeListUserData* pNewData = new DBTreeListModel::DBTreeListUserData;
pNewData->bTable = pData->bTable;
::cppu::extractInterface(pNewData->xObject,_rEvent.Element);// remember the new element
pNewEntry->SetUserData(pNewData);
}
}
else if (xNames.get() == m_xDatabaseContext.get())
{ // a new datasource has been added to the context
// the name of the new ds
::rtl::OUString sNewDS;
_rEvent.Accessor >>= sNewDS;
// add new entries to the list box model
Image a, b, c; // not interested in reusing them
String d, e;
implAddDatasource(sNewDS, a, d, b, e, c);
}
else
SbaXDataBrowserController::elementInserted(_rEvent);
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
// get the top-level representing the removed data source
// and search for the queries and tables
SvLBoxEntry* pEntry = getNameAccessFromEntry(xNames);
if (pEntry)
{ // a query or table has been removed
String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
if (m_pCurrentlyDisplayed && m_pTreeView->getListBox()->GetEntryText(m_pCurrentlyDisplayed) == aName)
{
// we need to remember the old value
SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
// unload
unloadForm(sal_False, sal_False); // don't dispose the connection, don't flush
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pTemp->GetUserData());
delete pData; // the data could be null because we have a table which isn't correct
m_pTreeModel->Remove(pTemp);
}
else
{
// remove the entry from the model
SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pEntry);
while(pChild)
{
if (m_pTreeView->getListBox()->GetEntryText(pChild) == aName)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pChild->GetUserData());
delete pData;
m_pTreeModel->Remove(pChild);
break;
}
pChild = m_pTreeModel->NextSibling(pChild);
}
}
}
else if (xNames.get() == m_xDatabaseContext.get())
{ // a datasource has been removed from the context
// the name
::rtl::OUString sNewDS;
_rEvent.Accessor >>= sNewDS;
String sNewDatasource = sNewDS;
// get the top-level representing the removed data source
SvLBoxEntry* pDSLoop = m_pTreeView->getListBox()->FirstChild(NULL);
while (pDSLoop)
{
if (m_pTreeView->getListBox()->GetEntryText(pDSLoop) == sNewDatasource)
break;
pDSLoop = m_pTreeView->getListBox()->NextSibling(pDSLoop);
}
if (pDSLoop)
{
if (isSelected(pDSLoop))
{ // a table or query belonging to the deleted data source is currently beeing displayed.
OSL_ENSURE(m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed) == pDSLoop, "SbaTableQueryBrowser::elementRemoved: inconsistence (1)!");
unloadForm();
}
else
OSL_ENSURE(
(NULL == m_pCurrentlyDisplayed)
|| (m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed) != pDSLoop), "SbaTableQueryBrowser::elementRemoved: inconsistence (2)!");
// look for user data to delete
SvTreeEntryList* pList = m_pTreeModel->GetChildList(pDSLoop);
if(pList)
{
SvLBoxEntry* pEntryLoop = static_cast<SvLBoxEntry*>(pList->First());
while (pEntryLoop)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pEntryLoop->GetUserData());
delete pData;
pEntryLoop = static_cast<SvLBoxEntry*>(pList->Next());
}
}
// remove the entry. This should remove all children, too.
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pDSLoop->GetUserData());
delete pData;
m_pTreeModel->Remove(pDSLoop);
}
else
DBG_ERROR("SbaTableQueryBrowser::elementRemoved: unknown datasource name!");
}
else
SbaXDataBrowserController::elementRemoved(_rEvent);
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
SvLBoxEntry* pEntry = getNameAccessFromEntry(xNames);
if (pEntry)
{ // a table or query as been replaced
String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
if (m_pCurrentlyDisplayed && m_pTreeView->getListBox()->GetEntryText(m_pCurrentlyDisplayed) == aName)
{
// we need to remember the old value
SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
unloadForm(sal_False); // don't dispose the connection
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pTemp->GetUserData());
OSL_ENSURE(pData,"elementReplaced: There must be user data!");
if(pData->bTable)
{ // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
::cppu::extractInterface(pData->xObject,_rEvent.Element);// remember the new element
}
else
{
delete pData;
pTemp->SetUserData(NULL);
}
}
else
{
// find the entry for this name
SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pEntry);
while(pChild)
{
if (m_pTreeView->getListBox()->GetEntryText(pChild) == aName)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pChild->GetUserData());
OSL_ENSURE(pData,"elementReplaced: There must be user data!");
if(pData->bTable)
{ // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
::cppu::extractInterface(pData->xObject,_rEvent.Element);// remember the new element
}
else
{
delete pData;
pChild->SetUserData(NULL);
}
break;
}
pChild = m_pTreeModel->NextSibling(pChild);
}
}
}
else if (xNames.get() == m_xDatabaseContext.get())
{ // a datasource has been replaced in the context
DBG_ERROR("SbaTableQueryBrowser::elementReplaced: no support for replaced data sources!");
// very suspicious: the database context should not allow to replace data source, only to register
// and revoke them
}
else
SbaXDataBrowserController::elementReplaced(_rEvent);
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::closeConnection(SvLBoxEntry* _pDSEntry,sal_Bool _bDisposeConnection)
{
DBG_ASSERT(_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (NULL)!");
OSL_ENSURE(m_pTreeView->getListBox()->GetRootLevelParent(_pDSEntry) == _pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!");
// if one of the entries of the given DS is displayed currently, unload the form
if (m_pCurrentlyDisplayed && (m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed) == _pDSEntry))
unloadForm(_bDisposeConnection);
// collapse the query/table container
for (SvLBoxEntry* pContainers = m_pTreeModel->FirstChild(_pDSEntry); pContainers; pContainers= m_pTreeModel->NextSibling(pContainers))
{
m_pTreeView->getListBox()->Collapse(pContainers);
m_pTreeView->getListBox()->EnableExpandHandler(pContainers);
// and delete their children (they are connection-relative)
for (SvLBoxEntry* pElements = m_pTreeModel->FirstChild(pContainers); pElements; )
{
SvLBoxEntry* pRemove = pElements;
pElements= m_pTreeModel->NextSibling(pElements);
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pRemove->GetUserData());
delete pData;
m_pTreeModel->Remove(pRemove);
}
}
// collapse the entry itself
m_pTreeView->getListBox()->Collapse(_pDSEntry);
// get the connection
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(_pDSEntry->GetUserData());
if(_bDisposeConnection) // and dispose/reset it
{
Reference< XComponent > xComponent(pData->xObject, UNO_QUERY);
if (xComponent.is())
{
Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
xComponent->removeEventListener(xEvtL);
}
::comphelper::disposeComponent(pData->xObject);
}
pData->xObject.clear();
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::unloadForm(sal_Bool _bDisposeConnection, sal_Bool _bFlushData)
{
if (!m_pCurrentlyDisplayed)
// nothing to do
return;
SvLBoxEntry* pDSEntry = m_pTreeView->getListBox()->GetRootLevelParent(m_pCurrentlyDisplayed);
// de-select the path for the currently displayed table/query
if (m_pCurrentlyDisplayed)
{
if (_bFlushData)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
try
{
if(pData)
{
Reference<XFlushable> xFlush(pData->xObject, UNO_QUERY);
if(xFlush.is())
xFlush->flush();
}
}
catch (RuntimeException&)
{
OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadForm: could not flush the data (caught a RuntimeException)!");
}
}
selectPath(m_pCurrentlyDisplayed, sal_False);
}
m_pCurrentlyDisplayed = NULL;
try
{
// get the active connection. We need to dispose it.
Reference< XPropertySet > xProp(getRowSet(),UNO_QUERY);
Reference< XConnection > xConn;
::cppu::extractInterface(xConn, xProp->getPropertyValue(PROPERTY_ACTIVECONNECTION));
#ifdef DEBUG
{
Reference< XComponent > xComp;
::cppu::extractInterface(xComp, xProp->getPropertyValue(PROPERTY_ACTIVECONNECTION));
}
#endif
// unload the form
Reference< XLoadable > xLoadable(getRowSet(), UNO_QUERY);
xLoadable->unload();
// clear the grid control
Reference< XNameContainer > xColContainer(getControlModel(), UNO_QUERY);
// first we have to clear the grid
{
Sequence< ::rtl::OUString > aNames = xColContainer->getElementNames();
const ::rtl::OUString* pBegin = aNames.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
for (; pBegin != pEnd;++pBegin)
xColContainer->removeByName(*pBegin);
}
// dispose the connection
if(_bDisposeConnection)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pDSEntry->GetUserData());
if(pData)
{
Reference< XComponent > xComponent(pData->xObject, UNO_QUERY);
if (xComponent.is())
{
Reference< ::com::sun::star::lang::XEventListener> xEvtL((::cppu::OWeakObject*)this,UNO_QUERY);
xComponent->removeEventListener(xEvtL);
}
pData->xObject = NULL;
}
::comphelper::disposeComponent(xConn);
}
}
catch(SQLException& e)
{
showError(SQLExceptionInfo(e));
}
catch(Exception&)
{
OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadForm: could not reset the form");
}
}
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
{
::vos::OGuard aGuard(Application::GetSolarMutex());
// doin' a lot of VCL stuff here -> lock the SolarMutex
// first initialize the parent
SbaXDataBrowserController::initialize( aArguments );
Reference<XConnection> xConnection;
PropertyValue aValue;
const Any* pBegin = aArguments.getConstArray();
const Any* pEnd = pBegin + aArguments.getLength();
::rtl::OUString aTableName,aCatalogName,aSchemaName;
sal_Bool bEsacpeProcessing = sal_True;
m_nDefaultCommandType = -1;
for(;pBegin != pEnd;++pBegin)
{
if((*pBegin >>= aValue) && aValue.Name == PROPERTY_DATASOURCENAME)
aValue.Value >>= m_sDefaultDataSourceName;
else if(aValue.Name == PROPERTY_COMMANDTYPE)
aValue.Value >>= m_nDefaultCommandType;
else if(aValue.Name == PROPERTY_COMMAND)
aValue.Value >>= m_sDefaultCommand;
else if(aValue.Name == PROPERTY_ACTIVECONNECTION)
::cppu::extractInterface(xConnection,aValue.Value);
else if(aValue.Name == PROPERTY_UPDATE_CATALOGNAME)
aValue.Value >>= aCatalogName;
else if(aValue.Name == PROPERTY_UPDATE_SCHEMANAME)
aValue.Value >>= aSchemaName;
else if(aValue.Name == PROPERTY_UPDATE_TABLENAME)
aValue.Value >>= aTableName;
else if(aValue.Name == PROPERTY_USE_ESCAPE_PROCESSING)
bEsacpeProcessing = ::cppu::any2bool(aValue.Value);
else if(aValue.Name == PROPERTY_SHOWTREEVIEW)
{
try
{
if(::cppu::any2bool(aValue.Value))
showExplorer();
else
hideExplorer();
}
catch(Exception&)
{
}
}
else if(aValue.Name == PROPERTY_SHOWTREEVIEWBUTTON)
{
try
{
if(!::cppu::any2bool(aValue.Value) && getView())
{
// hide the explorer and the separator
getView()->getToolBox()->HideItem(ID_BROWSER_EXPLORER);
getView()->getToolBox()->HideItem(getView()->getToolBox()->GetItemId(getView()->getToolBox()->GetItemPos(ID_BROWSER_EXPLORER)+1));
getView()->getToolBox()->ShowItem(ID_BROWSER_CLOSE);
}
}
catch(Exception&)
{
}
}
}
if(m_sDefaultDataSourceName.getLength() && m_sDefaultCommand.getLength() && m_nDefaultCommandType != -1)
{
SvLBoxEntry* pDataSource = m_pTreeView->getListBox()->GetEntryPosByName(m_sDefaultDataSourceName,NULL);
if(pDataSource)
{
m_pTreeView->getListBox()->Expand(pDataSource);
SvLBoxEntry* pCommandType = NULL;
if(CommandType::TABLE == m_nDefaultCommandType)
pCommandType = m_pTreeView->getListBox()->GetModel()->GetEntry(pDataSource, CONTAINER_TABLES);
else if(CommandType::QUERY == m_nDefaultCommandType)
pCommandType = m_pTreeView->getListBox()->GetModel()->GetEntry(pDataSource, CONTAINER_QUERIES);
if(pCommandType)
{
// we need to expand the command
m_pTreeView->getListBox()->Expand(pCommandType);
SvLBoxEntry* pCommand = m_pTreeView->getListBox()->GetEntryPosByName(m_sDefaultCommand,pCommandType);
if(pCommand)
m_pTreeView->getListBox()->Select(pCommand);
}
else // we have a command and need to display this in the rowset
{
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
if(xProp.is())
{
Reference< ::com::sun::star::form::XLoadable > xLoadable(xProp,UNO_QUERY);
try
{
// the values allowing the RowSet to re-execute
xProp->setPropertyValue(PROPERTY_DATASOURCENAME,makeAny(m_sDefaultDataSourceName));
// set this _before_ setting the connection, else the rowset would rebuild it ...
if(xConnection.is())
xProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,makeAny(xConnection));
xProp->setPropertyValue(PROPERTY_COMMANDTYPE,makeAny(m_nDefaultCommandType));
xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sDefaultCommand));
xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(aCatalogName));
xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(aSchemaName));
xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(aTableName));
xProp->setPropertyValue(PROPERTY_USE_ESCAPE_PROCESSING,::cppu::bool2any(bEsacpeProcessing));
// the formatter depends on the data source we're working on, so rebuild it here ...
initFormatter();
// switch the grid to design mode while loading
getBrowserView()->getGridControl()->setDesignMode(sal_True);
InitializeForm(getRowSet());
{
FormErrorHelper aHelper(this);
// load the row set
if (xLoadable->isLoaded())
// reload does not work if not already loaded
xLoadable->reload();
else
xLoadable->load();
// initialize the model
InitializeGridModel(getFormComponent());
Reference< ::com::sun::star::form::XLoadable > xLoadable(getRowSet(),UNO_QUERY);
if (xLoadable->isLoaded() && !errorOccured())
xLoadable->reload();
}
FormLoaded(sal_True);
}
catch(SQLException& e)
{
showError(SQLExceptionInfo(e));
}
catch(Exception&)
{
}
}
}
}
}
}
// -------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::haveExplorer() const
{
return m_pTreeView && m_pTreeView->IsVisible();
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::hideExplorer()
{
if (!haveExplorer())
return;
if (!getBrowserView())
return;
m_pTreeView->Hide();
m_pSplitter->Hide();
getBrowserView()->Resize();
InvalidateFeature(ID_BROWSER_EXPLORER);
}
// -------------------------------------------------------------------------
void SbaTableQueryBrowser::showExplorer()
{
if (haveExplorer())
return;
if (!getBrowserView())
return;
m_pTreeView->Show();
m_pSplitter->Show();
getBrowserView()->Resize();
InvalidateFeature(ID_BROWSER_EXPLORER);
}
// -----------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pAnyEntry, Reference< XConnection>& _xConnection)
{
SvLBoxEntry* pDSEntry = m_pTreeView->getListBox()->GetRootLevelParent(_pAnyEntry);
DBTreeListModel::DBTreeListUserData* pDSData =
pDSEntry
? static_cast<DBTreeListModel::DBTreeListUserData*>(pDSEntry->GetUserData())
: NULL;
return ensureConnection( pDSEntry, pDSData, _xConnection);
}
// -----------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pDSEntry, void* pDSData, Reference<XConnection>& _xConnection)
{
if(_pDSEntry)
{
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(pDSData);
::rtl::OUString aDSName = getEntryText(_pDSEntry);
if (pData)
_xConnection = Reference<XConnection>(pData->xObject,UNO_QUERY);
if(!_xConnection.is() && pData)
{
_xConnection = connect(aDSName);
pData->xObject = _xConnection; // share the conenction with the querydesign
}
}
return _xConnection.is();
}
// -----------------------------------------------------------------------------
IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortData )
{
SvLBoxEntry* pLHS = static_cast<SvLBoxEntry*>(_pSortData->pLeft);
SvLBoxEntry* pRHS = static_cast<SvLBoxEntry*>(_pSortData->pRight);
DBG_ASSERT(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
DBG_ASSERT(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
String sLeftText = pLeftTextItem->GetText();
String sRightText = pRightTextItem->GetText();
sal_Int32 nCompareResult = 0; // equal by default
if (m_xCollator.is())
{
try
{
nCompareResult = m_xCollator->compareString(sLeftText, sRightText);
}
catch(Exception&)
{
}
}
else
// default behaviour if we do not have a collator -> do the simple string compare
nCompareResult = sLeftText.CompareTo(sRightText);
return nCompareResult;
}
// -----------------------------------------------------------------------------
void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo )
{
try
{
// the parameters:
Sequence< Any > aArgs(2);
// the parent window
aArgs[0] <<= PropertyValue(
::rtl::OUString::createFromAscii("ParentWindow"), 0,
makeAny(VCLUnoHelper::GetInterface(m_pTreeView->getListBox()->Window::GetParent())), PropertyState_DIRECT_VALUE);
// the initial selection
SvLBoxEntry* pTopLevelSelected = _pApplyTo;
while (pTopLevelSelected && m_pTreeView->getListBox()->GetParent(pTopLevelSelected))
pTopLevelSelected = m_pTreeView->getListBox()->GetParent(pTopLevelSelected);
::rtl::OUString sInitialSelection;
if (pTopLevelSelected)
sInitialSelection = m_pTreeView->getListBox()->GetEntryText(pTopLevelSelected);
aArgs[1] <<= PropertyValue(
::rtl::OUString::createFromAscii("InitialSelection"), 0,
makeAny(sInitialSelection), PropertyState_DIRECT_VALUE);
// create the dialog
Reference< XExecutableDialog > xAdminDialog;
xAdminDialog = Reference< XExecutableDialog >(
m_xMultiServiceFacatory->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.sdb.DatasourceAdministrationDialog"),
aArgs), UNO_QUERY);
// execute it
if (xAdminDialog.is())
xAdminDialog->execute();
}
catch(::com::sun::star::uno::Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::implAdministrate: caught an exception while creating/executing the dialog!");
}
}
// -----------------------------------------------------------------------------
void SbaTableQueryBrowser::implCreateObject( SvLBoxEntry* _pApplyTo, sal_uInt16 _nAction )
{
try
{
::osl::MutexGuard aGuard(m_aEntryMutex);
// get all needed properties for design
Reference<XConnection> xConnection; // supports the service sdb::connection
if(!ensureConnection(_pApplyTo, xConnection))
return;
::rtl::OUString sCurrentObject;
if ((ID_TREE_QUERY_EDIT == _nAction || ID_TREE_TABLE_EDIT == _nAction) && _pApplyTo)
{
// get the name of the query
SvLBoxItem* pQueryTextItem = _pApplyTo->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
if (pQueryTextItem)
sCurrentObject = static_cast<SvLBoxString*>(pQueryTextItem)->GetText();
DBTreeListModel::DBTreeListUserData* pData = static_cast<DBTreeListModel::DBTreeListUserData*>(_pApplyTo->GetUserData());
if(!pData)
{
// the query has not been accessed before -> create it's user data
pData = new DBTreeListModel::DBTreeListUserData;
pData->bTable = sal_False;
Reference<XNameAccess> xNameAccess;
if(ID_TREE_TABLE_EDIT == _nAction)
{
Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
if(xSup.is())
xNameAccess = xSup->getTables();
}
else
{
Reference<XQueriesSupplier> xSup(xConnection,UNO_QUERY);
if(xSup.is())
xNameAccess = xSup->getQueries();
}
SvLBoxItem* pTextItem = _pApplyTo->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
if (pTextItem)
sCurrentObject = static_cast<SvLBoxString*>(pTextItem)->GetText();
if(xNameAccess.is() && xNameAccess->hasByName(sCurrentObject) &&
::cppu::extractInterface(pData->xObject,xNameAccess->getByName(sCurrentObject))) // remember the table or query object
_pApplyTo->SetUserData(pData);
else
{
delete pData;
pData = NULL;
}
}
}
ODesignAccess* pDispatcher = NULL;
sal_Bool bEdit = sal_False;
switch(_nAction)
{
case ID_TREE_RELATION_DESIGN:
pDispatcher = new ORelationDesignAccess(m_xMultiServiceFacatory) ;
break;
case ID_TREE_TABLE_EDIT:
bEdit = sal_True; // run through
case ID_TREE_TABLE_CREATE_DESIGN:
pDispatcher = new OTableDesignAccess(m_xMultiServiceFacatory) ;
break;
case ID_TREE_QUERY_EDIT:
bEdit = sal_True; // run through
case ID_TREE_QUERY_CREATE_DESIGN:
case ID_TREE_QUERY_CREATE_TEXT:
pDispatcher = new OQueryDesignAccess(m_xMultiServiceFacatory) ;
break;
}
::rtl::OUString aDSName = getEntryText( m_pTreeView->getListBox()->GetRootLevelParent( _pApplyTo ) );
if (bEdit)
pDispatcher->edit(aDSName, sCurrentObject, xConnection);
else
pDispatcher->create(aDSName, xConnection, ID_TREE_QUERY_CREATE_DESIGN == _nAction);
}
catch(SQLException& e)
{
showError(SQLExceptionInfo(e));
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::implCreateObject: caught an exception!");
}
}
// -----------------------------------------------------------------------------
void SbaTableQueryBrowser::implRemoveQuery( SvLBoxEntry* _pApplyTo )
{
String sDsName = getEntryText( m_pTreeView->getListBox()->GetRootLevelParent( _pApplyTo ) );
String sName = getEntryText( _pApplyTo );
if (!sDsName.Len() || sName.Len())
{
DBG_ERROR("SbaTableQueryBrowser::implRemoveQuery: invalid entries detected!");
return;
}
String aMsg(ModuleRes(STR_QUERY_DELETE_QUERY));
aMsg.SearchAndReplace(String::CreateFromAscii("%1"), sName);
OSQLMessageBox aDlg(getBrowserView()->getVclControl(),String(ModuleRes(STR_TITLE_CONFIRM_DELETION )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
if(aDlg.Execute() == RET_YES)
{
Reference<XQueryDefinitionsSupplier> xSet;
try
{
if(m_xDatabaseContext->hasByName(sDsName))
m_xDatabaseContext->getByName(sDsName) >>= xSet;
}
catch(Exception&)
{
}
if(xSet.is())
{
Reference<XNameContainer> xNames(xSet->getQueryDefinitions(),UNO_QUERY);
if(xNames.is())
{
try
{
xNames->removeByName(sName);
}
catch(SQLException& e)
{
showError(SQLExceptionInfo(e));
}
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::implRemoveQuery: caught a generic exception!");
}
}
}
}
}
// -----------------------------------------------------------------------------
void SbaTableQueryBrowser::implDropTable( SvLBoxEntry* _pApplyTo )
{
::osl::MutexGuard aGuard(m_aEntryMutex);
Reference<XConnection> xConnection; // supports the service sdb::connection
if(!ensureConnection(_pApplyTo, xConnection))
return;
// get all needed properties for design
Reference<XTablesSupplier> xSup(xConnection,UNO_QUERY);
OSL_ENSURE(xSup.is(),"SbaTableQueryBrowser::implDropTable: no XTablesSuppier!");
if(!xSup.is())
return;
::rtl::OUString sTableName = getEntryText( _pApplyTo );
Reference<XNameAccess> xTables = xSup->getTables();
Reference<XDrop> xDrop(xTables,UNO_QUERY);
if(xDrop.is())
{
String aMsg(ModuleRes(STR_QUERY_DELETE_TABLE));
aMsg.SearchAndReplace(String::CreateFromAscii("%1"),String(sTableName));
OSQLMessageBox aDlg(getBrowserView()->getVclControl(),String(ModuleRes(STR_TITLE_CONFIRM_DELETION )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
if(aDlg.Execute() == RET_YES)
{
SQLExceptionInfo aErrorInfo;
try
{
xDrop->dropByName(sTableName);
}
catch(SQLContext& e) { aErrorInfo = e; }
catch(SQLWarning& e) { aErrorInfo = e; }
catch(SQLException& e) { aErrorInfo = e; }
catch(Exception&)
{
DBG_ERROR("SbaTableQueryBrowser::implDropTable: suspicious exception caught!");
}
if (aErrorInfo.isValid())
showError(aErrorInfo);
}
}
else
// TODO
;
}
// -----------------------------------------------------------------------------
sal_Bool SbaTableQueryBrowser::requestContextMenu( const CommandEvent& _rEvent )
{
PopupMenu aContextMenu(ModuleRes(MENU_BROWSERTREE_CONTEXT));
Point aPosition;
SvLBoxEntry* pEntry = NULL;
SvLBoxEntry* pOldSelection = NULL;
if (_rEvent.IsMouseEvent())
{
aPosition = _rEvent.GetMousePosPixel();
// ensure that the entry which the user clicked at is selected
pEntry = m_pTreeView->getListBox()->GetEntry(aPosition);
// if (!pEntry)
// // no context menu of no entry was hit ....
// return sal_False;
//
// OSL_ENSURE(pEntry,"No current entry!");
if (pEntry && !m_pTreeView->getListBox()->IsSelected(pEntry))
{
pOldSelection = m_pTreeView->getListBox()->FirstSelected();
m_pTreeView->getListBox()->lockAutoSelect();
m_pTreeView->getListBox()->Select(pEntry);
m_pTreeView->getListBox()->unlockAutoSelect();
}
}
else
{
// use the center of the current entry
pEntry = m_pTreeView->getListBox()->GetCurEntry();
OSL_ENSURE(pEntry,"No current entry!");
aPosition = m_pTreeView->getListBox()->GetEntryPos(pEntry);
aPosition.X() += m_pTreeView->getListBox()->GetOutputSizePixel().Width() / 2;
aPosition.Y() += m_pTreeView->getListBox()->GetEntryHeight() / 2;
}
// disable entries according to the currently selected entry
// does the datasource which the selected entry belongs to has an open connection ?
SvLBoxEntry* pDSEntry = NULL;
DBTreeListModel::DBTreeListUserData* pDSData = NULL;
if(pEntry)
{
pDSEntry = m_pTreeView->getListBox()->GetRootLevelParent(pEntry);
pDSData = pDSEntry
? static_cast<DBTreeListModel::DBTreeListUserData*>(pDSEntry->GetUserData())
: NULL;
}
if (!pDSData || !pDSData->xObject.is())
{ // no -> disable the connection-related menu entries
aContextMenu.EnableItem(ID_TREE_CLOSE_CONN, sal_False);
aContextMenu.EnableItem(ID_TREE_REBUILD_CONN, sal_False);
}
// enable menu entries
if(pEntry)
{
EntryType eType = getEntryType(pEntry);
// 1. for tables
sal_Bool bTablesOrTable = (ET_TABLE == eType) || (ET_TABLE_CONTAINER == eType);
// 1.1 new table / edit relations - available if a table or a table container is selected
aContextMenu.EnableItem(ID_TREE_TABLE_CREATE_DESIGN, bTablesOrTable);
aContextMenu.EnableItem(ID_TREE_RELATION_DESIGN, bTablesOrTable);
// 1.2 pasting tables
sal_Bool bPasteAble = bTablesOrTable;
if(bPasteAble)
{
TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard());
bPasteAble = aTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE)
|| aTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY)
|| aTransferData.HasFormat(SOT_FORMAT_RTF)
|| aTransferData.HasFormat(SOT_FORMATSTR_ID_HTML);
}
aContextMenu.EnableItem(ID_TREE_TABLE_PASTE, bPasteAble);
// 1.3 actions on existing tables
aContextMenu.EnableItem(ID_TREE_TABLE_EDIT, ET_TABLE == eType);
aContextMenu.EnableItem(ID_TREE_TABLE_DELETE, ET_TABLE == eType);
aContextMenu.EnableItem(ID_TREE_TABLE_COPY, ET_TABLE == eType);
// 2. for queries
// 2.1 creating new queries
sal_Bool bQueriesOrQuery = (ET_QUERY == eType) || (ET_QUERY_CONTAINER == eType);
aContextMenu.EnableItem(ID_TREE_QUERY_CREATE_DESIGN, bQueriesOrQuery);
aContextMenu.EnableItem(ID_TREE_QUERY_CREATE_TEXT, bQueriesOrQuery);
// 2.2 actions on existing queries
aContextMenu.EnableItem(ID_TREE_QUERY_EDIT, ET_QUERY == eType);
aContextMenu.EnableItem(ID_TREE_QUERY_DELETE, ET_QUERY == eType);
aContextMenu.EnableItem(ID_TREE_QUERY_COPY, ET_QUERY == eType);
}
else
{
// 1.1 new table / edit relations - available if a table or a table container is selected
aContextMenu.EnableItem(ID_TREE_TABLE_CREATE_DESIGN, FALSE);
aContextMenu.EnableItem(ID_TREE_RELATION_DESIGN, FALSE);
// 1.2 pasting tables
aContextMenu.EnableItem(ID_TREE_TABLE_PASTE, FALSE);
// 1.3 actions on existing tables
aContextMenu.EnableItem(ID_TREE_TABLE_EDIT, FALSE);
aContextMenu.EnableItem(ID_TREE_TABLE_DELETE, FALSE);
aContextMenu.EnableItem(ID_TREE_TABLE_COPY, FALSE);
// 2. for queries
// 2.1 creating new queries
aContextMenu.EnableItem(ID_TREE_QUERY_CREATE_DESIGN, FALSE);
aContextMenu.EnableItem(ID_TREE_QUERY_CREATE_TEXT, FALSE);
// 2.2 actions on existing queries
aContextMenu.EnableItem(ID_TREE_QUERY_EDIT, FALSE);
aContextMenu.EnableItem(ID_TREE_QUERY_DELETE, FALSE);
aContextMenu.EnableItem(ID_TREE_QUERY_COPY, FALSE);
}
// rebuild conn not implemented yet
aContextMenu.EnableItem(ID_TREE_REBUILD_CONN, sal_False);
if (!m_xMultiServiceFacatory.is())
// no ORB -> no administration dialog
aContextMenu.EnableItem(ID_TREE_ADMINISTRATE, sal_False);
// no disabled entries
aContextMenu.RemoveDisabledEntries();
sal_Bool bReopenConn = sal_False;
USHORT nPos = aContextMenu.Execute(m_pTreeView->getListBox(), aPosition);
// restore the old selection
if (pOldSelection)
{
m_pTreeView->getListBox()->lockAutoSelect();
m_pTreeView->getListBox()->Select(pOldSelection);
m_pTreeView->getListBox()->unlockAutoSelect();
}
switch (nPos)
{
case ID_TREE_ADMINISTRATE:
implAdministrate(pEntry);
break;
case ID_TREE_REBUILD_CONN:
bReopenConn = sal_True;
case ID_TREE_CLOSE_CONN:
closeConnection(pDSEntry);
break;
case ID_TREE_RELATION_DESIGN:
case ID_TREE_TABLE_CREATE_DESIGN:
case ID_TREE_QUERY_CREATE_DESIGN:
case ID_TREE_QUERY_CREATE_TEXT:
case ID_TREE_QUERY_EDIT:
case ID_TREE_TABLE_EDIT:
implCreateObject( pEntry, nPos );
break;
case ID_TREE_QUERY_DELETE:
implRemoveQuery(pDSEntry);
break;
case ID_TREE_TABLE_DELETE:
implDropTable( pEntry );
break;
case ID_TREE_QUERY_COPY:
implCopyObject( pEntry, CommandType::QUERY );
break;
case ID_TREE_TABLE_COPY:
{
TransferableHelper* pTransfer = implCopyObject( pEntry, CommandType::TABLE );
Reference< XTransferable> aEnsureDelete = pTransfer;
if (pTransfer)
pTransfer->CopyToClipboard();
}
break;
case ID_TREE_TABLE_PASTE:
{
TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard());
implPasteTable( pEntry, aTransferData );
}
break;
}
return sal_True; // handled
}
// -----------------------------------------------------------------------------
String SbaTableQueryBrowser::getEntryText( SvLBoxEntry* _pEntry )
{
SvLBoxItem* pTextItem = _pEntry ? _pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING) : NULL;
if (pTextItem)
return static_cast<SvLBoxString*>(pTextItem)->GetText();
return String();
}
// -----------------------------------------------------------------------------
SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvLBoxEntry* _pEntry )
{
if (!_pEntry)
return ET_UNKNOWN;
SvLBoxEntry* pRootEntry = m_pTreeView->getListBox()->GetRootLevelParent(_pEntry);
SvLBoxEntry* pEntryParent = m_pTreeView->getListBox()->GetParent(_pEntry);
SvLBoxEntry* pTables = m_pTreeView->getListBox()->GetEntry(pRootEntry, CONTAINER_TABLES);
SvLBoxEntry* pQueries = m_pTreeView->getListBox()->GetEntry(pRootEntry, CONTAINER_QUERIES);
if (pEntryParent == _pEntry)
return ET_DATASOURCE;
if (pTables == _pEntry)
return ET_TABLE_CONTAINER;
if (pQueries == _pEntry)
return ET_QUERY_CONTAINER;
if (pTables == pEntryParent)
return ET_TABLE;
if (pQueries == pEntryParent)
return ET_QUERY;
return ET_UNKNOWN;
}
// .........................................................................
} // namespace dbaui
// .........................................................................
|