Skip to content
Snippets Groups Projects
Commit 01276f34 authored by srosse's avatar srosse
Browse files

OO-1011: reload the objects, reuse them...

parent 5c25743f
No related branches found
No related tags found
No related merge requests found
......@@ -76,14 +76,14 @@ public class ChecklistEditController extends ActivateableTabbableDefaultControll
super(ureq, wControl);
this.course = course;
this.courseNode = checklistCourseNode;
this.checklist = courseNode.loadOrCreateChecklist(this.course.getCourseEnvironment().getCoursePropertyManager());
checklist = courseNode.loadOrCreateChecklist(course.getCourseEnvironment().getCoursePropertyManager());
Condition accessCondition = courseNode.getPreConditionAccess();
accessibilityCondContr = new ConditionEditController(ureq, wControl, course.getCourseEnvironment().getCourseGroupManager(),
accessCondition, "accessabilityConditionForm", AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), courseNode), euce);
this.listenTo(accessibilityCondContr);
listenTo(accessibilityCondContr);
editVc = this.createVelocityContainer("edit");
editVc = createVelocityContainer("edit");
manageCheckpointsButton = LinkFactory.createButton("manage", editVc, this);
checklistFormContr = ChecklistUIFactory.getInstance().createEditCheckpointsController(ureq, getWindowControl(), checklist, "cl.save", ChecklistUIFactory.comparatorTitleAsc);
checklistFormContr.addControllerListener(this);
......@@ -156,16 +156,16 @@ public class ChecklistEditController extends ActivateableTabbableDefaultControll
fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if(source == checklistFormContr && event == Event.CHANGED_EVENT) {
ChecklistManager.getInstance().saveChecklist(this.checklist);
//checklist = ChecklistManager.getInstance().saveChecklist(checklist);
fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT);
} else if(source == manageController && event == Event.DONE_EVENT) {
cmcManage.deactivate();
} else if(event == NodeEditController.NODECONFIG_CHANGED_EVENT) {
// update title and description according to the course node
Checklist cl = ChecklistManager.getInstance().loadChecklist(this.checklist);
cl.setTitle(this.courseNode.getShortTitle());
cl.setDescription(this.courseNode.getLongTitle());
ChecklistManager.getInstance().saveChecklist(cl);
Checklist cl = ChecklistManager.getInstance().loadChecklist(checklist);
cl.setTitle(courseNode.getShortTitle());
cl.setDescription(courseNode.getLongTitle());
checklist = ChecklistManager.getInstance().saveChecklist(cl);
}
}
......
......@@ -71,6 +71,17 @@ public class Checklist extends PersistentObject implements ModifiedInfo, Seriali
return description;
}
public Checkpoint getCheckpoint(Checkpoint cl) {
if(checkpoints != null) {
for(Checkpoint checkpoint:checkpoints) {
if(checkpoint.equals(cl)) {
return checkpoint;
}
}
}
return null;
}
/**
* @return Returns the checkpoints.
*/
......@@ -127,7 +138,7 @@ public class Checklist extends PersistentObject implements ModifiedInfo, Seriali
* @param checkpoint
*/
public void addCheckpoint(int index, Checkpoint checkpoint) {
this.checkpoints.add(index, checkpoint);
checkpoints.add(index, checkpoint);
}
/**
......@@ -135,7 +146,7 @@ public class Checklist extends PersistentObject implements ModifiedInfo, Seriali
* @param checkpoint
*/
public void removeCheckpoint(Checkpoint checkpoint) {
this.checkpoints.remove(checkpoint);
checkpoints.remove(checkpoint);
}
/**
......
......@@ -22,6 +22,7 @@ package de.bps.olat.modules.cl;
import java.util.ArrayList;
import java.util.Date;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
......@@ -66,24 +67,27 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
// helpers
private boolean deletedOK = true;
private final ChecklistManager checklistManager;
public ChecklistEditCheckpointsController(UserRequest ureq, WindowControl wControl, Checklist checklist, String submitKey, CheckpointComparator checkpointComparator) {
super(ureq, wControl);
this.checklist = checklist;
this.submitKey = submitKey;
checklistManager = ChecklistManager.getInstance();
if (checkpointComparator != null) {
this.checkpointComparator = checkpointComparator;
}
int size = checklist.getCheckpoints().size();
this.titleInputList = new ArrayList<TextElement>(size);
this.descriptionInputList = new ArrayList<TextElement>(size);
this.modeInputList = new ArrayList<SingleSelection>(size);
this.delButtonList = new ArrayList<FormLink>(size);
titleInputList = new ArrayList<TextElement>(size);
descriptionInputList = new ArrayList<TextElement>(size);
modeInputList = new ArrayList<SingleSelection>(size);
delButtonList = new ArrayList<FormLink>(size);
initForm(this.flc, this, ureq);
initForm(ureq);
}
/**
......@@ -96,15 +100,30 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
@Override
protected void formOK(UserRequest ureq) {
for (int i = 0; i < this.checklist.getCheckpoints().size(); i++) {
Checkpoint checkpoint = this.checklist.getCheckpoints().get(i);
checkpoint.setChecklist(this.checklist);
checkpoint.setLastModified(new Date());
checkpoint.setTitle(this.titleInputList.get(i).getValue());
checkpoint.setDescription(this.descriptionInputList.get(i).getValue());
checkpoint.setMode(this.modeInputList.get(i).getSelectedKey());
checklist = checklistManager.loadChecklist(checklist);
for (int i = 0; i < titleInputList.size(); i++) {
boolean deleted = ! titleInputList.get(i).isVisible();
Checkpoint checkpoint = (Checkpoint)titleInputList.get(i).getUserObject();
if(deleted) {
Checkpoint currentCheckpoint = checklist.getCheckpoint(checkpoint);
checklist.removeCheckpoint(currentCheckpoint);
} else {
Checkpoint currentCheckpoint = checklist.getCheckpoint(checkpoint);
if(currentCheckpoint == null) {
currentCheckpoint = checkpoint;//the point is a new one
}
currentCheckpoint.setChecklist(checklist);
currentCheckpoint.setLastModified(new Date());
currentCheckpoint.setTitle(titleInputList.get(i).getValue());
currentCheckpoint.setDescription(descriptionInputList.get(i).getValue());
currentCheckpoint.setMode(modeInputList.get(i).getSelectedKey());
if(currentCheckpoint.getKey() == null) {
checklist.addCheckpoint(i, currentCheckpoint);
}
}
}
ChecklistManager.getInstance().updateChecklist(this.checklist);
checklist = checklistManager.updateChecklist(checklist);
DBFactory.getInstance().commit();
// Inform all listeners about the changes
fireEvent(ureq, Event.CHANGED_EVENT);
}
......@@ -156,13 +175,13 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
if (addButton.equals(source)) {
// add a new form link
Checkpoint newCheckpoint = new Checkpoint();
newCheckpoint.setChecklist(this.checklist);
newCheckpoint.setChecklist(checklist);
newCheckpoint.setLastModified(new Date());
newCheckpoint.setTitle("");
newCheckpoint.setDescription("");
newCheckpoint.setMode(CheckpointMode.MODE_EDITABLE);
int index = this.checklist.getCheckpoints().size();
this.checklist.addCheckpoint(index, newCheckpoint);
int index = checklist.getCheckpoints().size();
checklist.addCheckpoint(index, newCheckpoint);
addNewFormCheckpoint(index, newCheckpoint);
} else if (delButtonList.contains(source)) {
// special case: only one line existent
......@@ -181,32 +200,11 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
}
private void removeFormLink(Checkpoint checkpoint) {
checklist.removeCheckpoint(checkpoint);
int i;
for (i = 0; i < titleInputList.size(); i++) {
for (int i = 0; i < titleInputList.size(); i++) {
if (titleInputList.get(i).getUserObject().equals(checkpoint)) {
break;
}
}
titleContainer.remove(titleInputList.remove(i));
for (i = 0; i < descriptionInputList.size(); i++) {
if (descriptionInputList.get(i).getUserObject().equals(checkpoint)) {
break;
}
}
titleContainer.remove(descriptionInputList.remove(i));
for (i = 0; i < modeInputList.size(); i++) {
if (modeInputList.get(i).getUserObject().equals(checkpoint)) {
break;
}
}
titleContainer.remove(modeInputList.remove(i));
for (i = 0; i < delButtonList.size(); i++) {
if (delButtonList.get(i).getUserObject().equals(checkpoint)) {
break;
titleInputList.get(i).setVisible(false);
}
}
titleContainer.remove(delButtonList.remove(i));
}
@Override
......@@ -224,7 +222,7 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
newCheckpoint.setTitle("");
newCheckpoint.setDescription("");
newCheckpoint.setMode(CheckpointMode.MODE_EDITABLE);
this.checklist.addCheckpoint(0, newCheckpoint);
checklist.addCheckpoint(0, newCheckpoint);
addNewFormCheckpoint(0, newCheckpoint);
} else {
for (int i = 0; i < checklist.getCheckpoints().size(); i++) {
......@@ -293,7 +291,7 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
this.modeInputList = new ArrayList<SingleSelection>(size);
this.delButtonList = new ArrayList<FormLink>(size);
mainForm.setDirtyMarking(false);
initForm(this.flc, this, ureq);
initForm(flc, this, ureq);
fireEvent(ureq, Event.CANCELLED_EVENT);
}
......
......@@ -293,12 +293,12 @@ public class ChecklistManageCheckpointsController extends BasicController {
}
private void loadData() {
this.checklist = ChecklistManager.getInstance().loadChecklist(checklist);
checklist = ChecklistManager.getInstance().loadChecklist(checklist);
}
private void updateCheckpointsFor(Identity identity, BitSet selection) {
ChecklistManager manager = ChecklistManager.getInstance();
int size = this.checklist.getCheckpoints().size();
int size = checklist.getCheckpoints().size();
for(int i = 0; i < size; i++) {
Checkpoint checkpoint = this.checklist.getCheckpoints().get(i);
Boolean selected = checkpoint.getSelectionFor(identity);
......
......@@ -27,6 +27,7 @@ import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.coordinate.CoordinatorManager;
import org.olat.core.util.coordinate.SyncerCallback;
import org.olat.core.util.coordinate.SyncerExecutor;
import org.olat.core.util.resource.OresHelper;
......@@ -92,21 +93,21 @@ public class ChecklistManager {
* Save new checklist.
* @param checklist
*/
public void saveChecklist(Checklist cl) {
public Checklist saveChecklist(Checklist cl) {
cl.setLastModified(new Date());
DBFactory.getInstance().saveObject(cl);
return DBFactory.getInstance().getCurrentEntityManager().merge(cl);
}
/**
* Update checklist.
* @param checklist
*/
public void updateChecklist(final Checklist cl) {
public Checklist updateChecklist(final Checklist cl) {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Checklist.class, cl.getKey());
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Checklist>() {
public Checklist execute() {
cl.setLastModified(new Date());
DBFactory.getInstance().updateObject(cl);
return DBFactory.getInstance().getCurrentEntityManager().merge(cl);
}
});
}
......
......@@ -182,5 +182,21 @@ public class Checkpoint extends PersistentObject implements ModifiedInfo, Serial
result.setCheckpoint(this);
getResults().add(result);
}
@Override
public int hashCode() {
return getKey() == null ? -34892 : getKey().hashCode();
}
@Override
public boolean equals(Object obj) {
if(this == obj) {
return true;
}
if(obj instanceof Checkpoint) {
Checkpoint entry = (Checkpoint)obj;
return getKey() != null && getKey().equals(entry.getKey());
}
return false;
}
}
......@@ -12,16 +12,18 @@
#set( $descr = $descriptionInputList.get($iter).getName() )
#set( $descrErr = $descr + "_ERROR" )
#set( $hasError = "false" )
<tr>
<td>$r.render($titleErr)</td>
<td>$r.render($titleInputList.get($iter).getName())</td>
<td>$r.render($descriptionInputList.get($iter).getName())</td>
<td>$r.render($modeInputList.get($iter).getName())</td>
<!-- IE7-compatibility -->
<td style="white-space: nowrap; ">
$r.render($delButtonList.get($iter).getName())
</td>
</tr>
#if($titleInputList.get($iter).visible)
<tr>
<td>$r.render($titleErr)</td>
<td>$r.render($titleInputList.get($iter).getName())</td>
<td>$r.render($descriptionInputList.get($iter).getName())</td>
<td>$r.render($modeInputList.get($iter).getName())</td>
<!-- IE7-compatibility -->
<td style="white-space: nowrap; ">
$r.render($delButtonList.get($iter).getName())
</td>
</tr>
#end
#end
<tr>
<td colspan="4"></td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment