Mercurial > projects > dwt-addons
comparison dwtx/ui/forms/DetailsPart.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 | 5d489b9f966c |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
26 import dwtx.jface.viewers.IStructuredSelection; | 26 import dwtx.jface.viewers.IStructuredSelection; |
27 import dwtx.ui.forms.widgets.ScrolledPageBook; | 27 import dwtx.ui.forms.widgets.ScrolledPageBook; |
28 | 28 |
29 import dwt.dwthelper.utils; | 29 import dwt.dwthelper.utils; |
30 import dwt.dwthelper.Runnable; | 30 import dwt.dwthelper.Runnable; |
31 import tango.util.collection.HashMap; | 31 import dwtx.dwtxhelper.Collection; |
32 | 32 |
33 /** | 33 /** |
34 * This managed form part handles the 'details' portion of the | 34 * This managed form part handles the 'details' portion of the |
35 * 'master/details' block. It has a page book that manages pages | 35 * 'master/details' block. It has a page book that manages pages |
36 * of details registered for the current selection. | 36 * of details registered for the current selection. |
49 public final class DetailsPart : IFormPart, IPartSelectionListener { | 49 public final class DetailsPart : IFormPart, IPartSelectionListener { |
50 private IManagedForm managedForm; | 50 private IManagedForm managedForm; |
51 private ScrolledPageBook pageBook; | 51 private ScrolledPageBook pageBook; |
52 private IFormPart masterPart; | 52 private IFormPart masterPart; |
53 private IStructuredSelection currentSelection; | 53 private IStructuredSelection currentSelection; |
54 private HashMap!(Object,Object) pages; | 54 private Hashtable pages; |
55 private IDetailsPageProvider pageProvider; | 55 private IDetailsPageProvider pageProvider; |
56 private int pageLimit=Integer.MAX_VALUE; | 56 private int pageLimit=Integer.MAX_VALUE; |
57 | 57 |
58 private static class PageBag { | 58 private static class PageBag { |
59 private static int counter; | 59 private static int counter; |
91 * @param mform the parent form | 91 * @param mform the parent form |
92 * @param pageBook the page book to wrap | 92 * @param pageBook the page book to wrap |
93 */ | 93 */ |
94 public this(IManagedForm mform, ScrolledPageBook pageBook) { | 94 public this(IManagedForm mform, ScrolledPageBook pageBook) { |
95 this.pageBook = pageBook; | 95 this.pageBook = pageBook; |
96 pages = new HashMap!(Object,Object); | 96 pages = new Hashtable(); |
97 initialize(mform); | 97 initialize(mform); |
98 } | 98 } |
99 /** | 99 /** |
100 * Creates a new details part in the provided form by creating | 100 * Creates a new details part in the provided form by creating |
101 * the page book. | 101 * the page book. |
116 public void registerPage(Object objectClass, IDetailsPage page) { | 116 public void registerPage(Object objectClass, IDetailsPage page) { |
117 registerPage(objectClass, page, true); | 117 registerPage(objectClass, page, true); |
118 } | 118 } |
119 | 119 |
120 private void registerPage(Object objectClass, IDetailsPage page, bool fixed) { | 120 private void registerPage(Object objectClass, IDetailsPage page, bool fixed) { |
121 pages.add(objectClass, new PageBag(page, fixed)); | 121 pages.put(objectClass, new PageBag(page, fixed)); |
122 page.initialize(managedForm); | 122 page.initialize(managedForm); |
123 } | 123 } |
124 /** | 124 /** |
125 * Sets the dynamic page provider. The dynamic provider can return | 125 * Sets the dynamic page provider. The dynamic provider can return |
126 * different pages for objects of the same class based on their state. | 126 * different pages for objects of the same class based on their state. |
156 * (non-Javadoc) | 156 * (non-Javadoc) |
157 * | 157 * |
158 * @see dwtx.ui.forms.IFormPart#dispose() | 158 * @see dwtx.ui.forms.IFormPart#dispose() |
159 */ | 159 */ |
160 public void dispose() { | 160 public void dispose() { |
161 foreach( k, v; pages ){ | 161 for (Enumeration enm = pages.elements(); enm.hasMoreElements();) { |
162 PageBag pageBag = cast(PageBag) v; | 162 PageBag pageBag = cast(PageBag) enm.nextElement(); |
163 pageBag.dispose(); | 163 pageBag.dispose(); |
164 } | 164 } |
165 } | 165 } |
166 /* | 166 /* |
167 * (non-Javadoc) | 167 * (non-Javadoc) |
233 update(); | 233 update(); |
234 } | 234 } |
235 private void update() { | 235 private void update() { |
236 Object key = null; | 236 Object key = null; |
237 if (currentSelection !is null) { | 237 if (currentSelection !is null) { |
238 foreach ( obj; currentSelection.iterator() ) { | 238 for (Iterator iter = currentSelection.iterator(); iter.hasNext();) { |
239 Object obj = iter.next(); | |
239 if (key is null) | 240 if (key is null) |
240 key = getKey(obj); | 241 key = getKey(obj); |
241 else if (getKey(obj).opEquals(key) is false) { | 242 else if (getKey(obj).opEquals(key) is false) { |
242 key = null; | 243 key = null; |
243 break; | 244 break; |
297 private void checkLimit() { | 298 private void checkLimit() { |
298 if (pages.size() <= getPageLimit()) return; | 299 if (pages.size() <= getPageLimit()) return; |
299 // overflow | 300 // overflow |
300 int currentTicket = PageBag.getCurrentTicket(); | 301 int currentTicket = PageBag.getCurrentTicket(); |
301 int cutoffTicket = currentTicket - getPageLimit(); | 302 int cutoffTicket = currentTicket - getPageLimit(); |
302 foreach( key, v; cast(HashMap!(Object,Object))pages.dup ){ | 303 for (Enumeration enm=pages.keys(); enm.hasMoreElements();) { |
303 PageBag pageBag = cast(PageBag)v; | 304 Object key = enm.nextElement(); |
305 PageBag pageBag = cast(PageBag)pages.get(key); | |
304 if (pageBag.getTicket()<=cutoffTicket) { | 306 if (pageBag.getTicket()<=cutoffTicket) { |
305 // candidate - see if it is active and not fixed | 307 // candidate - see if it is active and not fixed |
306 if (!pageBag.isFixed() && !(cast(Object)pageBag.getPage()).opEquals(cast(Object)getCurrentPage())) { | 308 if (!pageBag.isFixed() && !(cast(Object)pageBag.getPage()).opEquals(cast(Object)getCurrentPage())) { |
307 // drop it | 309 // drop it |
308 pageBag.dispose(); | 310 pageBag.dispose(); |