comparison dwtx/jface/window/WindowManager.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 8a302fdb4140
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwtx.jface.window.WindowManager; 13 module dwtx.jface.window.WindowManager;
14 14
15 import dwtx.jface.window.Window; 15 import dwtx.jface.window.Window;
16 16
17 import tango.util.collection.ArraySeq;
18 import tango.util.collection.model.Seq;
19 17
20 import dwtx.core.runtime.Assert; 18 import dwtx.core.runtime.Assert;
21 19
22 import dwt.dwthelper.utils; 20 import dwt.dwthelper.utils;
21 import dwtx.dwtxhelper.Collection;
23 22
24 /** 23 /**
25 * A manager for a group of windows. Window managers are an optional JFace 24 * A manager for a group of windows. Window managers are an optional JFace
26 * feature used in applications which create many different windows (dialogs, 25 * feature used in applications which create many different windows (dialogs,
27 * wizards, etc.) in addition to a main window. A window manager can be used to 26 * wizards, etc.) in addition to a main window. A window manager can be used to
42 41
43 /** 42 /**
44 * List of windows managed by this window manager 43 * List of windows managed by this window manager
45 * (element type: <code>Window</code>). 44 * (element type: <code>Window</code>).
46 */ 45 */
47 private ArraySeq!(Window) windows; 46 private ArrayList windows;
48 47
49 /** 48 /**
50 * List of window managers who have this window manager 49 * List of window managers who have this window manager
51 * as their parent (element type: <code>WindowManager</code>). 50 * as their parent (element type: <code>WindowManager</code>).
52 */ 51 */
53 private Seq!(WindowManager) subManagers; 52 private List subManagers;
54 53
55 /** 54 /**
56 * Creates an empty window manager without a parent window 55 * Creates an empty window manager without a parent window
57 * manager (that is, a root window manager). 56 * manager (that is, a root window manager).
58 */ 57 */
59 public this() { 58 public this() {
60 windows = new ArraySeq!(Window); 59 windows = new ArrayList();
61 } 60 }
62 61
63 /** 62 /**
64 * Creates an empty window manager with the given 63 * Creates an empty window manager with the given
65 * window manager as parent. 64 * window manager as parent.
66 * 65 *
67 * @param parent the parent window manager 66 * @param parent the parent window manager
68 */ 67 */
69 public this(WindowManager parent) { 68 public this(WindowManager parent) {
70 windows = new ArraySeq!(Window); 69 windows = new ArrayList();
71 Assert.isNotNull(parent); 70 Assert.isNotNull(parent);
72 parent.addWindowManager(this); 71 parent.addWindowManager(this);
73 } 72 }
74 73
75 /** 74 /**
79 * 78 *
80 * @param window the window 79 * @param window the window
81 */ 80 */
82 public void add(Window window) { 81 public void add(Window window) {
83 if (!windows.contains(window)) { 82 if (!windows.contains(window)) {
84 windows.append(window); 83 windows.add(window);
85 window.setWindowManager(this); 84 window.setWindowManager(this);
86 } 85 }
87 } 86 }
88 87
89 /** 88 /**
92 * </p> 91 * </p>
93 * @param wm the child window manager 92 * @param wm the child window manager
94 */ 93 */
95 private void addWindowManager(WindowManager wm) { 94 private void addWindowManager(WindowManager wm) {
96 if (subManagers is null) { 95 if (subManagers is null) {
97 subManagers = new ArraySeq!(WindowManager); 96 subManagers = new ArrayList();
98 } 97 }
99 if (!subManagers.contains(wm)) { 98 if (!subManagers.contains(wm)) {
100 subManagers.append(wm); 99 subManagers.add(wm);
101 } 100 }
102 } 101 }
103 102
104 /** 103 /**
105 * Attempts to close all windows managed by this window manager, 104 * Attempts to close all windows managed by this window manager,
107 * 106 *
108 * @return <code>true</code> if all windows were sucessfully closed, 107 * @return <code>true</code> if all windows were sucessfully closed,
109 * and <code>false</code> if any window refused to close 108 * and <code>false</code> if any window refused to close
110 */ 109 */
111 public bool close() { 110 public bool close() {
112 auto t = windows.dup(); // make iteration robust 111 List t = cast(List) windows.clone(); // make iteration robust
113 foreach( window; t ){ 112 Iterator e = t.iterator();
113 while (e.hasNext()) {
114 Window window = cast(Window) e.next();
114 bool closed = window.close(); 115 bool closed = window.close();
115 if (!closed) { 116 if (!closed) {
116 return false; 117 return false;
117 } 118 }
118 } 119 }
119 if (subManagers !is null) { 120 if (subManagers !is null) {
120 foreach( wm; subManagers ){ 121 e = subManagers.iterator();
122 while (e.hasNext()) {
123 WindowManager wm = cast(WindowManager) e.next();
121 bool closed = wm.close(); 124 bool closed = wm.close();
122 if (!closed) { 125 if (!closed) {
123 return false; 126 return false;
124 } 127 }
125 } 128 }
141 * Returns this window manager's set of windows. 144 * Returns this window manager's set of windows.
142 * 145 *
143 * @return a possibly empty list of window 146 * @return a possibly empty list of window
144 */ 147 */
145 public Window[] getWindows() { 148 public Window[] getWindows() {
146 return windows.toArray(); 149 return arraycast!(Window)(windows.toArray());
147 } 150 }
148 151
149 /** 152 /**
150 * Removes the given window from the set of windows managed by 153 * Removes the given window from the set of windows managed by
151 * this window manager. Does nothing is this window is 154 * this window manager. Does nothing is this window is