Package de.bps.olat.modules.cl

Source Code of de.bps.olat.modules.cl.ChecklistAuthorOptionsForm

/**
*
* BPS Bildungsportal Sachsen GmbH<br>
* Bahnhofstrasse 6<br>
* 09111 Chemnitz<br>
* Germany<br>
*
* Copyright (c) 2005-2009 by BPS Bildungsportal Sachsen GmbH<br>
* http://www.bps-system.de<br>
*
* All rights reserved.
*/
package de.bps.olat.modules.cl;

import java.util.BitSet;
import java.util.List;

import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormEvent;
import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.panel.Panel;
import org.olat.core.gui.components.table.DefaultColumnDescriptor;
import org.olat.core.gui.components.table.TableController;
import org.olat.core.gui.components.table.TableGuiConfiguration;
import org.olat.core.gui.components.table.TableMultiSelectEvent;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController;
import org.olat.core.gui.control.generic.modal.DialogBoxController;
import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory;
import org.olat.course.ICourse;

/**
* Description:<br>
* Display table with checkpoints of the checklist and the choice
* for the actual identity.
*
* <P>
* Initial Date:  22.07.2009 <br>
* @author bja <bja@bps-system.de>
*/
public class ChecklistDisplayController extends BasicController {

  // GUI
  private boolean canEdit, canManage;
  private ChecklistAuthorOptionsForm authorOptions;
  private TableController runChecklistTable;
  private Panel panel;
  private CloseableModalController cmcEdit, cmcManage;
  private DialogBoxController yesNoDialog;
  private Controller manageController, editController;
 
  // data
  private List<ChecklistFilter> filter;
  private Checklist checklist;
  private ICourse course;
  private List<Checkpoint> visibleCheckpoints;
  private ChecklistRunTableDataModel runTableData;
  private BitSet selection;
 
  protected ChecklistDisplayController(UserRequest ureq, WindowControl wControl, Checklist checklist, List<ChecklistFilter> filter, boolean canEdit, boolean canManage, ICourse course) {
    super(ureq, wControl);
    // initialize attributes
    this.checklist = checklist;
    this.course = course;
    this.filter = filter;
    this.canEdit = canEdit;
    this.canManage = canManage;
    this.visibleCheckpoints = checklist.getVisibleCheckpoints();
   
    // display checklist
    displayChecklist(ureq, wControl);
  }
 
  private void displayChecklist(UserRequest ureq, WindowControl wControl) {
    // add title
    VelocityContainer displayChecklistVC = this.createVelocityContainer("display");
    displayChecklistVC.contextPut("checklistTitle", this.checklist.getTitle());
    // add edit and manage button
    if((canEdit | canManage) && course != null) {
      displayChecklistVC.contextPut("showAuthorBtns", Boolean.TRUE);
      authorOptions = new ChecklistAuthorOptionsForm(ureq, getWindowControl(), canEdit, canManage);
      authorOptions.addControllerListener(this);
      displayChecklistVC.put("authorOptions", authorOptions.getInitialComponent());
    } else {
      displayChecklistVC.contextPut("showAuthorBtns", Boolean.FALSE);
    }
   
    panel = new Panel("runTable");
   
    initTable(ureq);
   
    displayChecklistVC.put("runTable", panel);

    putInitialPanel(displayChecklistVC);
  }
 
  private void initTable(UserRequest ureq) {
    // reload data
    loadData();
    // prepare table for run view
    runTableData = new ChecklistRunTableDataModel(visibleCheckpoints, getTranslator());
   
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setTableEmptyMessage(translate("cl.table.empty"));
    tableConfig.setColumnMovingOffered(true);
    if(runChecklistTable != null) {
      runChecklistTable.dispose();
      runChecklistTable = null;
    }
    runChecklistTable = new TableController(tableConfig, ureq, getWindowControl(), getTranslator(), this);
    runChecklistTable.addColumnDescriptor(new DefaultColumnDescriptor("cl.table.title", 0, null, ureq.getLocale()));
    runChecklistTable.addColumnDescriptor(new DefaultColumnDescriptor("cl.table.description", 1, null, ureq.getLocale()));
    runChecklistTable.addColumnDescriptor(new DefaultColumnDescriptor("cl.table.mode", 2, null, ureq.getLocale()));
    runChecklistTable.setMultiSelect(true);
    runChecklistTable.addMultiSelectAction("cl.table.run.action", "save");
    runChecklistTable.setTableDataModel(runTableData);
   
    for(int i = 0; i < visibleCheckpoints.size(); i++) {
      Checkpoint checkpoint = (Checkpoint) runTableData.getObject(i);
      boolean selected = checkpoint.getSelectionFor(ureq.getIdentity()).booleanValue();
      runChecklistTable.setMultiSelectSelectedAt(i, selected);
      if(checkpoint.getMode().equals(CheckpointMode.MODE_LOCKED) ||
        (checkpoint.getMode().equals(CheckpointMode.MODE_EDITABLE_ONCE) && selected)) {
        runChecklistTable.setMultiSelectReadonlyAt(i, true);
      } else {
        runChecklistTable.setMultiSelectReadonlyAt(i, false);
      }
    }
   
    panel.setContent(runChecklistTable.getInitialComponent());
  }
 
  private void loadData() {
    this.checklist = ChecklistManager.getInstance().loadChecklist(checklist);
    this.visibleCheckpoints = checklist.getVisibleCheckpoints();
  }
 
  private void updateCheckpoints(UserRequest ureq) {
    ChecklistManager manager = ChecklistManager.getInstance();
    int size = visibleCheckpoints.size();
    for(int i = 0; i < size; i++) {
      Checkpoint checkpoint = visibleCheckpoints.get(i);
      Boolean selected = checkpoint.getSelectionFor(ureq.getIdentity());
      if(selected.booleanValue() != selection.get(i)) {
        checkpoint.setSelectionFor(ureq.getIdentity(), selection.get(i));
        manager.updateCheckpoint(checkpoint);
      }
    }
    initTable(ureq);
  }

