Пример #1
0
  private void buildLessonTree(Response response) {
    TreeItem item = null;
    JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText());

    for (int i = 0; i < lessonJSArray.length(); i++) {
      LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i);
      TreeItem category = new TreeItem();
      category.setText(lessonCategoryJS.getName());

      JsArray<LessonJS> lessons = lessonCategoryJS.getChildren();
      for (int j = 0; j < lessons.length(); j++) {
        LessonJS lesson = lessons.get(j);

        TreeItem lessonItem = new TreeItem();
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        String lastUrl = sessionStorage.getItem("lastUrl");
        lessonItem.setText(lesson.getText());
        category.addItem(lessonItem);
        lessonsTreeMap.put(lessonItem.getText(), lesson);
        if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) {
          addLessonToMap(lesson);
        }
        if (lastUrl != null && lastUrl.equals(lesson.getUrl())) {
          item = lessonItem;
          lessonPanel.setSelectedLesson(lesson);
          category.setState(true);
        }
      }
      lessonTree.addItem(category);
    }
    lessonTree.setSelectedItem(item);
  }
Пример #2
0
  private void initLessonTree() {
    lessonTree.addSelectionHandler(
        new SelectionHandler<TreeItem>() {
          @Override
          public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem selectedItem = event.getSelectedItem();
            TreeItem parentItem = selectedItem.getParentItem();
            if (parentItem == null) {
              boolean opened = selectedItem.getState();
              selectedItem.setState(!opened);
            } else {
              String text = selectedItem.getText();
              LessonJS lessonJS = lessonsTreeMap.get(text);
              if (lessonJS != null) {
                Storage sessionStorage = Storage.getSessionStorageIfSupported();
                String url = lessonJS.getUrl();
                if (!lessonJS.getTechnology().equals(LessonTechnology.GWT.toString())) {
                  sessionStorage.setItem("lastUrl", url);
                  sessionStorage.setItem("select", Boolean.toString(true));
                  Window.Location.replace(url);

                } else {
                  lessonPanel.setSelectedLesson(lessonJS);
                }
              }
            }
          }
        });
  }