001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.search;
022:
023: import com.liferay.portal.kernel.dao.search.SearchContainer;
024: import com.liferay.portal.kernel.util.OrderByComparator;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortletKeys;
028: import com.liferay.portlet.PortalPreferences;
029: import com.liferay.portlet.PortletPreferencesFactoryUtil;
030: import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
031: import com.liferay.util.CollectionFactory;
032:
033: import java.util.ArrayList;
034: import java.util.List;
035: import java.util.Map;
036:
037: import javax.portlet.PortletURL;
038: import javax.portlet.RenderRequest;
039:
040: import org.apache.commons.logging.Log;
041: import org.apache.commons.logging.LogFactory;
042:
043: /**
044: * <a href="UserGroupSearch.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Charles May
047: *
048: */
049: public class UserGroupSearch extends SearchContainer {
050:
051: static List headerNames = new ArrayList();
052: static Map orderableHeaders = CollectionFactory.getHashMap();
053:
054: static {
055: headerNames.add("name");
056: headerNames.add("description");
057:
058: orderableHeaders.put("name", "name");
059: orderableHeaders.put("description", "description");
060: }
061:
062: public static final String EMPTY_RESULTS_MESSAGE = "no-user-groups-were-found";
063:
064: public UserGroupSearch(RenderRequest req, PortletURL iteratorURL) {
065: super (req, new UserGroupDisplayTerms(req),
066: new UserGroupSearchTerms(req), DEFAULT_CUR_PARAM,
067: DEFAULT_DELTA, iteratorURL, headerNames,
068: EMPTY_RESULTS_MESSAGE);
069:
070: UserGroupDisplayTerms displayTerms = (UserGroupDisplayTerms) getDisplayTerms();
071:
072: iteratorURL.setParameter(UserGroupDisplayTerms.NAME,
073: displayTerms.getName());
074: iteratorURL.setParameter(UserGroupDisplayTerms.DESCRIPTION,
075: displayTerms.getDescription());
076:
077: try {
078: PortalPreferences prefs = PortletPreferencesFactoryUtil
079: .getPortalPreferences(req);
080:
081: String orderByCol = ParamUtil.getString(req, "orderByCol");
082: String orderByType = ParamUtil
083: .getString(req, "orderByType");
084:
085: if (Validator.isNotNull(orderByCol)
086: && Validator.isNotNull(orderByType)) {
087:
088: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
089: "user-groups-order-by-col", orderByCol);
090: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
091: "user-groups-order-by-type", orderByType);
092: } else {
093: orderByCol = prefs.getValue(
094: PortletKeys.ENTERPRISE_ADMIN,
095: "user-groups-order-by-col", "name");
096: orderByType = prefs.getValue(
097: PortletKeys.ENTERPRISE_ADMIN,
098: "user-groups-order-by-type", "asc");
099: }
100:
101: OrderByComparator orderByComparator = EnterpriseAdminUtil
102: .getUserGroupOrderByComparator(orderByCol,
103: orderByType);
104:
105: setOrderableHeaders(orderableHeaders);
106: setOrderByCol(orderByCol);
107: setOrderByType(orderByType);
108: setOrderByComparator(orderByComparator);
109: } catch (Exception e) {
110: _log.error(e);
111: }
112: }
113:
114: private static Log _log = LogFactory.getLog(UserGroupSearch.class);
115:
116: }
|