[jsword-devel] Patch for sidebar delete problem

DM Smith dmsmith555 at yahoo.com
Wed Aug 25 06:01:48 MST 2004


As I noted in an earlier e-mail, the problem with the sidebar delete was 
that the list's model was not changing via the list or list model 
interfaces. This breaks the list.

The PassageListModel is written to respond to external changes, but it 
does not work. Down in the bowels of the JList code are all kinds of 
assumptions on its invariant and it tries to get at data that is not 
there anymore.

Anyway, I have a hack. It does not solve the problem, but prevents it 
from happening. It works on a copy and sets the list model's data to it 
after changing it.

Index: PassageGuiUtil.java
===================================================================
RCS file: 
/cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/passage/PassageGuiUtil.java,v
retrieving revision 1.4
diff -u -r1.4 PassageGuiUtil.java
--- PassageGuiUtil.java    16 Aug 2004 22:09:21 -0000    1.4
+++ PassageGuiUtil.java    25 Aug 2004 12:52:27 -0000
@@ -52,7 +52,10 @@
     {
         PassageListModel plm = (PassageListModel) list.getModel();
 
-        Passage ref = plm.getPassage();
+        // TODO(DMS): this is a hack.
+        // Model is not changing through list or model inteface
+        // Therefore we have to work on a copy.
+        Passage ref = (Passage) plm.getPassage().clone();
         Object[] selected = list.getSelectedValues();
         for (int i = 0; i < selected.length; i++)
         {
@@ -60,7 +63,7 @@
             ref.remove(range);
         }
 
-        list.setSelectedIndices(new int[0]);
+        plm.setPassage(ref);
     }
 
     /**




More information about the jsword-devel mailing list