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.

LocatorStrategy.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.componentlocator;
  17. import java.util.List;
  18. import com.google.gwt.dom.client.Element;
  19. /**
  20. * This interface should be implemented by all locator strategies. A locator
  21. * strategy is responsible for generating and decoding a string that identifies
  22. * an element in the DOM. A strategy can implement its own syntax for the
  23. * locator string, which may be completely different from any other strategy's
  24. * syntax.
  25. *
  26. * @since 7.2
  27. * @author Vaadin Ltd
  28. */
  29. public interface LocatorStrategy {
  30. /**
  31. * Test the given input path for formatting errors. If a given path can not
  32. * be validated, the locator strategy will not be attempted.
  33. *
  34. * @param path
  35. * a locator path expression
  36. * @return true, if the implementing class can process the given path,
  37. * otherwise false
  38. */
  39. boolean validatePath(String path);
  40. /**
  41. * Generates a String locator which uniquely identifies the target element.
  42. * The {@link #getElementByPath(String)} method can be used for the inverse
  43. * operation, i.e. locating an element based on the return value from this
  44. * method.
  45. * <p>
  46. * Note that getElementByPath(getPathForElement(element)) == element is not
  47. * always true as #getPathForElement(Element) can return a path to another
  48. * element if the widget determines an action on the other element will give
  49. * the same result as the action on the target element.
  50. * </p>
  51. *
  52. * @param targetElement
  53. * The element to generate a path for.
  54. * @return A String locator that identifies the target element or null if a
  55. * String locator could not be created.
  56. */
  57. String getPathForElement(Element targetElement);
  58. /**
  59. * Locates an element using a String locator (path) which identifies a DOM
  60. * element. The {@link #getPathForElement(Element)} method can be used for
  61. * the inverse operation, i.e. generating a string expression for a DOM
  62. * element.
  63. *
  64. * @param path
  65. * The String locator which identifies the target element.
  66. * @return The DOM element identified by {@code path} or null if the element
  67. * could not be located.
  68. */
  69. Element getElementByPath(String path);
  70. /**
  71. * Locates an element using a String locator (path) which identifies a DOM
  72. * element. The path starts from the specified root element.
  73. *
  74. * @see #getElementByPath(String)
  75. *
  76. * @param path
  77. * The String locator which identifies the target element.
  78. * @param root
  79. * The element that is at the root of the path.
  80. * @return The DOM element identified by {@code path} or null if the element
  81. * could not be located.
  82. */
  83. Element getElementByPathStartingAt(String path, Element root);
  84. /**
  85. * Locates all elements that match a String locator (path) which identifies
  86. * DOM elements.
  87. *
  88. * This functionality is limited in {@link LegacyLocatorStrategy}.
  89. *
  90. * @param path
  91. * The String locator which identifies target elements.
  92. * @return List that contains all matched elements. Empty list if none
  93. * found.
  94. */
  95. List<Element> getElementsByPath(String path);
  96. /**
  97. * Locates all elements that match a String locator (path) which identifies
  98. * DOM elements. The path starts from the specified root element.
  99. *
  100. * This functionality is limited in {@link LegacyLocatorStrategy}.
  101. *
  102. * @see #getElementsByPath(String)
  103. *
  104. * @param path
  105. * The String locator which identifies target elements.
  106. * @param root
  107. * The element that is at the root of the path.
  108. * @return List that contains all matched elements. Empty list if none
  109. * found.
  110. */
  111. List<Element> getElementsByPathStartingAt(String path, Element root);
  112. }