001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.search;
034:
035: import com.flexive.shared.FxSharedUtils;
036: import com.flexive.shared.exceptions.FxInvalidParameterException;
037:
038: import java.util.ArrayList;
039: import java.util.List;
040:
041: /**
042: * Modifiable result preferences object.
043: *
044: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
045: * @version $Rev: 181 $
046: */
047: public class ResultPreferencesEdit extends ResultPreferences {
048: private static final long serialVersionUID = 5669756888973924325L;
049:
050: public ResultPreferencesEdit(
051: List<ResultColumnInfo> selectedColumns,
052: List<ResultOrderByInfo> orderByColumns, int rowsPerPage,
053: int thumbBoxSize) {
054: super (selectedColumns, orderByColumns, rowsPerPage,
055: thumbBoxSize);
056: }
057:
058: public <T extends ResultColumnInfo> void addSelectedColumn(T info) {
059: FxSharedUtils.checkParameterEmpty(info, "SELECTEDCOLUMN");
060: if (!selectedColumns.contains(info)) {
061: selectedColumns.add(info);
062: }
063: }
064:
065: public <T extends ResultColumnInfo> void addSelectedColumn(
066: int index, T info) {
067: FxSharedUtils.checkParameterEmpty(info, "SELECTEDCOLUMN");
068: if (!selectedColumns.contains(info)) {
069: selectedColumns.add(Math.max(0, Math.min(selectedColumns
070: .size(), index)), info);
071: }
072: }
073:
074: public <T extends ResultColumnInfo> ResultColumnInfo removeSelectedColumn(
075: T info) {
076: return removeSelectedColumn(selectedColumns.indexOf(info));
077: }
078:
079: public ResultColumnInfo removeSelectedColumn(int index) {
080: if (index >= 0 && selectedColumns.size() > index) {
081: return selectedColumns.remove(index);
082: } else {
083: throw new FxInvalidParameterException("INDEX",
084: "ex.ResultPreferences.selectedColumn.remove.index",
085: index, selectedColumns.size()).asRuntimeException();
086: }
087: }
088:
089: public <T extends ResultOrderByInfo> void addOrderByColumn(T info) {
090: FxSharedUtils.checkParameterEmpty(info, "ORDERBYCOLUMN");
091: if (!orderByColumns.contains(info)) {
092: orderByColumns.add(info);
093: }
094: }
095:
096: public <T extends ResultOrderByInfo> void addOrderByColumn(
097: int index, T info) {
098: FxSharedUtils.checkParameterEmpty(info, "ORDERBYCOLUMN");
099: if (!orderByColumns.contains(info)) {
100: orderByColumns.add(Math.max(0, Math.min(orderByColumns
101: .size(), index)), info);
102: }
103: }
104:
105: public <T extends ResultOrderByInfo> ResultOrderByInfo removeOrderByColumn(
106: T info) {
107: return removeOrderByColumn(orderByColumns.indexOf(info));
108: }
109:
110: public ResultOrderByInfo removeOrderByColumn(int index) {
111: if (index >= 0 && orderByColumns.size() > index) {
112: return orderByColumns.remove(index);
113: } else {
114: throw new FxInvalidParameterException("INDEX",
115: "ex.ResultPreferences.orderByColumn.remove.index",
116: index, orderByColumns.size()).asRuntimeException();
117: }
118: }
119:
120: public void setSelectedColumns(
121: List<ResultColumnInfo> selectedColumns) {
122: this .selectedColumns = new ArrayList<ResultColumnInfo>(
123: selectedColumns);
124: }
125:
126: public void setOrderByColumns(List<ResultOrderByInfo> orderByColumns) {
127: this .orderByColumns = new ArrayList<ResultOrderByInfo>(
128: orderByColumns);
129: }
130:
131: public void setRowsPerPage(int rowsPerPage) {
132: this .rowsPerPage = rowsPerPage;
133: }
134:
135: public void setThumbBoxSize(int thumbBoxSize) {
136: this .thumbBoxSize = thumbBoxSize;
137: }
138:
139: public void setLastChecked(long lastChecked) {
140: this.lastChecked = lastChecked;
141: }
142: }
|