# HG changeset patch # User dirk # Date 1316533679 -7200 # Node ID cc648f83cdbcb6ac19e433f6293416c693b36e54 # Parent a6388599b1062d92bac3a24c24d05fafc409a072 remove the selected conflict after saving - does not fully work yet, e.g. does not proplerly reset the differences table diff -r a6388599b106 -r cc648f83cdbc conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Tue Sep 20 17:21:03 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Tue Sep 20 17:47:59 2011 +0200 @@ -180,12 +180,14 @@ { // the index that's passed in from the list selection event is wrong! index = _frame.getDifferencesTable().getSelectedRow(); + if (index > -1) + { + DifferenceTableModel model = (DifferenceTableModel)_frame.getDifferencesTable().getModel(); + Difference difference = model.differenceAtIndex(index); + _controller.setCurrentDifference(difference); - DifferenceTableModel model = (DifferenceTableModel)_frame.getDifferencesTable().getModel(); - Difference difference = model.differenceAtIndex(index); - _controller.setCurrentDifference(difference); - - _frame.enableButtons(); + _frame.enableButtons(); + } } protected void useCurrentValue() @@ -221,5 +223,27 @@ protected void save() throws Exception { _controller.save(); + + resetDifferencesTableModel(); + + JsonNode resolvedConflict = _controller.getCurrentConflict(); + ConflictsListModel conflictsModel = (ConflictsListModel)_frame.getConflictsList().getModel(); + conflictsModel.remove(resolvedConflict); + + clearSelectionInConflictsList(); + } + + private void clearSelectionInConflictsList() + { + _frame.getConflictsList().getSelectionModel().clearSelection(); + } + + private void resetDifferencesTableModel() + { + _controller.setCurrentDifference(null); + + DifferenceTableModel model = new DifferenceTableModel(); + _frame.getDifferencesTable().setModel(model); + _frame.repaint(); } } diff -r a6388599b106 -r cc648f83cdbc conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Tue Sep 20 17:21:03 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Tue Sep 20 17:47:59 2011 +0200 @@ -115,8 +115,11 @@ URL updateUrl = _database.urlForDocument(id); InputStream input = new HttpClientHttpAccess(updateUrl).put(_currentConflict.toString()); - // TODO take care of the return value - System.out.println(new ObjectMapper().readTree(input)); + JsonNode result = parseJson(input); + if (result.get("ok").getValueAsBoolean() == false) + { + throw new IllegalStateException("update failed: " + result.toString()); + } } private void deleteConflictVersion() throws Exception @@ -125,7 +128,10 @@ URL deleteUrl = _database.urlForDocumentAndRevision(id, _conflictRevision); InputStream input = new HttpClientHttpAccess(deleteUrl).delete(); - // TODO take care of the return value - System.out.println(new ObjectMapper().readTree(input)); + JsonNode result = parseJson(input); + if (result.get("ok").getValueAsBoolean() == false) + { + throw new IllegalStateException("delete failed: " + result.toString()); + } } } diff -r a6388599b106 -r cc648f83cdbc conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictsListModel.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictsListModel.java Tue Sep 20 17:21:03 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictsListModel.java Tue Sep 20 17:47:59 2011 +0200 @@ -1,29 +1,69 @@ package de.codedo.conflicteditor.gui; +import java.util.ArrayList; +import java.util.List; + import javax.swing.AbstractListModel; import org.codehaus.jackson.JsonNode; public class ConflictsListModel extends AbstractListModel { - private JsonNode _conflictsNode; + private List _conflicts; public ConflictsListModel(JsonNode conflictsNode) { super(); - _conflictsNode = conflictsNode; + initConflicts(conflictsNode); + } + + private void initConflicts(JsonNode conflictsNode) + { + _conflicts = new ArrayList(); + + int size = conflictsNode.size(); + for (int i = 0; i < size; i++) + { + _conflicts.add(conflictsNode.get(i)); + } } @Override public int getSize() { - return _conflictsNode.size(); + return _conflicts.size(); } @Override public Object getElementAt(int index) { - return _conflictsNode.get(index); + return _conflicts.get(index); + } + + public void remove(JsonNode resolvedConflict) + { + int index = findIndex(resolvedConflict); + if (index > -1) + { + _conflicts.remove(index); + fireContentsChanged(this, index, index); + } + } + + private int findIndex(JsonNode node) + { + JsonNode id = node.get("_id"); + int index = 0; + for (JsonNode currentNode : _conflicts) + { + JsonNode currentId = currentNode.get("id"); + if (currentId.equals(id)) + { + return index; + } + index++; + } + return -1; } }