|
@@ -1,166 +1,166 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import com.google.gwt.user.client.*; |
7 |
|
- |
import com.google.gwt.user.client.ui.*; |
8 |
|
- |
|
9 |
|
- |
import java.util.*; |
10 |
|
- |
|
11 |
|
- |
public abstract class AbstractSizeablePanel extends AbstractSizeableWidget implements HasWidgets { |
12 |
|
- |
private AbstractSizeableHelper mHelper = new AbstractSizeableHelper( this ); |
13 |
|
- |
// Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element) |
14 |
|
- |
// Style Element: Normally the Div that is sandwiched between the inner and outer tables |
15 |
|
- |
// Inner Element: Inner most Element |
16 |
|
- |
|
17 |
|
- |
@Override |
18 |
|
- |
protected AbstractSizeableHelper getHelper() { |
19 |
|
- |
return mHelper; |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
protected void initializeElements( Element pContainerElement, String pStyleClassName ) { |
23 |
|
- |
mContainerElement = pContainerElement; |
24 |
|
- |
setElement( getHelper().getOuterElement() ); |
25 |
|
- |
initialize(); |
26 |
|
- |
if ( null != (pStyleClassName = Strings.noEmpty( pStyleClassName )) ) { |
27 |
|
- |
setStyleName( getHelper().getStyleElement(), pStyleClassName, true ); |
28 |
|
- |
} |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
abstract public boolean anyChildren(); |
32 |
|
- |
|
33 |
|
- |
// vvvvvvvvvvv HasWidgets |
34 |
|
- |
|
35 |
|
- |
/** |
36 |
|
- |
* Removes all child widgets. |
37 |
|
- |
*/ |
38 |
|
- |
@Override |
39 |
|
- |
public void clear() { |
40 |
|
- |
Iterator<Widget> it = iterator(); |
41 |
|
- |
while ( it.hasNext() ) { |
42 |
|
- |
it.next(); |
43 |
|
- |
it.remove(); |
44 |
|
- |
} |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
// ^^^^^^^^^^^ HasWidgets |
48 |
|
- |
|
49 |
|
- |
/** |
50 |
|
- |
* This method must be called as part of the add method of any panel. It |
51 |
|
- |
* ensures that the Widget's parent is set properly, and that it is removed |
52 |
|
- |
* from any existing parent widget. It also attaches the child widget's |
53 |
|
- |
* DOM element to its new container, ensuring that this process occurs in the |
54 |
|
- |
* right order. |
55 |
|
- |
* |
56 |
|
- |
* @param w the widget to be adopted |
57 |
|
- |
* @param container the element within which it will be contained |
58 |
|
- |
* |
59 |
|
- |
* @return container element passed in |
60 |
|
- |
*/ |
61 |
|
- |
protected Element adopt( Widget w, Element container ) { |
62 |
|
- |
// Remove the widget from its current parent, if any. |
63 |
|
- |
w.removeFromParent(); |
64 |
|
- |
|
65 |
|
- |
// Attach it at the DOM and GWT levels. |
66 |
|
- |
if ( container != null ) { |
67 |
|
- |
appendChild( container, w.getElement() ); |
68 |
|
- |
} |
69 |
|
- |
//noinspection NonJREEmulationClassesInClientCode |
70 |
|
- |
BackDoorToWidget.setParent( w, this ); |
71 |
|
- |
|
72 |
|
- |
return container; |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
/** |
76 |
|
- |
* This method must be called whenever a Widget is removed. It ensures that |
77 |
|
- |
* the Widget's parent is cleared. |
78 |
|
- |
* |
79 |
|
- |
* @param w the widget to be disowned |
80 |
|
- |
* |
81 |
|
- |
* @return Parent Element |
82 |
|
- |
*/ |
83 |
|
- |
protected Element disown( Widget w ) { |
84 |
|
- |
// Only disown it if it's actually contained in this panel. |
85 |
|
- |
if ( !isOur( w ) ) { |
86 |
|
- |
throw new IllegalArgumentException( "widget (" + w + ") is not a child of this panel" ); |
87 |
|
- |
} |
88 |
|
- |
|
89 |
|
- |
// Remove it at the DOM and GWT levels. |
90 |
|
- |
Element elem = w.getElement(); |
91 |
|
- |
//noinspection NonJREEmulationClassesInClientCode |
92 |
|
- |
BackDoorToWidget.setParent( w, null ); |
93 |
|
- |
return removeAsChildAndGetParent( elem ); |
94 |
|
- |
} |
95 |
|
- |
|
96 |
|
- |
protected Element removeAsChildAndGetParent( Element pElem ) { |
97 |
|
- |
Element zParent = DOM.getParent( pElem ); |
98 |
|
- |
DOM.removeChild( zParent, pElem ); |
99 |
|
- |
return zParent; |
100 |
|
- |
} |
101 |
|
- |
|
102 |
|
- |
protected static Element prependChild( Element pParent, Element pChild ) { |
103 |
|
- |
DOM.insertChild( pParent, pChild, 0 ); |
104 |
|
- |
return pParent; |
105 |
|
- |
} |
106 |
|
- |
|
107 |
|
- |
protected static Element appendChild( Element pParent, Element pChild ) { |
108 |
|
- |
DOM.appendChild( pParent, pChild ); |
109 |
|
- |
return pParent; |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
protected static Element getParentElement( Widget pWidget ) { |
113 |
|
- |
return DOM.getParent( pWidget.getElement() ); |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
protected static Element getGrandParentElement( Widget pWidget ) { |
117 |
|
- |
return DOM.getParent( getParentElement( pWidget ) ); |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
@Override |
121 |
|
- |
protected void onAttach() { |
122 |
|
- |
super.onAttach(); |
123 |
|
- |
|
124 |
|
- |
// Ensure that all child widgets are attached. |
125 |
|
- |
for ( Widget child : this ) { |
126 |
|
- |
//noinspection NonJREEmulationClassesInClientCode |
127 |
|
- |
BackDoorToWidget.onAttach( child ); |
128 |
|
- |
} |
129 |
|
- |
} |
130 |
|
- |
|
131 |
|
- |
@Override |
132 |
|
- |
protected void onDetach() { |
133 |
|
- |
super.onDetach(); |
134 |
|
- |
|
135 |
|
- |
// Ensure that all child widgets are detached. |
136 |
|
- |
for ( Widget child : this ) { |
137 |
|
- |
//noinspection NonJREEmulationClassesInClientCode |
138 |
|
- |
BackDoorToWidget.onDetach( child ); |
139 |
|
- |
} |
140 |
|
- |
} |
141 |
|
- |
|
142 |
|
- |
/** |
143 |
|
- |
* Override this method to specify that an element other than the root element |
144 |
|
- |
* be the container for the panel's child widget. This can be useful when you |
145 |
|
- |
* want to create a simple panel that decorates its contents. |
146 |
|
- |
* |
147 |
|
- |
* @return the element to be used as the panel's container |
148 |
|
- |
*/ |
149 |
|
- |
protected Element getContainerElement() { |
150 |
|
- |
return mContainerElement; |
151 |
|
- |
} |
152 |
|
- |
|
153 |
|
- |
private Element mContainerElement; |
154 |
|
- |
|
155 |
|
- |
public void setContainerElement( Element pContainerElement ) { |
156 |
|
- |
mContainerElement = pContainerElement; |
157 |
|
- |
} |
158 |
|
- |
|
159 |
|
- |
protected boolean isOur( Widget pWidget ) { |
160 |
|
- |
return (pWidget != null) && (pWidget.getParent() == this); |
161 |
|
- |
} |
162 |
|
- |
|
163 |
|
- |
protected ISizeableWidget getSizeableWidget( Widget pWidget ) { |
164 |
|
- |
return (pWidget instanceof ISizeableWidget) ? (ISizeableWidget) pWidget : ISizeableWidget.NULL; |
165 |
|
- |
} |
166 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
5 |
+ |
|
|
6 |
+ |
import com.google.gwt.user.client.*; |
|
7 |
+ |
import com.google.gwt.user.client.ui.*; |
|
8 |
+ |
|
|
9 |
+ |
import java.util.*; |
|
10 |
+ |
|
|
11 |
+ |
public abstract class AbstractSizeablePanel extends AbstractSizeableWidget implements HasWidgets { |
|
12 |
+ |
private AbstractSizeableHelper mHelper = new AbstractSizeableHelper( this ); |
|
13 |
+ |
// Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element) |
|
14 |
+ |
// Style Element: Normally the Div that is sandwiched between the inner and outer tables |
|
15 |
+ |
// Inner Element: Inner most Element |
|
16 |
+ |
|
|
17 |
+ |
@Override |
|
18 |
+ |
protected AbstractSizeableHelper getHelper() { |
|
19 |
+ |
return mHelper; |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
protected void initializeElements( Element pContainerElement, String pStyleClassName ) { |
|
23 |
+ |
mContainerElement = pContainerElement; |
|
24 |
+ |
setElement( getHelper().getOuterElement() ); |
|
25 |
+ |
initialize(); |
|
26 |
+ |
if ( null != (pStyleClassName = ConstrainTo.significantOrNull( pStyleClassName )) ) { |
|
27 |
+ |
setStyleName( getHelper().getStyleElement(), pStyleClassName, true ); |
|
28 |
+ |
} |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
abstract public boolean anyChildren(); |
|
32 |
+ |
|
|
33 |
+ |
// vvvvvvvvvvv HasWidgets |
|
34 |
+ |
|
|
35 |
+ |
/** |
|
36 |
+ |
* Removes all child widgets. |
|
37 |
+ |
*/ |
|
38 |
+ |
@Override |
|
39 |
+ |
public void clear() { |
|
40 |
+ |
Iterator<Widget> it = iterator(); |
|
41 |
+ |
while ( it.hasNext() ) { |
|
42 |
+ |
it.next(); |
|
43 |
+ |
it.remove(); |
|
44 |
+ |
} |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
// ^^^^^^^^^^^ HasWidgets |
|
48 |
+ |
|
|
49 |
+ |
/** |
|
50 |
+ |
* This method must be called as part of the add method of any panel. It |
|
51 |
+ |
* ensures that the Widget's parent is set properly, and that it is removed |
|
52 |
+ |
* from any existing parent widget. It also attaches the child widget's |
|
53 |
+ |
* DOM element to its new container, ensuring that this process occurs in the |
|
54 |
+ |
* right order. |
|
55 |
+ |
* |
|
56 |
+ |
* @param w the widget to be adopted |
|
57 |
+ |
* @param container the element within which it will be contained |
|
58 |
+ |
* |
|
59 |
+ |
* @return container element passed in |
|
60 |
+ |
*/ |
|
61 |
+ |
protected Element adopt( Widget w, Element container ) { |
|
62 |
+ |
// Remove the widget from its current parent, if any. |
|
63 |
+ |
w.removeFromParent(); |
|
64 |
+ |
|
|
65 |
+ |
// Attach it at the DOM and GWT levels. |
|
66 |
+ |
if ( container != null ) { |
|
67 |
+ |
appendChild( container, w.getElement() ); |
|
68 |
+ |
} |
|
69 |
+ |
//noinspection NonJREEmulationClassesInClientCode |
|
70 |
+ |
BackDoorToWidget.setParent( w, this ); |
|
71 |
+ |
|
|
72 |
+ |
return container; |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
/** |
|
76 |
+ |
* This method must be called whenever a Widget is removed. It ensures that |
|
77 |
+ |
* the Widget's parent is cleared. |
|
78 |
+ |
* |
|
79 |
+ |
* @param w the widget to be disowned |
|
80 |
+ |
* |
|
81 |
+ |
* @return Parent Element |
|
82 |
+ |
*/ |
|
83 |
+ |
protected Element disown( Widget w ) { |
|
84 |
+ |
// Only disown it if it's actually contained in this panel. |
|
85 |
+ |
if ( !isOur( w ) ) { |
|
86 |
+ |
throw new IllegalArgumentException( "widget (" + w + ") is not a child of this panel" ); |
|
87 |
+ |
} |
|
88 |
+ |
|
|
89 |
+ |
// Remove it at the DOM and GWT levels. |
|
90 |
+ |
Element elem = w.getElement(); |
|
91 |
+ |
//noinspection NonJREEmulationClassesInClientCode |
|
92 |
+ |
BackDoorToWidget.setParent( w, null ); |
|
93 |
+ |
return removeAsChildAndGetParent( elem ); |
|
94 |
+ |
} |
|
95 |
+ |
|
|
96 |
+ |
protected Element removeAsChildAndGetParent( Element pElem ) { |
|
97 |
+ |
Element zParent = DOM.getParent( pElem ); |
|
98 |
+ |
DOM.removeChild( zParent, pElem ); |
|
99 |
+ |
return zParent; |
|
100 |
+ |
} |
|
101 |
+ |
|
|
102 |
+ |
protected static Element prependChild( Element pParent, Element pChild ) { |
|
103 |
+ |
DOM.insertChild( pParent, pChild, 0 ); |
|
104 |
+ |
return pParent; |
|
105 |
+ |
} |
|
106 |
+ |
|
|
107 |
+ |
protected static Element appendChild( Element pParent, Element pChild ) { |
|
108 |
+ |
DOM.appendChild( pParent, pChild ); |
|
109 |
+ |
return pParent; |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
protected static Element getParentElement( Widget pWidget ) { |
|
113 |
+ |
return DOM.getParent( pWidget.getElement() ); |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
protected static Element getGrandParentElement( Widget pWidget ) { |
|
117 |
+ |
return DOM.getParent( getParentElement( pWidget ) ); |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
@Override |
|
121 |
+ |
protected void onAttach() { |
|
122 |
+ |
super.onAttach(); |
|
123 |
+ |
|
|
124 |
+ |
// Ensure that all child widgets are attached. |
|
125 |
+ |
for ( Widget child : this ) { |
|
126 |
+ |
//noinspection NonJREEmulationClassesInClientCode |
|
127 |
+ |
BackDoorToWidget.onAttach( child ); |
|
128 |
+ |
} |
|
129 |
+ |
} |
|
130 |
+ |
|
|
131 |
+ |
@Override |
|
132 |
+ |
protected void onDetach() { |
|
133 |
+ |
super.onDetach(); |
|
134 |
+ |
|
|
135 |
+ |
// Ensure that all child widgets are detached. |
|
136 |
+ |
for ( Widget child : this ) { |
|
137 |
+ |
//noinspection NonJREEmulationClassesInClientCode |
|
138 |
+ |
BackDoorToWidget.onDetach( child ); |
|
139 |
+ |
} |
|
140 |
+ |
} |
|
141 |
+ |
|
|
142 |
+ |
/** |
|
143 |
+ |
* Override this method to specify that an element other than the root element |
|
144 |
+ |
* be the container for the panel's child widget. This can be useful when you |
|
145 |
+ |
* want to create a simple panel that decorates its contents. |
|
146 |
+ |
* |
|
147 |
+ |
* @return the element to be used as the panel's container |
|
148 |
+ |
*/ |
|
149 |
+ |
protected Element getContainerElement() { |
|
150 |
+ |
return mContainerElement; |
|
151 |
+ |
} |
|
152 |
+ |
|
|
153 |
+ |
private Element mContainerElement; |
|
154 |
+ |
|
|
155 |
+ |
public void setContainerElement( Element pContainerElement ) { |
|
156 |
+ |
mContainerElement = pContainerElement; |
|
157 |
+ |
} |
|
158 |
+ |
|
|
159 |
+ |
protected boolean isOur( Widget pWidget ) { |
|
160 |
+ |
return (pWidget != null) && (pWidget.getParent() == this); |
|
161 |
+ |
} |
|
162 |
+ |
|
|
163 |
+ |
protected ISizeableWidget getSizeableWidget( Widget pWidget ) { |
|
164 |
+ |
return (pWidget instanceof ISizeableWidget) ? (ISizeableWidget) pWidget : ISizeableWidget.NULL; |
|
165 |
+ |
} |
|
166 |
+ |
} |