  /**
   * @see org.olat.core.gui.control.DefaultController#doDispose()
   */
  @Override
  protected void doDispose() {
    if(runChecklistTable != null) {
      runChecklistTable.dispose();
      runChecklistTable = null;
    }
    if(authorOptions != null) {
      authorOptions.dispose();
      authorOptions = null;
    }
    if(cmcEdit != null) {
      cmcEdit.dispose();
      cmcEdit = null;
    }
    if(editController != null) {
      editController.dispose();
      editController = null;
    }
    if(cmcManage != null) {
      cmcManage.dispose();
      cmcManage = null;
    }
    if(manageController != null) {
      manageController.dispose();
      manageController = null;
    }
    if(yesNoDialog != null) {
      yesNoDialog.dispose();
      yesNoDialog = null;
    }
  }

  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
   */
  @Override
  protected void event(UserRequest ureq, Controller source, Event event) {
    if(source == runChecklistTable) {
      if(event instanceof TableMultiSelectEvent) {
        TableMultiSelectEvent tmse = (TableMultiSelectEvent)event;
        selection = tmse.getSelection();
        boolean doUpdate = true;
        int size = visibleCheckpoints.size();
        // check for once editable checkpoints -> show confirmation dialog
        for(int i = 0; i < size; i++) {
          Checkpoint checkpoint = visibleCheckpoints.get(i);
          Boolean selected = checkpoint.getSelectionFor(ureq.getIdentity());
          if(checkpoint.getMode().equals(CheckpointMode.MODE_EDITABLE_ONCE) && selected.booleanValue() != selection.get(i)) {
            yesNoDialog = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("dialog.save.title"), translate("dialog.save.text"));
            yesNoDialog.addControllerListener(this);
            yesNoDialog.activate();
            doUpdate = false;
            break;
          }
        }
        // no confirmation necessary, do update immediately
        if(doUpdate) updateCheckpoints(ureq);
      }
    } else if(source == yesNoDialog) {
      // do update after confirmation
      if(DialogBoxUIFactory.isYesEvent(event)) updateCheckpoints(ureq);
      yesNoDialog.dispose();
      yesNoDialog = null;
    } else if(source == authorOptions) {
      if(event == ChecklistAuthorOptionsForm.CONFIG_CHECKPOINT) {
        editController = ChecklistUIFactory.getInstance().createEditCheckpointsController(ureq, getWindowControl(), checklist, "cl.save.close");
        listenTo(editController);
        cmcEdit = new CloseableModalController(getWindowControl(), translate("cl.close"), editController.getInitialComponent(), true, translate("cl.edit.title"));
        cmcEdit.addControllerListener(this);
        cmcEdit.activate();
      } else if(event == ChecklistAuthorOptionsForm.MANAGE_CHECKPOINT) {
        manageController = ChecklistUIFactory.getInstance().createManageCheckpointsController(ureq, getWindowControl(), checklist, course);
        listenTo(manageController);
        cmcManage = new CloseableModalController(getWindowControl(), translate("cl.close"), manageController.getInitialComponent(), true, translate("cl.manage.title"));
        cmcManage.addControllerListener(this);
        cmcManage.activate();
      }
    } else if(source == cmcEdit) {
      initTable(ureq);
    } else if(source == editController) {
      if(event == Event.CHANGED_EVENT | event == Event.CANCELLED_EVENT) {
        initTable(ureq);
        cmcEdit.deactivate();
      }
    } else if(source == cmcManage) {
      initTable(ureq);
    } else if(source == manageController && event == Event.DONE_EVENT) {
      initTable(ureq);
      cmcManage.deactivate();
    }
  }

  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
   */
  @Override
  protected void event(UserRequest ureq, Component source, Event event) {
    // nothing to do
  }

}

class ChecklistAuthorOptionsForm extends FormBasicController {

  public static final Event MANAGE_CHECKPOINT = new Event("manage");
  public static final Event CONFIG_CHECKPOINT = new Event("config");

  private FormLinkImpl manageCheckpointsBtn, configCheckpointsBtn;
  private boolean canEdit, canManage;

  public ChecklistAuthorOptionsForm(UserRequest ureq, WindowControl wControl, boolean canEdit, boolean canManage) {
    super(ureq, wControl);
    this.canEdit = canEdit;
    this.canManage = canManage;
    initForm(this.flc, this, ureq);
  }

  @Override
  @SuppressWarnings("unused")
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer mainLayout = FormLayoutContainer.createHorizontalFormLayout("mainLayout", getTranslator());
    formLayout.add(mainLayout);
    if(canManage) {
      manageCheckpointsBtn = new FormLinkImpl("manageCheckpointsButton", MANAGE_CHECKPOINT.getCommand(), "cl.manage.button", Link.BUTTON);
      mainLayout.add(manageCheckpointsBtn);
    }
    if(canEdit) {
      configCheckpointsBtn = new FormLinkImpl("configCheckpointsButton", CONFIG_CHECKPOINT.getCommand(), "cl.config.button", Link.BUTTON);
      mainLayout.add(configCheckpointsBtn);
    }
  }

  @Override
  protected void formInnerEvent(UserRequest ureq, FormItem source, @SuppressWarnings("unused") FormEvent event) {
    if(source == manageCheckpointsBtn) {
      fireEvent(ureq, MANAGE_CHECKPOINT);
    } else if(source == configCheckpointsBtn) {
      fireEvent(ureq, CONFIG_CHECKPOINT);
    }
  }

  @Override
  protected void doDispose() {
    // nothing to do
  }

  @Override
  protected void formOK(@SuppressWarnings("unused") UserRequest ureq) {
    // nothing to do
  }

}
TOP

Related Classes of de.bps.olat.modules.cl.ChecklistAuthorOptionsForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.