1 package jimm.datavision.gui.cmd; 2 import jimm.datavision.Selectable; 3 import jimm.datavision.source.Query; 4 import jimm.datavision.gui.SortWinListItem; 5 import jimm.util.I18N; 6 import java.util.Collection ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 10 15 public class SortEditCommand extends CommandAdapter { 16 17 protected static final int NO_CHANGE = 0; 18 protected static final int ONLY_SORTING_CHANGE = 1; 19 protected static final int DRASTIC_CHANGE = 2; 20 21 protected Query query; 22 protected Collection newSortItems; 23 protected Collection oldSortItems; 24 25 public SortEditCommand(Query query, Collection sortItems) { 26 super(I18N.get("SortEditCommand.name")); 27 this.query = query; 28 this.newSortItems = sortItems; 29 30 oldSortItems = new ArrayList (); 32 for (Iterator iter = query.sortedSelectables(); iter.hasNext(); ) { 33 Selectable g = (Selectable)iter.next(); 34 oldSortItems.add(new SortWinListItem(g, query.sortOrderOf(g))); 35 } 36 } 37 38 public void perform() { 39 setSorts(newSortItems); 40 } 41 42 public void undo() { 43 setSorts(oldSortItems); 44 } 45 46 protected void setSorts(Collection itemList) { 47 query.clearSorts(); 48 for (Iterator iter = itemList.iterator(); iter.hasNext(); ) { 49 SortWinListItem item = (SortWinListItem)iter.next(); 50 query.addSort(item.getSelectable(), item.sortsAscending() 51 ? Query.SORT_ASCENDING : Query.SORT_DESCENDING); 52 } 53 } 54 55 } 56 | Popular Tags |