/** @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);
   }
 }
  @SuppressWarnings("serial")
  private void rebuildSocialMedias() {
    socialMediaRepeater.removeAll();
    if (model.getObject().getSocialMedia() != null) {
      for (final LabelValueBean<InstantMessagingType, String> socialMediaValue :
          model.getObject().getSocialMedia()) {

        final WebMarkupContainer item = new WebMarkupContainer(socialMediaRepeater.newChildId());
        socialMediaRepeater.add(item);

        final DropDownChoice<InstantMessagingType> socialMediaChoice =
            new DropDownChoice<InstantMessagingType>(
                "socialMediaChoice",
                new PropertyModel<InstantMessagingType>(socialMediaValue, "label"),
                socialMediaChoiceRenderer.getValues(),
                socialMediaChoiceRenderer);
        item.add(socialMediaChoice);
        socialMediaChoice.add(
            new AjaxFormComponentUpdatingBehavior("onchange") {
              @Override
              protected void onUpdate(final AjaxRequestTarget target) {
                //          socialMediaValue.setSocialMediaType(socialMediaChoice.getModelObject());
                //
                // model.getObject().setSocialMediaValues(contactDao.getSocialMediaValuesAsXml(socialMediaValues));
                // target.add(mainContainer);
              }
            });

        item.add(
            new AjaxMaxLengthEditableLabel(
                "editableLabel", new PropertyModel<String>(socialMediaValue, "value")) {
              @Override
              protected void onSubmit(final AjaxRequestTarget target) {
                super.onSubmit(target);
                model
                    .getObject()
                    .setSocialMedia(socialMediaValue.getLabel(), socialMediaValue.getValue());
                rebuildSocialMedias();
                target.add(mainContainer);
              }
            });

        final WebMarkupContainer deleteDiv = new WebMarkupContainer("deleteDiv");
        deleteDiv.setOutputMarkupId(true);
        deleteDiv.add(
            new AjaxIconLinkPanel(
                "delete", IconType.REMOVE, new PropertyModel<String>(socialMediaValue, "value")) {
              /**
               * @see
               *     org.projectforge.web.wicket.flowlayout.AjaxIconLinkPanel#onClick(org.apache.wicket.ajax.AjaxRequestTarget)
               */
              @Override
              protected void onClick(final AjaxRequestTarget target) {
                //          super.onClick(target);
                //          final Iterator<SocialMediaValue> it = socialMediaValues.iterator();
                //          while (it.hasNext() == true) {
                //            if (it.next() == socialMediaValue) {
                //              it.remove();
                //            }
                //          }
                //          rebuildSocialMedias();
                //
                // model.getObject().setSocialMediaValues(contactDao.getSocialMediaValuesAsXml(socialMediaValues));
                //          target.add(mainContainer);
              }
            });
        item.add(deleteDiv);
      }
    }
  }
  /** @see org.apache.wicket.Component#onBeforeRender() */
  @SuppressWarnings("serial")
  protected void redraw(
      final TemplateEntry activeTemplateEntry, final List<TeamCalDO> selectedCalendars) {
    columnRepeater.removeAll();
    final int counter = selectedCalendars.size();
    int rowsPerColumn = counter / 3;
    if (counter % 3 > 0) {
      ++rowsPerColumn; // Need one more row.
    }
    int rowCounter = 0;
    WebMarkupContainer columnContainer;
    RepeatingView rowRepeater = null;
    for (final TeamCalDO calendar : selectedCalendars) {
      if (rowCounter++ % rowsPerColumn == 0) {
        // Start new column:
        columnContainer = new WebMarkupContainer(columnRepeater.newChildId());
        columnContainer.add(AttributeModifier.append("class", GridSize.COL33.getClassAttrValue()));
        columnRepeater.add(columnContainer);
        rowRepeater = new RepeatingView("rowRepeater");
        columnContainer.add(rowRepeater);
      }
      final WebMarkupContainer container = new WebMarkupContainer(rowRepeater.newChildId());
      rowRepeater.add(container);
      final IModel<Boolean> model =
          Model.of(activeTemplateEntry.isVisible(calendar.getId()) == true);
      final CheckBoxPanel checkBoxPanel = new CheckBoxPanel("isVisible", model, "");
      checkBoxPanel
          .getCheckBox()
          .add(
              new AjaxFormComponentUpdatingBehavior("onChange") {
                private static final long serialVersionUID = 3523446385818267608L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                  final Boolean newSelection = checkBoxPanel.getCheckBox().getConvertedInput();
                  final TemplateCalendarProperties properties =
                      activeTemplateEntry.getCalendarProperties(calendar.getId());
                  if (newSelection != properties.isVisible()) {
                    properties.setVisible(newSelection);
                    activeTemplateEntry.setDirty();
                  }
                }
              });
      container.add(checkBoxPanel);
      WicketUtils.addTooltip(
          checkBoxPanel.getCheckBox(),
          getString("plugins.teamcal.filterDialog.calendarIsVisible.tooltip"));
      container.add(new Label("name", calendar.getTitle()));
      final ColorPickerPanel picker =
          new ColorPickerPanel("colorPicker", activeTemplateEntry.getColorCode(calendar.getId())) {
            @Override
            protected void onColorUpdate(final String selectedColor) {
              final TemplateCalendarProperties props =
                  activeTemplateEntry.getCalendarProperties(calendar.getId());
              if (props != null) {
                props.setColorCode(selectedColor);
              } else {
                log.warn(
                    "TeamCalendarProperties not found: calendar.id='"
                        + calendar.getId()
                        + "' + for active template '"
                        + activeTemplateEntry.getName()
                        + "'.");
              }
            }
          };
      container.add(picker);
    }
  }