1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package net.wotonomy.web; |
20 |
|
|
21 |
|
import net.wotonomy.foundation.NSDictionary; |
22 |
|
import net.wotonomy.foundation.NSMutableDictionary; |
23 |
|
|
24 |
|
public class WOSwitchComponent extends WODynamicElement { |
25 |
|
|
26 |
|
private NSMutableDictionary elements; |
27 |
|
private String currentName; |
28 |
|
private WOElement currentElement; |
29 |
|
|
30 |
|
protected WOSwitchComponent() |
31 |
|
{ |
32 |
0 |
super(); |
33 |
0 |
elements = new NSMutableDictionary(); |
34 |
0 |
} |
35 |
|
|
36 |
|
public WOSwitchComponent(String aName, NSDictionary aMap, WOElement template) |
37 |
|
{ |
38 |
0 |
super(aName, aMap, template); |
39 |
0 |
elements = new NSMutableDictionary(); |
40 |
0 |
} |
41 |
|
|
42 |
|
private WOElement getCurrentElement( WOContext c ) |
43 |
|
{ |
44 |
0 |
String name = stringForProperty( "WOComponentName", c.component() ); |
45 |
0 |
if ( name == null ) return null; |
46 |
|
|
47 |
0 |
if ( currentElement != null && name.equals( currentName ) ) return currentElement; |
48 |
|
|
49 |
0 |
currentName = name; |
50 |
0 |
currentElement = (WOElement) elements.objectForKey( name ); |
51 |
0 |
if ( currentElement == null ) |
52 |
|
{ |
53 |
0 |
currentElement = WOApplication.application().pageWithName( name, c ); |
54 |
0 |
if ( currentElement != null ) |
55 |
|
{ |
56 |
0 |
currentElement.associations = associations; |
57 |
0 |
elements.setObjectForKey( currentElement, name ); |
58 |
|
} |
59 |
|
} |
60 |
|
|
61 |
0 |
return currentElement; |
62 |
|
} |
63 |
|
|
64 |
|
void ensureAwakeInContext (WOContext aContext) |
65 |
|
{ |
66 |
0 |
if ( aContext != null ) |
67 |
|
{ |
68 |
0 |
WOElement element = getCurrentElement( aContext ); |
69 |
0 |
if ( element != null ) |
70 |
|
{ |
71 |
0 |
aContext.pushElement( element ); |
72 |
0 |
element.ensureAwakeInContext( aContext ); |
73 |
0 |
aContext.popElement(); |
74 |
|
} |
75 |
|
} |
76 |
0 |
} |
77 |
|
|
78 |
|
public void takeValuesFromRequest(WORequest r, WOContext c) |
79 |
|
{ |
80 |
0 |
WOElement element = getCurrentElement( c ); |
81 |
0 |
if ( element != null ) |
82 |
|
{ |
83 |
0 |
c.pushElement( element ); |
84 |
0 |
element.takeValuesFromRequest( r, c ); |
85 |
0 |
c.popElement(); |
86 |
|
} |
87 |
0 |
} |
88 |
|
|
89 |
|
public WOActionResults invokeAction(WORequest r, WOContext c) |
90 |
|
{ |
91 |
0 |
WOActionResults result = null; |
92 |
0 |
WOElement element = getCurrentElement( c ); |
93 |
0 |
if ( element != null ) |
94 |
|
{ |
95 |
0 |
c.pushElement( element ); |
96 |
0 |
result = element.invokeAction( r, c ); |
97 |
0 |
c.popElement(); |
98 |
|
} |
99 |
0 |
return result; |
100 |
|
} |
101 |
|
|
102 |
|
public void appendToResponse(WOResponse r, WOContext c) |
103 |
|
{ |
104 |
0 |
WOElement element = getCurrentElement( c ); |
105 |
0 |
if ( element != null ) |
106 |
|
{ |
107 |
0 |
c.pushElement( element ); |
108 |
0 |
element.appendToResponse( r, c ); |
109 |
0 |
c.popElement(); |
110 |
|
} |
111 |
0 |
} |
112 |
|
} |