2626import com .google .gwt .event .logical .shared .OpenEvent ;
2727import com .google .gwt .event .logical .shared .OpenHandler ;
2828import com .google .gwt .event .shared .HandlerRegistration ;
29+ import com .google .gwt .user .client .ui .RootPanel ;
2930import com .google .gwt .user .client .ui .Widget ;
3031import gwt .material .design .addins .client .MaterialAddins ;
3132import gwt .material .design .addins .client .banner .event .HasBannerHandlers ;
3940import gwt .material .design .client .ui .MaterialLabel ;
4041import gwt .material .design .client .ui .MaterialPanel ;
4142
43+ import java .util .ArrayList ;
44+ import java .util .Arrays ;
45+ import java .util .List ;
46+
4247import static gwt .material .design .jquery .client .api .JQuery .$ ;
4348
4449public class MaterialBanner extends MaterialWidget implements HasOpenClose , HasBannerHandlers {
@@ -48,9 +53,9 @@ public class MaterialBanner extends MaterialWidget implements HasOpenClose, HasB
4853 private final MaterialPanel actions ;
4954 private int offsetTop = 0 ;
5055 private int durationInMillis = 300 ;
51- private Element targetElement ;
56+ private List < Element > targetPushElements ;
5257
53- private ToggleStyleMixin <MaterialBanner > openMixin ;
58+ private ToggleStyleMixin <Widget > openMixin ;
5459
5560 static {
5661 if (MaterialAddins .isDebug ()) {
@@ -72,6 +77,8 @@ public MaterialBanner() {
7277
7378 actions = new MaterialPanel ();
7479 actions .addStyleName ("actions" );
80+
81+ targetPushElements = new ArrayList <>();
7582 }
7683
7784 @ Override
@@ -104,38 +111,29 @@ public boolean isOpen() {
104111 @ Override
105112 public void open () {
106113 getOpenMixin ().setOn (true );
107-
108114 setTop (offsetTop );
109- pushTargetContainer (getOuterHeight ());
115+ pushTargetElements (getOuterHeight ());
110116 OpenEvent .fire (this , getMessage ());
111117 }
112118
113- public void open (Element targetElement ) {
114- setTargetElement ( targetElement );
119+ public void open (Element ... targetElements ) {
120+ setTargetPushElements ( Arrays . asList ( targetElements ) );
115121 open ();
116122 }
117123
118124 @ Override
119125 public void close () {
120126 getOpenMixin ().setOn (false );
121-
122127 setTop (-getOuterHeight ());
123- pushTargetContainer (0 );
124-
128+ pushTargetElements (0 );
125129 CloseEvent .fire (this , getMessage ());
126130 }
127131
128- protected void pushTargetContainer (int translateY ) {
129- updateTransition ();
130- if (targetElement != null ) {
131- $ (targetElement ).css ("transform" , "translateY(" + translateY + "px)" );
132- }
133- }
134-
135- protected void updateTransition () {
132+ protected void pushTargetElements (int translateY ) {
136133 $ (getElement ()).css ("transition" , "all " + durationInMillis + "ms ease" );
137- if (targetElement != null ) {
138- $ (targetElement ).css ("transition" , "all " + durationInMillis + "ms ease" );
134+ for (Element element : targetPushElements ) {
135+ $ (element ).css ("transition" , "all " + durationInMillis + "ms ease" );
136+ $ (element ).css ("transform" , "translateY(" + translateY + "px)" );
139137 }
140138 }
141139
@@ -180,16 +178,12 @@ public MaterialLabel getMessageLabel() {
180178 return messageLabel ;
181179 }
182180
183- public void setTargetContainer (Widget targetContainer ) {
184- this .targetElement = targetContainer .getElement ();
185- }
186-
187- public Element getTargetElement () {
188- return targetElement ;
181+ public List <Element > getTargetPushElements () {
182+ return targetPushElements ;
189183 }
190184
191- public void setTargetElement ( Element targetElement ) {
192- this .targetElement = targetElement ;
185+ public void setTargetPushElements ( List < Element > targetPushElements ) {
186+ this .targetPushElements = targetPushElements ;
193187 }
194188
195189 public int getOffsetTop () {
@@ -204,9 +198,9 @@ public int getOuterHeight() {
204198 return $ (getElement ()).outerHeight (true );
205199 }
206200
207- public ToggleStyleMixin <MaterialBanner > getOpenMixin () {
201+ public ToggleStyleMixin <Widget > getOpenMixin () {
208202 if (openMixin == null ) {
209- openMixin = new ToggleStyleMixin <>(this , "open" );
203+ openMixin = new ToggleStyleMixin <>(RootPanel . get () , "banner- open" );
210204 }
211205 return openMixin ;
212206 }
0 commit comments