Exemple #1
0
  public PingLayout() {
    panel.setSizeFull();
    panel.addStyleName("panel-centered-title");
    // Le listener pour si on lance le scan d'ici
    ping.addScanEndListener(
        new ScanEndListener() {
          @Override
          public void onScanTerminated() {
            try {
              scan = neo.getScanOfSite(site, Ping.NAME);
            } catch (ScanNotFoundException e) {
              e.printStackTrace();
            }
            panel.setContent(resultLayout());
          }
        });

    try {
      this.scan = neo.getScanOfSite(site, Ping.NAME);
    } catch (ScanNotFoundException e) {
    }
    if (scan != null) {
      if (scan.isFinished()) {
        panel.setContent(resultLayout());
      } else if (scan.isRunning()) {
        panel.setContent(runningLayout());
      }
    } else {
      panel.setContent(startLayout());
    }

    layout.addComponent(panel);
  }
  private void buildCategoryTree() {
    tree = categoryTree.initialize();
    tree.addItemClickListener(this);
    tree.setSizeUndefined();

    treePanel.addStyleName(Runo.PANEL_LIGHT);
    treePanel.setHeight("100%");
    treePanel.setContent(treeLayout);

    treeLayout.setImmediate(true);
    treeLayout.setMargin(true);
    treeLayout.setSizeUndefined();
    treeLayout.addStyleName(Reindeer.LAYOUT_WHITE);
    treeLayout.addComponent(tree);

    topTreeLayout.setHeight("100%");
    topTreeLayout.setCaption("Categories");
    topTreeLayout.addStyleName(Runo.LAYOUT_DARKER);
    // topTreeLayout.addComponent(lblCategoryCaption);
    topTreeLayout.addComponent(treePanel);

    btnCreate.addClickListener(this);
    btnUpdate.addClickListener(this);
    btnDelete.addClickListener(this);
  }
 private Component buildNavBar() {
   Panel navPanel = new Panel();
   navPanel.addStyleName("ait-content-nav");
   HorizontalLayout nav = new HorizontalLayout();
   nav.addComponent(new Label(AitView.getNavText(menu), ContentMode.HTML));
   navPanel.setContent(nav);
   return navPanel;
 }
Exemple #4
0
    @Override
    public void attach() {
      super.attach();
      Panel panel = new Panel();
      panel.setSizeFull();
      panel.addStyleName(Reindeer.PANEL_LIGHT);
      panel.addStyleName("mocha-shotcut");
      VerticalLayout noMarginLayout = new VerticalLayout();
      noMarginLayout.setSizeFull();
      panel.setContent(noMarginLayout);
      // panel title.
      panel.setCaption(message.getString(shotcut.getTitle()));

      for (ShotcutItem item : shotcut.getShotcutItems()) {
        NativeButton itemButton = createNativeButton(item);
        panel.addComponent(itemButton);
      }
      setCompositionRoot(panel);
    }
Exemple #5
0
  private void initLayouts() {
    navBar = new NavBar();
    // Use panel as main content container to allow it's content to scroll
    content = new Panel();
    content.setSizeFull();
    content.addStyleName(MyTheme.PANEL_BORDERLESS);

    addComponents(navBar, content);
    setExpandRatio(content, 1);
  }
