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.

EmbeddedBrowserExample.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import com.vaadin.data.Property.ValueChangeEvent;
  8. import com.vaadin.terminal.ExternalResource;
  9. import com.vaadin.ui.Embedded;
  10. import com.vaadin.ui.Select;
  11. import com.vaadin.ui.VerticalLayout;
  12. import com.vaadin.ui.Window.Notification;
  13. /**
  14. * Demonstrates the use of Embedded and "suggesting" Select by creating a simple
  15. * web-browser. Note: does not check for recursion.
  16. *
  17. * @author IT Mill Ltd.
  18. * @see com.vaadin.ui.Window
  19. */
  20. @SuppressWarnings("serial")
  21. public class EmbeddedBrowserExample extends VerticalLayout implements
  22. Select.ValueChangeListener {
  23. // Default URL to open.
  24. private static final String DEFAULT_URL = "http://www.itmill.com/index_itmill_toolkit.htm";
  25. // The embedded page
  26. Embedded emb = new Embedded();
  27. public EmbeddedBrowserExample() {
  28. this(new String[] { DEFAULT_URL,
  29. "http://www.itmill.com/index_developers.htm",
  30. "http://toolkit.itmill.com/demo/doc/api/",
  31. "http://www.itmill.com/manual/index.html" });
  32. }
  33. public EmbeddedBrowserExample(String[] urls) {
  34. setSizeFull();
  35. // create the address combobox
  36. final Select select = new Select();
  37. // allow input
  38. select.setNewItemsAllowed(true);
  39. // no empty selection
  40. select.setNullSelectionAllowed(false);
  41. // no 'go' -button clicking necessary
  42. select.setImmediate(true);
  43. // add some pre-configured URLs
  44. for (int i = 0; i < urls.length; i++) {
  45. select.addItem(urls[i]);
  46. }
  47. // add to layout
  48. addComponent(select);
  49. // add listener and select initial URL
  50. select.addListener(this);
  51. select.setValue(urls[0]);
  52. select.setWidth("100%");
  53. // configure the embedded and add to layout
  54. emb.setType(Embedded.TYPE_BROWSER);
  55. emb.setSizeFull();
  56. addComponent(emb);
  57. // make the embedded as large as possible
  58. setExpandRatio(emb, 1);
  59. }
  60. public void valueChange(ValueChangeEvent event) {
  61. final String url = (String) event.getProperty().getValue();
  62. if (url != null) {
  63. try {
  64. // the selected url has changed, let's go there
  65. @SuppressWarnings("unused")
  66. URL u = new URL(url);
  67. emb.setSource(new ExternalResource(url));
  68. } catch (MalformedURLException e) {
  69. getWindow().showNotification("Invalid address",
  70. e.getMessage() + " (example: http://www.itmill.com)",
  71. Notification.TYPE_WARNING_MESSAGE);
  72. }
  73. }
  74. }
  75. }