001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package com.sun.data.provider;
043:
044: import java.io.Serializable;
045:
046: /**
047: * <p>The abstract SortCriteria class defines a single sort criteria for a
048: * {@link TableDataFilter}. This includes a boolean to indicate an ascending
049: * (<code>true</code>) or descending (<code>false</code>) sort critiera.
050: * Subclasses override the {@link #getSortValue(TableDataProvider, RowKey)}
051: * method to provide a sortable value for the particular row in the table.
052: * An array of these SortCriteria objects are used to define the sort order
053: * for a {@link TableDataProvider}.</p>
054: */
055: public abstract class SortCriteria implements Serializable {
056:
057: /**
058: * <p>Constructs a new SortCriteria object with no display name and the
059: * default state for include (<code>true</code>).</p>
060: */
061: public SortCriteria() {
062: }
063:
064: /**
065: * <p>Constructs a new SortCriteria object with the specified display name
066: * and the default state for the include/exclude (<code>true == </code>
067: * include).</p>
068: *
069: * @param displayName The desired display name for this filter criteria
070: */
071: public SortCriteria(String displayName) {
072: this .displayName = displayName;
073: }
074:
075: /**
076: * <p>Constructs a new SortCriteria object with the specified display name
077: * and state for include/exclude (<code>true</code> == include).</p>
078: *
079: * @param displayName The desired display name for this filter criteria
080: * @param ascending <code>true</code> for ascending sort, or
081: * <code>false</code> for descending.
082: */
083: public SortCriteria(String displayName, boolean ascending) {
084: this .displayName = displayName;
085: this .ascending = ascending;
086: }
087:
088: /**
089: * <p>Sets the display name for this filter criteria.</p>
090: *
091: * @param displayName The desired display name for this filter criteria
092: */
093: public void setDisplayName(String displayName) {
094: this .displayName = displayName;
095: }
096:
097: /**
098: * <p>Returns the display name for this sort criteria.</p>
099: *
100: * @return The display name of this sort criteria
101: */
102: public String getDisplayName() {
103: return displayName;
104: }
105:
106: /**
107: * Sets the ascending sort state for this SortCriteria
108: *
109: * @param ascending <code>true</code> for ascending, <code>false</code>
110: * for desscending
111: */
112: public void setAscending(boolean ascending) {
113: this .ascending = ascending;
114: }
115:
116: /**
117: * Returns the ascending sort state for this SortCriteria
118: *
119: * @return <code>true</code> for ascending, <code>false</code> for
120: * descending
121: */
122: public boolean isAscending() {
123: return ascending;
124: }
125:
126: /**
127: * Returns a String uniquely identifying this sort criteria. This is used
128: * to match up a sort criteria object with a user gesture in UI.
129: *
130: * @return A String that uniquely identifies this sort criteria
131: */
132: abstract public String getCriteriaKey();
133:
134: /**
135: * <p>Provides the data value to use while sorting a particular row.
136: * Implementations may perform whatever logic is desired to provide the
137: * data object to represent this row in a sort.</p>
138: *
139: * @param provider {@link TableDataProvider} containing the data on display
140: * @param rowKey The {@link RowKey} of the row to be sorted
141: * @return the data object representing this row for this sort criteria
142: * @throws DataProviderException Implementations may wish to surface
143: * internal exceptions (nested in DataProviderException) rather
144: * than simply returning null. A DPE may also indicate that the
145: * passed TableDataProvider or RowKey is not valid. Consult the
146: * documentation of the specific SortCriteria implementation for
147: * details on what exceptions might be wrapped by a DPE.
148: */
149: abstract public Object getSortValue(TableDataProvider provider,
150: RowKey rowKey) throws DataProviderException;
151:
152: private String displayName;
153: private boolean ascending = true;
154: }
|