comparison org.eclipse.jface/src/org/eclipse/jface/window/WindowManager.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.jface.window.WindowManager;
14
15 import org.eclipse.jface.window.Window;
16
17
18 import org.eclipse.core.runtime.Assert;
19
20 import java.lang.all;
21 import java.util.List;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.Set;
25
26 /**
27 * A manager for a group of windows. Window managers are an optional JFace
28 * feature used in applications which create many different windows (dialogs,
29 * wizards, etc.) in addition to a main window. A window manager can be used to
30 * remember all the windows that an application has created (independent of
31 * whether they are presently open or closed). There can be several window
32 * managers, and they can be arranged into a tree. This kind of organization
33 * makes it simple to close whole subgroupings of windows.
34 * <p>
35 * Creating a window manager is as simple as creating an instance of
36 * <code>WindowManager</code>. Associating a window with a window manager is
37 * done with <code>WindowManager.add(Window)</code>. A window is automatically
38 * removed from its window manager as a side effect of closing the window.
39 * </p>
40 *
41 * @see Window
42 */
43 public class WindowManager {
44
45 /**
46 * List of windows managed by this window manager
47 * (element type: <code>Window</code>).
48 */
49 private ArrayList windows;
50
51 /**
52 * List of window managers who have this window manager
53 * as their parent (element type: <code>WindowManager</code>).
54 */
55 private List subManagers;
56
57 /**
58 * Creates an empty window manager without a parent window
59 * manager (that is, a root window manager).
60 */
61 public this() {
62 windows = new ArrayList();
63 }
64
65 /**
66 * Creates an empty window manager with the given
67 * window manager as parent.
68 *
69 * @param parent the parent window manager
70 */
71 public this(WindowManager parent) {
72 windows = new ArrayList();
73 Assert.isNotNull(parent);
74 parent.addWindowManager(this);
75 }
76
77 /**
78 * Adds the given window to the set of windows managed by
79 * this window manager. Does nothing is this window is
80 * already managed by this window manager.
81 *
82 * @param window the window
83 */
84 public void add(Window window) {
85 if (!windows.contains(window)) {
86 windows.add(window);
87 window.setWindowManager(this);
88 }
89 }
90
91 /**
92 * Adds the given window manager to the list of
93 * window managers that have this one as a parent.
94 * </p>
95 * @param wm the child window manager
96 */
97 private void addWindowManager(WindowManager wm) {
98 if (subManagers is null) {
99 subManagers = new ArrayList();
100 }
101 if (!subManagers.contains(wm)) {
102 subManagers.add(wm);
103 }
104 }
105
106 /**
107 * Attempts to close all windows managed by this window manager,
108 * as well as windows managed by any descendent window managers.
109 *
110 * @return <code>true</code> if all windows were sucessfully closed,
111 * and <code>false</code> if any window refused to close
112 */
113 public bool close() {
114 List t = cast(List) windows.clone(); // make iteration robust
115 Iterator e = t.iterator();
116 while (e.hasNext()) {
117 Window window = cast(Window) e.next();
118 bool closed = window.close();
119 if (!closed) {
120 return false;
121 }
122 }
123 if (subManagers !is null) {
124 e = subManagers.iterator();
125 while (e.hasNext()) {
126 WindowManager wm = cast(WindowManager) e.next();
127 bool closed = wm.close();
128 if (!closed) {
129 return false;
130 }
131 }
132 }
133 return true;
134 }
135
136 /**
137 * Returns this window manager's number of windows
138 *
139 * @return the number of windows
140 * @since 3.0
141 */
142 public int getWindowCount() {
143 return windows.size();
144 }
145
146 /**
147 * Returns this window manager's set of windows.
148 *
149 * @return a possibly empty list of window
150 */
151 public Window[] getWindows() {
152 return arraycast!(Window)(windows.toArray());
153 }
154
155 /**
156 * Removes the given window from the set of windows managed by
157 * this window manager. Does nothing is this window is
158 * not managed by this window manager.
159 *
160 * @param window the window
161 */
162 public final void remove(Window window) {
163 if (windows.contains(window)) {
164 windows.remove(window);
165 window.setWindowManager(null);
166 }
167 }
168 }