01: /*
02: * NamedSortDefinition.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.storage;
13:
14: /**
15: * A class to save the sort definition for a DataStoreTableModel.
16: * The sorted columns are saved by name, not by index position.
17: *
18: * @author support@sql-workbench.net
19: */
20: public class NamedSortDefinition {
21: private String[] sortColumns;
22: private boolean[] sortAscending;
23:
24: public NamedSortDefinition(DataStore data, SortDefinition sort) {
25: if (sort != null && sort.hasColumns()) {
26: sortColumns = new String[sort.getColumnCount()];
27: sortAscending = new boolean[sort.getColumnCount()];
28: for (int i = 0; i < sort.getColumnCount(); i++) {
29: int dataColumn = sort.getSortColumnByIndex(i);
30: sortColumns[i] = data.getColumnName(dataColumn);
31: sortAscending[i] = sort.isSortAscending(dataColumn);
32: }
33: }
34: }
35:
36: public SortDefinition getSortDefinition(DataStore data) {
37: if (sortColumns == null)
38: return new SortDefinition();
39:
40: int[] columns = new int[sortColumns.length];
41: for (int i = 0; i < sortColumns.length; i++) {
42: columns[i] = data.getColumnIndex(sortColumns[i]);
43: }
44: return new SortDefinition(columns, sortAscending);
45: }
46:
47: }
|