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.

PaintTarget.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal;
  5. import java.io.Serializable;
  6. import java.util.Map;
  7. import com.vaadin.terminal.StreamVariable.StreamingStartEvent;
  8. import com.vaadin.terminal.gwt.server.ClientConnector;
  9. import com.vaadin.ui.Component;
  10. /**
  11. * This interface defines the methods for painting XML to the UIDL stream.
  12. *
  13. * @author Vaadin Ltd.
  14. * @since 3.0
  15. */
  16. public interface PaintTarget extends Serializable {
  17. /**
  18. * Prints single XMLsection.
  19. *
  20. * Prints full XML section. The section data is escaped from XML tags and
  21. * surrounded by XML start and end-tags.
  22. *
  23. * @param sectionTagName
  24. * the name of the tag.
  25. * @param sectionData
  26. * the scetion data.
  27. * @throws PaintException
  28. * if the paint operation failed.
  29. */
  30. public void addSection(String sectionTagName, String sectionData)
  31. throws PaintException;
  32. /**
  33. * Result of starting to paint a Component (
  34. * {@link PaintTarget#startPaintable(Component, String)}).
  35. *
  36. * @since 7.0
  37. */
  38. public enum PaintStatus {
  39. /**
  40. * Painting started, addVariable() and addAttribute() etc. methods may
  41. * be called.
  42. */
  43. PAINTING,
  44. /**
  45. * A previously unpainted or painted {@link Component} has been queued
  46. * be created/update later in a separate change in the same set of
  47. * changes.
  48. */
  49. CACHED
  50. }
  51. /**
  52. * Prints element start tag of a paintable section. Starts a paintable
  53. * section using the given tag. The PaintTarget may implement a caching
  54. * scheme, that checks the paintable has actually changed or can a cached
  55. * version be used instead. This method should call the startTag method.
  56. * <p>
  57. * If the {@link Component} is found in cache and this function returns true
  58. * it may omit the content and close the tag, in which case cached content
  59. * should be used.
  60. * </p>
  61. * <p>
  62. * This method may also add only a reference to the paintable and queue the
  63. * paintable to be painted separately.
  64. * </p>
  65. * <p>
  66. * Each paintable being painted should be closed by a matching
  67. * {@link #endPaintable(Component)} regardless of the {@link PaintStatus}
  68. * returned.
  69. * </p>
  70. *
  71. * @param paintable
  72. * the paintable to start.
  73. * @param tag
  74. * the name of the start tag.
  75. * @return {@link PaintStatus} - ready to paint or already cached on the
  76. * client (also used for sub paintables that are painted later
  77. * separately)
  78. * @throws PaintException
  79. * if the paint operation failed.
  80. * @see #startTag(String)
  81. * @since 7.0 (previously using startTag(Paintable, String))
  82. */
  83. public PaintStatus startPaintable(Component paintable, String tag)
  84. throws PaintException;
  85. /**
  86. * Prints paintable element end tag.
  87. *
  88. * Calls to {@link #startPaintable(Component, String)}should be matched by
  89. * {@link #endPaintable(Component)}. If the parent tag is closed before
  90. * every child tag is closed a PaintException is raised.
  91. *
  92. * @param paintable
  93. * the paintable to close.
  94. * @throws PaintException
  95. * if the paint operation failed.
  96. * @since 7.0 (previously using engTag(String))
  97. */
  98. public void endPaintable(Component paintable) throws PaintException;
  99. /**
  100. * Prints element start tag.
  101. *
  102. * <pre>
  103. * Todo:
  104. * Checking of input values
  105. * </pre>
  106. *
  107. * @param tagName
  108. * the name of the start tag.
  109. * @throws PaintException
  110. * if the paint operation failed.
  111. */
  112. public void startTag(String tagName) throws PaintException;
  113. /**
  114. * Prints element end tag.
  115. *
  116. * If the parent tag is closed before every child tag is closed an
  117. * PaintException is raised.
  118. *
  119. * @param tagName
  120. * the name of the end tag.
  121. * @throws PaintException
  122. * if the paint operation failed.
  123. */
  124. public void endTag(String tagName) throws PaintException;
  125. /**
  126. * Adds a boolean attribute to component. Atributes must be added before any
  127. * content is written.
  128. *
  129. * @param name
  130. * the Attribute name.
  131. * @param value
  132. * the Attribute value.
  133. *
  134. * @throws PaintException
  135. * if the paint operation failed.
  136. */
  137. public void addAttribute(String name, boolean value) throws PaintException;
  138. /**
  139. * Adds a integer attribute to component. Atributes must be added before any
  140. * content is written.
  141. *
  142. * @param name
  143. * the Attribute name.
  144. * @param value
  145. * the Attribute value.
  146. *
  147. * @throws PaintException
  148. * if the paint operation failed.
  149. */
  150. public void addAttribute(String name, int value) throws PaintException;
  151. /**
  152. * Adds a resource attribute to component. Atributes must be added before
  153. * any content is written.
  154. *
  155. * @param name
  156. * the Attribute name
  157. * @param value
  158. * the Attribute value
  159. *
  160. * @throws PaintException
  161. * if the paint operation failed.
  162. */
  163. public void addAttribute(String name, Resource value) throws PaintException;
  164. /**
  165. * Adds details about {@link StreamVariable} to the UIDL stream. Eg. in web
  166. * terminals Receivers are typically rendered for the client side as URLs,
  167. * where the client side implementation can do an http post request.
  168. * <p>
  169. * The urls in UIDL message may use Vaadin specific protocol. Before
  170. * actually using the urls on the client side, they should be passed via
  171. * {@link com.vaadin.terminal.gwt.client.ApplicationConnection#translateVaadinUri(String)}.
  172. * <p>
  173. * Note that in current terminal implementation StreamVariables are cleaned
  174. * from the terminal only when:
  175. * <ul>
  176. * <li>a StreamVariable with same name replaces an old one
  177. * <li>the variable owner is no more attached
  178. * <li>the developer signals this by calling
  179. * {@link StreamingStartEvent#disposeStreamVariable()}
  180. * </ul>
  181. * Most commonly a component developer can just ignore this issue, but with
  182. * strict memory requirements and lots of StreamVariables implementations
  183. * that reserve a lot of memory this may be a critical issue.
  184. *
  185. * @param owner
  186. * the ReceiverOwner that can track the progress of streaming to
  187. * the given StreamVariable
  188. * @param name
  189. * an identifying name for the StreamVariable
  190. * @param value
  191. * the StreamVariable to paint
  192. *
  193. * @throws PaintException
  194. * if the paint operation failed.
  195. */
  196. public void addVariable(VariableOwner owner, String name,
  197. StreamVariable value) throws PaintException;
  198. /**
  199. * Adds a long attribute to component. Atributes must be added before any
  200. * content is written.
  201. *
  202. * @param name
  203. * the Attribute name.
  204. * @param value
  205. * the Attribute value.
  206. *
  207. * @throws PaintException
  208. * if the paint operation failed.
  209. */
  210. public void addAttribute(String name, long value) throws PaintException;
  211. /**
  212. * Adds a float attribute to component. Atributes must be added before any
  213. * content is written.
  214. *
  215. * @param name
  216. * the Attribute name.
  217. * @param value
  218. * the Attribute value.
  219. *
  220. * @throws PaintException
  221. * if the paint operation failed.
  222. */
  223. public void addAttribute(String name, float value) throws PaintException;
  224. /**
  225. * Adds a double attribute to component. Atributes must be added before any
  226. * content is written.
  227. *
  228. * @param name
  229. * the Attribute name.
  230. * @param value
  231. * the Attribute value.
  232. *
  233. * @throws PaintException
  234. * if the paint operation failed.
  235. */
  236. public void addAttribute(String name, double value) throws PaintException;
  237. /**
  238. * Adds a string attribute to component. Atributes must be added before any
  239. * content is written.
  240. *
  241. * @param name
  242. * the Boolean attribute name.
  243. * @param value
  244. * the Boolean attribute value.
  245. *
  246. * @throws PaintException
  247. * if the paint operation failed.
  248. */
  249. public void addAttribute(String name, String value) throws PaintException;
  250. /**
  251. * TODO
  252. *
  253. * @param name
  254. * @param value
  255. * @throws PaintException
  256. */
  257. public void addAttribute(String name, Map<?, ?> value)
  258. throws PaintException;
  259. /**
  260. * Adds a Component type attribute. On client side the value will be a
  261. * terminal specific reference to corresponding component on client side
  262. * implementation.
  263. *
  264. * @param name
  265. * the name of the attribute
  266. * @param value
  267. * the Component to be referenced on client side
  268. * @throws PaintException
  269. */
  270. public void addAttribute(String name, Component value)
  271. throws PaintException;
  272. /**
  273. * Adds a string type variable.
  274. *
  275. * @param owner
  276. * the Listener for variable changes.
  277. * @param name
  278. * the Variable name.
  279. * @param value
  280. * the Variable initial value.
  281. *
  282. * @throws PaintException
  283. * if the paint operation failed.
  284. */
  285. public void addVariable(VariableOwner owner, String name, String value)
  286. throws PaintException;
  287. /**
  288. * Adds a int type variable.
  289. *
  290. * @param owner
  291. * the Listener for variable changes.
  292. * @param name
  293. * the Variable name.
  294. * @param value
  295. * the Variable initial value.
  296. *
  297. * @throws PaintException
  298. * if the paint operation failed.
  299. */
  300. public void addVariable(VariableOwner owner, String name, int value)
  301. throws PaintException;
  302. /**
  303. * Adds a long type variable.
  304. *
  305. * @param owner
  306. * the Listener for variable changes.
  307. * @param name
  308. * the Variable name.
  309. * @param value
  310. * the Variable initial value.
  311. *
  312. * @throws PaintException
  313. * if the paint operation failed.
  314. */
  315. public void addVariable(VariableOwner owner, String name, long value)
  316. throws PaintException;
  317. /**
  318. * Adds a float type variable.
  319. *
  320. * @param owner
  321. * the Listener for variable changes.
  322. * @param name
  323. * the Variable name.
  324. * @param value
  325. * the Variable initial value.
  326. *
  327. * @throws PaintException
  328. * if the paint operation failed.
  329. */
  330. public void addVariable(VariableOwner owner, String name, float value)
  331. throws PaintException;
  332. /**
  333. * Adds a double type variable.
  334. *
  335. * @param owner
  336. * the Listener for variable changes.
  337. * @param name
  338. * the Variable name.
  339. * @param value
  340. * the Variable initial value.
  341. *
  342. * @throws PaintException
  343. * if the paint operation failed.
  344. */
  345. public void addVariable(VariableOwner owner, String name, double value)
  346. throws PaintException;
  347. /**
  348. * Adds a boolean type variable.
  349. *
  350. * @param owner
  351. * the Listener for variable changes.
  352. * @param name
  353. * the Variable name.
  354. * @param value
  355. * the Variable initial value.
  356. *
  357. * @throws PaintException
  358. * if the paint operation failed.
  359. */
  360. public void addVariable(VariableOwner owner, String name, boolean value)
  361. throws PaintException;
  362. /**
  363. * Adds a string array type variable.
  364. *
  365. * @param owner
  366. * the Listener for variable changes.
  367. * @param name
  368. * the Variable name.
  369. * @param value
  370. * the Variable initial value.
  371. *
  372. * @throws PaintException
  373. * if the paint operation failed.
  374. */
  375. public void addVariable(VariableOwner owner, String name, String[] value)
  376. throws PaintException;
  377. /**
  378. * Adds a Component type variable. On client side the variable value will be
  379. * a terminal specific reference to corresponding component on client side
  380. * implementation. When updated from client side, terminal will map the
  381. * client side component reference back to a corresponding server side
  382. * reference.
  383. *
  384. * @param owner
  385. * the Listener for variable changes
  386. * @param name
  387. * the name of the variable
  388. * @param value
  389. * the initial value of the variable
  390. *
  391. * @throws PaintException
  392. * if the paint oparation fails
  393. */
  394. public void addVariable(VariableOwner owner, String name, Component value)
  395. throws PaintException;
  396. /**
  397. * Adds a upload stream type variable.
  398. *
  399. * @param owner
  400. * the Listener for variable changes.
  401. * @param name
  402. * the Variable name.
  403. *
  404. * @throws PaintException
  405. * if the paint operation failed.
  406. */
  407. public void addUploadStreamVariable(VariableOwner owner, String name)
  408. throws PaintException;
  409. /**
  410. * Prints single XML section.
  411. * <p>
  412. * Prints full XML section. The section data must be XML and it is
  413. * surrounded by XML start and end-tags.
  414. * </p>
  415. *
  416. * @param sectionTagName
  417. * the tag name.
  418. * @param sectionData
  419. * the section data to be printed.
  420. * @param namespace
  421. * the namespace.
  422. * @throws PaintException
  423. * if the paint operation failed.
  424. */
  425. public void addXMLSection(String sectionTagName, String sectionData,
  426. String namespace) throws PaintException;
  427. /**
  428. * Adds UIDL directly. The UIDL must be valid in accordance with the
  429. * UIDL.dtd
  430. *
  431. * @param uidl
  432. * the UIDL to be added.
  433. * @throws PaintException
  434. * if the paint operation failed.
  435. */
  436. public void addUIDL(java.lang.String uidl) throws PaintException;
  437. /**
  438. * Adds text node. All the contents of the text are XML-escaped.
  439. *
  440. * @param text
  441. * the Text to add
  442. * @throws PaintException
  443. * if the paint operation failed.
  444. */
  445. void addText(String text) throws PaintException;
  446. /**
  447. * Adds CDATA node to target UIDL-tree.
  448. *
  449. * @param text
  450. * the Character data to add
  451. * @throws PaintException
  452. * if the paint operation failed.
  453. * @since 3.1
  454. */
  455. void addCharacterData(String text) throws PaintException;
  456. public void addAttribute(String string, Object[] keys);
  457. /**
  458. * @return the "tag" string used in communication to present given
  459. * {@link ClientConnector} type. Terminal may define how to present
  460. * the connector.
  461. */
  462. public String getTag(ClientConnector paintable);
  463. /**
  464. * @return true if a full repaint has been requested. E.g. refresh in a
  465. * browser window or such.
  466. */
  467. public boolean isFullRepaint();
  468. }