/** @see org.projectforge.web.wicket.AbstractSelectPanel#onBeforeRender() */
 @SuppressWarnings("serial")
 @Override
 protected void onBeforeRender() {
   super.onBeforeRender();
   final TaskDO task = getModelObject();
   final Integer taskId = task != null ? task.getId() : null;
   if (currentTaskId == taskId) {
     return;
   }
   currentTaskId = taskId;
   if (showPath == true && task != null) {
     ancestorRepeater.removeAll();
     final TaskNode taskNode = taskTree.getTaskNodeById(task.getId());
     final List<Integer> ancestorIds = taskNode.getAncestorIds();
     final ListIterator<Integer> it = ancestorIds.listIterator(ancestorIds.size());
     while (it.hasPrevious() == true) {
       final Integer ancestorId = it.previous();
       final TaskDO ancestorTask = taskTree.getTaskById(ancestorId);
       if (ancestorTask.getParentTask() == null) {
         // Don't show root node:
         continue;
       }
       final WebMarkupContainer cont = new WebMarkupContainer(ancestorRepeater.newChildId());
       ancestorRepeater.add(cont);
       final SubmitLink selectTaskLink =
           new SubmitLink("ancestorTaskLink") {
             @Override
             public void onSubmit() {
               caller.select(selectProperty, ancestorTask.getId());
             }
           };
       selectTaskLink.setDefaultFormProcessing(false);
       cont.add(selectTaskLink);
       WicketUtils.addTooltip(
           selectTaskLink, getString("task.selectPanel.selectAncestorTask.tooltip"));
       selectTaskLink.add(new Label("name", ancestorTask.getTitle()));
     }
     ancestorRepeater.setVisible(true);
   } else {
     ancestorRepeater.setVisible(false);
   }
 }
  @Override
  @SuppressWarnings("serial")
  public TaskSelectPanel init() {
    super.init();
    ancestorRepeater = new RepeatingView("ancestorTasks");
    divContainer.add(ancestorRepeater);
    final SubmitLink taskLink =
        new SubmitLink("taskLink") {
          @Override
          public void onSubmit() {
            final TaskDO task = getModelObject();
            if (task == null) {
              return;
            }
            final PageParameters pageParams = new PageParameters();
            pageParams.add(AbstractEditPage.PARAMETER_KEY_ID, String.valueOf(task.getId()));
            final TaskEditPage editPage = new TaskEditPage(pageParams);
            editPage.setReturnToPage((AbstractSecuredPage) getPage());
            setResponsePage(editPage);
          }
        };
    taskLink.setDefaultFormProcessing(false);
    divContainer.add(taskLink);
    // auto complete panels
    initAutoCompletePanels();

    WicketUtils.addTooltip(taskLink, getString("task.selectPanel.displayTask.tooltip"));
    taskLink.add(
        new Label(
            "name",
            new Model<String>() {
              /** @see org.apache.wicket.model.Model#getObject() */
              @Override
              public String getObject() {
                final TaskDO task = getModelObject();
                return task != null ? task.getTitle() : "";
              }
            }));

    final SubmitLink selectButton =
        new SubmitLink("select") {
          @Override
          public void onSubmit() {
            final TaskTreePage taskTreePage = new TaskTreePage(caller, selectProperty);
            if (getModelObject() != null) {
              taskTreePage.setHighlightedRowId(
                  getModelObject().getId()); // Preselect node for highlighting.
            }
            setResponsePage(taskTreePage);
          };
        };
    selectButton.setDefaultFormProcessing(false);
    divContainer.add(selectButton);
    selectButton.add(new IconPanel("selectHelp", IconType.TASK, getString("tooltip.selectTask")));
    final SubmitLink unselectButton =
        new SubmitLink("unselect") {
          @Override
          public void onSubmit() {
            caller.unselect(selectProperty);
          }

          @Override
          public boolean isVisible() {
            return isRequired() == false && getModelObject() != null;
          }
        };
    unselectButton.setDefaultFormProcessing(false);
    divContainer.add(unselectButton);
    unselectButton.add(
        new IconPanel("unselectHelp", IconType.REMOVE_SIGN, getString("tooltip.unselectTask"))
            .setColor(CSSColor.RED));
    // DropDownChoice favorites
    final FavoritesChoicePanel<TaskDO, TaskFavorite> favoritesPanel =
        new FavoritesChoicePanel<TaskDO, TaskFavorite>(
            "favorites", UserPrefArea.TASK_FAVORITE, tabIndex, "full text") {
          @Override
          protected void select(final TaskFavorite favorite) {
            if (favorite.getTask() != null) {
              TaskSelectPanel.this.selectTask(favorite.getTask());
            }
          }

          @Override
          protected TaskDO getCurrentObject() {
            return TaskSelectPanel.this.getModelObject();
          }

          @Override
          protected TaskFavorite newFavoriteInstance(final TaskDO currentObject) {
            final TaskFavorite favorite = new TaskFavorite();
            favorite.setTask(currentObject);
            return favorite;
          }
        };
    divContainer.add(favoritesPanel);
    favoritesPanel.init();
    if (showFavorites == false) {
      favoritesPanel.setVisible(false);
    }
    return this;
  }