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 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2011 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. import com.vaadin.client.Util;
  19. /**
  20. *
  21. */
  22. public abstract class Action implements Command {
  23. protected ActionOwner owner;
  24. protected String iconUrl = null;
  25. protected String caption = "";
  26. public Action(ActionOwner owner) {
  27. this.owner = owner;
  28. }
  29. /**
  30. * Executed when action fired
  31. */
  32. @Override
  33. public abstract void execute();
  34. public String getHTML() {
  35. final StringBuffer sb = new StringBuffer();
  36. sb.append("<div>");
  37. if (getIconUrl() != null) {
  38. sb.append("<img src=\"" + Util.escapeAttribute(getIconUrl())
  39. + "\" alt=\"icon\" />");
  40. }
  41. sb.append(getCaption());
  42. sb.append("</div>");
  43. return sb.toString();
  44. }
  45. public String getCaption() {
  46. return caption;
  47. }
  48. public void setCaption(String caption) {
  49. this.caption = caption;
  50. }
  51. public String getIconUrl() {
  52. return iconUrl;
  53. }
  54. public void setIconUrl(String url) {
  55. iconUrl = url;
  56. }
  57. }