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.

Component.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.itmill.toolkit.terminal.gwt.client.ui;
  2. import com.google.gwt.user.client.ui.Widget;
  3. import com.google.gwt.xml.client.Node;
  4. import com.itmill.toolkit.terminal.gwt.client.Client;
  5. public abstract class Component {
  6. private ContainerComponent parent;
  7. protected Client client;
  8. private final int id;
  9. public Component(int id, Client c) {
  10. client = c;
  11. this.id = id;
  12. }
  13. public abstract void updateFromUidl(Node n);
  14. public abstract Widget getWidget();
  15. public static boolean isComponent(String nodeName) {
  16. if(
  17. nodeName.equals("label") ||
  18. nodeName.equals("button") ||
  19. nodeName.equals("textfield") ||
  20. nodeName.equals("select") ||
  21. nodeName.equals("orderedlayout")
  22. ) return true;
  23. return false;
  24. }
  25. public static Component createComponent(Node uidl, Client cli) {
  26. Component c = null;
  27. String nodeName = uidl.getNodeName();
  28. if(nodeName.equals("label")) {
  29. c = new TkLabel(uidl, cli);
  30. } else if(nodeName.equals("orderedlayout")) {
  31. c = new TkOrderedLayout(uidl, cli);
  32. } else if(nodeName.equals("button")) {
  33. c = new TkButton(uidl, cli);
  34. } else if(nodeName.equals("textfield")) {
  35. c = new TkTextField(uidl, cli);
  36. } else {
  37. c = new TkUnknown(uidl, cli);
  38. }
  39. return c;
  40. }
  41. public void appendTo(ContainerComponent cont) {
  42. this.parent = cont;
  43. getClient().registerComponent(this);
  44. cont.appendChild(this);
  45. }
  46. public ContainerComponent getParent() {
  47. return parent;
  48. }
  49. public Client getClient() {
  50. if(client == null)
  51. client = parent.getClient();
  52. return client;
  53. }
  54. public static int getIdFromUidl(Node uidl) {
  55. Node pid = uidl.getAttributes().getNamedItem("id");
  56. return Integer.parseInt(pid.getNodeValue().substring(3));
  57. }
  58. public int getId() {
  59. return id;
  60. }
  61. }