Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FeatureParameters.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* *************************************************************************
  2. IT Mill Toolkit
  3. Development of Browser User Intarfaces Made Easy
  4. Copyright (C) 2000-2006 IT Mill Ltd
  5. *************************************************************************
  6. This product is distributed under commercial license that can be found
  7. from the product package on license/license.txt. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see license/licensing-guidelines.html
  10. *************************************************************************
  11. For more information, contact:
  12. IT Mill Ltd phone: +358 2 4802 7180
  13. Ruukinkatu 2-4 fax: +358 2 4802 7181
  14. 20540, Turku email: info@itmill.com
  15. Finland company www: www.itmill.com
  16. Primary source for information and releases: www.itmill.com
  17. ********************************************************************** */
  18. package com.itmill.toolkit.demo.features;
  19. import java.net.URL;
  20. import java.util.Iterator;
  21. import java.util.Map;
  22. import com.itmill.toolkit.terminal.DownloadStream;
  23. import com.itmill.toolkit.terminal.ExternalResource;
  24. import com.itmill.toolkit.terminal.ParameterHandler;
  25. import com.itmill.toolkit.terminal.URIHandler;
  26. import com.itmill.toolkit.ui.*;
  27. public class FeatureParameters
  28. extends Feature
  29. implements URIHandler, ParameterHandler {
  30. private Label context = new Label();
  31. private Label relative = new Label();
  32. private Table params = new Table();
  33. public FeatureParameters() {
  34. super();
  35. params.addContainerProperty("Values", String.class, "");
  36. }
  37. protected Component getDemoComponent() {
  38. OrderedLayout l = new OrderedLayout();
  39. Label info =
  40. new Label(
  41. "To test this feature, try to "
  42. + "add some get parameters to URL. For example if you have "
  43. + "the feature browser installed in your local host, try url: ");
  44. info.setCaption("Usage info");
  45. l.addComponent(info);
  46. try {
  47. URL u1 = new URL(getApplication().getURL(),"test/uri?test=1&test=2");
  48. URL u2 = new URL(getApplication().getURL(),"foo/bar?mary=john&count=3");
  49. l.addComponent(
  50. new Link(u1.toString(),new ExternalResource(u1)));
  51. l.addComponent(new Label("Or this: "));
  52. l.addComponent(
  53. new Link(u2.toString(),new ExternalResource(u2)));
  54. } catch (Exception e) {
  55. System.out.println(
  56. "Couldn't get hostname for this machine: " + e.toString());
  57. e.printStackTrace();
  58. }
  59. // URI
  60. Panel p1 = new Panel("URI Handler");
  61. context.setCaption("Last URI handler context");
  62. p1.addComponent(context);
  63. relative.setCaption("Last relative URI");
  64. p1.addComponent(relative);
  65. l.addComponent(p1);
  66. // Parameters
  67. Panel p2 = new Panel("Parameter Handler");
  68. params.setCaption("Last parameters");
  69. params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID);
  70. params.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
  71. p2.addComponent(params);
  72. l.addComponent(p2);
  73. return l;
  74. }
  75. protected String getDescriptionXHTML() {
  76. return "This is a demonstration of how URL parameters can be recieved and handled."
  77. + "Parameters and URL:s can be received trough the windows by registering "
  78. + "URIHandler and ParameterHandler classes window.";
  79. }
  80. protected String getImage() {
  81. return "parameters.jpg";
  82. }
  83. protected String getTitle() {
  84. return "Parameters";
  85. }
  86. /** Add URI and parametes handlers to window.
  87. * @see com.itmill.toolkit.ui.Component#attach()
  88. */
  89. public void attach() {
  90. super.attach();
  91. getWindow().addURIHandler(this);
  92. getWindow().addParameterHandler(this);
  93. }
  94. /** Remove all handlers from window
  95. * @see com.itmill.toolkit.ui.Component#detach()
  96. */
  97. public void detach() {
  98. super.detach();
  99. getWindow().removeURIHandler(this);
  100. getWindow().removeParameterHandler(this);
  101. }
  102. /** Update URI
  103. * @see com.itmill.toolkit.terminal.URIHandler#handleURI(URL, String)
  104. */
  105. public DownloadStream handleURI(URL context, String relativeUri) {
  106. this.context.setValue(context.toString());
  107. this.relative.setValue(relativeUri);
  108. return null;
  109. }
  110. /** Update parameters table
  111. * @see com.itmill.toolkit.terminal.ParameterHandler#handleParameters(Map)
  112. */
  113. public void handleParameters(Map parameters) {
  114. params.removeAllItems();
  115. for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
  116. String name = (String) i.next();
  117. String[] values = (String[]) parameters.get(name);
  118. String v = "";
  119. for (int j = 0; j < values.length; j++) {
  120. if (v.length() > 0)
  121. v += ", ";
  122. v += "'" + values[j] + "'";
  123. }
  124. params.addItem(new Object[] { v }, name);
  125. }
  126. }
  127. }