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="GroupSearch.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class GroupSearch 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("type");
057:
058: orderableHeaders.put("name", "name");
059: orderableHeaders.put("type", "type");
060: }
061:
062: public static final String EMPTY_RESULTS_MESSAGE = "no-communities-were-found";
063:
064: public GroupSearch(RenderRequest req, PortletURL iteratorURL) {
065: super (req, new GroupDisplayTerms(req),
066: new GroupSearchTerms(req), DEFAULT_CUR_PARAM,
067: DEFAULT_DELTA, iteratorURL, headerNames,
068: EMPTY_RESULTS_MESSAGE);
069:
070: GroupDisplayTerms displayTerms = (GroupDisplayTerms) getDisplayTerms();
071:
072: iteratorURL.setParameter(GroupDisplayTerms.NAME, displayTerms
073: .getName());
074: iteratorURL.setParameter(GroupDisplayTerms.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: "groups-order-by-col", orderByCol);
090: prefs.setValue(PortletKeys.ENTERPRISE_ADMIN,
091: "groups-order-by-type", orderByType);
092: } else {
093: orderByCol = prefs.getValue(
094: PortletKeys.ENTERPRISE_ADMIN,
095: "groups-order-by-col", "name");
096: orderByType = prefs.getValue(
097: PortletKeys.ENTERPRISE_ADMIN,
098: "groups-order-by-type", "asc");
099: }
100:
101: OrderByComparator orderByComparator = EnterpriseAdminUtil
102: .getGroupOrderByComparator(orderByCol, orderByType);
103:
104: setOrderableHeaders(orderableHeaders);
105: setOrderByCol(orderByCol);
106: setOrderByType(orderByType);
107: setOrderByComparator(orderByComparator);
108: } catch (Exception e) {
109: _log.error(e);
110: }
111: }
112:
113: private static Log _log = LogFactory.getLog(GroupSearch.class);
114:
115: }
|