Exemple #6
0
 private Component buildNavBar() {
   Panel navPanel = new Panel();
   navPanel.addStyleName("ait-content-nav");
   HorizontalLayout nav = new HorizontalLayout();
   nav.addComponent(new Label("Activos>>"));
   nav.addComponent(new Label("Recursos Humanos>>"));
   nav.addComponent(new Label("Unidad Organizacional>>"));
   nav.addComponent(new Label("<strong>Agregar</strong>", ContentMode.HTML));
   navPanel.setContent(nav);
   return navPanel;
 }
  @Override
  public void attach() {
    super.attach();

    rootPanel = new Panel("Connect to...");
    rootPanel.addStyleName(ValoTheme.PANEL_WELL);
    rootPanel.setWidth("500px");
    rootPanel.setHeight("300px");
    recreateRootLayout();

    setSizeFull();
    addComponent(rootPanel);
    setComponentAlignment(rootPanel, Alignment.MIDDLE_CENTER);
  }
 public SelectWindow(
     float width,
     int units,
     Collection<T> items,
     T selectedItem,
     Resource icon,
     String caption,
     String message,
     String okButtonText,
     String cancelButtonText) {
   super();
   if (caption != null) {
     setCaption(caption);
   }
   if (icon != null) {
     setIcon(icon);
   }
   setWidth(width, units);
   setModal(true);
   setClosable(false);
   setResizable(false);
   setDraggable(false);
   VerticalLayout verticalLayout = new VerticalLayout();
   verticalLayout.setMargin(true);
   verticalLayout.setSpacing(true);
   setContent(verticalLayout);
   Label label = new Label(message);
   addComponent(label);
   mySelect = new Select(null, items);
   mySelect.setNullSelectionAllowed(false);
   mySelect.setValue(selectedItem != null ? selectedItem : items.iterator().next());
   mySelect.setWidth(100, Sizeable.UNITS_PERCENTAGE);
   addComponent(mySelect);
   Panel panel = new Panel();
   addComponent(panel);
   verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT);
   panel.addStyleName("light");
   HorizontalLayout horizontalLayout = new HorizontalLayout();
   panel.setContent(horizontalLayout);
   horizontalLayout.setSpacing(true);
   verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT);
   myCancelButton = new Button(cancelButtonText, this);
   panel.addComponent(myCancelButton);
   myOkButton = new Button(okButtonText, this);
   panel.addComponent(myOkButton);
 }
    @Override
    public Object generateCell(Table source, Object itemId, Object columnId) {
      final ExampleQuery eQ = (ExampleQuery) itemId;
      Panel p = new Panel();
      p.addStyleName(ChameleonTheme.PANEL_BORDERLESS);
      HorizontalLayout l = new HorizontalLayout();
      Button btn = new Button();
      btn.setDescription("show corpus browser for " + eQ.getCorpusName());
      btn.addStyleName(BaseTheme.BUTTON_LINK);
      btn.setIcon(SEARCH_ICON);
      btn.setDescription(
          "show results for \"" + eQ.getExampleQuery() + "\" in " + eQ.getCorpusName());
      p.setContent(l);

      btn.addClickListener(
          new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
              ControlPanel controlPanel = ui.getControlPanel();
              QueryPanel queryPanel;
              QueryController qController;

              if (controlPanel == null) {
                log.error("controlPanel is not initialized");
                return;
              }

              queryPanel = controlPanel.getQueryPanel();
              if (queryPanel == null) {
                log.error("queryPanel is not initialized");
                return;
              }

              Set<String> corpusNameSet = new HashSet<String>();
              corpusNameSet.add(eQ.getCorpusName());
              QueryController controller = ui.getQueryController();
              if (controller != null) {
                controller.setQuery(new Query(eQ.getExampleQuery(), corpusNameSet));
                controller.executeQuery();
              }
            }
          });
      l.addComponent(btn);
      return p;
    }
  private Panel getOpenCorpusPanel(final String corpusName) {
    Panel p = new Panel();
    p.addStyleName(ChameleonTheme.PANEL_BORDERLESS);

    final Button btn = new Button(corpusName);
    final HorizontalLayout l = new HorizontalLayout();

    p.setContent(l);
    btn.setStyleName(BaseTheme.BUTTON_LINK);
    btn.addClickListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(Button.ClickEvent event) {
            CorpusListPanel corpusList = ui.getControlPanel().getCorpusList();
            corpusList.initCorpusBrowser(corpusName);
          }
        });

    l.addComponent(btn);

    return p;
  }
  protected Panel createMapPanel(final ConfigurationParameterMapImpl parameter) {
    Panel paramPanel = new Panel();
    paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    paramPanel.setWidth("100%");

    GridLayout paramLayout = new GridLayout(2, 3);
    paramLayout.setSpacing(true);
    paramLayout.setSizeFull();
    paramLayout.setMargin(true);
    paramLayout.setColumnExpandRatio(0, .25f);
    paramLayout.setColumnExpandRatio(1, .75f);

    final Map<String, String> valueMap = parameter.getValue();

    final GridLayout mapLayout =
        new GridLayout(5, (valueMap.size() != 0 ? valueMap.size() : 1) + 1);
    mapLayout.setColumnExpandRatio(0, .05f);
    mapLayout.setColumnExpandRatio(1, .425f);
    mapLayout.setColumnExpandRatio(2, .05f);
    mapLayout.setColumnExpandRatio(3, .425f);
    mapLayout.setColumnExpandRatio(4, .05f);

    mapLayout.setMargin(true);
    mapLayout.setSpacing(true);
    mapLayout.setWidth("100%");

    int i = 0;

    for (final String key : valueMap.keySet()) {
      final Label keyLabel = new Label("Name:");
      final Label valueLabel = new Label("Value:");

      final TextField keyField = new TextField();
      keyField.setValue(key);
      keyField.setWidth("100%");
      keyField.setNullSettingAllowed(false);
      keyField.addValidator(
          new NonZeroLengthStringValidator("Then configuration value name cannot be empty!"));
      keyField.setValidationVisible(false);

      final TextField valueField = new TextField();
      valueField.setWidth("100%");
      valueField.setValue(valueMap.get(key));
      valueField.setNullSettingAllowed(false);
      valueField.addValidator(
          new NonZeroLengthStringValidator("Then configuration value cannot be empty!"));
      valueField.setValidationVisible(false);

      mapLayout.addComponent(keyLabel, 0, i);
      mapLayout.setComponentAlignment(keyLabel, Alignment.MIDDLE_RIGHT);
      mapLayout.addComponent(keyField, 1, i);
      mapLayout.addComponent(valueLabel, 2, i);
      mapLayout.setComponentAlignment(valueLabel, Alignment.MIDDLE_RIGHT);
      mapLayout.addComponent(valueField, 3, i);
      final String mapKey = parameter.getName() + i;
      TextFieldKeyValuePair pair = new TextFieldKeyValuePair();
      pair.key = keyField;
      pair.value = valueField;

      this.mapTextFields.put(mapKey, pair);

      final Button removeButton = new Button("remove");
      removeButton.setStyleName(ValoTheme.BUTTON_LINK);
      removeButton.addClickListener(
          new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
              valueMap.remove(key);
              mapLayout.removeComponent(keyLabel);
              mapLayout.removeComponent(valueLabel);
              mapLayout.removeComponent(keyField);
              mapLayout.removeComponent(valueField);
              mapLayout.removeComponent(removeButton);

              mapTextFields.remove(mapKey);
            }
          });

      mapLayout.addComponent(removeButton, 4, i);

      i++;
    }

    final Button addButton = new Button("add");
    addButton.setStyleName(ValoTheme.BUTTON_LINK);
    addButton.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {
            final Label keyLabel = new Label("Name:");
            final Label valueLabel = new Label("Value:");

            final TextField keyField = new TextField();
            keyField.setWidth("100%");
            keyField.setNullSettingAllowed(false);
            keyField.addValidator(
                new NonZeroLengthStringValidator("Then configuration value name cannot be empty!"));
            keyField.setValidationVisible(false);

            final TextField valueField = new TextField();
            valueField.setWidth("100%");
            valueField.setNullSettingAllowed(false);
            valueField.addValidator(
                new NonZeroLengthStringValidator("Then configuration value cannot be empty!"));
            valueField.setValidationVisible(false);

            mapLayout.insertRow(mapLayout.getRows());

            mapLayout.removeComponent(addButton);
            mapLayout.addComponent(keyLabel, 0, mapLayout.getRows() - 2);
            mapLayout.setComponentAlignment(keyLabel, Alignment.MIDDLE_RIGHT);
            mapLayout.addComponent(keyField, 1, mapLayout.getRows() - 2);
            mapLayout.addComponent(valueLabel, 2, mapLayout.getRows() - 2);
            mapLayout.setComponentAlignment(valueLabel, Alignment.MIDDLE_RIGHT);
            mapLayout.addComponent(valueField, 3, mapLayout.getRows() - 2);

            final String mapKey = parameter.getName() + mapTextFields.size();
            TextFieldKeyValuePair pair = new TextFieldKeyValuePair();
            pair.key = keyField;
            pair.value = valueField;

            mapTextFields.put(mapKey, pair);

            final Button removeButton = new Button("remove");
            removeButton.setStyleName(ValoTheme.BUTTON_LINK);
            removeButton.addClickListener(
                new Button.ClickListener() {
                  public void buttonClick(ClickEvent event) {
                    mapLayout.removeComponent(keyLabel);
                    mapLayout.removeComponent(valueLabel);
                    mapLayout.removeComponent(keyField);
                    mapLayout.removeComponent(valueField);

                    mapLayout.removeComponent(removeButton);

                    mapTextFields.remove(mapKey);
                  }
                });

            mapLayout.addComponent(removeButton, 4, mapLayout.getRows() - 2);

            mapLayout.addComponent(addButton, 0, mapLayout.getRows() - 1);
          }
        });

    mapLayout.addComponent(addButton, 0, mapLayout.getRows() - 1);

    Panel mapPanel = new Panel();
    mapPanel.setStyleName(ValoTheme.PANEL_BORDERLESS);
    mapPanel.setContent(mapLayout);

    Button saveButton = new Button("Save");
    saveButton.addStyleName(ValoTheme.BUTTON_SMALL);
    saveButton.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {
            try {
              for (TextFieldKeyValuePair textField : mapTextFields.values()) {
                textField.key.validate();
                textField.value.validate();
              }

              usernameField.validate();
              passwordField.validate();
            } catch (InvalidValueException e) {
              for (TextFieldKeyValuePair textField : mapTextFields.values()) {
                textField.key.setValidationVisible(true);
                textField.value.setValidationVisible(true);
                usernameField.setValidationVisible(true);
                passwordField.setValidationVisible(true);
              }

              Notification.show("Validation errors have occurred!", Type.ERROR_MESSAGE);

              return;
            }

            HashMap<String, String> map = new HashMap<String, String>();

            logger.info("Saving map: " + mapTextFields.size());

            for (String key : mapTextFields.keySet()) {
              if (key.startsWith(parameter.getName())) {
                TextFieldKeyValuePair pair = mapTextFields.get(key);

                logger.info("Saving for key: " + key);

                if (pair.key.getValue() != "") {
                  map.put(pair.key.getValue(), pair.value.getValue());
                }
              }
            }

            parameter.setValue(map);
            userParam.setValue(usernameField.getValue());
            passwordParam.setValue(passwordField.getValue());

            PlatformConfigurationPanel.this.configurationManagement.saveConfiguration(
                platformConfiguration);

            Notification notification =
                new Notification(
                    "Saved",
                    "The configuration has been saved successfully!",
                    Type.HUMANIZED_MESSAGE);
            notification.setStyleName(ValoTheme.NOTIFICATION_CLOSABLE);
            notification.show(Page.getCurrent());
          }
        });

    Button deleteButton = new Button("Re-create");
    deleteButton.addStyleName(ValoTheme.BUTTON_SMALL);
    deleteButton.addClickListener(
        new Button.ClickListener() {
          public void buttonClick(ClickEvent event) {
            configurationManagement.deleteConfiguration(platformConfiguration);

            refresh();
          }
        });

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setHeight("100%");
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth(200, Unit.PIXELS);
    buttonLayout.setMargin(true);
    buttonLayout.addComponent(saveButton);
    buttonLayout.addComponent(deleteButton);

    paramLayout.addComponent(mapPanel, 0, 1, 1, 1);
    paramLayout.setComponentAlignment(mapPanel, Alignment.TOP_CENTER);
    paramLayout.addComponent(buttonLayout, 0, 2, 1, 2);
    paramLayout.setComponentAlignment(buttonLayout, Alignment.TOP_CENTER);
    paramPanel.setContent(paramLayout);

    return paramPanel;
  }
  protected Panel createTextFieldPanel(ConfigurationParameter parameter, Validator validator) {
    Panel paramPanel = new Panel();
    paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    paramPanel.setWidth("100%");

    GridLayout paramLayout = new GridLayout(3, 3);
    paramLayout.setSpacing(true);
    paramLayout.setSizeFull();
    paramLayout.setMargin(true);
    paramLayout.setColumnExpandRatio(0, .25f);
    paramLayout.setColumnExpandRatio(1, .75f);

    Label configLabel = new Label("Platform Configuration");
    configLabel.addStyleName(ValoTheme.LABEL_HUGE);
    configLabel.setSizeUndefined();
    paramLayout.addComponent(configLabel, 0, 0, 1, 0);
    paramLayout.setComponentAlignment(configLabel, Alignment.TOP_LEFT);

    Label label = new Label(parameter.getName());
    label.setIcon(VaadinIcons.COG);
    label.addStyleName(ValoTheme.LABEL_LARGE);
    label.addStyleName(ValoTheme.LABEL_BOLD);
    label.setSizeUndefined();
    paramLayout.addComponent(label, 0, 1, 1, 1);
    paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT);

    logger.info(parameter.getName() + " " + parameter.getValue());
    Label valueLabel = new Label("Value:");
    valueLabel.setSizeUndefined();
    usernameField = new TextField();
    usernameField.addValidator(validator);
    usernameField.setNullSettingAllowed(true);
    usernameField.setNullRepresentation("");
    usernameField.setValidationVisible(false);
    usernameField.setWidth("80%");
    usernameField.setId(parameter.getName());

    if (parameter instanceof ConfigurationParameterIntegerImpl) {
      StringToIntegerConverter plainIntegerConverter =
          new StringToIntegerConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      usernameField.setConverter(plainIntegerConverter);
    } else if (parameter instanceof ConfigurationParameterLongImpl) {
      StringToLongConverter plainLongConverter =
          new StringToLongConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      usernameField.setConverter(plainLongConverter);
    }

    BeanItem<ConfigurationParameter> parameterItem =
        new BeanItem<ConfigurationParameter>(parameter);

    if (parameter.getValue() != null) {
      usernameField.setPropertyDataSource(parameterItem.getItemProperty("value"));
    }

    paramLayout.addComponent(valueLabel, 0, 2);
    paramLayout.addComponent(usernameField, 1, 2);
    paramLayout.setComponentAlignment(valueLabel, Alignment.TOP_RIGHT);

    paramPanel.setContent(paramLayout);

    return paramPanel;
  }
  protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processDefinition.getId());

    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {

      boolean didDrawImage = false;

      if (ExplorerApp.get().isUseJavascriptDiagram()) {
        try {

          final InputStream definitionStream =
              repositoryService.getResourceAsStream(
                  processDefinition.getDeploymentId(), processDefinition.getResourceName());
          XMLInputFactory xif = XMLInputFactory.newInstance();
          XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
          BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

          if (bpmnModel.getFlowLocationMap().size() > 0) {

            int maxX = 0;
            int maxY = 0;
            for (String key : bpmnModel.getLocationMap().keySet()) {
              GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
              double elementX = graphicInfo.getX() + graphicInfo.getWidth();
              if (maxX < elementX) {
                maxX = (int) elementX;
              }
              double elementY = graphicInfo.getY() + graphicInfo.getHeight();
              if (maxY < elementY) {
                maxY = (int) elementY;
              }
            }

            Panel imagePanel = new Panel(); // using panel for scrollbars
            imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
            imagePanel.setWidth(100, UNITS_PERCENTAGE);
            imagePanel.setHeight(100, UNITS_PERCENTAGE);
            URL explorerURL = ExplorerApp.get().getURL();
            URL url =
                new URL(
                    explorerURL.getProtocol(),
                    explorerURL.getHost(),
                    explorerURL.getPort(),
                    explorerURL.getPath().replace("/ui", "")
                        + "diagram-viewer/index.html?processDefinitionId="
                        + processDefinition.getId()
                        + "&processInstanceId="
                        + processInstance.getId());
            Embedded browserPanel = new Embedded("", new ExternalResource(url));
            browserPanel.setType(Embedded.TYPE_BROWSER);
            browserPanel.setWidth(maxX + 350 + "px");
            browserPanel.setHeight(maxY + 220 + "px");

            HorizontalLayout panelLayoutT = new HorizontalLayout();
            panelLayoutT.setSizeUndefined();
            imagePanel.setContent(panelLayoutT);
            imagePanel.addComponent(browserPanel);

            panelLayout.addComponent(imagePanel);

            didDrawImage = true;
          }

        } catch (Exception e) {
          LOGGER.error("Error loading process diagram component", e);
        }
      }

      if (didDrawImage == false && processDefinitionEntity.isGraphicalNotationDefined()) {

        StreamResource diagram =
            new ProcessDefinitionImageStreamResourceBuilder()
                .buildStreamResource(processInstance, repositoryService, runtimeService);

        if (diagram != null) {
          Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
          header.addStyleName(ExplorerLayout.STYLE_H3);
          header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
          header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
          panelLayout.addComponent(header);

          Embedded embedded = new Embedded(null, diagram);
          embedded.setType(Embedded.TYPE_IMAGE);
          embedded.setSizeUndefined();

          Panel imagePanel = new Panel(); // using panel for scrollbars
          imagePanel.setScrollable(true);
          imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
          imagePanel.setWidth(100, UNITS_PERCENTAGE);
          imagePanel.setHeight(100, UNITS_PERCENTAGE);

          HorizontalLayout panelLayoutT = new HorizontalLayout();
          panelLayoutT.setSizeUndefined();
          imagePanel.setContent(panelLayoutT);
          imagePanel.addComponent(embedded);

          panelLayout.addComponent(imagePanel);
        }
      }
    }
  }
  public void init(final Window main) {
    VerticalLayout mainLayout = new VerticalLayout();
    main.setContent(mainLayout);
    mainLayout.setSizeFull();

    HorizontalLayout titlebar = new HorizontalLayout();
    titlebar.addStyleName("titlebar");
    titlebar.setWidth("100%");
    Label title = new Label("Book of Vaadin Examples");
    title.addStyleName("title");
    titlebar.addComponent(title);
    titlebar.setComponentAlignment(title, Alignment.MIDDLE_RIGHT);
    Embedded logo = new Embedded(null, new ThemeResource("img/vaadin-logo.png"));
    titlebar.addComponent(logo);
    titlebar.setComponentAlignment(logo, Alignment.MIDDLE_RIGHT);
    main.addComponent(titlebar);

    HorizontalLayout hor = new HorizontalLayout();
    hor.setSizeFull();
    main.addComponent(hor);
    mainLayout.setExpandRatio(hor, 1.0f);

    final Panel menupanel = new Panel("Examples");
    menupanel.addStyleName("menupanel");
    menupanel.setWidth(null);
    menupanel.setHeight("100%");
    menupanel.getContent().setWidth(null);
    // menupanel.getContent().setHeight("100%");
    hor.addComponent(menupanel);

    final Tree menu = new Tree();
    menu.setWidth(null);
    // menu.setHeight("100%");
    menu.setImmediate(true);
    menupanel.addComponent(menu);

    final Panel viewpanel = new Panel("Selected Example");
    viewpanel.addStyleName("viewpanel");
    viewpanel.setSizeFull();
    VerticalLayout viewlayout = new VerticalLayout();
    viewlayout.addStyleName("viewlayout");
    viewlayout.setSpacing(true);
    viewlayout.setMargin(true);
    viewpanel.setContent(viewlayout);

    hor.addComponent(viewpanel);
    hor.setExpandRatio(viewpanel, 1.0f);

    WebApplicationContext ctx = (WebApplicationContext) getContext();
    BookExampleLibrary library = BookExampleLibrary.getInstance(ctx.getBaseDirectory());

    AbstractExampleItem[] examples = library.getAllExamples();

    // Collect redirects here
    final HashMap<String, String> redirects = new HashMap<String, String>();

    // Collect examples here
    final HashMap<String, CaptionedExampleItem> exampleitems =
        new HashMap<String, CaptionedExampleItem>();

    // Build the menu and collect redirections
    for (int i = 0; i < examples.length; i++)
      if (examples[i] instanceof BookExample || examples[i] instanceof ExampleCtgr) {
        CaptionedExampleItem example = (CaptionedExampleItem) examples[i];
        exampleitems.put(example.getExampleId(), example);

        String itemid = example.getExampleId();
        menu.addItem(itemid);
        menu.setItemCaption(itemid, example.getShortName());

        if (examples[i].getParentId() != null) menu.setParent(itemid, examples[i].getParentId());
      } else if (examples[i] instanceof RedirctItem) {
        RedirctItem redirect = (RedirctItem) examples[i];
        redirects.put(redirect.getExampleId(), redirect.redirectid);
      }

    // Expand the menu
    for (int i = 0; i < examples.length; i++) {
      if (examples[i].getParentId() == null)
        menu.expandItemsRecursively(examples[i].getExampleId());

      if (examples[i].isCollapsed()) menu.collapseItem(examples[i].getExampleId());

      if (menu.getChildren(examples[i].getExampleId()) == null)
        menu.setChildrenAllowed(examples[i].getExampleId(), false);
    }

    // Set selected example as given in the URI fragment
    final UriFragmentUtility urifu = new UriFragmentUtility();
    urifu.addListener(
        new FragmentChangedListener() {
          private static final long serialVersionUID = -6588416218607827834L;

          public void fragmentChanged(FragmentChangedEvent source) {
            String fragment = source.getUriFragmentUtility().getFragment();
            if (fragment != null) {
              // Handle redirection
              while (redirects.containsKey(fragment)) fragment = redirects.get(fragment);

              menu.setValue(fragment);

              // Open the tree nodes leading to the example
              for (Object parent = menu.getParent(fragment);
                  parent != null;
                  parent = menu.getParent(parent)) menu.expandItem(parent);
            }
          }
        });
    mainLayout.addComponent(urifu);

    // Handle menu selection
    menu.addListener(
        new Property.ValueChangeListener() {
          private static final long serialVersionUID = 8236533959795019956L;

          public void valueChange(ValueChangeEvent event) {
            viewpanel.removeAllComponents();

            String selection = (String) event.getProperty().getValue();

            // Find the example
            CaptionedExampleItem exampleItem = exampleitems.get(selection);
            if (selection != null && exampleItem == null)
              main.showNotification("Invalid item " + selection);
            else if (exampleItem != null) {
              if (exampleItem.getClass().isAssignableFrom(ExampleCtgr.class)) {
                if (menu.hasChildren(exampleItem.getExampleId())) {
                  menu.select((String) menu.getChildren(exampleItem.getExampleId()).toArray()[0]);
                }
              } else { // A leaf
                BookExample example = (BookExample) exampleItem;

                // Load unless already loaded
                WebApplicationContext ctx = (WebApplicationContext) getContext();
                example.loadExample(ctx.getBaseDirectory());

                if (example.getDescription() != null) {
                  Label descLabel = new Label(example.getDescription(), Label.CONTENT_XHTML);
                  descLabel.addStyleName("example-description");
                  viewpanel.addComponent(descLabel);
                }

                // The actual example component
                viewpanel.addComponent(example.createInstance());

                // Java sources on the left, CSS on the right
                HorizontalLayout horizontalOrder = new HorizontalLayout();
                horizontalOrder.addStyleName("sourcecontainer");
                horizontalOrder.setSpacing(true);
                horizontalOrder.setMargin(true);

                Panel bookRefs = null;
                Panel forumLinks = null;
                Panel kbRefs = null;

                List<SourceFragment> fragments = example.getSourceFragments();
                if (fragments != null) {
                  // Java Sources are laid out vertically
                  VerticalLayout verticalListings = new VerticalLayout();
                  verticalListings.setSizeUndefined();
                  verticalListings.setSpacing(true);
                  horizontalOrder.addComponent(verticalListings);

                  // Find the widest source fragment
                  int widestIndex = 0;
                  int widestWidth = 0;
                  for (int fragmentNum = 0; fragmentNum < fragments.size(); fragmentNum++)
                    if (fragments.get(fragmentNum).getSrcWidth() > widestWidth) {
                      widestIndex = fragmentNum;
                      widestWidth = fragments.get(fragmentNum).getSrcWidth();
                    }
                  System.out.println("Widest listing: " + widestIndex + " which is " + widestWidth);

                  for (int fragmentNum = 0; fragmentNum < fragments.size(); fragmentNum++) {
                    SourceFragment fragment = fragments.get(fragmentNum);

                    // Have caption only in the beginning of the listings
                    String listingCaption = fragmentNum == 0 ? "Source Code" : "";

                    String srcurl =
                        "http://dev.vaadin.com/browser/doc/book-examples/trunk/src"
                            + fragment.getSrcName();
                    SourceListing listing = new SourceListing(listingCaption, srcurl, fragment);
                    verticalListings.addComponent(listing);

                    // Use the width of the widest listing for all listings
                    if (fragmentNum == widestIndex) listing.setWidth(Sizeable.SIZE_UNDEFINED, 0);
                    else listing.setWidth("100%");

                    if (!fragment.getBookRefs().isEmpty()) {
                      bookRefs = new Panel("Book References");
                      bookRefs.setSizeUndefined();
                      for (Iterator<String> iter = fragment.getBookRefs().iterator();
                          iter.hasNext(); ) {
                        String ref = iter.next();
                        int hashPos = ref.indexOf('#');
                        String refFragment = "";
                        if (hashPos != -1) {
                          refFragment = "#" + ref.replace('#', '.');
                          ref = ref.substring(0, hashPos);
                        }
                        String bookUrl =
                            "http://vaadin.com/book/-/page/" + ref + ".html" + refFragment;
                        Link link = new Link(bookUrl, new ExternalResource(bookUrl));
                        link.setTargetName("_new");
                        bookRefs.addComponent(link);
                      }
                    }

                    if (!fragment.getForumLinks().isEmpty()) {
                      forumLinks = new Panel("Forum Messages");
                      forumLinks.setSizeUndefined();
                      for (Iterator<String> iter = fragment.getForumLinks().iterator();
                          iter.hasNext(); ) {
                        String url = iter.next();
                        Link link = new Link(url, new ExternalResource(url));
                        link.setTargetName("_new");
                        forumLinks.addComponent(link);
                      }
                    }

                    if (!fragment.getKbRefs().isEmpty()) {
                      kbRefs = new Panel("Pro Account Knowledge Base Articles");
                      kbRefs.setSizeUndefined();
                      for (Iterator<SourceFragment.Ref> iter = fragment.getKbRefs().iterator();
                          iter.hasNext(); ) {
                        SourceFragment.Ref ref = iter.next();
                        String url = "http://vaadin.com/knowledge-base#" + ref.ref;
                        Link link = new Link(ref.caption, new ExternalResource(url));
                        link.setTargetName("_new");
                        forumLinks.addComponent(link);
                      }
                    }
                  }
                }

                // Show associated CSS
                if (example.getCssFragments() != null && example.getCssFragments().size() > 0) {
                  SourceFragment csscode = example.getCssFragments().get(0);
                  String srcurl =
                      "http://dev.vaadin.com/browser/doc/book-examples/trunk/WebContent/VAADIN/themes/book-examples/styles.css";
                  horizontalOrder.addComponent(new SourceListing("CSS Code", srcurl, csscode));
                }

                if (horizontalOrder.getComponentIterator().hasNext())
                  viewpanel.addComponent(horizontalOrder);
                if (bookRefs != null) viewpanel.addComponent(bookRefs);
                if (forumLinks != null) viewpanel.addComponent(forumLinks);
                if (kbRefs != null) viewpanel.addComponent(kbRefs);

                urifu.setFragment(example.getExampleId());
              }
            }
          }
        });

    Tree.ItemStyleGenerator itemStyleGenerator =
        new Tree.ItemStyleGenerator() {
          private static final long serialVersionUID = -3231268865512947125L;

          public String getStyle(Object itemId) {
            // Chapter title items do not contain a period
            if (!((String) itemId).contains(".")) return "chaptertitle";
            return null;
          }
        };
    menu.setItemStyleGenerator(itemStyleGenerator);
  }
  @Override
  public void attach() {
    super.attach();
    init(
        getBundleString("streamingConfigPanel.caption"),
        getComponentFactory().createGridLayout(1, 5, true, true));
    myVlcEnabled = getComponentFactory().createCheckBox("streamingConfigPanel.vlcEnabled");
    myVlcBinary =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.vlcBinary",
                new VlcExecutableFileValidator(
                    getBundleString("streamingConfigPanel.vlcBinary.invalidBinary")));
    myVlcBinary.setImmediate(false);
    myVlcBinarySelect =
        getComponentFactory().createButton("streamingConfigPanel.vlcBinary.select", this);
    myVlcHomepageButton =
        getComponentFactory().createButton("streamingConfigPanel.vlcHomepage", this);
    myVlcForm = getComponentFactory().createForm(null, true);
    myVlcForm.addField(myVlcEnabled, myVlcEnabled);
    myVlcForm.addField(myVlcBinary, myVlcBinary);
    myVlcForm.addField(myVlcBinarySelect, myVlcBinarySelect);
    myVlcForm.addField(myVlcHomepageButton, myVlcHomepageButton);
    Panel vlcPanel =
        getComponentFactory()
            .surroundWithPanel(
                myVlcForm,
                FORM_PANEL_MARGIN_INFO,
                getBundleString("streamingConfigPanel.caption.vlc"));
    addComponent(vlcPanel);
    Panel transcoderPanel = new Panel(getBundleString("streamingConfigPanel.caption.transcoder"));
    transcoderPanel.setContent(getComponentFactory().createVerticalLayout(true, true));
    Panel addTranscoderButtons = new Panel();
    addTranscoderButtons.addStyleName("light");
    addTranscoderButtons.setContent(
        getApplication().getComponentFactory().createHorizontalLayout(false, true));
    myAddTranscoder =
        getComponentFactory().createButton("streamingConfigPanel.transcoder.add", this);
    addTranscoderButtons.addComponent(myAddTranscoder);
    myTranscoderTable = new Table();
    myTranscoderTable.setCacheRate(50);
    myTranscoderTable.addContainerProperty(
        "name",
        String.class,
        null,
        getBundleString("streamingConfigPanel.transcoder.name"),
        null,
        null);
    myTranscoderTable.addContainerProperty("edit", Button.class, null, "", null, null);
    myTranscoderTable.addContainerProperty("delete", Button.class, null, "", null, null);
    myTranscoderTable.setSortContainerPropertyId("name");
    transcoderPanel.addComponent(myTranscoderTable);
    transcoderPanel.addComponent(addTranscoderButtons);
    addComponent(transcoderPanel);
    myCacheForm = getComponentFactory().createForm(null, true);
    myTranscodingCacheMaxGiB =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.cache.transcodingCacheMaxGiB",
                getApplication().getValidatorFactory().createMinMaxValidator(1, 1024));
    myCacheForm.addField("limitTranscoding", myTranscodingCacheMaxGiB);
    myHttpLiveStreamCacheMaxGiB =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.cache.httpLiveStreamCacheMaxGiB",
                getApplication().getValidatorFactory().createMinMaxValidator(1, 1024));
    myCacheForm.addField("limitHttpLiveStream", myHttpLiveStreamCacheMaxGiB);
    myClearAllCachesButton =
        getComponentFactory().createButton("streamingConfigPanel.clearAllCaches", this);
    myCacheForm.addField(myClearAllCachesButton, myClearAllCachesButton);
    addComponent(
        getComponentFactory()
            .surroundWithPanel(
                myCacheForm,
                FORM_PANEL_MARGIN_INFO,
                getBundleString("streamingConfigPanel.caption.cache")));

    addDefaultComponents(0, 4, 0, 4, false);

    initFromConfig();
  }