litesoft
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
package org.litesoft.GWT.client.widgets.nonpublic;
import java.util.*;
import org.litesoft.core.util.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
public abstract class AbstractSizeablePanel extends AbstractSizeableWidget implements HasWidgets
{
private AbstractSizeableHelper mHelper = new AbstractSizeableHelper( this );
// Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element)
// Style Element: Normally the Div that is sandwiched between the inner and outer tables
// Inner Element: Inner most Element
protected AbstractSizeableHelper getHelper()
{
return mHelper;
}
protected void initializeElements( Element pContainerElement, String pStyleClassName )
{
mContainerElement = pContainerElement;
setElement( getHelper().getOuterElement() );
initialize();
if ( null != (pStyleClassName = UtilsCommon.noEmpty( pStyleClassName )) )
{
setStyleName( getHelper().getStyleElement(), pStyleClassName, true );
}
}
abstract public boolean anyChildren();
// vvvvvvvvvvv HasWidgets
/**
* Removes all child widgets.
*/
public void clear()
{
Iterator<Widget> it = iterator();
while ( it.hasNext() )
{
it.next();
it.remove();
}
}
// ^^^^^^^^^^^ HasWidgets
/**
* This method must be called as part of the add method of any panel. It
* ensures that the Widget's parent is set properly, and that it is removed
* from any existing parent widget. It also attaches the child widget's
* DOM element to its new container, ensuring that this process occurs in the
* right order.
*
* @param w the widget to be adopted
* @param container the element within which it will be contained
*
* @return container element passed in
*/
protected Element adopt( Widget w, Element container )
{
// Remove the widget from its current parent, if any.
w.removeFromParent();
// Attach it at the DOM and GWT levels.
if ( container != null )
{
appendChild( container, w.getElement() );
}
//noinspection NonJREEmulationClassesInClientCode
BackDoorToWidget.setParent( w, this );
return container;
}
/**
* This method must be called whenever a Widget is removed. It ensures that
* the Widget's parent is cleared.
*
* @param w the widget to be disowned
*
* @return Parent Element
*/
protected Element disown( Widget w )
{
// Only disown it if it's actually contained in this panel.
if ( !isOur( w ) )
{
throw new IllegalArgumentException( "widget (" + w + ") is not a child of this panel" );
}
// Remove it at the DOM and GWT levels.
Element elem = w.getElement();
//noinspection NonJREEmulationClassesInClientCode
BackDoorToWidget.setParent( w, null );
return removeAsChildAndGetParent( elem );
}
protected Element removeAsChildAndGetParent( Element pElem )
{
Element zParent = DOM.getParent( pElem );
DOM.removeChild( zParent, pElem );
return zParent;
}
protected static Element prependChild( Element pParent, Element pChild )
{
DOM.insertChild( pParent, pChild, 0 );
return pParent;
}
protected static Element appendChild( Element pParent, Element pChild )
{
DOM.appendChild( pParent, pChild );
return pParent;
}
protected static Element getParentElement( Widget pWidget )
{
return DOM.getParent( pWidget.getElement() );
}
protected static Element getGrandParentElement( Widget pWidget )
{
return DOM.getParent( getParentElement( pWidget ) );
}
protected void onAttach()
{
super.onAttach();
// Ensure that all child widgets are attached.
for ( Widget child : this )
{
//noinspection NonJREEmulationClassesInClientCode
BackDoorToWidget.onAttach( child );
}
}
protected void onDetach()
{
super.onDetach();
// Ensure that all child widgets are detached.
for ( Widget child : this )
{
//noinspection NonJREEmulationClassesInClientCode
BackDoorToWidget.onDetach( child );
}
}
/**
* Override this method to specify that an element other than the root element
* be the container for the panel's child widget. This can be useful when you
* want to create a simple panel that decorates its contents.
*
* @return the element to be used as the panel's container
*/
protected Element getContainerElement()
{
return mContainerElement;
}
private Element mContainerElement;
public void setContainerElement( Element pContainerElement )
{
mContainerElement = pContainerElement;
}
protected boolean isOur( Widget pWidget )
{
return (pWidget != null) && (pWidget.getParent() == this);
}
protected ISizeableWidget getSizeableWidget( Widget pWidget )
{
return (pWidget instanceof ISizeableWidget) ? (ISizeableWidget) pWidget : ISizeableWidget.NULL;
}
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|