changeset 42:7380d8ff1a66 default tip

bring up a message dialog if the selected database did not contain any conflicts
author dirk
date Thu, 05 Jan 2012 05:33:19 +0100
parents 0c36e54a85b5
children
files conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java
diffstat 3 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java	Mon Oct 10 02:56:36 2011 +0200
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java	Thu Jan 05 05:33:19 2012 +0100
@@ -8,6 +8,7 @@
 
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.node.ArrayNode;
 
 /**
  * Creates a temporary view in the database to retrieve all documents that have conflicts.
@@ -43,7 +44,7 @@
         _httpAccess = httpAccess;
     }
 
-    public JsonNode getConflicts() throws IOException
+    public ArrayNode getConflicts() throws IOException
     {
         InputStream input = null;
         try
@@ -69,10 +70,10 @@
         return _httpAccess;
     }
 
-    private JsonNode rowsNodeFromJson(InputStream input) throws IOException
+    private ArrayNode rowsNodeFromJson(InputStream input) throws IOException
     {
         ObjectMapper mapper = new ObjectMapper();
         JsonNode rootNode = mapper.readTree(input);
-        return rootNode.get("rows");
+        return (ArrayNode)rootNode.get("rows");
     }
 }
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java	Mon Oct 10 02:56:36 2011 +0200
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java	Thu Jan 05 05:33:19 2012 +0100
@@ -14,6 +14,7 @@
 import javax.swing.ComboBoxModel;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JFrame;
+import javax.swing.JOptionPane;
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 import javax.swing.ListModel;
@@ -21,6 +22,7 @@
 
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.node.ArrayNode;
 
 public class ConflictEditor
 {
@@ -207,9 +209,23 @@
     protected void findConflicts() throws IOException
     {
         String dbUrl = _frame.getDatabaseUrl();
-        JsonNode conflicts = _controller.findConflicts(dbUrl);
-        ListModel model = new ConflictsListModel(conflicts);
-        _frame.getConflictsList().setModel(model);
+        ArrayNode conflicts = _controller.findConflicts(dbUrl);
+        if (conflicts.size() == 0)
+        {
+            displayNoConflictsMessage();
+        }
+        else
+        {
+            ListModel model = new ConflictsListModel(conflicts);
+            _frame.getConflictsList().setModel(model);
+        }
+    }
+
+    private void displayNoConflictsMessage()
+    {
+        String message = "No conflicts found.";
+        String title = "All clean";
+        JOptionPane.showMessageDialog(_frame, message, title, JOptionPane.INFORMATION_MESSAGE);
     }
 
     protected void selectConflictDocument() throws Exception
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java	Mon Oct 10 02:56:36 2011 +0200
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java	Thu Jan 05 05:33:19 2012 +0100
@@ -15,6 +15,7 @@
 
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.node.ArrayNode;
 import org.codehaus.jackson.node.ObjectNode;
 
 public class ConflictEditorController extends Object
@@ -24,7 +25,7 @@
     private Difference _currentDifference;
     private String _conflictRevision;
 
-    public JsonNode findConflicts(String dbUrl) throws IOException
+    public ArrayNode findConflicts(String dbUrl) throws IOException
     {
         _database = new CouchDb(dbUrl);
         ConflictsView conflictsView = new ConflictsView(_database);