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.

Action.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2018 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;
  17. import com.google.gwt.user.client.Command;
  18. public abstract class Action implements Command {
  19. protected ActionOwner owner;
  20. protected String iconUrl = null;
  21. protected String caption = "";
  22. public Action(ActionOwner owner) {
  23. this.owner = owner;
  24. }
  25. /**
  26. * Executed when action fired.
  27. */
  28. @Override
  29. public abstract void execute();
  30. public String getHTML() {
  31. final StringBuilder sb = new StringBuilder();
  32. sb.append("<div>");
  33. // Could store the icon in a field instead, but it doesn't really matter
  34. // right now because Actions are recreated every time they are needed
  35. Icon icon = owner.getClient().getIcon(getIconUrl());
  36. if (icon != null) {
  37. icon.setAlternateText("icon");
  38. sb.append(icon.getElement().getString());
  39. }
  40. sb.append(getCaption());
  41. sb.append("</div>");
  42. return sb.toString();
  43. }
  44. public String getCaption() {
  45. return caption;
  46. }
  47. public void setCaption(String caption) {
  48. this.caption = caption;
  49. }
  50. public String getIconUrl() {
  51. return iconUrl;
  52. }
  53. public void setIconUrl(String url) {
  54. iconUrl = url;
  55. }
  56. /*
  57. * (non-Javadoc)
  58. *
  59. * @see java.lang.Object#toString()
  60. */
  61. @Override
  62. public String toString() {
  63. return "Action [owner=" + owner + ", iconUrl=" + iconUrl + ", caption="
  64. + caption + "]";
  65. }
  66. }