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.

VLinkPaintable.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.user.client.DOM;
  7. import com.google.gwt.user.client.ui.Widget;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. public class VLinkPaintable extends VAbstractPaintableWidget {
  11. @Override
  12. protected boolean delegateCaptionHandling() {
  13. return false;
  14. }
  15. @Override
  16. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  17. // Ensure correct implementation,
  18. // but don't let container manage caption etc.
  19. super.updateFromUIDL(uidl, client);
  20. if (!isRealUpdate(uidl)) {
  21. return;
  22. }
  23. getWidgetForPaintable().client = client;
  24. getWidgetForPaintable().enabled = uidl.hasAttribute("disabled") ? false
  25. : true;
  26. getWidgetForPaintable().readonly = uidl.hasAttribute("readonly") ? true
  27. : false;
  28. if (uidl.hasAttribute("name")) {
  29. getWidgetForPaintable().target = uidl.getStringAttribute("name");
  30. getWidgetForPaintable().anchor.setAttribute("target",
  31. getWidgetForPaintable().target);
  32. }
  33. if (uidl.hasAttribute("src")) {
  34. getWidgetForPaintable().src = client.translateVaadinUri(uidl
  35. .getStringAttribute("src"));
  36. getWidgetForPaintable().anchor.setAttribute("href",
  37. getWidgetForPaintable().src);
  38. }
  39. if (uidl.hasAttribute("border")) {
  40. if ("none".equals(uidl.getStringAttribute("border"))) {
  41. getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_NONE;
  42. } else {
  43. getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_MINIMAL;
  44. }
  45. } else {
  46. getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_DEFAULT;
  47. }
  48. getWidgetForPaintable().targetHeight = uidl
  49. .hasAttribute("targetHeight") ? uidl
  50. .getIntAttribute("targetHeight") : -1;
  51. getWidgetForPaintable().targetWidth = uidl.hasAttribute("targetWidth") ? uidl
  52. .getIntAttribute("targetWidth") : -1;
  53. // Set link caption
  54. getWidgetForPaintable().captionElement.setInnerText(uidl
  55. .getStringAttribute("caption"));
  56. // handle error
  57. if (uidl.hasAttribute("error")) {
  58. if (getWidgetForPaintable().errorIndicatorElement == null) {
  59. getWidgetForPaintable().errorIndicatorElement = DOM.createDiv();
  60. DOM.setElementProperty(
  61. getWidgetForPaintable().errorIndicatorElement,
  62. "className", "v-errorindicator");
  63. }
  64. DOM.insertChild(getWidgetForPaintable().getElement(),
  65. getWidgetForPaintable().errorIndicatorElement, 0);
  66. } else if (getWidgetForPaintable().errorIndicatorElement != null) {
  67. DOM.setStyleAttribute(
  68. getWidgetForPaintable().errorIndicatorElement, "display",
  69. "none");
  70. }
  71. if (uidl.hasAttribute("icon")) {
  72. if (getWidgetForPaintable().icon == null) {
  73. getWidgetForPaintable().icon = new Icon(client);
  74. getWidgetForPaintable().anchor.insertBefore(
  75. getWidgetForPaintable().icon.getElement(),
  76. getWidgetForPaintable().captionElement);
  77. }
  78. getWidgetForPaintable().icon
  79. .setUri(uidl.getStringAttribute("icon"));
  80. }
  81. }
  82. @Override
  83. protected Widget createWidget() {
  84. return GWT.create(VLink.class);
  85. }
  86. @Override
  87. public VLink getWidgetForPaintable() {
  88. return (VLink) super.getWidgetForPaintable();
  89. }
  90. }