forked from joelhooks/robotlegsdemos
-
Notifications
You must be signed in to change notification settings - Fork 46
/
OpenWindowsProxy.as
120 lines (106 loc) · 2.77 KB
/
OpenWindowsProxy.as
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
package org.robotlegs.demos.whereswindow.model
{
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;
import mx.collections.ArrayCollection;
import mx.utils.UIDUtil;
import org.robotlegs.demos.whereswindow.events.InfoWindowEvent;
import org.robotlegs.demos.whereswindow.view.components.InfoWindow;
import org.robotlegs.mvcs.Actor;
/**
* Proxy to keep track of current open <code>InfoWindow</code> objects
* @author joel
*
*/
public class OpenWindowsProxy extends Actor
{
/**
* Hash of currently open windows
*/
protected var windowMap:IMap;
public function OpenWindowsProxy()
{
windowMap = new HashMap();
}
/**
* Create a new <code>InfoWindow</code>. If the <code>windowMap</code>
* already contains a window with the specified UID, return that window
* instead
*
* @param uid identifies the window
* @return
*
*/
public function createWindow(uid:String = null):InfoWindow
{
var infoWindow:InfoWindow;
if (this.hasWindowUID(uid))
{
infoWindow = this.getWindowFromUID(uid);
return infoWindow
}
if (!uid)
uid = UIDUtil.createUID();
infoWindow = new InfoWindow();
infoWindow.id = uid;
this.windowMap.put(infoWindow.id, infoWindow);
dispatch(new InfoWindowEvent(InfoWindowEvent.INFO_WINDOW_ADDED, uid));
return infoWindow;
}
/**
* Retrieve an <code>InfoWindow</code> by its unique identifier
*
* @param uid
* @return
*
*/
public function getWindowFromUID(uid:String):InfoWindow
{
return this.windowMap.getValue(uid) as InfoWindow;
}
/**
* Remove a <code>InfoWindow</code> from the <code>windowMap</code>
* by its unique identifier.
*
* @param uid
*
*/
public function removeWindowByUID(uid:String):void
{
this.windowMap.remove(uid);
dispatch(new InfoWindowEvent(InfoWindowEvent.INFO_WINDOW_REMOVED, uid));
}
/**
* Check if the <code>windowMap</code> contains an <code>InfoWindow</code>
* unique identifier as a key.
*
* @param uid
* @return
*
*/
public function hasWindowUID(uid:String):Boolean
{
return this.windowMap.containsKey(uid);
}
public function updateCollection(collection:ArrayCollection):void
{
var windows:Array = this.windowMap.getValues();
var infoWindow:InfoWindow;
trace("currently registered:", windows);
for each (infoWindow in windows)
{
if (collection.getItemIndex(infoWindow) < 0)
collection.addItem(infoWindow);
}
for each (infoWindow in collection)
{
if (!this.windowMap.containsValue(infoWindow))
collection.removeItemAt(collection.getItemIndex(infoWindow));
}
}
public function getAllWindows():ArrayCollection
{
return new ArrayCollection(this.windowMap.getValues());
}
}
}