Exemplo n.º 1
0
 @UiHandler("sourceList")
 void onChangeSourceList(ChangeEvent e) {
   Place currentPlace = placeController.getWhere();
   if (currentPlace instanceof PlaceWithSources) {
     PlaceWithSources<?> place = (PlaceWithSources<?>) currentPlace;
     int selectedIndex = sourceList.getSelectedIndex();
     // we were on the example page, we create a new place from the previous one and go to this new
     // place
     placeController.goTo(
         place.createPlace(sourceList.getValue(selectedIndex), selectedIndex > 0));
   }
 }
Exemplo n.º 2
0
 @UiHandler("exampleLink")
 void onClickExampleLink(ClickEvent e) {
   Place currentPlace = placeController.getWhere();
   if (currentPlace instanceof PlaceWithSources) {
     PlaceWithSources<?> place = (PlaceWithSources<?>) currentPlace;
     if (null != place.getFilename()) {
       // we were on the source page, we create a new place from the previous one and go to this
       // new place
       placeController.goTo(place.createPlace());
     }
   }
 }
Exemplo n.º 3
0
 @UiHandler("sourceLink")
 void onClickSourceLink(ClickEvent e) {
   Place currentPlace = placeController.getWhere();
   if (currentPlace instanceof PlaceWithSources) {
     PlaceWithSources<?> place = (PlaceWithSources<?>) currentPlace;
     // we were on the example page, we create a new place from the previous one and go to this new
     // place
     placeController.goTo(
         place.createPlace(
             place.getSourceFilename(),
             sourceList.isVisible() && sourceList.getSelectedIndex() > 0));
   }
 }
Exemplo n.º 4
0
  @Override
  public void onPlaceChange(PlaceChangeEvent event) {
    Place newPlace = event.getNewPlace();

    // select the link corresponding to the place
    for (Link link : links) {
      if (link.isPlaceMatchLink(newPlace)) {
        link.getLink().addStyleName(res.style().menuLinkSelected());
      } else {
        link.getLink().removeStyleName(res.style().menuLinkSelected());
      }
    }

    // clear the source list because we are going to update it with the raw source file
    // corresponding to the new
    // place
    sourceList.clear();

    if (newPlace instanceof PlaceWithSources) {
      exampleLink.setVisible(true);
      sourceLink.setVisible(true);

      PlaceWithSources<?> place = (PlaceWithSources<?>) newPlace;

      sourceList.addItem("Example", place.getSourceFilename());

      String[] rawFilenames = place.getRawSourceFilenames();

      if (null != rawFilenames && rawFilenames.length > 0) {
        // add the raw source files to the list and show the list
        String text = sourceLink.getText();
        if (!text.endsWith(":")) {
          sourceLink.setText(text + ":");
        }
        sourceList.setVisible(true);
        int indexRawSource = 0;
        // starting at 1 because the first item is the example
        int i = 1;
        for (String filename : rawFilenames) {
          sourceList.addItem(filename, filename);
          if (place.isRawSource() && filename.equals(place.getFilename())) {
            indexRawSource = i;
          }
          i++;
        }
        sourceList.setSelectedIndex(indexRawSource);
      } else {
        // no raw source file, we hide the list
        String text = sourceLink.getText();
        if (text.endsWith(":")) {
          sourceLink.setText(text.substring(0, text.length() - 1));
        }
        sourceList.setVisible(false);
      }

      if (null == place.getFilename()) {
        sourceLink.removeStyleName(res.style().sourceLinkSelected());
        exampleLink.addStyleName(res.style().sourceLinkSelected());
        container.getElement().getStyle().clearBackgroundColor();
        container.getElement().getStyle().clearProperty("border");
      } else {
        exampleLink.removeStyleName(res.style().sourceLinkSelected());
        sourceLink.addStyleName(res.style().sourceLinkSelected());
        container.getElement().getStyle().setBackgroundColor("#eee");
        container.getElement().getStyle().setProperty("border", "1px solid #c3c3c3");
      }
    } else {
      // should not happen
      exampleLink.setVisible(false);
      sourceLink.setVisible(false);
      sourceList.setVisible(false);
    }
  }