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
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
|
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Tasktop Technologies - Bug 302529 [UX] [Progress] Show Eclipse IDE progress in the Eclipse icon on the Windows 7 Task Bar
*******************************************************************************/
package org.eclipse.ui.internal;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.State;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
import org.eclipse.jface.action.ContributionManager;
import org.eclipse.jface.action.CoolBarManager;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.IContributionManagerOverrides;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.custom.CBanner;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TaskBar;
import org.eclipse.swt.widgets.TaskItem;
import org.eclipse.ui.ActiveShellExpression;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPageListener;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IPersistable;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.handlers.RegistryToggleState;
import org.eclipse.ui.internal.StartupThreading.StartupRunnable;
import org.eclipse.ui.internal.actions.CommandAction;
import org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog;
import org.eclipse.ui.internal.dnd.DragUtil;
import org.eclipse.ui.internal.dnd.SwtUtil;
import org.eclipse.ui.internal.handlers.ActionCommandMappingService;
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
import org.eclipse.ui.internal.intro.IIntroConstants;
import org.eclipse.ui.internal.layout.CacheWrapper;
import org.eclipse.ui.internal.layout.ITrimManager;
import org.eclipse.ui.internal.layout.IWindowTrim;
import org.eclipse.ui.internal.layout.LayoutUtil;
import org.eclipse.ui.internal.layout.TrimLayout;
import org.eclipse.ui.internal.menus.IActionSetsListener;
import org.eclipse.ui.internal.menus.LegacyActionPersistence;
import org.eclipse.ui.internal.menus.TrimBarManager2;
import org.eclipse.ui.internal.menus.TrimContributionManager;
import org.eclipse.ui.internal.menus.WorkbenchMenuService;
import org.eclipse.ui.internal.misc.Policy;
import org.eclipse.ui.internal.misc.UIListenerLogging;
import org.eclipse.ui.internal.misc.UIStats;
import org.eclipse.ui.internal.presentations.DefaultActionBarPresentationFactory;
import org.eclipse.ui.internal.progress.ProgressRegion;
import org.eclipse.ui.internal.progress.TaskBarProgressManager;
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
import org.eclipse.ui.internal.registry.ActionSetRegistry;
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
import org.eclipse.ui.internal.registry.UIExtensionTracker;
import org.eclipse.ui.internal.services.EvaluationReference;
import org.eclipse.ui.internal.services.IServiceLocatorCreator;
import org.eclipse.ui.internal.services.IWorkbenchLocationService;
import org.eclipse.ui.internal.services.ServiceLocator;
import org.eclipse.ui.internal.services.WorkbenchLocationService;
import org.eclipse.ui.internal.tweaklets.Tweaklets;
import org.eclipse.ui.internal.tweaklets.WorkbenchImplementation;
import org.eclipse.ui.internal.util.PrefUtil;
import org.eclipse.ui.internal.util.Util;
import org.eclipse.ui.menus.IMenuService;
import org.eclipse.ui.menus.MenuUtil;
import org.eclipse.ui.presentations.AbstractPresentationFactory;
import org.eclipse.ui.services.IDisposable;
import org.eclipse.ui.services.IEvaluationService;
import org.eclipse.ui.services.IServiceScopes;
/**
* A window within the workbench.
*/
public class WorkbenchWindow extends ApplicationWindow implements
IWorkbenchWindow {
private WorkbenchWindowAdvisor windowAdvisor;
private ActionBarAdvisor actionBarAdvisor;
private int number;
private PageList pageList = new PageList();
private PageListenerList pageListeners = new PageListenerList();
private PerspectiveListenerList perspectiveListeners = new PerspectiveListenerList();
private WWinPartService partService = new WWinPartService(this);
private ActionPresentation actionPresentation;
private WWinActionBars actionBars;
private boolean updateDisabled = true;
private boolean closing = false;
private boolean shellActivated = false;
private FastViewBar fastViewBar;
private PerspectiveSwitcher perspectiveSwitcher = null;
private TrimLayout defaultLayout;
ProgressRegion progressRegion = null;
// Legacy (3.2) contribution handling
private TrimBarManager2 trimMgr2 = null;
// 3.3 Trim Contribution handling
private TrimContributionManager trimContributionMgr = null;
/**
* The map of services maintained by the workbench window. These services
* are initialized during workbench window during the
* {@link #configureShell(Shell)}.
*/
private final ServiceLocator serviceLocator;
private HeapStatus heapStatus;
private WindowTrimProxy heapStatusTrim = null;
private boolean emptyWindowContentsCreated = false;
private Control emptyWindowContents;
private Rectangle normalBounds;
private boolean asMaximizedState = false;
private CBanner topBar;
private IWindowTrim topBarTrim;
// Previous shell size. Used to prevent the CBanner from triggering
// redundant layouts
private Point lastShellSize = new Point(0, 0);
/**
* The composite under which workbench pages create their controls.
*
* @since 3.0
*/
private Composite pageComposite;
/**
* Bit flags indication which submenus (New, Show Views, ...) this window
* contains. Initially none.
*
* @since 3.0
*/
private int submenus = 0x00;
/**
* Object for configuring this workbench window. Lazily initialized to an
* instance unique to this window.
*
* @since 3.0
*/
private WorkbenchWindowConfigurer windowConfigurer = null;
/**
* List of generic property listeners.
*
* @since 3.3
*/
private ListenerList genericPropertyListeners = new ListenerList();
private ShellPool detachedWindowShells;
static final String TEXT_DELIMITERS = TextProcessor.getDefaultDelimiters() + "-"; //$NON-NLS-1$
// constants for shortcut bar group ids
static final String GRP_PAGES = "pages"; //$NON-NLS-1$
static final String GRP_PERSPECTIVES = "perspectives"; //$NON-NLS-1$
static final String GRP_FAST_VIEWS = "fastViews"; //$NON-NLS-1$
// static fields for inner classes.
static final int VGAP = 0;
static final int CLIENT_INSET = 3;
static final int BAR_SIZE = 23;
/**
* Coolbar visibility change property.
*
* @since 3.3
*/
public static final String PROP_COOLBAR_VISIBLE = "coolbarVisible"; //$NON-NLS-1$
/**
* Perspective bar visibility change property.
*
* @since 3.3
*/
public static final String PROP_PERSPECTIVEBAR_VISIBLE = "perspectiveBarVisible"; //$NON-NLS-1$
/**
* The status line visibility change property. for internal use only.
*
* @since 3.4
*/
public static final String PROP_STATUS_LINE_VISIBLE = "statusLineVisible"; //$NON-NLS-1$
/**
* Constant (bit mask) indicating which the Show View submenu is probably
* present somewhere in this window.
*
* @see #addSubmenu
* @since 3.0
*/
public static final int SHOW_VIEW_SUBMENU = 0x01;
/**
* Constant (bit mask) indicating which the Open Perspective submenu is
* probably present somewhere in this window.
*
* @see #addSubmenu
* @since 3.0
*/
public static final int OPEN_PERSPECTIVE_SUBMENU = 0x02;
/**
* Constant (bit mask) indicating which the New Wizard submenu is probably
* present somewhere in this window.
*
* @see #addSubmenu
* @since 3.0
*/
public static final int NEW_WIZARD_SUBMENU = 0x04;
/**
* Remembers that this window contains the given submenu.
*
* @param type
* the type of submenu, one of:
* {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
* {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
* {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
* @see #containsSubmenu
* @since 3.0
*/
public void addSubmenu(int type) {
submenus |= type;
}
/**
* Checks to see if this window contains the given type of submenu.
*
* @param type
* the type of submenu, one of:
* {@link #NEW_WIZARD_SUBMENU NEW_WIZARD_SUBMENU},
* {@link #OPEN_PERSPECTIVE_SUBMENU OPEN_PERSPECTIVE_SUBMENU},
* {@link #SHOW_VIEW_SUBMENU SHOW_VIEW_SUBMENU}
* @return <code>true</code> if window contains submenu,
* <code>false</code> otherwise
* @see #addSubmenu
* @since 3.0
*/
public boolean containsSubmenu(int type) {
return ((submenus & type) != 0);
}
/**
* Constant indicating that all the actions bars should be filled.
*
* @since 3.0
*/
private static final int FILL_ALL_ACTION_BARS = ActionBarAdvisor.FILL_MENU_BAR
| ActionBarAdvisor.FILL_COOL_BAR
| ActionBarAdvisor.FILL_STATUS_LINE;
/**
* Creates and initializes a new workbench window.
*
* @param number
* the number for the window
*/
public WorkbenchWindow(int number) {
super(null);
this.number = number;
// Initialize a previous 'saved' state if applicable.
this.coolBarVisible = PrefUtil.getInternalPreferenceStore().getBoolean(
IPreferenceConstants.COOLBAR_VISIBLE);
this.perspectiveBarVisible = PrefUtil.getInternalPreferenceStore().getBoolean(
IPreferenceConstants.PERSPECTIVEBAR_VISIBLE);
// Make sure there is a workbench. This call will throw
// an exception if workbench not created yet.
final IWorkbench workbench = PlatformUI.getWorkbench();
IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
.getService(IServiceLocatorCreator.class);
this.serviceLocator = (ServiceLocator) slc
.createServiceLocator(workbench, null, new IDisposable(){
public void dispose() {
final Shell shell = getShell();
if (shell != null && !shell.isDisposed()) {
close();
}
}
});
initializeDefaultServices();
// Add contribution managers that are exposed to other plugins.
addMenuBar();
addCoolBar(SWT.NONE); // style is unused
addStatusLine();
// register with the tracker
getExtensionTracker()
.registerHandler(
actionSetHandler,
ExtensionTracker
.createExtensionPointFilter(getActionSetExtensionPoint()));
fireWindowOpening();
// set the shell style
setShellStyle(getWindowConfigurer().getShellStyle());
// Fill the action bars
fillActionBars(FILL_ALL_ACTION_BARS);
}
/**
* Return the action set extension point.
*
* @return the action set extension point
* @since 3.1
*/
private IExtensionPoint getActionSetExtensionPoint() {
return Platform.getExtensionRegistry().getExtensionPoint(
PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTION_SETS);
}
/**
* Return the style bits for the shortcut bar.
*
* @return int
*/
protected int perspectiveBarStyle() {
return SWT.FLAT | SWT.WRAP | SWT.RIGHT | SWT.HORIZONTAL;
}
private TrimDropTarget trimDropTarget;
private boolean coolBarVisible = true;
private boolean perspectiveBarVisible = true;
private boolean fastViewBarVisible = true;
private boolean statusLineVisible = true;
private IWindowTrim statusLineTrim = null;
/**
* The handlers for global actions that were last submitted to the workbench
* command support. This is a map of command identifiers to
* <code>ActionHandler</code>. This map is never <code>null</code>,
* and is never empty as long as at least one global action has been
* registered.
*/
private Map globalActionHandlersByCommandId = new HashMap();
/**
* The list of handler submissions submitted to the workbench command
* support. This list may be empty, but it is never <code>null</code>.
*/
private List handlerActivations = new ArrayList();
/**
* The number of large updates that are currently going on. If this is
* number is greater than zero, then UI updateActionBars is a no-op.
*
* @since 3.1
*/
private int largeUpdates = 0;
private IExtensionTracker tracker;
private IExtensionChangeHandler actionSetHandler = new IExtensionChangeHandler() {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker,
* org.eclipse.core.runtime.IExtension)
*/
public void addExtension(IExtensionTracker tracker, IExtension extension) {
// this assumes that the workbench-level tracker will have already
// updated the registry
ArrayList setsToActivate = new ArrayList();
// look for all new sets that are on by default. Examine the tracker
// at the workbench level to see what descriptors are registered
// against this extension
Object[] registeredObjects = getWorkbench().getExtensionTracker()
.getObjects(extension);
for (int i = 0; i < registeredObjects.length; i++) {
if (registeredObjects[i] instanceof IActionSetDescriptor) {
IActionSetDescriptor desc = (IActionSetDescriptor) registeredObjects[i];
if (desc.isInitiallyVisible()) {
setsToActivate.add(desc);
}
}
}
// if none of the new sets are marked as initially visible, abort.
if (setsToActivate.isEmpty()) {
return;
}
IActionSetDescriptor[] descriptors = (IActionSetDescriptor[]) setsToActivate
.toArray(new IActionSetDescriptor[setsToActivate.size()]);
WorkbenchPage page = getActiveWorkbenchPage();
if (page != null) {
Perspective[] perspectives = page.getOpenInternalPerspectives();
for (int i = 0; i < perspectives.length; i++) {
perspectives[i].turnOnActionSets(descriptors);
}
}
updateActionSets();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
* java.lang.Object[])
*/
public void removeExtension(IExtension extension, Object[] objects) {
// remove the contributions from the window bars and dispose of the
// actions
for (int i = 0; i < objects.length; i++) {
if (objects[i] instanceof PluginActionSetBuilder.Binding) {
PluginActionSetBuilder.Binding binding = (PluginActionSetBuilder.Binding) objects[i];
binding.tracker = null;
binding.builder.removeActionExtensions(binding.set,
binding.window);
binding.set.dispose();
}
}
// update all opened perspectives
Perspective[] perspectives = getActiveWorkbenchPage()
.getOpenInternalPerspectives();
boolean updateNeeded = true;
IContextService contextService = (IContextService) getService(IContextService.class);
try {
contextService.deferUpdates(true);
for (int i = 0; i < perspectives.length; i++) {
for (int j = 0; j < objects.length; j++) {
if (objects[j] instanceof IActionSetDescriptor) {
perspectives[i]
.removeActionSet((IActionSetDescriptor) objects[j]);
getActionPresentation().removeActionSet(
(IActionSetDescriptor) objects[j]);
}
}
}
} finally {
contextService.deferUpdates(false);
}
if (updateNeeded) {
// refresh the window
updateActionSets();
}
}
};
void registerGlobalAction(IAction globalAction) {
String commandId = globalAction.getActionDefinitionId();
if (commandId != null) {
final Object value = globalActionHandlersByCommandId.remove(commandId);
if (value instanceof ActionHandler) {
// This handler is about to get clobbered, so dispose it.
final ActionHandler handler = (ActionHandler) value;
handler.dispose();
}
if (globalAction instanceof CommandAction) {
final String actionId = globalAction.getId();
if (actionId != null) {
final IActionCommandMappingService mappingService = (IActionCommandMappingService) serviceLocator
.getService(IActionCommandMappingService.class);
mappingService.map(actionId, commandId);
}
} else {
globalActionHandlersByCommandId.put(commandId,
new ActionHandler(globalAction));
}
}
submitGlobalActions();
}
/**
* <p>
* Submits the action handlers for action set actions and global actions.
* Global actions are given priority, so that if a global action and an
* action set action both handle the same command, the global action is
* given priority.
* </p>
* <p>
* These submissions are submitted as <code>Priority.LEGACY</code>, which
* means that they are the lowest priority. This means that if a higher
* priority submission handles the same command under the same conditions,
* that that submission will become the handler.
* </p>
*/
void submitGlobalActions() {
final IHandlerService handlerService = (IHandlerService) getWorkbench().getService(IHandlerService.class);
/*
* Mash the action sets and global actions together, with global actions
* taking priority.
*/
Map handlersByCommandId = new HashMap();
handlersByCommandId.putAll(globalActionHandlersByCommandId);
List newHandlers = new ArrayList(handlersByCommandId.size());
Iterator existingIter = handlerActivations.iterator();
while (existingIter.hasNext()) {
IHandlerActivation next = (IHandlerActivation) existingIter.next();
String cmdId = next.getCommandId();
Object handler = handlersByCommandId.get(cmdId);
if (handler == next.getHandler()) {
handlersByCommandId.remove(cmdId);
newHandlers.add(next);
} else {
handlerService.deactivateHandler(next);
}
}
final Shell shell = getShell();
if (shell != null) {
final Expression expression = new ActiveShellExpression(shell);
for (Iterator iterator = handlersByCommandId.entrySet().iterator(); iterator
.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String commandId = (String) entry.getKey();
IHandler handler = (IHandler) entry.getValue();
newHandlers.add(handlerService.activateHandler(commandId,
handler, expression));
}
}
handlerActivations = newHandlers;
}
/**
* Add a generic property listener.
*
* @param listener the listener to add
* @since 3.3
*/
public void addPropertyChangeListener(IPropertyChangeListener listener) {
genericPropertyListeners.add(listener);
}
/**
* Removes a generic property listener.
*
* @param listener the listener to remove
* @since 3.3
*/
public void removePropertyChangeListener(IPropertyChangeListener listener) {
genericPropertyListeners.remove(listener);
}
private void firePropertyChanged(final String property, final Object oldValue, final Object newValue) {
PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue);
Object[] listeners = genericPropertyListeners.getListeners();
for (int i = 0; i < listeners.length; i++) {
IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
listener.propertyChange(event);
}
}
/*
* Adds an listener to the part service.
*/
public void addPageListener(IPageListener l) {
pageListeners.addPageListener(l);
}
/**
* @see org.eclipse.ui.IPageService
*/
public void addPerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
perspectiveListeners.addPerspectiveListener(l);
}
/**
* Configures this window to have a perspecive bar. Does nothing if it
* already has one.
*/
protected void addPerspectiveBar(int style) {
Assert.isTrue(perspectiveSwitcher == null);
perspectiveSwitcher = new PerspectiveSwitcher(this, topBar, style);
}
/**
* Close the window.
*
* Assumes that busy cursor is active.
*/
private boolean busyClose() {
// Whether the window was actually closed or not
boolean windowClosed = false;
// Setup internal flags to indicate window is in
// progress of closing and no update should be done.
closing = true;
updateDisabled = true;
try {
Workbench workbench = getWorkbenchImpl();
if (shouldCloseWorkbench(workbench)) {
windowClosed = workbench.close();
} else {
if (okToClose()) {
windowClosed = hardClose();
}
}
} finally {
if (!windowClosed) {
// Reset the internal flags if window was not closed.
closing = false;
updateDisabled = false;
}
}
if (windowClosed && tracker != null) {
tracker.close();
}
return windowClosed;
}
/**
*
* Checks and returns whether we should close the workbench when closing
* this window
*
* @param workbench
* @return <code>true</code>, if the workbench needs to be closed,
* <code>false</code> otherwise
*/
private boolean shouldCloseWorkbench(Workbench workbench) {
// also check for starting - if the first window dies on startup
// then we'll need to open a default window.
if (workbench.isStarting())
return false;
// Only do the check if it is OK to close if we are not closing
// via the workbench as the workbench will check this itself.
if (workbench.isClosing())
return false;
int count = workbench.getWorkbenchWindowCount();
// we have more windows apart from this. Dont' close workbench
if(count >1 )
return false;
// now do whatever the workbenchconfigurer says ...
return workbench.getWorkbenchConfigurer().getExitOnLastWindowClose();
}
/**
* Opens a new page. Assumes that busy cursor is active.
* <p>
* <b>Note:</b> Since release 2.0, a window is limited to contain at most
* one page. If a page exist in the window when this method is used, then
* another window is created for the new page. Callers are strongly
* recommended to use the <code>IWorkbench.openPerspective</code> APIs to
* programmatically show a perspective.
* </p>
*/
protected IWorkbenchPage busyOpenPage(String perspID, IAdaptable input)
throws WorkbenchException {
IWorkbenchPage newPage = null;
if (pageList.isEmpty()) {
newPage = ((WorkbenchImplementation) Tweaklets
.get(WorkbenchImplementation.KEY)).createWorkbenchPage(this, perspID, input);
pageList.add(newPage);
firePageOpened(newPage);
setActivePage(newPage);
} else {
IWorkbenchWindow window = getWorkbench().openWorkbenchWindow(
perspID, input);
newPage = window.getActivePage();
}
return newPage;
}
/**
* @see Window
*/
public int open() {
if (getPages().length == 0) {
showEmptyWindowContents();
}
fireWindowCreated();
getWindowAdvisor().openIntro();
int result = super.open();
// It's time for a layout ... to insure that if TrimLayout
// is in play, it updates all of the trim it's responsible
// for. We have to do this before updating in order to get
// the PerspectiveBar management correct...see defect 137334
getShell().layout();
fireWindowOpened();
if (perspectiveSwitcher != null) {
perspectiveSwitcher.updatePerspectiveBar();
perspectiveSwitcher.updateBarParent();
}
return result;
}
/*
* (non-Javadoc) Method declared on Window.
*/
protected boolean canHandleShellCloseEvent() {
if (!super.canHandleShellCloseEvent()) {
return false;
}
// Ensure that any pending 'Close' event are flushed
// before opening any dialogs
final boolean[] boundingAsynchDone = { false };
Display display = getShell().getDisplay();
display.asyncExec(new Runnable() {
public void run() {
boundingAsynchDone[0] = true;
}
});
while (!boundingAsynchDone[0] && display.readAndDispatch())
;
// let the advisor or other interested parties
// veto the user's explicit request to close the window
return fireWindowShellClosing();
}
/**
* @see IWorkbenchWindow
*/
public boolean close() {
final boolean[] ret = new boolean[1];
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
ret[0] = busyClose();
}
});
return ret[0];
}
protected boolean isClosing() {
return closing || getWorkbenchImpl().isClosing();
}
/**
* Close all of the pages.
*/
private void closeAllPages() {
// Deactivate active page.
setActivePage(null);
// Clone and deref all so that calls to getPages() returns
// empty list (if call by pageClosed event handlers)
PageList oldList = pageList;
pageList = new PageList();
// Close all.
Iterator itr = oldList.iterator();
while (itr.hasNext()) {
WorkbenchPage page = (WorkbenchPage) itr.next();
firePageClosed(page);
page.dispose();
}
if (!closing) {
showEmptyWindowContents();
}
}
/**
* Save and close all of the pages.
*/
public void closeAllPages(boolean save) {
if (save) {
boolean ret = saveAllPages(true);
if (!ret) {
return;
}
}
closeAllPages();
}
/**
* closePerspective method comment.
*/
protected boolean closePage(IWorkbenchPage in, boolean save) {
// Validate the input.
if (!pageList.contains(in)) {
return false;
}
WorkbenchPage oldPage = (WorkbenchPage) in;
// Save old perspective.
if (save && oldPage.isSaveNeeded()) {
if (!oldPage.saveAllEditors(true)) {
return false;
}
}
// If old page is activate deactivate.
boolean oldIsActive = (oldPage == getActiveWorkbenchPage());
if (oldIsActive) {
setActivePage(null);
}
// Close old page.
pageList.remove(oldPage);
firePageClosed(oldPage);
oldPage.dispose();
// Activate new page.
if (oldIsActive) {
IWorkbenchPage newPage = pageList.getNextActive();
if (newPage != null) {
setActivePage(newPage);
}
}
if (!closing && pageList.isEmpty()) {
showEmptyWindowContents();
}
return true;
}
private void showEmptyWindowContents() {
if (!emptyWindowContentsCreated) {
Composite parent = getPageComposite();
emptyWindowContents = getWindowAdvisor().createEmptyWindowContents(
parent);
emptyWindowContentsCreated = true;
// force the empty window composite to be layed out
((StackLayout) parent.getLayout()).topControl = emptyWindowContents;
parent.layout();
}
}
private void hideEmptyWindowContents() {
if (emptyWindowContentsCreated) {
if (emptyWindowContents != null) {
emptyWindowContents.dispose();
emptyWindowContents = null;
getPageComposite().layout();
}
emptyWindowContentsCreated = false;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell(Shell shell) {
super.configureShell(shell);
detachedWindowShells = new ShellPool(shell, SWT.TOOL | SWT.TITLE
| SWT.MAX | SWT.RESIZE | getDefaultOrientation());
String title = getWindowConfigurer().basicGetTitle();
if (title != null) {
shell.setText(TextProcessor.process(title, TEXT_DELIMITERS));
}
final IWorkbench workbench = getWorkbench();
workbench.getHelpSystem().setHelp(shell,
IWorkbenchHelpContextIds.WORKBENCH_WINDOW);
// initializeDefaultServices();
final IContextService contextService = (IContextService) getWorkbench().getService(IContextService.class);
contextService.registerShell(shell, IContextService.TYPE_WINDOW);
trackShellActivation(shell);
trackShellResize(shell);
}
/* package */ShellPool getDetachedWindowPool() {
return detachedWindowShells;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.ApplicationWindow#createTrimWidgets(org.eclipse.swt.widgets.Shell)
*/
protected void createTrimWidgets(Shell shell) {
// do nothing -- trim widgets are created in createDefaultContents
}
/**
* Creates and remembers the client composite, under which workbench pages
* create their controls.
*
* @since 3.0
*/
protected Composite createPageComposite(Composite parent) {
pageComposite = new Composite(parent, SWT.NONE);
// use a StackLayout instead of a FillLayout (see bug 81460 [Workbench]
// (regression) Close all perspectives, open Java perspective, layout
// wrong)
pageComposite.setLayout(new StackLayout());
return pageComposite;
}
/**
* Creates the contents of the workbench window, including trim controls and
* the client composite. This MUST create the client composite via a call to
* <code>createClientComposite</code>.
*
* @since 3.0
*/
protected Control createContents(Composite parent) {
// we know from Window.create that the parent is a Shell.
getWindowAdvisor().createWindowContents((Shell) parent);
// the page composite must be set by createWindowContents
Assert
.isNotNull(pageComposite,
"createWindowContents must call configurer.createPageComposite"); //$NON-NLS-1$
return pageComposite;
}
/**
* If the perspective bar is drawn on the top right corner of the window,
* then this method changes its appearance from curved to square. This
* should have its own preference, but for now it piggy-backs on the
* SHOW_TRADITIONAL_STYLE_TABS preference.
*
* @param square
* true for a square banner and false otherwise
*/
public void setBannerCurve(boolean square) {
if (topBar != null) {
topBar.setSimple(square);
}
}
/**
* Creates the default contents and layout of the shell.
*
* @param shell
* the shell
*/
protected void createDefaultContents(final Shell shell) {
defaultLayout = new TrimLayout();
shell.setLayout(defaultLayout);
Menu menuBar = getMenuBarManager().createMenuBar(shell);
if (getWindowConfigurer().getShowMenuBar()) {
shell.setMenuBar(menuBar);
}
// Create the CBanner widget which parents both the Coolbar
// and the perspective switcher, and supports some configurations
// on the left right and bottom
topBar = new CBanner(shell, SWT.NONE);
topBarTrim = new WindowTrimProxy(topBar,
"org.eclipse.ui.internal.WorkbenchWindow.topBar", //$NON-NLS-1$
WorkbenchMessages.TrimCommon_Main_TrimName, SWT.NONE, true);
// the banner gets a curve along with the new tab style
// TODO create a dedicated preference for this
setBannerCurve(PrefUtil.getAPIPreferenceStore().getBoolean(
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
CacheWrapper coolbarCacheWrapper = new CacheWrapper(topBar);
final Control coolBar = createCoolBarControl(coolbarCacheWrapper
.getControl());
// need to resize the shell, not just the coolbar's immediate
// parent, if the coolbar wants to grow or shrink
coolBar.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
// If the user is dragging the sash then we will need to force
// a resize. However, if the coolbar was resized programatically
// then everything is already layed out correctly. There is no
// direct way to tell the difference between these cases,
// however
// we take advantage of the fact that dragging the sash does not
// change the size of the shell, and only force another layout
// if the shell size is unchanged.
Rectangle clientArea = shell.getClientArea();
if (lastShellSize.x == clientArea.width
&& lastShellSize.y == clientArea.height) {
LayoutUtil.resize(coolBar);
}
lastShellSize.x = clientArea.width;
lastShellSize.y = clientArea.height;
}
});
if (getWindowConfigurer().getShowCoolBar()) {
topBar.setLeft(coolbarCacheWrapper.getControl());
}
createStatusLine(shell);
fastViewBar = new FastViewBar(this);
fastViewBar.createControl(shell);
if (getWindowConfigurer().getShowPerspectiveBar()) {
addPerspectiveBar(perspectiveBarStyle());
perspectiveSwitcher.createControl(shell);
}
createProgressIndicator(shell);
if (getShowHeapStatus()) {
createHeapStatus(shell);
}
// Insert any contributed trim into the layout
// Legacy (3.2) trim
trimMgr2 = new TrimBarManager2(this);
// 3.3 Trim contributions
trimContributionMgr = new TrimContributionManager(this);
trimDropTarget = new TrimDropTarget(shell, this);
DragUtil.addDragTarget(shell, trimDropTarget);
DragUtil.addDragTarget(null, trimDropTarget);
// Create the client composite area (where page content goes).
createPageComposite(shell);
setLayoutDataForContents();
// System.err.println(defaultLayout.displayTrim());
}
/**
* Returns whether the heap status indicator should be shown.
*
* @return <code>true</code> to show the heap status indicator,
* <code>false</code> otherwise
*/
private boolean getShowHeapStatus() {
return // Show if the preference is set or debug option is on
PrefUtil.getAPIPreferenceStore().getBoolean(
IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR)
|| Boolean.valueOf(
Platform.getDebugOption(PlatformUI.PLUGIN_ID
+ "/perf/showHeapStatus")).booleanValue(); //$NON-NLS-1$
}
/**
* Creates the controls for the heap status indicator.
*
* @param parent
* the parent composite
*/
private void createHeapStatus(Composite parent) {
heapStatus = new HeapStatus(parent, PrefUtil
.getInternalPreferenceStore());
// Subclass the trim to allow closing...
heapStatusTrim = new WindowTrimProxy(heapStatus,
"org.eclipse.ui.internal.HeapStatus", //$NON-NLS-1$
WorkbenchMessages.TrimCommon_HeapStatus_TrimName, SWT.BOTTOM
| SWT.TOP) {
public void handleClose() {
getControl().dispose();
}
public boolean isCloseable() {
return true;
}
};
}
private IContributionManagerOverrides menuOverride = new IContributionManagerOverrides() {
public Integer getAccelerator(IContributionItem item) {
return null;
}
public String getAcceleratorText(IContributionItem item) {
return null;
}
public Boolean getEnabled(IContributionItem item) {
return null;
}
public String getText(IContributionItem item) {
return null;
}
public Boolean getVisible(IContributionItem item) {
final IWorkbenchPage page = getActivePage();
if(page == null) {
return null;
}
Perspective perspective = ((WorkbenchPage)page).getActivePerspective();
//Find the command ID
String id = CustomizePerspectiveDialog.getIDFromIContributionItem(item);
if(id == null)
return null;
//Has the client intentionally hidden the menu item?
if(perspective != null && perspective.getHiddenMenuItems().contains(id)) {
return Boolean.FALSE;
}
return null;
}
};
private IContributionManagerOverrides toolbarOverride = new IContributionManagerOverrides() {
public Integer getAccelerator(IContributionItem item) {
return null;
}
public String getAcceleratorText(IContributionItem item) {
return null;
}
public Boolean getEnabled(IContributionItem item) {
return null;
}
public String getText(IContributionItem item) {
return null;
}
public Boolean getVisible(IContributionItem item) {
final IWorkbenchPage page = getActivePage();
if(page == null) {
return null;
}
Perspective perspective = ((WorkbenchPage)page).getActivePerspective();
//Find the command ID
String id = CustomizePerspectiveDialog.getIDFromIContributionItem(item);
if(id == null)
return null;
//Has the client intentionally hidden the menu item?
if(perspective != null && perspective.getHiddenToolbarItems().contains(id)) {
return Boolean.FALSE;
}
//Short circuit this logic
if(!item.isVisible())
return Boolean.FALSE;
return null;
}
};
/**
* <p>
* Returns a new menu manager for this workbench window. This menu manager
* will just be a proxy to the new command-based menu service.
* </p>
* <p>
* Subclasses may override this method to customize the menu manager.
* </p>
*
* @return a menu manager for this workbench window; never <code>null</code>.
*/
protected MenuManager createMenuManager() {
MenuManager manager = super.createMenuManager();
manager.setOverrides(menuOverride);
return manager;
}
/**
* Set the perspective bar location
*
* @param location
* the location to place the bar
*/
public void setPerspectiveBarLocation(String location) {
if (perspectiveSwitcher != null) {
perspectiveSwitcher.setPerspectiveBarLocation(location);
}
updateLayoutDataForContents();
getShell().layout();
}
/**
* Notifies interested parties (namely the advisor) that the window is about
* to be opened.
*
* @since 3.1
*/
private void fireWindowOpening() {
// let the application do further configuration
getWindowAdvisor().preWindowOpen();
}
/**
* Notifies interested parties (namely the advisor) that the window has been
* restored from a previously saved state.
*
* @throws WorkbenchException
* passed through from the advisor
* @since 3.1
*/
void fireWindowRestored() throws WorkbenchException {
StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
getWindowAdvisor().postWindowRestore();
}
});
}
/**
* Notifies interested parties (namely the advisor) that the window has been
* created.
*
* @since 3.1
*/
private void fireWindowCreated() {
getWindowAdvisor().postWindowCreate();
}
/**
* Notifies interested parties (namely the advisor and the window listeners)
* that the window has been opened.
*
* @since 3.1
*/
private void fireWindowOpened() {
getWorkbenchImpl().fireWindowOpened(this);
getWindowAdvisor().postWindowOpen();
}
/**
* Notifies interested parties (namely the advisor) that the window's shell
* is closing. Allows the close to be vetoed.
*
* @return <code>true</code> if the close should proceed,
* <code>false</code> if it should be canceled
* @since 3.1
*/
private boolean fireWindowShellClosing() {
return getWindowAdvisor().preWindowShellClose();
}
/**
* Notifies interested parties (namely the advisor and the window listeners)
* that the window has been closed.
*
* @since 3.1
*/
private void fireWindowClosed() {
// let the application do further deconfiguration
getWindowAdvisor().postWindowClose();
getWorkbenchImpl().fireWindowClosed(this);
}
/**
* Fires page activated
*/
private void firePageActivated(IWorkbenchPage page) {
String label = null; // debugging only
if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
label = "activated " + page.getLabel(); //$NON-NLS-1$
}
try {
UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
UIListenerLogging.logPageEvent(this, page,
UIListenerLogging.WPE_PAGE_ACTIVATED);
pageListeners.firePageActivated(page);
partService.pageActivated(page);
} finally {
UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
}
}
/**
* Fires page closed
*/
private void firePageClosed(IWorkbenchPage page) {
String label = null; // debugging only
if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
label = "closed " + page.getLabel(); //$NON-NLS-1$
}
try {
UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
UIListenerLogging.logPageEvent(this, page,
UIListenerLogging.WPE_PAGE_CLOSED);
pageListeners.firePageClosed(page);
partService.pageClosed(page);
} finally {
UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
}
}
/**
* Fires page opened
*/
private void firePageOpened(IWorkbenchPage page) {
String label = null; // debugging only
if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
label = "opened " + page.getLabel(); //$NON-NLS-1$
}
try {
UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
UIListenerLogging.logPageEvent(this, page,
UIListenerLogging.WPE_PAGE_OPENED);
pageListeners.firePageOpened(page);
partService.pageOpened(page);
} finally {
UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, page.getLabel(), label);
}
}
/**
* Fires perspective activated
*/
void firePerspectiveActivated(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
UIListenerLogging.logPerspectiveEvent(this, page, perspective,
UIListenerLogging.PLE_PERSP_ACTIVATED);
perspectiveListeners.firePerspectiveActivated(page, perspective);
}
/**
* Fires perspective deactivated.
*
* @since 3.2
*/
void firePerspectivePreDeactivate(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
UIListenerLogging.logPerspectiveEvent(this, page, perspective,
UIListenerLogging.PLE_PERSP_PRE_DEACTIVATE);
perspectiveListeners.firePerspectivePreDeactivate(page, perspective);
}
/**
* Fires perspective deactivated.
*
* @since 3.1
*/
void firePerspectiveDeactivated(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
UIListenerLogging.logPerspectiveEvent(this, page, perspective,
UIListenerLogging.PLE_PERSP_DEACTIVATED);
perspectiveListeners.firePerspectiveDeactivated(page, perspective);
}
/**
* Fires perspective changed
*/
public void firePerspectiveChanged(IWorkbenchPage page,
IPerspectiveDescriptor perspective, String changeId) {
// Some callers call this even when there is no active perspective.
// Just ignore this case.
if (perspective != null) {
UIListenerLogging.logPerspectiveChangedEvent(this, page,
perspective, null, changeId);
perspectiveListeners.firePerspectiveChanged(page, perspective,
changeId);
}
}
/**
* Fires perspective changed for an affected part
*/
public void firePerspectiveChanged(IWorkbenchPage page,
IPerspectiveDescriptor perspective,
IWorkbenchPartReference partRef, String changeId) {
// Some callers call this even when there is no active perspective.
// Just ignore this case.
if (perspective != null) {
UIListenerLogging.logPerspectiveChangedEvent(this, page,
perspective, partRef, changeId);
perspectiveListeners.firePerspectiveChanged(page, perspective,
partRef, changeId);
}
}
/**
* Fires perspective closed
*/
void firePerspectiveClosed(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
UIListenerLogging.logPerspectiveEvent(this, page, perspective,
UIListenerLogging.PLE_PERSP_CLOSED);
perspectiveListeners.firePerspectiveClosed(page, perspective);
}
/**
* Fires perspective opened
*/
void firePerspectiveOpened(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
UIListenerLogging.logPerspectiveEvent(this, page, perspective,
UIListenerLogging.PLE_PERSP_OPENED);
perspectiveListeners.firePerspectiveOpened(page, perspective);
}
/**
* Fires perspective saved as.
*
* @since 3.1
*/
void firePerspectiveSavedAs(IWorkbenchPage page,
IPerspectiveDescriptor oldPerspective,
IPerspectiveDescriptor newPerspective) {
UIListenerLogging.logPerspectiveSavedAs(this, page, oldPerspective,
newPerspective);
perspectiveListeners.firePerspectiveSavedAs(page, oldPerspective,
newPerspective);
}
/**
* Returns the action bars for this window.
*/
public WWinActionBars getActionBars() {
if (actionBars == null) {
actionBars = new WWinActionBars(this);
}
return actionBars;
}
/**
* Returns the active page.
*
* @return the active page
*/
public IWorkbenchPage getActivePage() {
return pageList.getActive();
}
/**
* Returns the active workbench page.
*
* @return the active workbench page
*/
/* package */
WorkbenchPage getActiveWorkbenchPage() {
return pageList.getActive();
}
/**
* Returns the page composite, under which the window's pages create their
* controls.
*/
protected Composite getPageComposite() {
return pageComposite;
}
/**
* Answer the menu manager for this window.
*/
public MenuManager getMenuManager() {
return getMenuBarManager();
}
/**
* Returns the number. This corresponds to a page number in a window or a
* window number in the workbench.
*/
public int getNumber() {
return number;
}
/**
* Returns an array of the pages in the workbench window.
*
* @return an array of pages
*/
public IWorkbenchPage[] getPages() {
return pageList.getPages();
}
/**
* @see IWorkbenchWindow
*/
public IPartService getPartService() {
return partService;
}
/**
* Returns the layout for the shell.
*
* @return the layout for the shell
*/
protected Layout getLayout() {
return null;
}
/**
* @see IWorkbenchWindow
*/
public ISelectionService getSelectionService() {
return partService.getSelectionService();
}
/**
* Returns <code>true</code> when the window's shell is activated,
* <code>false</code> when it's shell is deactivated
*
* @return boolean <code>true</code> when shell activated,
* <code>false</code> when shell deactivated
*/
public boolean getShellActivated() {
return shellActivated;
}
/**
* Returns the status line manager for this window (if it has one).
*
* @return the status line manager, or <code>null</code> if this window
* does not have a status line
* @see ApplicationWindow#addStatusLine
*/
public StatusLineManager getStatusLineManager() {
return super.getStatusLineManager();
}
private IWindowTrim getStatusLineTrim() {
if (statusLineTrim == null) {
statusLineTrim = new WindowTrimProxy(
getStatusLineManager().getControl(),
"org.eclipse.jface.action.StatusLineManager", //$NON-NLS-1$
WorkbenchMessages.TrimCommon_StatusLine_TrimName, SWT.NONE,
true);
}
return statusLineTrim;
}
/**
* @see IWorkbenchWindow
*/
public IWorkbench getWorkbench() {
return PlatformUI.getWorkbench();
}
public String getToolbarLabel(String actionSetId) {
ActionSetRegistry registry = WorkbenchPlugin.getDefault()
.getActionSetRegistry();
IActionSetDescriptor actionSet = registry.findActionSet(actionSetId);
if (actionSet != null) {
return actionSet.getLabel();
}
if (IWorkbenchActionConstants.TOOLBAR_FILE
.equalsIgnoreCase(actionSetId)) {
return WorkbenchMessages.WorkbenchWindow_FileToolbar;
}
if (IWorkbenchActionConstants.TOOLBAR_NAVIGATE
.equalsIgnoreCase(actionSetId)) {
return WorkbenchMessages.WorkbenchWindow_NavigateToolbar;
}
return (String) toolbarLabelContributions.get(actionSetId);
}
private Map toolbarLabelContributions = new HashMap();
public void putToolbarLabel(String id, String label) {
toolbarLabelContributions.put(id, label);
}
/**
* Unconditionally close this window. Assumes the proper flags have been set
* correctly (e.i. closing and updateDisabled)
*/
private boolean hardClose() {
boolean result;
try {
// clear some lables
if (toolbarLabelContributions != null) {
toolbarLabelContributions.clear();
toolbarLabelContributions = null;
}
// Remove the handler submissions. Bug 64024.
final IWorkbench workbench = getWorkbench();
final IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
handlerService.deactivateHandlers(handlerActivations);
final Iterator activationItr = handlerActivations.iterator();
while (activationItr.hasNext()) {
final IHandlerActivation activation = (IHandlerActivation) activationItr
.next();
activation.getHandler().dispose();
}
handlerActivations.clear();
globalActionHandlersByCommandId.clear();
// Remove the enabled submissions. Bug 64024.
final IContextService contextService = (IContextService) workbench.getService(IContextService.class);
contextService.unregisterShell(getShell());
closeAllPages();
fireWindowClosed();
// time to wipe our our populate
IMenuService menuService = (IMenuService) workbench
.getService(IMenuService.class);
menuService
.releaseContributions(((ContributionManager) getActionBars()
.getMenuManager()));
ICoolBarManager coolbar = getActionBars().getCoolBarManager();
if (coolbar != null) {
menuService
.releaseContributions(((ContributionManager) coolbar));
}
getActionBarAdvisor().dispose();
getWindowAdvisor().dispose();
detachedWindowShells.dispose();
// Null out the progress region. Bug 64024.
progressRegion = null;
// Remove drop targets
DragUtil.removeDragTarget(null, trimDropTarget);
DragUtil.removeDragTarget(getShell(), trimDropTarget);
trimDropTarget = null;
if (trimMgr2 != null) {
trimMgr2.dispose();
trimMgr2 = null;
}
if (trimContributionMgr != null) {
trimContributionMgr.dispose();
trimContributionMgr = null;
}
} finally {
result = super.close();
// Clear the action sets, fix for bug 27416.
getActionPresentation().clearActionSets();
try {
// Bring down all of the services ... after the window goes away
serviceLocator.dispose();
} catch (Exception ex) {
WorkbenchPlugin.log(ex);
}
menuRestrictions.clear();
}
return result;
}
/**
* @see IWorkbenchWindow
*/
public boolean isApplicationMenu(String menuID) {
// delegate this question to the action bar advisor
return getActionBarAdvisor().isApplicationMenu(menuID);
}
/**
* Return whether or not the given id matches the id of the coolitems that
* the application creates.
*/
/* package */
boolean isWorkbenchCoolItemId(String id) {
return windowConfigurer.containsCoolItem(id);
}
/**
* Makes the window visible and frontmost.
*/
void makeVisible() {
Shell shell = getShell();
if (shell != null && !shell.isDisposed()) {
// see bug 96700 and bug 4414 for a discussion on the use of open()
// here
shell.open();
}
}
/**
* Called when this window is about to be closed.
*
* Subclasses may overide to add code that returns <code>false</code> to
* prevent closing under certain conditions.
*/
public boolean okToClose() {
// Save all of the editors.
if (!getWorkbenchImpl().isClosing()) {
if (!saveAllPages(true)) {
return false;
}
}
return true;
}
/**
* Opens a new page.
* <p>
* <b>Note:</b> Since release 2.0, a window is limited to contain at most
* one page. If a page exist in the window when this method is used, then
* another window is created for the new page. Callers are strongly
* recommended to use the <code>IWorkbench.openPerspective</code> APIs to
* programmatically show a perspective.
* </p>
*/
public IWorkbenchPage openPage(final String perspId, final IAdaptable input)
throws WorkbenchException {
Assert.isNotNull(perspId);
// Run op in busy cursor.
final Object[] result = new Object[1];
BusyIndicator.showWhile(null, new Runnable() {
public void run() {
try {
result[0] = busyOpenPage(perspId, input);
} catch (WorkbenchException e) {
result[0] = e;
}
}
});
if (result[0] instanceof IWorkbenchPage) {
return (IWorkbenchPage) result[0];
} else if (result[0] instanceof WorkbenchException) {
throw (WorkbenchException) result[0];
} else {
throw new WorkbenchException(
WorkbenchMessages.WorkbenchWindow_exceptionMessage);
}
}
/**
* Opens a new page.
* <p>
* <b>Note:</b> Since release 2.0, a window is limited to contain at most
* one page. If a page exist in the window when this method is used, then
* another window is created for the new page. Callers are strongly
* recommended to use the <code>IWorkbench.openPerspective</code> APIs to
* programmatically show a perspective.
* </p>
*/
public IWorkbenchPage openPage(IAdaptable input) throws WorkbenchException {
String perspId = getWorkbenchImpl().getPerspectiveRegistry()
.getDefaultPerspective();
return openPage(perspId, input);
}
/*
* Removes an listener from the part service.
*/
public void removePageListener(IPageListener l) {
pageListeners.removePageListener(l);
}
/**
* @see org.eclipse.ui.IPageService
*/
public void removePerspectiveListener(org.eclipse.ui.IPerspectiveListener l) {
perspectiveListeners.removePerspectiveListener(l);
}
private IStatus unableToRestorePage(IMemento pageMem) {
String pageName = pageMem.getString(IWorkbenchConstants.TAG_LABEL);
if (pageName == null) {
pageName = ""; //$NON-NLS-1$
}
return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind(
WorkbenchMessages.WorkbenchWindow_unableToRestorePerspective,
pageName), null);
}
public IStatus restoreState(IMemento memento,
IPerspectiveDescriptor activeDescriptor) {
Assert.isNotNull(getShell());
final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
WorkbenchMessages.WorkbenchWindow_problemsRestoringWindow, null);
// Restore the window advisor state.
IMemento windowAdvisorState = memento
.getChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
if (windowAdvisorState != null) {
result.add(getWindowAdvisor().restoreState(windowAdvisorState));
}
// Restore actionbar advisor state.
IMemento actionBarAdvisorState = memento
.getChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
if (actionBarAdvisorState != null) {
result.add(getActionBarAdvisor()
.restoreState(actionBarAdvisorState));
}
// Read window's bounds and state.
final Rectangle [] displayBounds = new Rectangle[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() {
displayBounds[0] = getShell().getDisplay().getBounds();
}});
final Rectangle shellBounds = new Rectangle(0, 0, 0, 0);
final IMemento fastViewMem = memento
.getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
if (fastViewMem != null) {
if (fastViewBar != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() {
fastViewBar.restoreState(fastViewMem);
}});
}
}
Integer bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
shellBounds.x = bigInt == null ? 0 : bigInt.intValue();
bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
shellBounds.y = bigInt == null ? 0 : bigInt.intValue();
bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
shellBounds.width = bigInt == null ? 0 : bigInt.intValue();
bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
shellBounds.height = bigInt == null ? 0 : bigInt.intValue();
if (!shellBounds.isEmpty()) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() {
if (!shellBounds.intersects(displayBounds[0])) {
Rectangle clientArea = getShell().getDisplay().getClientArea();
shellBounds.x = clientArea.x;
shellBounds.y = clientArea.y;
}
getShell().setBounds(shellBounds);
}});
}
if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MAXIMIZED))) { //$NON-NLS-1$
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() {
getShell().setMaximized(true);
}});
}
if ("true".equals(memento.getString(IWorkbenchConstants.TAG_MINIMIZED))) { //$NON-NLS-1$
// getShell().setMinimized(true);
}
// restore the width of the perspective bar
if (perspectiveSwitcher != null) {
perspectiveSwitcher.restoreState(memento);
}
// Restore the cool bar order by creating all the tool bar contribution
// items
// This needs to be done before pages are created to ensure proper
// canonical creation
// of cool items
final ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
if (coolBarMgr != null) {
IMemento coolBarMem = memento
.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
if (coolBarMem != null) {
restoreCoolBarLocked(coolBarMgr, coolBarMem);
// The new layout of the cool bar manager
ArrayList coolBarLayout = new ArrayList();
// Traverse through all the cool item in the memento
IMemento contributionMems[] = coolBarMem
.getChildren(IWorkbenchConstants.TAG_COOLITEM);
for (int i = 0; i < contributionMems.length; i++) {
IMemento contributionMem = contributionMems[i];
String type = contributionMem
.getString(IWorkbenchConstants.TAG_ITEM_TYPE);
if (type == null) {
// Do not recognize that type
continue;
}
String id = contributionMem
.getString(IWorkbenchConstants.TAG_ID);
// Prevent duplicate items from being read back in.
IContributionItem existingItem = coolBarMgr.find(id);
if ((id != null) && (existingItem != null)) {
if (Policy.DEBUG_TOOLBAR_DISPOSAL) {
System.out
.println("Not loading duplicate cool bar item: " + id); //$NON-NLS-1$
}
coolBarLayout.add(existingItem);
continue;
}
IContributionItem newItem = null;
if (type.equals(IWorkbenchConstants.TAG_TYPE_SEPARATOR)) {
if (id != null) {
newItem = new Separator(id);
} else {
newItem = new Separator();
}
} else if (id != null) {
if (type
.equals(IWorkbenchConstants.TAG_TYPE_GROUPMARKER)) {
newItem = new GroupMarker(id);
} else if (type
.equals(IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION)
|| type
.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
// Get Width and height
Integer width = contributionMem
.getInteger(IWorkbenchConstants.TAG_ITEM_X);
Integer height = contributionMem
.getInteger(IWorkbenchConstants.TAG_ITEM_Y);
// Look for the object in the current cool bar
// manager
IContributionItem oldItem = coolBarMgr.find(id);
// If a tool bar contribution item already exists
// for this id then use the old object
if (oldItem != null) {
newItem = oldItem;
} else {
IActionBarPresentationFactory actionBarPresentation = getActionBarPresentationFactory();
newItem = actionBarPresentation.createToolBarContributionItem(
actionBarPresentation.createToolBarManager(), id);
if (type
.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
IToolBarContributionItem newToolBarItem = (IToolBarContributionItem) newItem;
if (height != null) {
newToolBarItem.setCurrentHeight(height
.intValue());
}
if (width != null) {
newToolBarItem.setCurrentWidth(width
.intValue());
}
newItem = new PlaceholderContributionItem(
newToolBarItem);
}
// make it invisible by default
newItem.setVisible(false);
// Need to add the item to the cool bar manager
// so that its canonical order can be preserved
IContributionItem refItem = findAlphabeticalOrder(
IWorkbenchActionConstants.MB_ADDITIONS,
id, coolBarMgr);
if (refItem != null) {
coolBarMgr.insertAfter(refItem.getId(),
newItem);
} else {
coolBarMgr.add(newItem);
}
}
// Set the current height and width
if ((width != null)
&& (newItem instanceof IToolBarContributionItem)) {
((IToolBarContributionItem) newItem)
.setCurrentWidth(width.intValue());
}
if ((height != null)
&& (newItem instanceof IToolBarContributionItem)) {
((IToolBarContributionItem) newItem)
.setCurrentHeight(height.intValue());
}
}
}
// Add new item into cool bar manager
if (newItem != null) {
coolBarLayout.add(newItem);
newItem.setParent(coolBarMgr);
coolBarMgr.markDirty();
}
}
// We need to check if we have everything we need in the layout.
boolean newlyAddedItems = false;
IContributionItem[] existingItems = coolBarMgr.getItems();
for (int i = 0; i < existingItems.length && !newlyAddedItems; i++) {
IContributionItem existingItem = existingItems[i];
/*
* This line shouldn't be necessary, but is here for
* robustness.
*/
if (existingItem == null) {
continue;
}
boolean found = false;
Iterator layoutItemItr = coolBarLayout.iterator();
while (layoutItemItr.hasNext()) {
IContributionItem layoutItem = (IContributionItem) layoutItemItr
.next();
if ((layoutItem != null)
&& (layoutItem.equals(existingItem))) {
found = true;
break;
}
}
if (!found) {
if (existingItem != null) {
newlyAddedItems = true;
}
}
}
// Set the cool bar layout to the given layout.
if (!newlyAddedItems) {
final IContributionItem[] itemsToSet = new IContributionItem[coolBarLayout
.size()];
coolBarLayout.toArray(itemsToSet);
StartupThreading
.runWithoutExceptions(new StartupRunnable() {
public void runWithException() {
coolBarMgr.setItems(itemsToSet);
}
});
}
} else {
// For older workbenchs
coolBarMem = memento
.getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
if (coolBarMem != null) {
// Restore an older layout
restoreOldCoolBar(coolBarMem);
}
}
}
// Recreate each page in the window.
IWorkbenchPage newActivePage = null;
IMemento[] pageArray = memento
.getChildren(IWorkbenchConstants.TAG_PAGE);
for (int i = 0; i < pageArray.length; i++) {
final IMemento pageMem = pageArray[i];
String strFocus = pageMem.getString(IWorkbenchConstants.TAG_FOCUS);
if (strFocus == null || strFocus.length() == 0) {
continue;
}
// Get the input factory.
final IAdaptable [] input = new IAdaptable[1];
final IMemento inputMem = pageMem.getChild(IWorkbenchConstants.TAG_INPUT);
if (inputMem != null) {
final String factoryID = inputMem
.getString(IWorkbenchConstants.TAG_FACTORY_ID);
if (factoryID == null) {
WorkbenchPlugin
.log("Unable to restore page - no input factory ID."); //$NON-NLS-1$
result.add(unableToRestorePage(pageMem));
continue;
}
try {
UIStats.start(UIStats.RESTORE_WORKBENCH,
"WorkbenchPageFactory"); //$NON-NLS-1$
StartupThreading
.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
IElementFactory factory = PlatformUI
.getWorkbench().getElementFactory(
factoryID);
if (factory == null) {
WorkbenchPlugin
.log("Unable to restore page - cannot instantiate input factory: " + factoryID); //$NON-NLS-1$
result
.add(unableToRestorePage(pageMem));
return;
}
// Get the input element.
input[0] = factory.createElement(inputMem);
}
});
if (input[0] == null) {
WorkbenchPlugin
.log("Unable to restore page - cannot instantiate input element: " + factoryID); //$NON-NLS-1$
result.add(unableToRestorePage(pageMem));
continue;
}
} finally {
UIStats.end(UIStats.RESTORE_WORKBENCH, factoryID,
"WorkbenchPageFactory"); //$NON-NLS-1$
}
}
// Open the perspective.
final IAdaptable finalInput = input[0];
final WorkbenchPage [] newPage = new WorkbenchPage[1];
try {
StartupThreading.runWithWorkbenchExceptions(new StartupRunnable(){
public void runWithException() throws WorkbenchException {
newPage[0] = ((WorkbenchImplementation) Tweaklets
.get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, finalInput);
}});
result.add(newPage[0].restoreState(pageMem, activeDescriptor));
pageList.add(newPage[0]);
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
firePageOpened(newPage[0]);
}});
} catch (WorkbenchException e) {
WorkbenchPlugin
.log(
"Unable to restore perspective - constructor failed.", e); //$NON-NLS-1$
result.add(e.getStatus());
continue;
}
if (strFocus != null && strFocus.length() > 0) {
newActivePage = newPage[0];
}
}
// If there are no pages create a default.
if (pageList.isEmpty()) {
try {
final String defPerspID = getWorkbenchImpl().getPerspectiveRegistry()
.getDefaultPerspective();
if (defPerspID != null) {
final WorkbenchPage [] newPage = new WorkbenchPage[1];
StartupThreading.runWithWorkbenchExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
newPage[0] = ((WorkbenchImplementation) Tweaklets
.get(WorkbenchImplementation.KEY)).createWorkbenchPage(WorkbenchWindow.this, defPerspID,
getDefaultPageInput());
}});
pageList.add(newPage[0]);
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
firePageOpened(newPage[0]);
}});
}
} catch (WorkbenchException e) {
WorkbenchPlugin
.log(
"Unable to create default perspective - constructor failed.", e); //$NON-NLS-1$
result.add(e.getStatus());
String productName = WorkbenchPlugin.getDefault()
.getProductName();
if (productName == null) {
productName = ""; //$NON-NLS-1$
}
getShell().setText(productName);
}
}
// Set active page.
if (newActivePage == null) {
newActivePage = pageList.getNextActive();
}
final IWorkbenchPage myPage = newActivePage;
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
setActivePage(myPage);
}});
final IMemento introMem = memento.getChild(IWorkbenchConstants.TAG_INTRO);
if (introMem != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
getWorkbench()
.getIntroManager()
.showIntro(
WorkbenchWindow.this,
Boolean
.valueOf(
introMem
.getString(IWorkbenchConstants.TAG_STANDBY))
.booleanValue());
}
});
}
// Only restore the trim state if we're using the default layout
if (defaultLayout != null) {
// Restore the trim state. We pass in the 'root'
// memento since we have to check for pre-3.2
// state.
result.add(restoreTrimState(memento));
}
return result;
}
/**
* Restores the locked state of coolbar.
*
* The state is first looked in the memento. If its not available in there,
* then its taken from the command's state
*
* @param coolBarMgr
* @param memento
*/
private void restoreCoolBarLocked(final ICoolBarManager2 coolBarMgr, IMemento memento) {
// Check if the layout is locked
final boolean locked[] = new boolean[] { false };
Integer lockedInt = memento.getInteger(IWorkbenchConstants.TAG_LOCKED);
if (lockedInt != null) {
// saved by 3.6 or earlier
locked[0] = lockedInt.intValue() == 1;
} else {
// saved by 3.7 or later, get it from command state
ICommandService service = (ICommandService) getService(ICommandService.class);
Command command = service.getCommand(IWorkbenchCommandConstants.WINDOW_LOCK_TOOLBAR);
State state = command.getState(RegistryToggleState.STATE_ID);
if (state != null && state.getValue() instanceof Boolean) {
locked[0] = ((Boolean) state.getValue()).booleanValue();
}
}
StartupThreading.runWithoutExceptions(new StartupRunnable(){
public void runWithException() {
coolBarMgr.setLockLayout(locked[0]);
}
});
}
/**
* Restores cool item order from an old workbench.
*/
private boolean restoreOldCoolBar(IMemento coolbarMem) {
// Make sure the tag exist
if (coolbarMem == null) {
return false;
}
ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
// Check to see if layout is locked
Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
boolean state = (locked != null) && (locked.intValue() == 1);
coolBarMgr.setLockLayout(state);
// Get the visual layout
IMemento visibleLayout = coolbarMem
.getChild(IWorkbenchConstants.TAG_TOOLBAR_LAYOUT);
ArrayList visibleWrapIndicies = new ArrayList();
ArrayList visibleItems = new ArrayList();
if (visibleLayout != null) {
if (readLayout(visibleLayout, visibleItems, visibleWrapIndicies) == false) {
return false;
}
}
// Get the remembered layout
IMemento rememberedLayout = coolbarMem
.getChild(IWorkbenchConstants.TAG_LAYOUT);
ArrayList rememberedWrapIndicies = new ArrayList();
ArrayList rememberedItems = new ArrayList();
if (rememberedLayout != null) {
if (readLayout(rememberedLayout, rememberedItems,
rememberedWrapIndicies) == false) {
return false;
}
}
// Create the objects
if (visibleItems != null) {
// Merge remembered layout into visible layout
if (rememberedItems != null) {
// Traverse through all the remembered items
int currentIndex = 0;
for (Iterator i = rememberedItems.iterator(); i.hasNext(); currentIndex++) {
String id = (String) i.next();
int index = -1;
for (Iterator iter = visibleItems.iterator(); iter
.hasNext();) {
String visibleId = (String) iter.next();
if (visibleId.equals(id)) {
index = visibleItems.indexOf(visibleId);
break;
}
}
// The item is not in the visible list
if (index == -1) {
int insertAt = Math.max(0, Math.min(currentIndex,
visibleItems.size()));
boolean separateLine = false;
// Check whether this item is on a separate line
for (Iterator iter = rememberedWrapIndicies.iterator(); iter
.hasNext();) {
Integer wrapIndex = (Integer) iter.next();
if (wrapIndex.intValue() <= insertAt) {
insertAt = visibleItems.size();
// Add new wrap index for this Item
visibleWrapIndicies.add(new Integer(insertAt));
separateLine = true;
}
}
// Add item to array list
visibleItems.add(insertAt, id);
// If the item was not on a separate line then adjust
// the visible wrap indicies
if (!separateLine) {
// Adjust visible wrap indicies
for (int j = 0; j < visibleWrapIndicies.size(); j++) {
Integer index2 = (Integer) visibleWrapIndicies
.get(j);
if (index2.intValue() >= insertAt) {
visibleWrapIndicies.set(j, new Integer(
index2.intValue() + 1));
}
}
}
}
}
}
// The new layout of the cool bar manager
ArrayList coolBarLayout = new ArrayList(visibleItems.size());
// Add all visible items to the layout object
for (Iterator i = visibleItems.iterator(); i.hasNext();) {
String id = (String) i.next();
// Look for the object in the current cool bar manager
IContributionItem oldItem = null;
IContributionItem newItem = null;
if (id != null) {
oldItem = coolBarMgr.find(id);
}
// If a tool bar contribution item already exists for this id
// then use the old object
if (oldItem instanceof IToolBarContributionItem) {
newItem = oldItem;
} else {
IActionBarPresentationFactory actionBarPresentaiton = getActionBarPresentationFactory();
newItem = actionBarPresentaiton.createToolBarContributionItem(
actionBarPresentaiton.createToolBarManager(), id);
// make it invisible by default
newItem.setVisible(false);
// Need to add the item to the cool bar manager so that its
// canonical order can be preserved
IContributionItem refItem = findAlphabeticalOrder(
IWorkbenchActionConstants.MB_ADDITIONS, id,
coolBarMgr);
if (refItem != null) {
coolBarMgr.insertAfter(refItem.getId(), newItem);
} else {
coolBarMgr.add(newItem);
}
}
// Add new item into cool bar manager
if (newItem != null) {
coolBarLayout.add(newItem);
newItem.setParent(coolBarMgr);
coolBarMgr.markDirty();
}
}
// Add separators to the displayed Items data structure
int offset = 0;
for (int i = 1; i < visibleWrapIndicies.size(); i++) {
int insertAt = ((Integer) visibleWrapIndicies.get(i))
.intValue()
+ offset;
coolBarLayout.add(insertAt, new Separator(
CoolBarManager.USER_SEPARATOR));
offset++;
}
// Add any group markers in their appropriate places
IContributionItem[] items = coolBarMgr.getItems();
for (int i = 0; i < items.length; i++) {
IContributionItem item = items[i];
if (item.isGroupMarker()) {
coolBarLayout.add(Math.max(Math
.min(i, coolBarLayout.size()), 0), item);
}
}
IContributionItem[] itemsToSet = new IContributionItem[coolBarLayout
.size()];
coolBarLayout.toArray(itemsToSet);
coolBarMgr.setItems(itemsToSet);
}
return true;
}
/**
* Helper method used for restoring an old cool bar layout. This method
* reads the memento and populates the item id's and wrap indices.
*/
private boolean readLayout(IMemento memento, ArrayList itemIds,
ArrayList wrapIndicies) {
// Get the Wrap indices
IMemento[] wraps = memento
.getChildren(IWorkbenchConstants.TAG_ITEM_WRAP_INDEX);
if (wraps == null) {
return false;
}
for (int i = 0; i < wraps.length; i++) {
IMemento wrapMem = wraps[i];
Integer index = wrapMem.getInteger(IWorkbenchConstants.TAG_INDEX);
if (index == null) {
return false;
}
wrapIndicies.add(index);
}
// Get the Item ids
IMemento[] savedItems = memento
.getChildren(IWorkbenchConstants.TAG_ITEM);
if (savedItems == null) {
return false;
}
for (int i = 0; i < savedItems.length; i++) {
IMemento savedMem = savedItems[i];
String id = savedMem.getString(IWorkbenchConstants.TAG_ID);
if (id == null) {
return false;
}
itemIds.add(id);
}
return true;
}
/**
* Returns the contribution item that the given contribution item should be
* inserted after.
*
* @param startId
* the location to start looking alphabetically.
* @param itemId
* the target item id.
* @param mgr
* the contribution manager.
* @return the contribution item that the given items should be returned
* after.
*/
private IContributionItem findAlphabeticalOrder(String startId,
String itemId, IContributionManager mgr) {
IContributionItem[] items = mgr.getItems();
int insertIndex = 0;
// look for starting point
while (insertIndex < items.length) {
IContributionItem item = items[insertIndex];
if (item.getId() != null && item.getId().equals(startId)) {
break;
}
++insertIndex;
}
// Find the index that this item should be inserted in
for (int i = insertIndex + 1; i < items.length; i++) {
IContributionItem item = items[i];
String testId = item.getId();
if (item.isGroupMarker()) {
break;
}
if (itemId != null && testId != null) {
if (itemId.compareTo(testId) < 1) {
break;
}
}
insertIndex = i;
}
if (insertIndex >= items.length) {
return null;
}
return items[insertIndex];
}
/*
* (non-Javadoc) Method declared on IRunnableContext.
*/
public void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable) throws InvocationTargetException,
InterruptedException {
IWorkbenchContextSupport contextSupport = getWorkbench()
.getContextSupport();
final boolean keyFilterEnabled = contextSupport.isKeyFilterEnabled();
Control fastViewBarControl = getFastViewBar() == null ? null
: getFastViewBar().getControl();
boolean fastViewBarWasEnabled = fastViewBarControl == null ? false
: fastViewBarControl.getEnabled();
Control perspectiveBarControl = getPerspectiveBar() == null ? null
: getPerspectiveBar().getControl();
boolean perspectiveBarWasEnabled = perspectiveBarControl == null ? false
: perspectiveBarControl.getEnabled();
// Cache for any disabled trim controls
List disabledControls = null;
try {
if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
fastViewBarControl.setEnabled(false);
}
if (perspectiveBarControl != null
&& !perspectiveBarControl.isDisposed()) {
perspectiveBarControl.setEnabled(false);
}
if (keyFilterEnabled) {
contextSupport.setKeyFilterEnabled(false);
}
// Disable all trim -except- the StatusLine
if (defaultLayout != null)
disabledControls = defaultLayout.disableTrim(getStatusLineTrim());
super.run(fork, cancelable, runnable);
} finally {
if (fastViewBarControl != null && !fastViewBarControl.isDisposed()) {
fastViewBarControl.setEnabled(fastViewBarWasEnabled);
}
if (perspectiveBarControl != null
&& !perspectiveBarControl.isDisposed()) {
perspectiveBarControl.setEnabled(perspectiveBarWasEnabled);
}
if (keyFilterEnabled) {
contextSupport.setKeyFilterEnabled(true);
}
// Re-enable any disabled trim
if (defaultLayout != null && disabledControls != null)
defaultLayout.enableTrim(disabledControls);
}
}
/**
* Save all of the pages. Returns true if the operation succeeded.
*/
private boolean saveAllPages(boolean bConfirm) {
boolean bRet = true;
Iterator itr = pageList.iterator();
while (bRet && itr.hasNext()) {
WorkbenchPage page = (WorkbenchPage) itr.next();
bRet = page.saveAllEditors(bConfirm);
}
return bRet;
}
/**
* @see IPersistable
*/
public IStatus saveState(IMemento memento) {
MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
WorkbenchMessages.WorkbenchWindow_problemsSavingWindow, null);
// Save the window's state and bounds.
if (getShell().getMaximized() || asMaximizedState) {
memento.putString(IWorkbenchConstants.TAG_MAXIMIZED, "true"); //$NON-NLS-1$
}
if (getShell().getMinimized()) {
memento.putString(IWorkbenchConstants.TAG_MINIMIZED, "true"); //$NON-NLS-1$
}
if (normalBounds == null) {
normalBounds = getShell().getBounds();
}
IMemento fastViewBarMem = memento
.createChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
if (fastViewBar != null) {
fastViewBar.saveState(fastViewBarMem);
}
memento.putInteger(IWorkbenchConstants.TAG_X, normalBounds.x);
memento.putInteger(IWorkbenchConstants.TAG_Y, normalBounds.y);
memento.putInteger(IWorkbenchConstants.TAG_WIDTH, normalBounds.width);
memento.putInteger(IWorkbenchConstants.TAG_HEIGHT, normalBounds.height);
IWorkbenchPage activePage = getActivePage();
if (activePage != null
&& activePage.findView(IIntroConstants.INTRO_VIEW_ID) != null) {
IMemento introMem = memento
.createChild(IWorkbenchConstants.TAG_INTRO);
boolean isStandby = getWorkbench()
.getIntroManager()
.isIntroStandby(getWorkbench().getIntroManager().getIntro());
introMem.putString(IWorkbenchConstants.TAG_STANDBY, String
.valueOf(isStandby));
}
// save the width of the perspective bar
IMemento persBarMem = memento
.createChild(IWorkbenchConstants.TAG_PERSPECTIVE_BAR);
if (perspectiveSwitcher != null) {
perspectiveSwitcher.saveState(persBarMem);
}
// / Save the order of the cool bar contribution items
ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
if (coolBarMgr != null) {
coolBarMgr.refresh();
IMemento coolBarMem = memento
.createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
IContributionItem[] items = coolBarMgr.getItems();
for (int i = 0; i < items.length; i++) {
IMemento coolItemMem = coolBarMem
.createChild(IWorkbenchConstants.TAG_COOLITEM);
IContributionItem item = items[i];
// The id of the contribution item
if (item.getId() != null) {
coolItemMem.putString(IWorkbenchConstants.TAG_ID, item
.getId());
}
// Write out type and size if applicable
if (item.isSeparator()) {
coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
IWorkbenchConstants.TAG_TYPE_SEPARATOR);
} else if (item.isGroupMarker() && !item.isSeparator()) {
coolItemMem.putString(IWorkbenchConstants.TAG_ITEM_TYPE,
IWorkbenchConstants.TAG_TYPE_GROUPMARKER);
} else {
if (item instanceof PlaceholderContributionItem) {
coolItemMem.putString(
IWorkbenchConstants.TAG_ITEM_TYPE,
IWorkbenchConstants.TAG_TYPE_PLACEHOLDER);
} else {
// Store the identifier.
coolItemMem
.putString(
IWorkbenchConstants.TAG_ITEM_TYPE,
IWorkbenchConstants.TAG_TYPE_TOOLBARCONTRIBUTION);
}
/*
* Retrieve a reasonable approximation of the height and
* width, if possible.
*/
final int height;
final int width;
if (item instanceof IToolBarContributionItem) {
IToolBarContributionItem toolBarItem = (IToolBarContributionItem) item;
toolBarItem.saveWidgetState();
height = toolBarItem.getCurrentHeight();
width = toolBarItem.getCurrentWidth();
} else if (item instanceof PlaceholderContributionItem) {
PlaceholderContributionItem placeholder = (PlaceholderContributionItem) item;
height = placeholder.getHeight();
width = placeholder.getWidth();
} else {
height = -1;
width = -1;
}
// Store the height and width.
coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_X,
width);
coolItemMem.putInteger(IWorkbenchConstants.TAG_ITEM_Y,
height);
}
}
}
// Save each page.
Iterator itr = pageList.iterator();
while (itr.hasNext()) {
WorkbenchPage page = (WorkbenchPage) itr.next();
// Save perspective.
IMemento pageMem = memento
.createChild(IWorkbenchConstants.TAG_PAGE);
pageMem.putString(IWorkbenchConstants.TAG_LABEL, page.getLabel());
result.add(page.saveState(pageMem));
if (page == getActiveWorkbenchPage()) {
pageMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
}
// Get the input.
IAdaptable input = page.getInput();
if (input != null) {
IPersistableElement persistable = (IPersistableElement) Util.getAdapter(input,
IPersistableElement.class);
if (persistable == null) {
WorkbenchPlugin
.log("Unable to save page input: " //$NON-NLS-1$
+ input
+ ", because it does not adapt to IPersistableElement"); //$NON-NLS-1$
} else {
// Save input.
IMemento inputMem = pageMem
.createChild(IWorkbenchConstants.TAG_INPUT);
inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
persistable.getFactoryId());
persistable.saveState(inputMem);
}
}
}
// Save window advisor state.
IMemento windowAdvisorState = memento
.createChild(IWorkbenchConstants.TAG_WORKBENCH_WINDOW_ADVISOR);
result.add(getWindowAdvisor().saveState(windowAdvisorState));
// Save actionbar advisor state.
IMemento actionBarAdvisorState = memento
.createChild(IWorkbenchConstants.TAG_ACTION_BAR_ADVISOR);
result.add(getActionBarAdvisor().saveState(actionBarAdvisorState));
// Only save the trim state if we're using the default layout
if (defaultLayout != null) {
IMemento trimState = memento.createChild(IWorkbenchConstants.TAG_TRIM);
result.add(saveTrimState(trimState));
}
return result;
}
/**
* Save the trim layout trim area and trim ordering.
*
* @param memento
* the memento to update
* @return the status, OK or not..
* @since 3.2
*/
private IStatus saveTrimState(IMemento memento) {
int[] ids = defaultLayout.getAreaIds();
for (int i = 0; i < ids.length; i++) {
int id = ids[i];
List trim = defaultLayout.getAreaTrim(id);
if (!trim.isEmpty()) {
IMemento area = memento
.createChild(IWorkbenchConstants.TAG_TRIM_AREA, Integer
.toString(id));
Iterator d = trim.iterator();
while (d.hasNext()) {
IWindowTrim item = (IWindowTrim) d.next();
area.createChild(IWorkbenchConstants.TAG_TRIM_ITEM, item
.getId());
}
}
}
return Status.OK_STATUS;
}
/**
* Restore the trim layout state from the memento.
*
* @param memento
* the 'root' Workbench memento to restore
* @return the status, OK or not
* @since 3.2
*/
private IStatus restoreTrimState(IMemento memento) {
// Determine if we have saved state. If we don't have any 3.2
// type state we're not done because the FastViewBar maintained
// its own 'side' state in 3.1 so we'll honor its value
IMemento trimState = memento.getChild(IWorkbenchConstants.TAG_TRIM);
if (trimState != null) {
// first pass sets up ordering for all trim areas
IMemento[] areas = trimState
.getChildren(IWorkbenchConstants.TAG_TRIM_AREA);
// We need to remember all the trim that was repositioned
// here so we can re-site -newly contributed- trim after
// we're done
final List knownIds = new ArrayList();
List[] trimOrder = new List[areas.length];
for (int i = 0; i < areas.length; i++) {
trimOrder[i] = new ArrayList();
List preferredLocations = new ArrayList();
IMemento area = areas[i];
IMemento[] items = area
.getChildren(IWorkbenchConstants.TAG_TRIM_ITEM);
for (int j = 0; j < items.length; j++) {
IMemento item = items[j];
String id = item.getID();
knownIds.add(id);
preferredLocations.add(id);
IWindowTrim t = defaultLayout.getTrim(id);
if (t != null) {
trimOrder[i].add(t);
}
}
// Inform the TrimLayout of the preferred location for this area
String areaIdString = areas[i].getID();
int areaId = Integer.parseInt(areaIdString);
defaultLayout.setPreferredLocations(areaId, preferredLocations);
}
// second pass applies all of the window trim
for (int i = 0; i < areas.length; i++) {
IMemento area = areas[i];
final int id = Integer.parseInt(area.getID());
final List myTrimOrderList = trimOrder[i];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
defaultLayout.updateAreaTrim(id, myTrimOrderList, false);
}});
}
// get the trim manager to re-locate any -newly contributed-
// trim widgets
// Legacy (3.2) trim
if (trimMgr2 != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
trimMgr2.updateLocations(knownIds);
}});
}
// 3.3 Trim Contributions
if (trimContributionMgr != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
trimContributionMgr.updateLocations(knownIds);
// Update the GUI with the new locations
WorkbenchPage page = getActiveWorkbenchPage();
if (page != null) {
Perspective perspective = page.getActivePerspective();
if (perspective != null) {
// Ensure that only the upper/right editor stack has
// min/max buttons
page.getEditorPresentation().updateStackButtons();
// The perspective's onActivate manipulates the trim under the
// new min/max story so cause it to refresh...
perspective.onActivate();
}
}
}});
}
}
else {
// No 3.2 state...check if the FVB has state
IMemento fastViewMem = memento
.getChild(IWorkbenchConstants.TAG_FAST_VIEW_DATA);
if (fastViewMem != null) {
if (fastViewBar != null) {
final Integer bigInt = fastViewMem.getInteger(IWorkbenchConstants.TAG_FAST_VIEW_SIDE);
if (bigInt != null) {
StartupThreading.runWithoutExceptions(new StartupRunnable() {
public void runWithException() throws Throwable {
fastViewBar.dock(bigInt.intValue());
getTrimManager().addTrim(bigInt.intValue(), fastViewBar);
}});
}
}
}
}
return Status.OK_STATUS;
}
/**
* Sets the active page within the window.
*
* @param in
* identifies the new active page, or <code>null</code> for no
* active page
*/
public void setActivePage(final IWorkbenchPage in) {
if (getActiveWorkbenchPage() == in) {
return;
}
// 1FVGTNR: ITPUI:WINNT - busy cursor for switching perspectives
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
// Deactivate old persp.
WorkbenchPage currentPage = getActiveWorkbenchPage();
if (currentPage != null) {
currentPage.onDeactivate();
}
// Activate new persp.
if (in == null || pageList.contains(in)) {
pageList.setActive(in);
}
WorkbenchPage newPage = pageList.getActive();
Composite parent = getPageComposite();
StackLayout layout = (StackLayout) parent.getLayout();
if (newPage != null) {
layout.topControl = newPage.getClientComposite();
parent.layout();
hideEmptyWindowContents();
newPage.onActivate();
firePageActivated(newPage);
if (newPage.getPerspective() != null) {
firePerspectiveActivated(newPage, newPage
.getPerspective());
}
} else {
layout.topControl = null;
parent.layout();
}
updateFastViewBar();
if (isClosing()) {
return;
}
updateDisabled = false;
// Update action bars ( implicitly calls updateActionBars() )
updateActionSets();
submitGlobalActions();
if (perspectiveSwitcher != null) {
perspectiveSwitcher.update(false);
}
getMenuManager().update(IAction.TEXT);
}
});
}
/**
* Returns whether or not children exist for the Window's toolbar control.
* Overridden for coolbar support.
* <p>
*
* @return boolean true if children exist, false otherwise
*/
protected boolean toolBarChildrenExist() {
CoolBar coolBarControl = (CoolBar) getCoolBarControl();
return coolBarControl.getItemCount() > 0;
}
private Set menuRestrictions = new HashSet();
private Boolean valueOf(boolean result) {
return result ? Boolean.TRUE : Boolean.FALSE;
}
public Set getMenuRestrictions() {
return menuRestrictions;
}
void liftRestrictions() {
if (menuRestrictions.isEmpty()) {
return;
}
EvaluationReference[] refs = (EvaluationReference[]) menuRestrictions
.toArray(new EvaluationReference[menuRestrictions.size()]);
IEvaluationService es = (IEvaluationService) serviceLocator
.getService(IEvaluationService.class);
IEvaluationContext currentState = es.getCurrentState();
boolean changeDetected = false;
for (int i = 0; i < refs.length; i++) {
EvaluationReference reference = refs[i];
reference.setPostingChanges(true);
boolean os = reference.evaluate(currentState);
reference.clearResult();
boolean ns = reference.evaluate(currentState);
if (os != ns) {
changeDetected = true;
reference.getListener().propertyChange(
new PropertyChangeEvent(reference, reference
.getProperty(), valueOf(os), valueOf(ns)));
}
}
if (changeDetected) {
IMenuService ms = (IMenuService) getWorkbench().getService(
IMenuService.class);
if (ms instanceof WorkbenchMenuService) {
((WorkbenchMenuService) ms).updateManagers();
}
}
}
void imposeRestrictions() {
Iterator i = menuRestrictions.iterator();
while (i.hasNext()) {
EvaluationReference ref = (EvaluationReference) i.next();
ref.setPostingChanges(false);
}
}
/**
* Hooks a listener to track the activation and deactivation of the window's
* shell. Notifies the active part and editor of the change
*/
private void trackShellActivation(Shell shell) {
shell.addShellListener(new ShellAdapter() {
public void shellActivated(ShellEvent event) {
shellActivated = true;
serviceLocator.activate();
getWorkbenchImpl().setActivatedWindow(WorkbenchWindow.this);
WorkbenchPage currentPage = getActiveWorkbenchPage();
if (currentPage != null) {
IWorkbenchPart part = currentPage.getActivePart();
if (part != null) {
PartSite site = (PartSite) part.getSite();
site.getPane().shellActivated();
}
IEditorPart editor = currentPage.getActiveEditor();
if (editor != null) {
PartSite site = (PartSite) editor.getSite();
site.getPane().shellActivated();
}
getWorkbenchImpl()
.fireWindowActivated(WorkbenchWindow.this);
}
liftRestrictions();
}
public void shellDeactivated(ShellEvent event) {
shellActivated = false;
imposeRestrictions();
serviceLocator.deactivate();
WorkbenchPage currentPage = getActiveWorkbenchPage();
if (currentPage != null) {
IWorkbenchPart part = currentPage.getActivePart();
if (part != null) {
PartSite site = (PartSite) part.getSite();
site.getPane().shellDeactivated();
}
IEditorPart editor = currentPage.getActiveEditor();
if (editor != null) {
PartSite site = (PartSite) editor.getSite();
site.getPane().shellDeactivated();
}
getWorkbenchImpl().fireWindowDeactivated(
WorkbenchWindow.this);
}
}
});
}
/**
* Hooks a listener to track the resize of the window's shell. Stores the
* new bounds if in normal state - that is, not in minimized or maximized
* state)
*/
private void trackShellResize(Shell newShell) {
newShell.addControlListener(new ControlAdapter() {
public void controlMoved(ControlEvent e) {
saveBounds();
}
public void controlResized(ControlEvent e) {
saveBounds();
}
private void saveBounds() {
Shell shell = getShell();
if (shell == null) {
return;
}
if (shell.isDisposed()) {
return;
}
if (shell.getMinimized()) {
return;
}
if (shell.getMaximized()) {
asMaximizedState = true;
return;
}
asMaximizedState = false;
normalBounds = shell.getBounds();
}
});
}
/**
* update the action bars.
*/
public void updateActionBars() {
if (updateDisabled || updatesDeferred()) {
return;
}
// updateAll required in order to enable accelerators on pull-down menus
getMenuBarManager().update(false);
try {
getShell().setLayoutDeferred(true);
getCoolBarManager2().update(false);
} finally {
getShell().setLayoutDeferred(false);
}
getStatusLineManager().update(false);
}
/**
* Returns true iff we are currently deferring UI processing due to a large
* update
*
* @return true iff we are deferring UI updates.
* @since 3.1
*/
private boolean updatesDeferred() {
return largeUpdates > 0;
}
/**
* <p>
* Indicates the start of a large update within this window. This is used to
* disable CPU-intensive, change-sensitive services that were temporarily
* disabled in the midst of large changes. This method should always be
* called in tandem with <code>largeUpdateEnd</code>, and the event loop
* should not be allowed to spin before that method is called.
* </p>
* <p>
* Important: always use with <code>largeUpdateEnd</code>!
* </p>
*
* @since 3.1
*/
public final void largeUpdateStart() {
largeUpdates++;
}
/**
* <p>
* Indicates the end of a large update within this window. This is used to
* re-enable services that were temporarily disabled in the midst of large
* changes. This method should always be called in tandem with
* <code>largeUpdateStart</code>, and the event loop should not be
* allowed to spin before this method is called.
* </p>
* <p>
* Important: always protect this call by using <code>finally</code>!
* </p>
*
* @since 3.1
*/
public final void largeUpdateEnd() {
if (--largeUpdates == 0) {
updateActionBars();
}
}
/**
* Update the visible action sets. This method is typically called from a
* page when the user changes the visible action sets within the
* prespective.
*/
public void updateActionSets() {
if (updateDisabled) {
return;
}
WorkbenchPage currentPage = getActiveWorkbenchPage();
if (currentPage == null) {
getActionPresentation().clearActionSets();
} else {
ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
if (coolBarManager != null) {
coolBarManager.refresh();
}
getActionPresentation().setActionSets(
currentPage.getActionSets());
}
fireActionSetsChanged();
updateActionBars();
// hide the launch menu if it is empty
String path = IWorkbenchActionConstants.M_WINDOW
+ IWorkbenchActionConstants.SEP
+ IWorkbenchActionConstants.M_LAUNCH;
IMenuManager manager = getMenuBarManager().findMenuUsingPath(path);
IContributionItem item = getMenuBarManager().findUsingPath(path);
if (manager == null || item == null) {
return;
}
item.setVisible(manager.getItems().length >= 2);
// there is a separator for the additions group thus >= 2
}
private ListenerList actionSetListeners = null;
private ListenerList backgroundSaveListeners = new ListenerList(ListenerList.IDENTITY);
private final void fireActionSetsChanged() {
if (actionSetListeners != null) {
final Object[] listeners = actionSetListeners.getListeners();
for (int i = 0; i < listeners.length; i++) {
final IActionSetsListener listener = (IActionSetsListener) listeners[i];
final WorkbenchPage currentPage = getActiveWorkbenchPage();
final IActionSetDescriptor[] newActionSets;
if (currentPage == null) {
newActionSets = null;
} else {
newActionSets = currentPage.getActionSets();
}
final ActionSetsEvent event = new ActionSetsEvent(newActionSets);
listener.actionSetsChanged(event);
}
}
}
final void addActionSetsListener(final IActionSetsListener listener) {
if (actionSetListeners == null) {
actionSetListeners = new ListenerList();
}
actionSetListeners.add(listener);
}
final void removeActionSetsListener(final IActionSetsListener listener) {
if (actionSetListeners != null) {
actionSetListeners.remove(listener);
if (actionSetListeners.isEmpty()) {
actionSetListeners = null;
}
}
}
/**
* Create the progress indicator for the receiver.
*
* @param shell
* the parent shell
*/
private void createProgressIndicator(Shell shell) {
if (getWindowConfigurer().getShowProgressIndicator()) {
progressRegion = new ProgressRegion();
progressRegion.createContents(shell, this);
}
if (shell.getDisplay() != null && shell.getDisplay().getSystemTaskBar() != null) {
// only create the TaskBarProgressManager if there is a TaskBar that
// the progress can be displayed on
TaskItem taskItem = null;
TaskBar systemTaskBar = shell.getDisplay().getSystemTaskBar();
taskItem = systemTaskBar.getItem(shell);
if (taskItem == null) {
// try to get the application TaskItem
taskItem = systemTaskBar.getItem(null);
}
if (taskItem != null) {
// If there is a TaskItem, see if there is
// TaskBarProgressManager already associated with it to make
// sure that we don't duplicate the progress information
String taskBarProgressManagerKey = TaskBarProgressManager.class.getName()
+ ".instance"; //$NON-NLS-1$
Object data = taskItem.getData(taskBarProgressManagerKey);
if (data == null || !(data instanceof TaskBarProgressManager)) {
taskItem.setData(taskBarProgressManagerKey,
new TaskBarProgressManager(taskItem));
}
}
}
}
class PageList {
// List of pages in the order they were created;
private List pagesInCreationOrder;
// List of pages where the top is the last activated.
private List pageInActivationOrder;
// The page explicitly activated
private Object active;
public PageList() {
pagesInCreationOrder = new ArrayList(4);
pageInActivationOrder = new ArrayList(4);
}
public boolean add(Object object) {
pagesInCreationOrder.add(object);
pageInActivationOrder.add(0, object);
// It will be moved to top only when activated.
return true;
}
public Iterator iterator() {
return pagesInCreationOrder.iterator();
}
public boolean contains(Object object) {
return pagesInCreationOrder.contains(object);
}
public boolean remove(Object object) {
if (active == object) {
active = null;
}
pageInActivationOrder.remove(object);
return pagesInCreationOrder.remove(object);
}
public boolean isEmpty() {
return pagesInCreationOrder.isEmpty();
}
public IWorkbenchPage[] getPages() {
int nSize = pagesInCreationOrder.size();
IWorkbenchPage[] retArray = new IWorkbenchPage[nSize];
pagesInCreationOrder.toArray(retArray);
return retArray;
}
public void setActive(Object page) {
if (active == page) {
return;
}
active = page;
if (page != null) {
pageInActivationOrder.remove(page);
pageInActivationOrder.add(page);
}
}
public WorkbenchPage getActive() {
return (WorkbenchPage) active;
}
public WorkbenchPage getNextActive() {
if (active == null) {
if (pageInActivationOrder.isEmpty()) {
return null;
}
return (WorkbenchPage) pageInActivationOrder
.get(pageInActivationOrder.size() - 1);
}
if (pageInActivationOrder.size() < 2) {
return null;
}
return (WorkbenchPage) pageInActivationOrder
.get(pageInActivationOrder.size() - 2);
}
}
/**
* Returns the unique object that applications use to configure this window.
* <p>
* IMPORTANT This method is declared package-private to prevent regular
* plug-ins from downcasting IWorkbenchWindow to WorkbenchWindow and getting
* hold of the workbench window configurer that would allow them to tamper
* with the workbench window. The workbench window configurer is available
* only to the application.
* </p>
*/
/* package - DO NOT CHANGE */
WorkbenchWindowConfigurer getWindowConfigurer() {
if (windowConfigurer == null) {
// lazy initialize
windowConfigurer = new WorkbenchWindowConfigurer(this);
}
return windowConfigurer;
}
/**
* Returns the workbench advisor. Assumes the workbench has been created
* already.
* <p>
* IMPORTANT This method is declared private to prevent regular plug-ins
* from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
* the workbench advisor that would allow them to tamper with the workbench.
* The workbench advisor is internal to the application.
* </p>
*/
private/* private - DO NOT CHANGE */
WorkbenchAdvisor getAdvisor() {
return getWorkbenchImpl().getAdvisor();
}
/**
* Returns the window advisor, creating a new one for this window if needed.
* <p>
* IMPORTANT This method is declared package private to prevent regular plug-ins
* from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
* the window advisor that would allow them to tamper with the window. The
* window advisor is internal to the application.
* </p>
*/
/* package private - DO NOT CHANGE */
WorkbenchWindowAdvisor getWindowAdvisor() {
if (windowAdvisor == null) {
windowAdvisor = getAdvisor().createWorkbenchWindowAdvisor(
getWindowConfigurer());
Assert.isNotNull(windowAdvisor);
}
return windowAdvisor;
}
/**
* Returns the action bar advisor, creating a new one for this window if
* needed.
* <p>
* IMPORTANT This method is declared private to prevent regular plug-ins
* from downcasting IWorkbenchWindow to WorkbenchWindow and getting hold of
* the action bar advisor that would allow them to tamper with the window's
* action bars. The action bar advisor is internal to the application.
* </p>
*/
private/* private - DO NOT CHANGE */
ActionBarAdvisor getActionBarAdvisor() {
if (actionBarAdvisor == null) {
actionBarAdvisor = getWindowAdvisor().createActionBarAdvisor(
getWindowConfigurer().getActionBarConfigurer());
Assert.isNotNull(actionBarAdvisor);
}
return actionBarAdvisor;
}
/*
* Returns the IWorkbench implementation.
*/
private Workbench getWorkbenchImpl() {
return Workbench.getInstance();
}
/**
* Fills the window's real action bars.
*
* @param flags
* indicate which bars to fill
*/
public void fillActionBars(int flags) {
Workbench workbench = getWorkbenchImpl();
workbench.largeUpdateStart();
try {
getActionBarAdvisor().fillActionBars(flags);
//
// 3.3 start
final IMenuService menuService = (IMenuService) serviceLocator
.getService(IMenuService.class);
menuService.populateContributionManager(
(ContributionManager) getActionBars().getMenuManager(),
MenuUtil.MAIN_MENU);
ICoolBarManager coolbar = getActionBars().getCoolBarManager();
if (coolbar != null) {
menuService.populateContributionManager(
(ContributionManager) coolbar,
MenuUtil.MAIN_TOOLBAR);
}
// 3.3 end
} finally {
workbench.largeUpdateEnd();
}
}
/**
* Fills the window's proxy action bars.
*
* @param proxyBars
* the proxy configurer
* @param flags
* indicate which bars to fill
*/
public void fillActionBars(IActionBarConfigurer2 proxyBars, int flags) {
Assert.isNotNull(proxyBars);
WorkbenchWindowConfigurer.WindowActionBarConfigurer wab = (WorkbenchWindowConfigurer.WindowActionBarConfigurer) getWindowConfigurer()
.getActionBarConfigurer();
wab.setProxy(proxyBars);
try {
getActionBarAdvisor().fillActionBars(
flags | ActionBarAdvisor.FILL_PROXY);
} finally {
wab.setProxy(null);
}
}
/**
* The <code>WorkbenchWindow</code> implementation of this method has the
* same logic as <code>Window</code>'s implementation, but without the
* resize check. We don't want to skip setting the bounds if the shell has
* been resized since a free resize event occurs on Windows when the menubar
* is set in configureShell.
*/
protected void initializeBounds() {
Point size = getInitialSize();
Point location = getInitialLocation(size);
getShell().setBounds(
getConstrainedShellBounds(new Rectangle(location.x, location.y,
size.x, size.y)));
}
/*
* Unlike dialogs, the position of the workbench window is set by the user
* and persisted across sessions. If the user wants to put the window
* offscreen or spanning multiple monitors, let them (bug 74762)
*/
protected void constrainShellSize() {
// As long as the shell is visible on some monitor, don't change it.
Rectangle bounds = getShell().getBounds();
if (!SwtUtil.intersectsAnyMonitor(Display.getCurrent(), bounds)) {
super.constrainShellSize();
}
}
/*
* Unlike dialogs, the position of the workbench window is set by the user
* and persisted across sessions. If the user wants to put the window
* offscreen or spanning multiple monitors, let them (bug 74762)
*/
protected Point getInitialLocation(Point size) {
Shell shell = getShell();
if (shell != null) {
return shell.getLocation();
}
return super.getInitialLocation(size);
}
/**
* The <code>WorkbenchWindow</code> implementation of this method
* delegates to the window configurer.
*
* @since 3.0
*/
protected Point getInitialSize() {
return getWindowConfigurer().getInitialSize();
}
/**
* @param visible
* whether the cool bar should be shown. This is only applicable
* if the window configurer also wishes either the cool bar to be
* visible.
* @since 3.0
*/
public void setCoolBarVisible(boolean visible) {
boolean oldValue = coolBarVisible;
coolBarVisible = visible;
if (oldValue != coolBarVisible) {
updateLayoutDataForContents();
firePropertyChanged(PROP_COOLBAR_VISIBLE,
oldValue ? Boolean.TRUE : Boolean.FALSE,
coolBarVisible ? Boolean.TRUE : Boolean.FALSE);
}
}
/**
* @return whether the cool bar should be shown. This is only applicable if
* the window configurer also wishes either the cool bar to be
* visible.
* @since 3.0
*/
public boolean getCoolBarVisible() {
return getWindowConfigurer().getShowCoolBar() && coolBarVisible;
}
/**
* @param visible
* whether the perspective bar should be shown. This is only
* applicable if the window configurer also wishes either the
* perspective bar to be visible.
* @since 3.0
*/
public void setPerspectiveBarVisible(boolean visible) {
boolean oldValue = perspectiveBarVisible;
perspectiveBarVisible = visible;
if (oldValue != perspectiveBarVisible) {
updateLayoutDataForContents();
firePropertyChanged(PROP_PERSPECTIVEBAR_VISIBLE,
oldValue ? Boolean.TRUE : Boolean.FALSE,
perspectiveBarVisible ? Boolean.TRUE : Boolean.FALSE);
}
}
/**
* @return whether the perspective bar should be shown. This is only
* applicable if the window configurer also wishes either the
* perspective bar to be visible.
* @since 3.0
*/
public boolean getPerspectiveBarVisible() {
return getWindowConfigurer().getShowPerspectiveBar() && perspectiveBarVisible;
}
/**
* Tell the workbench window a visible state for the fastview bar. This is
* only applicable if the window configurer also wishes the fast view bar to
* be visible.
*
* @param visible
* <code>true</code> or <code>false</code>
* @since 3.2
*/
public void setFastViewBarVisible(boolean visible) {
boolean oldValue = fastViewBarVisible;
fastViewBarVisible = visible;
if (oldValue != fastViewBarVisible) {
updateLayoutDataForContents();
}
}
/**
* The workbench window take on the fastview bar. This is only applicable if
* the window configurer also wishes the fast view bar to be visible.
*
* @return <code>true</code> if the workbench window thinks the fastview
* bar should be visible.
* @since 3.2
*/
public boolean getFastViewBarVisible() {
return fastViewBarVisible;
}
/**
* @param visible
* whether the perspective bar should be shown. This is only
* applicable if the window configurer also wishes either the
* perspective bar to be visible.
* @since 3.0
*/
public void setStatusLineVisible(boolean visible) {
boolean oldValue = statusLineVisible;
statusLineVisible = visible;
if (oldValue != statusLineVisible) {
updateLayoutDataForContents();
firePropertyChanged(PROP_STATUS_LINE_VISIBLE,
oldValue ? Boolean.TRUE : Boolean.FALSE,
statusLineVisible ? Boolean.TRUE : Boolean.FALSE);
}
}
/**
* @return whether the perspective bar should be shown. This is only
* applicable if the window configurer also wishes either the
* perspective bar to be visible.
* @since 3.0
*/
public boolean getStatusLineVisible() {
return statusLineVisible;
}
/**
* Note that this will only have an effect if the default implementation of
* WorkbenchAdvisor.createWindowContents() has been invoked.
*
* called IWorkbench
*
* @since 3.0
*/
private void updateLayoutDataForContents() {
if (defaultLayout == null) {
return;
}
// @issue this is not ideal; coolbar and perspective shortcuts should be
// separately configurable
String perspectiveBarOnTheLeftString = PlatformUI.getPreferenceStore()
.getString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR);
boolean perspectiveBarOnTheLeft = perspectiveBarOnTheLeftString != null
&& perspectiveBarOnTheLeftString
.equalsIgnoreCase(IWorkbenchPreferenceConstants.LEFT);
if ((getCoolBarVisible() && getWindowConfigurer().getShowCoolBar())
|| (getPerspectiveBarVisible()
&& getWindowConfigurer().getShowPerspectiveBar() && !perspectiveBarOnTheLeft)) {
if (defaultLayout.getTrim(topBarTrim.getId()) == null) {
defaultLayout.addTrim(SWT.TOP, topBarTrim);
}
topBar.setVisible(true);
} else {
defaultLayout.removeTrim(topBarTrim);
topBar.setVisible(false);
}
if (fastViewBar != null) {
if (getFastViewBarVisible()
&& getWindowConfigurer().getShowFastViewBars()) {
int side = fastViewBar.getSide();
if (defaultLayout.getTrim(fastViewBar.getId()) == null) {
defaultLayout.addTrim(side, fastViewBar);
}
fastViewBar.getControl().setVisible(true);
} else {
defaultLayout.removeTrim(fastViewBar);
fastViewBar.getControl().setVisible(false);
}
}
if (getStatusLineVisible() && getWindowConfigurer().getShowStatusLine()) {
if (defaultLayout.getTrim(getStatusLineTrim().getId()) == null) {
defaultLayout.addTrim(SWT.BOTTOM, getStatusLineTrim());
}
getStatusLineManager().getControl().setVisible(true);
} else {
defaultLayout.removeTrim(getStatusLineTrim());
getStatusLineManager().getControl().setVisible(false);
}
if (heapStatus != null) {
if (getShowHeapStatus()) {
if (heapStatus.getLayoutData() == null) {
heapStatusTrim.setWidthHint(heapStatus.computeSize(
SWT.DEFAULT, SWT.DEFAULT).x);
heapStatusTrim
.setHeightHint(getStatusLineManager().getControl()
.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
}
if (defaultLayout.getTrim(heapStatusTrim.getId()) == null) {
defaultLayout.addTrim(SWT.BOTTOM, heapStatusTrim);
}
heapStatus.setVisible(true);
} else {
defaultLayout.removeTrim(heapStatusTrim);
heapStatus.setVisible(false);
}
}
if (progressRegion != null) {
if (getWindowConfigurer().getShowProgressIndicator()) {
if (defaultLayout.getTrim(progressRegion.getId()) == null) {
defaultLayout.addTrim(SWT.BOTTOM, progressRegion);
}
progressRegion.getControl().setVisible(true);
} else {
defaultLayout.removeTrim(progressRegion);
progressRegion.getControl().setVisible(false);
}
}
defaultLayout.setCenterControl(getPageComposite());
// Re-populate the trim elements
if (trimMgr2 != null)
trimMgr2.update(true, false, !topBar.getVisible());
if (trimContributionMgr != null)
trimContributionMgr.update(true, !topBar.getVisible());
}
public boolean getShowFastViewBars() {
return getWindowConfigurer().getShowFastViewBars();
}
/**
* Set the layout data for the contents of the window.
*/
private void setLayoutDataForContents() {
updateLayoutDataForContents();
}
/**
* Returns the fast view bar.
*/
public FastViewBar getFastViewBar() {
return fastViewBar;
}
/**
* Returns the perspective bar.
*
* @return Returns the perspective bar, or <code>null</code> if it has not
* been initialized.
*/
public PerspectiveBarManager getPerspectiveBar() {
return perspectiveSwitcher == null ? null : perspectiveSwitcher
.getPerspectiveBar();
}
/**
* Returns the action presentation for dynamic UI
* @return action presentation
*/
public ActionPresentation getActionPresentation() {
if (actionPresentation == null) {
actionPresentation = new ActionPresentation(this);
}
return actionPresentation;
}
/**
* Return the action bar presentation used for creating toolbars. This
* is for internal use only, used for consistency with the window.
*
* @return the presentation used.
*/
public IActionBarPresentationFactory getActionBarPresentationFactory() {
// allow replacement of the actionbar presentation
IActionBarPresentationFactory actionBarPresentation;
AbstractPresentationFactory presentationFactory =
getWindowConfigurer().getPresentationFactory();
if (presentationFactory instanceof IActionBarPresentationFactory) {
actionBarPresentation = ((IActionBarPresentationFactory) presentationFactory);
} else {
actionBarPresentation = new DefaultActionBarPresentationFactory();
}
return actionBarPresentation;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.ApplicationWindow#showTopSeperator()
*/
protected boolean showTopSeperator() {
return false;
}
/**
* Returns a new cool bar manager for the window.
* <p>
* Subclasses may override this method to customize the cool bar manager.
* </p>
*
* @return a cool bar manager
* @since 3.2
*/
protected ICoolBarManager createCoolBarManager2(int style) {
final ICoolBarManager2 coolBarManager = getActionBarPresentationFactory().createCoolBarManager();
coolBarManager.setOverrides(toolbarOverride);
return coolBarManager;
}
/**
* Returns a new tool bar manager for the window.
* <p>
* Subclasses may override this method to customize the tool bar manager.
* </p>
* @return a tool bar manager
* @since 3.2
*/
protected IToolBarManager createToolBarManager2(int style) {
final IToolBarManager2 toolBarManager = getActionBarPresentationFactory().createToolBarManager();
toolBarManager.setOverrides(toolbarOverride);
return toolBarManager;
}
/**
* Delegate to the presentation factory.
*
* @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager
* @since 3.0
*/
protected StatusLineManager createStatusLineManager() {
// @issue ApplicationWindow and WorkbenchWindow should allow full
// IStatusLineManager
return (StatusLineManager) getWindowConfigurer()
.getPresentationFactory().createStatusLineManager();
}
/**
* Delegate to the presentation factory.
*
* @see org.eclipse.jface.window.ApplicationWindow#createStatusLine
* @since 3.0
*/
protected void createStatusLine(Shell shell) {
getWindowConfigurer().getPresentationFactory().createStatusLineControl(
getStatusLineManager(), shell);
}
/**
* Updates the fast view bar, if present. TODO: The fast view bar should
* update itself as necessary. All calls to this should be cleaned up.
*
* @since 3.0
*/
public void updateFastViewBar() {
if (getFastViewBar() != null) {
getFastViewBar().update(true);
}
}
/**
* @return Returns the progressRegion.
*/
public ProgressRegion getProgressRegion() {
return progressRegion;
}
/**
* Adds the given control to the specified side of this window's trim.
*
* @param trim
* the bar's IWindowTrim
* @param side
* one of <code>SWT.LEFT</code>,<code>SWT.BOTTOM</code>,
* or <code>SWT.RIGHT</code> (only LEFT has been tested)
* @since 3.0
*/
public void addToTrim(IWindowTrim trim, int side) {
IWindowTrim reference = null;
defaultLayout.addTrim(side, trim, reference);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbenchWindow#getExtensionTracker()
*/
public IExtensionTracker getExtensionTracker() {
if (tracker == null) {
tracker = new UIExtensionTracker(getWorkbench().getDisplay());
}
return tracker;
}
/**
* Creates the perspective customization dialog.
*
* @param persp
* perspective to customize
*
* @return a new perspective customization dialog
* @since 3.1
*/
public CustomizePerspectiveDialog createCustomizePerspectiveDialog(
Perspective persp) {
return new CustomizePerspectiveDialog(getWindowConfigurer(), persp);
}
/**
* Returns the default page input for workbench pages opened in this window.
*
* @return the default page input or <code>null</code> if none
* @since 3.1
*/
IAdaptable getDefaultPageInput() {
return getWorkbenchImpl().getDefaultPageInput();
}
/**
* Add a listener for perspective reordering.
*
* @param listener
*/
public void addPerspectiveReorderListener(IReorderListener listener) {
if (perspectiveSwitcher != null) {
perspectiveSwitcher.addReorderListener(listener);
}
}
/**
* Show the heap status
*
* @param selection
*/
public void showHeapStatus(boolean selection) {
if (selection) {
if (heapStatus == null) {
createHeapStatus(getShell());
updateLayoutDataForContents();
getShell().layout();
}
} else {
if (heapStatus != null) {
heapStatus.dispose();
heapStatus = null;
}
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbenchWindow#getTrimManager()
*/
public ITrimManager getTrimManager() {
return defaultLayout;
}
/**
* Initializes all of the default command-based services for the workbench
* window.
*/
private final void initializeDefaultServices() {
serviceLocator.registerService(IWorkbenchLocationService.class,
new WorkbenchLocationService(IServiceScopes.WINDOW_SCOPE,
getWorkbench(), this, null, null, null, 1));
// added back for legacy reasons
serviceLocator.registerService(IWorkbenchWindow.class, this);
final ActionCommandMappingService mappingService = new ActionCommandMappingService();
serviceLocator.registerService(IActionCommandMappingService.class,
mappingService);
final LegacyActionPersistence actionPersistence = new LegacyActionPersistence(
this);
serviceLocator.registerService(LegacyActionPersistence.class,
actionPersistence);
actionPersistence.read();
}
public final Object getService(final Class key) {
return serviceLocator.getService(key);
}
public final boolean hasService(final Class key) {
return serviceLocator.hasService(key);
}
/**
* Toggle the visibility of the coolbar/perspective bar. This method
* respects the window configurer and will only toggle visibility if the
* item in question was originally declared visible by the window advisor.
*
* @since 3.3
*/
public void toggleToolbarVisibility() {
boolean coolbarVisible = getCoolBarVisible();
boolean perspectivebarVisible = getPerspectiveBarVisible();
IPreferenceStore prefs = PrefUtil.getInternalPreferenceStore();
// only toggle the visibility of the components that
// were on initially
if (getWindowConfigurer().getShowCoolBar()) {
setCoolBarVisible(!coolbarVisible);
prefs.setValue(IPreferenceConstants.COOLBAR_VISIBLE, !coolbarVisible);
}
if (getWindowConfigurer().getShowPerspectiveBar()) {
setPerspectiveBarVisible(!perspectivebarVisible);
prefs.setValue(IPreferenceConstants.PERSPECTIVEBAR_VISIBLE, !perspectivebarVisible);
}
getShell().layout();
}
/*package*/ void addBackgroundSaveListener(IBackgroundSaveListener listener) {
backgroundSaveListeners.add(listener);
}
/*package*/ void fireBackgroundSaveStarted() {
Object[] listeners = backgroundSaveListeners.getListeners();
for (int i = 0; i < listeners.length; i++) {
IBackgroundSaveListener listener = (IBackgroundSaveListener) listeners[i];
listener.handleBackgroundSaveStarted();
}
}
/*package*/ void removeBackgroundSaveListener(IBackgroundSaveListener listener) {
backgroundSaveListeners.remove(listener);
}
}
|