avatar

607

Better preserve column order between runs. It would do it before, but it wasn't consistent. Now it processes column ordering from first to last, so later column reorders don't affect earlier ones.

[#317 state:resolved]

There are a bunch of other tickets on this problem, all throughout the ticket system, which I'll link to this checkin later.

by mrs, 15 Aug, 2008 04:10 PM
599 607  
1313 import java.awt.event.MouseListener;
1414 import java.awt.Point;
1515 import java.awt.Dimension;
16 import java.util.TreeMap;
16 import java.util.*;
1717 
1818 /**
1919  * Created by IntelliJ IDEA.
------
152152 
153153   private static int notify_delay = 0;
154154 
155   private class Pair<K,V> {
156     private K mFirst;
157     private V mLast;
158 
159     public Pair(K k, V v) {
160       mFirst = k;
161       mLast = v;
162     }
163 
164     public K getFirst() {
165       return mFirst;
166     }
167 
168     public V getLast() {
169       return mLast;
170     }
171   }
172 
173   private class ColumnIndex extends Pair<String,Integer> {
174     public ColumnIndex(String s, Integer i) { super(s, i); }
175   }
176 
155177   private void loadColumnSettings(String prefix, TableModel atm) {
156178     String curColumnName = "";
157179 
158     TreeMap<String, Integer> initialToSaved = new TreeMap<String, Integer>();
180     List<ColumnIndex> initialToSaved = new LinkedList<ColumnIndex>();
159181     //  This code would need to be somewhat revamped if we allowed
160182     //  arbitrary, or user-selected column names.
161183     try {
------
171193           if (dotIndex != -1) {
172194             String colIndex = colWidth.substring(0, dotIndex);
173195             colWidth = colWidth.substring(dotIndex + 1);
174             initialToSaved.put(curColumnName, Integer.parseInt(colIndex));
196             initialToSaved.add(new ColumnIndex(curColumnName, Integer.parseInt(colIndex)));
175197           }
176198           makeNewColumn(curColumnName, colWidth);
177199         }
------
198220     }
199221 
200222     if(!initialToSaved.isEmpty()) {
201       for (String colName : initialToSaved.keySet()) {
202         int colFrom = getColumnModel().getColumnIndex(colName);
203         int colTo = initialToSaved.get(colName);
223       Collections.sort(initialToSaved, new Comparator<ColumnIndex>() {
224         public int compare(ColumnIndex o1, ColumnIndex o2) {
225           if(o1.getLast() < o2.getLast()) return -1;
226           if(o1.getLast() > o2.getLast()) return 1;
227           return 0;
228         }
229       });
230       for (ColumnIndex pair : initialToSaved) {
231         int colFrom = getColumnModel().getColumnIndex(pair.getFirst());
232         int colTo = pair.getLast();
233         System.err.println("Moving column " + colFrom + " to " + colTo);
204234         try {
205235           moveColumn(colFrom, colTo);
206236         } catch (IllegalArgumentException iae) {