You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VAbstractOrderedLayout.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.orderedlayout;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.dom.client.Node;
  21. import com.google.gwt.dom.client.Style;
  22. import com.google.gwt.dom.client.Style.Unit;
  23. import com.google.gwt.dom.client.Style.Visibility;
  24. import com.google.gwt.regexp.shared.MatchResult;
  25. import com.google.gwt.regexp.shared.RegExp;
  26. import com.google.gwt.user.client.DOM;
  27. import com.google.gwt.user.client.ui.FlowPanel;
  28. import com.google.gwt.user.client.ui.RequiresResize;
  29. import com.google.gwt.user.client.ui.Widget;
  30. import com.vaadin.client.BrowserInfo;
  31. import com.vaadin.client.LayoutManager;
  32. import com.vaadin.client.Profiler;
  33. import com.vaadin.client.Util;
  34. import com.vaadin.client.WidgetUtil;
  35. import com.vaadin.shared.ui.MarginInfo;
  36. /**
  37. * Base class for ordered layouts
  38. */
  39. public class VAbstractOrderedLayout extends FlowPanel {
  40. protected boolean spacing = false;
  41. /** For internal use only. May be removed or replaced in the future. */
  42. public boolean vertical = true;
  43. protected boolean definedHeight = false;
  44. private Map<Widget, Slot> widgetToSlot = new HashMap<Widget, Slot>();
  45. private Element expandWrapper;
  46. private LayoutManager layoutManager;
  47. /**
  48. * Keep track of the last allocated expand size to help detecting when it
  49. * changes.
  50. */
  51. private int lastExpandSize = -1;
  52. public VAbstractOrderedLayout(boolean vertical) {
  53. this.vertical = vertical;
  54. }
  55. /**
  56. * See the method {@link #addOrMoveSlot(Slot, int, boolean)}.
  57. *
  58. * <p>
  59. * This method always adjusts spacings for the whole layout.
  60. *
  61. * @param slot
  62. * The slot to move or add
  63. * @param index
  64. * The index where the slot should be placed.
  65. * @deprecated since 7.1.4, use {@link #addOrMoveSlot(Slot, int, boolean)}
  66. */
  67. @Deprecated
  68. public void addOrMoveSlot(Slot slot, int index) {
  69. addOrMoveSlot(slot, index, true);
  70. }
  71. /**
  72. * Add or move a slot to another index.
  73. * <p>
  74. * For internal use only. May be removed or replaced in the future.
  75. * <p>
  76. * You should note that the index does not refer to the DOM index if
  77. * spacings are used. If spacings are used then the index will be adjusted
  78. * to include the spacings when inserted.
  79. * <p>
  80. * For instance when using spacing the index converts to DOM index in the
  81. * following way:
  82. *
  83. * <pre>
  84. * index : 0 -> DOM index: 0
  85. * index : 1 -> DOM index: 1
  86. * index : 2 -> DOM index: 3
  87. * index : 3 -> DOM index: 5
  88. * index : 4 -> DOM index: 7
  89. * </pre>
  90. *
  91. * When using this method never account for spacings.
  92. * <p>
  93. * The caller should remove all spacings before calling this method and
  94. * re-add them (if necessary) after this method. This can be done before and
  95. * after all slots have been added/moved.
  96. * </p>
  97. *
  98. * @since 7.1.4
  99. *
  100. * @param slot
  101. * The slot to move or add
  102. * @param index
  103. * The index where the slot should be placed.
  104. * @param adjustSpacing
  105. * true to recalculate spacings for the whole layout after the
  106. * operation
  107. */
  108. public void addOrMoveSlot(Slot slot, int index, boolean adjustSpacing) {
  109. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  110. if (slot.getParent() == this) {
  111. int currentIndex = getWidgetIndex(slot);
  112. if (index == currentIndex) {
  113. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  114. return;
  115. }
  116. }
  117. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  118. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  119. insert(slot, index);
  120. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  121. if (adjustSpacing) {
  122. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  123. setSpacing(spacing);
  124. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  125. }
  126. }
  127. /**
  128. * {@inheritDoc}
  129. *
  130. * @deprecated As of 7.2, use or override
  131. * {@link #insert(Widget, Element, int, boolean)} instead.
  132. */
  133. @Override
  134. @Deprecated
  135. protected void insert(Widget child,
  136. com.google.gwt.user.client.Element container, int beforeIndex,
  137. boolean domInsert) {
  138. // Validate index; adjust if the widget is already a child of this
  139. // panel.
  140. beforeIndex = adjustIndex(child, beforeIndex);
  141. // Detach new child.
  142. child.removeFromParent();
  143. // Logical attach.
  144. getChildren().insert(child, beforeIndex);
  145. // Physical attach.
  146. container = expandWrapper != null ? DOM.asOld(expandWrapper)
  147. : getElement();
  148. if (domInsert) {
  149. if (spacing) {
  150. if (beforeIndex != 0) {
  151. /*
  152. * Since the spacing elements are located at the same DOM
  153. * level as the slots we need to take them into account when
  154. * calculating the slot position.
  155. *
  156. * The spacing elements are always located before the actual
  157. * slot except for the first slot which do not have a
  158. * spacing element like this
  159. *
  160. * |<slot1><spacing2><slot2><spacing3><slot3>...|
  161. */
  162. beforeIndex = beforeIndex * 2 - 1;
  163. }
  164. }
  165. DOM.insertChild(container, child.getElement(), beforeIndex);
  166. } else {
  167. DOM.appendChild(container, child.getElement());
  168. }
  169. // Adopt.
  170. adopt(child);
  171. }
  172. /**
  173. * {@inheritDoc}
  174. *
  175. * @since 7.2
  176. */
  177. @Override
  178. protected void insert(Widget child, Element container, int beforeIndex,
  179. boolean domInsert) {
  180. insert(child, DOM.asOld(container), beforeIndex, domInsert);
  181. }
  182. /**
  183. * Remove a slot from the layout
  184. *
  185. * @param widget
  186. * @return
  187. */
  188. public void removeWidget(Widget widget) {
  189. Slot slot = widgetToSlot.get(widget);
  190. remove(slot);
  191. widgetToSlot.remove(widget);
  192. }
  193. /**
  194. * Get the containing slot for a widget. If no slot is found a new slot is
  195. * created and returned.
  196. *
  197. * @param widget
  198. * The widget whose slot you want to get
  199. *
  200. * @return
  201. */
  202. public Slot getSlot(Widget widget) {
  203. Slot slot = widgetToSlot.get(widget);
  204. if (slot == null) {
  205. slot = new Slot(this, widget);
  206. widgetToSlot.put(widget, slot);
  207. }
  208. return slot;
  209. }
  210. /**
  211. * Gets a slot based on the widget element. If no slot is found then null is
  212. * returned.
  213. *
  214. * @param widgetElement
  215. * The element of the widget ( Same as getWidget().getElement() )
  216. * @return
  217. * @deprecated As of 7.2, call or override {@link #getSlot(Element)} instead
  218. */
  219. @Deprecated
  220. public Slot getSlot(com.google.gwt.user.client.Element widgetElement) {
  221. for (Map.Entry<Widget, Slot> entry : widgetToSlot.entrySet()) {
  222. if (entry.getKey().getElement() == widgetElement) {
  223. return entry.getValue();
  224. }
  225. }
  226. return null;
  227. }
  228. /**
  229. * Gets a slot based on the widget element. If no slot is found then null is
  230. * returned.
  231. *
  232. * @param widgetElement
  233. * The element of the widget ( Same as getWidget().getElement() )
  234. * @return
  235. *
  236. * @since 7.2
  237. */
  238. public Slot getSlot(Element widgetElement) {
  239. return getSlot(DOM.asOld(widgetElement));
  240. }
  241. /**
  242. * Set the layout manager for the layout
  243. *
  244. * @param manager
  245. * The layout manager to use
  246. */
  247. public void setLayoutManager(LayoutManager manager) {
  248. layoutManager = manager;
  249. }
  250. /**
  251. * Get the layout manager used by this layout
  252. *
  253. */
  254. public LayoutManager getLayoutManager() {
  255. return layoutManager;
  256. }
  257. /**
  258. * Deducts the caption position by examining the wrapping element.
  259. * <p>
  260. * For internal use only. May be removed or replaced in the future.
  261. *
  262. * @param captionWrap
  263. * The wrapping element
  264. *
  265. * @return The caption position
  266. * @deprecated As of 7.2, call or override
  267. * {@link #getCaptionPositionFromElement(Element)} instead
  268. */
  269. @Deprecated
  270. public CaptionPosition getCaptionPositionFromElement(
  271. com.google.gwt.user.client.Element captionWrap) {
  272. RegExp captionPositionRegexp = RegExp.compile("v-caption-on-(\\S+)");
  273. // Get caption position from the classname
  274. MatchResult matcher = captionPositionRegexp.exec(captionWrap
  275. .getClassName());
  276. if (matcher == null || matcher.getGroupCount() < 2) {
  277. return CaptionPosition.TOP;
  278. }
  279. String captionClass = matcher.getGroup(1);
  280. CaptionPosition captionPosition = CaptionPosition.valueOf(
  281. CaptionPosition.class, captionClass.toUpperCase());
  282. return captionPosition;
  283. }
  284. /**
  285. * Deducts the caption position by examining the wrapping element.
  286. * <p>
  287. * For internal use only. May be removed or replaced in the future.
  288. *
  289. * @param captionWrap
  290. * The wrapping element
  291. *
  292. * @return The caption position
  293. * @since 7.2
  294. */
  295. public CaptionPosition getCaptionPositionFromElement(Element captionWrap) {
  296. return getCaptionPositionFromElement(DOM.asOld(captionWrap));
  297. }
  298. /**
  299. * Update the offset off the caption relative to the slot
  300. * <p>
  301. * For internal use only. May be removed or replaced in the future.
  302. *
  303. * @param caption
  304. * The caption element
  305. * @deprecated As of 7.2, call or override
  306. * {@link #updateCaptionOffset(Element)} instead
  307. */
  308. @Deprecated
  309. public void updateCaptionOffset(com.google.gwt.user.client.Element caption) {
  310. Element captionWrap = caption.getParentElement();
  311. Style captionWrapStyle = captionWrap.getStyle();
  312. captionWrapStyle.clearPaddingTop();
  313. captionWrapStyle.clearPaddingRight();
  314. captionWrapStyle.clearPaddingBottom();
  315. captionWrapStyle.clearPaddingLeft();
  316. Style captionStyle = caption.getStyle();
  317. captionStyle.clearMarginTop();
  318. captionStyle.clearMarginRight();
  319. captionStyle.clearMarginBottom();
  320. captionStyle.clearMarginLeft();
  321. // Get caption position from the classname
  322. CaptionPosition captionPosition = getCaptionPositionFromElement(captionWrap);
  323. if (captionPosition == CaptionPosition.LEFT
  324. || captionPosition == CaptionPosition.RIGHT) {
  325. int captionWidth;
  326. if (layoutManager != null) {
  327. captionWidth = layoutManager.getOuterWidth(caption)
  328. - layoutManager.getMarginWidth(caption);
  329. } else {
  330. captionWidth = caption.getOffsetWidth();
  331. }
  332. if (captionWidth > 0) {
  333. if (captionPosition == CaptionPosition.LEFT) {
  334. captionWrapStyle.setPaddingLeft(captionWidth, Unit.PX);
  335. captionStyle.setMarginLeft(-captionWidth, Unit.PX);
  336. } else {
  337. captionWrapStyle.setPaddingRight(captionWidth, Unit.PX);
  338. captionStyle.setMarginRight(-captionWidth, Unit.PX);
  339. }
  340. }
  341. }
  342. if (captionPosition == CaptionPosition.TOP
  343. || captionPosition == CaptionPosition.BOTTOM) {
  344. int captionHeight;
  345. if (layoutManager != null) {
  346. captionHeight = layoutManager.getOuterHeight(caption)
  347. - layoutManager.getMarginHeight(caption);
  348. } else {
  349. captionHeight = caption.getOffsetHeight();
  350. }
  351. if (captionHeight > 0) {
  352. if (captionPosition == CaptionPosition.TOP) {
  353. captionWrapStyle.setPaddingTop(captionHeight, Unit.PX);
  354. captionStyle.setMarginTop(-captionHeight, Unit.PX);
  355. } else {
  356. captionWrapStyle.setPaddingBottom(captionHeight, Unit.PX);
  357. captionStyle.setMarginBottom(-captionHeight, Unit.PX);
  358. }
  359. }
  360. }
  361. }
  362. /**
  363. * Update the offset off the caption relative to the slot
  364. * <p>
  365. * For internal use only. May be removed or replaced in the future.
  366. *
  367. * @param caption
  368. * The caption element
  369. * @since 7.2
  370. */
  371. public void updateCaptionOffset(Element caption) {
  372. updateCaptionOffset(DOM.asOld(caption));
  373. }
  374. /**
  375. * Set the margin of the layout
  376. *
  377. * @param marginInfo
  378. * The margin information
  379. */
  380. public void setMargin(MarginInfo marginInfo) {
  381. if (marginInfo != null) {
  382. setStyleName("v-margin-top", marginInfo.hasTop());
  383. setStyleName("v-margin-right", marginInfo.hasRight());
  384. setStyleName("v-margin-bottom", marginInfo.hasBottom());
  385. setStyleName("v-margin-left", marginInfo.hasLeft());
  386. }
  387. }
  388. /**
  389. * Turn on or off spacing in the layout
  390. *
  391. * @param spacing
  392. * True if spacing should be used, false if not
  393. */
  394. public void setSpacing(boolean spacing) {
  395. Profiler.enter("VAOL.onConnectorHierarchyChange setSpacing");
  396. this.spacing = spacing;
  397. // first widget does not have spacing on
  398. // optimization to avoid looking up widget indices on every iteration
  399. Widget firstSlot = null;
  400. if (getWidgetCount() > 0) {
  401. firstSlot = getWidget(0);
  402. }
  403. for (Slot slot : widgetToSlot.values()) {
  404. slot.setSpacing(spacing && firstSlot != slot);
  405. }
  406. Profiler.leave("VAOL.onConnectorHierarchyChange setSpacing");
  407. }
  408. /**
  409. * Assigns relative sizes to the children that should expand based on their
  410. * expand ratios.
  411. */
  412. public void updateExpandedSizes() {
  413. // Ensure the expand wrapper is in place
  414. if (expandWrapper == null) {
  415. expandWrapper = DOM.createDiv();
  416. expandWrapper.setClassName("v-expand");
  417. // Detach all widgets before modifying DOM
  418. for (Widget widget : getChildren()) {
  419. orphan(widget);
  420. }
  421. while (getElement().getChildCount() > 0) {
  422. Node el = getElement().getChild(0);
  423. expandWrapper.appendChild(el);
  424. }
  425. getElement().appendChild(expandWrapper);
  426. // Attach all widgets again
  427. for (Widget widget : getChildren()) {
  428. adopt(widget);
  429. }
  430. }
  431. // Sum up expand ratios to get the denominator
  432. double total = 0;
  433. for (Slot slot : widgetToSlot.values()) {
  434. // FIXME expandRatio might be <0
  435. total += slot.getExpandRatio();
  436. }
  437. // Give each expanded child its own share
  438. for (Slot slot : widgetToSlot.values()) {
  439. Element slotElement = slot.getElement();
  440. slotElement.removeAttribute("aria-hidden");
  441. Style slotStyle = slotElement.getStyle();
  442. slotStyle.clearVisibility();
  443. slotStyle.clearMarginLeft();
  444. slotStyle.clearMarginTop();
  445. if (slot.getExpandRatio() != 0) {
  446. // FIXME expandRatio might be <0
  447. double size = 100 * (slot.getExpandRatio() / total);
  448. if (vertical) {
  449. slot.setHeight(size + "%");
  450. if (slot.hasRelativeHeight()) {
  451. Util.notifyParentOfSizeChange(this, true);
  452. }
  453. } else {
  454. slot.setWidth(size + "%");
  455. if (slot.hasRelativeWidth()) {
  456. Util.notifyParentOfSizeChange(this, true);
  457. }
  458. }
  459. } else if (slot.isRelativeInDirection(vertical)) {
  460. // Relative child without expansion gets no space at all
  461. if (vertical) {
  462. slot.setHeight("0");
  463. } else {
  464. slot.setWidth("0");
  465. }
  466. slotStyle.setVisibility(Visibility.HIDDEN);
  467. slotElement.setAttribute("aria-hidden", "true");
  468. } else {
  469. // Non-relative child without expansion should be unconstrained
  470. if (BrowserInfo.get().isIE8()) {
  471. // unconstrained in IE8 is auto
  472. if (vertical) {
  473. slot.setHeight("auto");
  474. } else {
  475. slot.setWidth("auto");
  476. }
  477. } else {
  478. if (vertical) {
  479. slotStyle.clearHeight();
  480. } else {
  481. slotStyle.clearWidth();
  482. }
  483. }
  484. }
  485. }
  486. }
  487. /**
  488. * Removes elements used to expand a slot.
  489. * <p>
  490. * For internal use only. May be removed or replaced in the future.
  491. */
  492. public void clearExpand() {
  493. if (expandWrapper != null) {
  494. // Detach all widgets before modifying DOM
  495. for (Widget widget : getChildren()) {
  496. orphan(widget);
  497. }
  498. lastExpandSize = -1;
  499. while (expandWrapper.getChildCount() > 0) {
  500. Element el = expandWrapper.getChild(0).cast();
  501. getElement().appendChild(el);
  502. if (vertical) {
  503. el.getStyle().clearHeight();
  504. el.getStyle().clearMarginTop();
  505. } else {
  506. el.getStyle().clearWidth();
  507. el.getStyle().clearMarginLeft();
  508. }
  509. }
  510. expandWrapper.removeFromParent();
  511. expandWrapper = null;
  512. // Attach children again
  513. for (Widget widget : getChildren()) {
  514. adopt(widget);
  515. }
  516. }
  517. }
  518. /**
  519. * Updates the expand compensation based on the measured sizes of children
  520. * without expand.
  521. */
  522. public void updateExpandCompensation() {
  523. boolean isExpanding = false;
  524. for (Widget slot : getChildren()) {
  525. // FIXME expandRatio might be <0
  526. if (((Slot) slot).getExpandRatio() != 0) {
  527. isExpanding = true;
  528. break;
  529. }
  530. }
  531. if (isExpanding) {
  532. /*
  533. * Expanded slots have relative sizes that together add up to 100%.
  534. * To make room for slots without expand, we will add padding that
  535. * is not considered for relative sizes and a corresponding negative
  536. * margin for the unexpanded slots. We calculate the size by summing
  537. * the size of all non-expanded non-relative slots.
  538. *
  539. * Relatively sized slots without expansion are considered to get
  540. * 0px, but we still keep them visible (causing overflows) to help
  541. * the developer see what's happening. Forcing them to only get 0px
  542. * would make them disappear which would avoid overflows but would
  543. * instead cause confusion as they would then just disappear without
  544. * any obvious reason.
  545. */
  546. int totalSize = 0;
  547. for (Widget w : getChildren()) {
  548. Slot slot = (Slot) w;
  549. if (slot.getExpandRatio() == 0
  550. && !slot.isRelativeInDirection(vertical)) {
  551. if (layoutManager != null) {
  552. // TODO check caption position
  553. if (vertical) {
  554. int size = layoutManager.getOuterHeight(slot
  555. .getWidget().getElement());
  556. if (slot.hasCaption()) {
  557. size += layoutManager.getOuterHeight(slot
  558. .getCaptionElement());
  559. }
  560. if (size > 0) {
  561. totalSize += size;
  562. }
  563. } else {
  564. int max = -1;
  565. max = layoutManager.getOuterWidth(slot.getWidget()
  566. .getElement());
  567. if (slot.hasCaption()) {
  568. int max2 = layoutManager.getOuterWidth(slot
  569. .getCaptionElement());
  570. max = Math.max(max, max2);
  571. }
  572. if (max > 0) {
  573. totalSize += max;
  574. }
  575. }
  576. } else {
  577. // FIXME expandRatio might be <0
  578. totalSize += vertical ? slot.getOffsetHeight() : slot
  579. .getOffsetWidth();
  580. }
  581. }
  582. // TODO fails in Opera, always returns 0
  583. int spacingSize = vertical ? slot.getVerticalSpacing() : slot
  584. .getHorizontalSpacing();
  585. if (spacingSize > 0) {
  586. totalSize += spacingSize;
  587. }
  588. }
  589. // When we set the margin to the first child, we don't need
  590. // overflow:hidden in the layout root element, since the wrapper
  591. // would otherwise be placed outside of the layout root element
  592. // and block events on elements below it.
  593. if (vertical) {
  594. expandWrapper.getStyle().setPaddingTop(totalSize, Unit.PX);
  595. expandWrapper.getFirstChildElement().getStyle()
  596. .setMarginTop(-totalSize, Unit.PX);
  597. } else {
  598. expandWrapper.getStyle().setPaddingLeft(totalSize, Unit.PX);
  599. expandWrapper.getFirstChildElement().getStyle()
  600. .setMarginLeft(-totalSize, Unit.PX);
  601. }
  602. // Measure expanded children again if their size might have changed
  603. if (totalSize != lastExpandSize) {
  604. lastExpandSize = totalSize;
  605. for (Widget w : getChildren()) {
  606. Slot slot = (Slot) w;
  607. // FIXME expandRatio might be <0
  608. if (slot.getExpandRatio() != 0) {
  609. if (layoutManager != null) {
  610. layoutManager.setNeedsMeasure(Util
  611. .findConnectorFor(slot.getWidget()));
  612. } else if (slot.getWidget() instanceof RequiresResize) {
  613. ((RequiresResize) slot.getWidget()).onResize();
  614. }
  615. }
  616. }
  617. }
  618. }
  619. WidgetUtil.forceIE8Redraw(getElement());
  620. }
  621. /**
  622. * {@inheritDoc}
  623. */
  624. @Override
  625. public void setHeight(String height) {
  626. super.setHeight(height);
  627. definedHeight = (height != null && !"".equals(height));
  628. }
  629. /**
  630. * Sets the slots style names. The style names will be prefixed with the
  631. * v-slot prefix.
  632. *
  633. * @param stylenames
  634. * The style names of the slot.
  635. */
  636. public void setSlotStyleNames(Widget widget, String... stylenames) {
  637. Slot slot = getSlot(widget);
  638. if (slot == null) {
  639. throw new IllegalArgumentException(
  640. "A slot for the widget could not be found. Has the widget been added to the layout?");
  641. }
  642. slot.setStyleNames(stylenames);
  643. }
  644. }