Example usage for com.liferay.portal.kernel.util KeyValuePairComparator KeyValuePairComparator

List of usage examples for com.liferay.portal.kernel.util KeyValuePairComparator KeyValuePairComparator

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util KeyValuePairComparator KeyValuePairComparator.

Prototype

public KeyValuePairComparator(boolean byKey, boolean ascending) 

Source Link

Usage

From source file:com.inikah.slayer.model.impl.ProfileImpl.java

License:Open Source License

public List<KeyValuePair> getLanguagesSpokenAsList() {
    List<KeyValuePair> items = new ArrayList<KeyValuePair>();

    Map<Long, String> languages = getLanguagesSpoken();
    Iterator<Long> itr = languages.keySet().iterator();

    while (itr.hasNext()) {
        long key = itr.next();
        String value = languages.get(key);

        items.add(new KeyValuePair(String.valueOf(key), value));
    }/*ww w  .  j  a  v a2 s.  co  m*/

    return ListUtil.sort(items, new KeyValuePairComparator(false, true));
}

From source file:com.inikah.slayer.model.impl.ProfileImpl.java

License:Open Source License

public List<KeyValuePair> getLanguagesSpokenForFilter() {

    List<KeyValuePair> results = new ArrayList<KeyValuePair>();

    List<KeyValuePair> original = getLanguagesSpokenAsList();
    List<KeyValuePair> actuals = FilterUtil.getLanguagesSpoken(isBride());

    for (KeyValuePair kvPair1 : actuals) {
        String key1 = kvPair1.getKey();
        for (KeyValuePair kvPair2 : original) {
            String key2 = kvPair2.getKey();
            if (key2.equalsIgnoreCase(key1)) {
                StringBuilder sb = new StringBuilder();
                sb.append(kvPair2.getValue());
                sb.append(StringPool.SPACE);
                sb.append(StringPool.OPEN_PARENTHESIS);
                sb.append(kvPair1.getValue());
                sb.append(StringPool.CLOSE_PARENTHESIS);
                results.add(new KeyValuePair(key1, sb.toString()));
                break;
            }//from  w  ww  . ja va2 s. c  o  m
        }
    }

    return ListUtil.sort(results, new KeyValuePairComparator(false, true));
}

From source file:com.inikah.slayer.service.impl.MyKeyValueLocalServiceImpl.java

License:Open Source License

public List<KeyValuePair> getItemsForFilter(boolean bride, String column, long parentId, String parentColumn) {
    List<MyKeyValue> items = myKeyValueFinder.findResults(bride, column, parentId, parentColumn);

    List<KeyValuePair> kvPairs = new ArrayList<KeyValuePair>();
    for (MyKeyValue myKeyValue : items) {

        long key = myKeyValue.getMyKey();

        String name = LanguageUtil.get(Locale.ENGLISH, myKeyValue.getMyName());
        if (column.contains("ountry")) {
            name = TextFormatter.formatName(name);
        }//ww w.  j  a v a 2s .  co  m

        StringBuilder sb = new StringBuilder(name);
        sb.append(StringPool.SPACE);
        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(myKeyValue.getMyValue());
        sb.append(StringPool.CLOSE_PARENTHESIS);
        kvPairs.add(new KeyValuePair(String.valueOf(key), sb.toString()));
    }

    return ListUtil.sort(kvPairs, new KeyValuePairComparator(false, true));
}

From source file:com.knowarth.portlets.themepersonalizer.ThemePersonalizerAdminPortlet.java

License:Open Source License

@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse)
        throws PortletException, IOException {

    try {//from   w  ww.ja  v  a 2s  . c o m
        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

        List selectedThemeIdList = new ArrayList();

        List<AvailablePersonalizedTheme> selectedPersonalizedThemes = AvailablePersonalizedThemeLocalServiceUtil
                .findAllByCompanyId(themeDisplay.getCompanyId());
        List<String> selectedThemeIds = new ArrayList<String>();
        for (AvailablePersonalizedTheme selectedPersonalizedTheme : selectedPersonalizedThemes) {
            Theme themeObject = ThemeLocalServiceUtil.fetchTheme(themeDisplay.getCompanyId(),
                    selectedPersonalizedTheme.getThemeId());
            if (Validator.isNotNull(themeObject)) {
                selectedThemeIdList.add(new KeyValuePair(themeObject.getThemeId(), themeObject.getName()));
                selectedThemeIds.add(themeObject.getThemeId());
            }
        }
        List availableThemeIdsList = new ArrayList();

        List<Theme> themes = ThemeLocalServiceUtil.getThemes(themeDisplay.getCompanyId());

        for (Theme themeObject : themes) {
            if (!selectedThemeIds.contains(themeObject.getThemeId()) && !themeObject.isWapTheme()) {
                availableThemeIdsList.add(new KeyValuePair(themeObject.getThemeId(), themeObject.getName()));
            }
        }

        availableThemeIdsList = ListUtil.sort(availableThemeIdsList, new KeyValuePairComparator(false, true));
        renderRequest.setAttribute("selectedThemeIdList", selectedThemeIdList);
        renderRequest.setAttribute("availableThemeIdsList", availableThemeIdsList);
    } catch (SystemException e) {
        SessionErrors.add(renderRequest, "system-error-please-contact-adminstrator");
        _log.error("Error retriving available theme information", e);
    }
    include(viewJSP, renderRequest, renderResponse);

}

From source file:com.liferay.asset.categories.navigation.web.internal.display.context.AssetCategoriesNavigationDisplayContext.java

License:Open Source License

public List<KeyValuePair> getAvailableVocabularyNames() {
    List<KeyValuePair> availableVocabularNames = new ArrayList<>();

    long[] assetVocabularyIds = getAssetVocabularyIds();

    Arrays.sort(assetVocabularyIds);

    Set<Long> availableAssetVocabularyIdsSet = SetUtil.fromArray(getAvailableAssetVocabularyIds());

    for (long assetVocabularyId : availableAssetVocabularyIdsSet) {
        if (Arrays.binarySearch(assetVocabularyIds, assetVocabularyId) < 0) {

            AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil
                    .fetchAssetVocabulary(assetVocabularyId);

            availableVocabularNames/*w  ww  . j  ava2 s  .  c om*/
                    .add(new KeyValuePair(String.valueOf(assetVocabularyId), getTitle(assetVocabulary)));
        }
    }

    return ListUtil.sort(availableVocabularNames, new KeyValuePairComparator(false, true));
}

From source file:com.liferay.content.targeting.portlet.UserSegmentContentListPortlet.java

License:Open Source License

protected void populateViewContext(String path, PortletRequest portletRequest, PortletResponse portletResponse,
        Template template, TemplateHashModel staticModels) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    long[] availableClassNameIds = getAvailableClassNameIds(themeDisplay.getCompanyId());

    long[] classNameIds = getClassNameIds(portletPreferences, availableClassNameIds);

    populatePortletDisplayTemplateContext(template, portletPreferences, themeDisplay.getScopeGroupId(),
            "abstracts");

    if (Validator.isNull(path) || path.equals(UserSegmentContentListPath.VIEW)) {

        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);

        long[] userSegmentIds = (long[]) portletRequest.getAttribute(WebKeys.USER_SEGMENT_IDS);

        List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

        if (ArrayUtil.isNotEmpty(userSegmentIds)) {
            AssetEntryQuery entryQuery = new AssetEntryQuery();

            entryQuery.setAnyCategoryIds(
                    ContentTargetingUtil.getAssetCategoryIds(themeDisplay.getScopeGroupId(), userSegmentIds));
            entryQuery.setClassNameIds(classNameIds);

            assetEntries = AssetEntryServiceUtil.getEntries(entryQuery);

            portletRequest.setAttribute("view.jsp-results", new ArrayList());
            portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
            portletRequest.setAttribute("view.jsp-show", new Boolean(true));
            portletRequest.setAttribute("view.jsp-print", new Boolean(false));
        }//from w w  w. j a v  a 2 s .c o m

        template.put("assetEntries", assetEntries);
        template.put("assetRendererFactoryRegistryUtilClass",
                staticModels.get(AssetRendererFactoryRegistryUtil.class.getName()));

        if (assetEntries.isEmpty()) {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }

        populatePortletDisplayTemplateViewContext(template, portletRequest, themeDisplay, assetEntries, null);
    } else if (path.equals(UserSegmentContentListPath.VIEW_CONTENT)) {
        long assetEntryId = ParamUtil.getLong(portletRequest, "assetEntryId");

        AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryId);

        AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

        portletRequest.setAttribute("view.jsp-results", new ArrayList());
        portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
        portletRequest.setAttribute("view.jsp-assetEntry", assetEntry);
        portletRequest.setAttribute("view.jsp-assetRendererFactory", assetRendererFactory);
        portletRequest.setAttribute("view.jsp-assetRenderer", assetRenderer);
        portletRequest.setAttribute("view.jsp-title", assetEntry.getTitle(themeDisplay.getLocale()));
        portletRequest.setAttribute("view.jsp-show", new Boolean(false));
        portletRequest.setAttribute("view.jsp-print", new Boolean(false));
    } else if (path.equals(UserSegmentContentListPath.CONFIGURATION)) {
        List<KeyValuePair> typesLeftList = new ArrayList<KeyValuePair>();

        for (long classNameId : classNameIds) {
            String className = PortalUtil.getClassName(classNameId);

            typesLeftList.add(new KeyValuePair(String.valueOf(classNameId),
                    ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className)));
        }

        List<KeyValuePair> typesRightList = new ArrayList<KeyValuePair>();

        Arrays.sort(classNameIds);

        List<String> modelResources = new ArrayList<String>();

        for (long classNameId : availableClassNameIds) {
            ClassName className = ClassNameLocalServiceUtil.getClassName(classNameId);

            if (Arrays.binarySearch(classNameIds, classNameId) < 0) {
                typesRightList.add(new KeyValuePair(String.valueOf(classNameId),
                        ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue())));
            }

            modelResources
                    .add(ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue()));
        }

        typesRightList = ListUtil.sort(typesRightList, new KeyValuePairComparator(false, true));

        boolean anyAssetType = GetterUtil.getBoolean(portletPreferences.getValue("anyAssetType", null), true);

        template.put("anyAssetType", anyAssetType);
        template.put("availableClassNameIds", availableClassNameIds);
        template.put("classNameIds", classNameIds);
        template.put("modelResources", modelResources);
        template.put("typesLeftList", typesLeftList);
        template.put("typesRightList", typesRightList);
    }
}

From source file:com.liferay.contenttargeting.portlet.UserSegmentContentListPortlet.java

License:Open Source License

protected void populateViewContext(String path, PortletRequest portletRequest, PortletResponse portletResponse,
        Template template, TemplateHashModel staticModels) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    long[] availableClassNameIds = getAvailableClassNameIds(themeDisplay.getCompanyId());

    long[] classNameIds = getClassNameIds(portletPreferences, availableClassNameIds);

    if (Validator.isNull(path) || path.equals(UserSegmentContentListPath.VIEW)) {

        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);

        long[] userSegmentIds = (long[]) portletRequest.getAttribute(WebKeys.USER_SEGMENT_IDS);

        List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

        if (ArrayUtil.isNotEmpty(userSegmentIds)) {
            AssetEntryQuery entryQuery = new AssetEntryQuery();

            entryQuery.setAnyCategoryIds(ContentTargetingUtil.getAssetCategoryIds(userSegmentIds));
            entryQuery.setClassNameIds(classNameIds);

            assetEntries = AssetEntryServiceUtil.getEntries(entryQuery);

            portletRequest.setAttribute("view.jsp-results", new ArrayList());
            portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
            portletRequest.setAttribute("view.jsp-show", new Boolean(true));
            portletRequest.setAttribute("view.jsp-print", new Boolean(false));
        }//  w  ww . j a v  a 2s . co m

        template.put("assetEntries", assetEntries);
        template.put("assetRendererFactoryRegistryUtilClass",
                staticModels.get("com.liferay.portlet.asset." + "AssetRendererFactoryRegistryUtil"));

        if (assetEntries.isEmpty()) {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }
    } else if (path.equals(UserSegmentContentListPath.VIEW_CONTENT)) {
        long assetEntryId = ParamUtil.getLong(portletRequest, "assetEntryId");

        AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryId);

        AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

        portletRequest.setAttribute("view.jsp-results", new ArrayList());
        portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
        portletRequest.setAttribute("view.jsp-assetEntry", assetEntry);
        portletRequest.setAttribute("view.jsp-assetRendererFactory", assetRendererFactory);
        portletRequest.setAttribute("view.jsp-assetRenderer", assetRenderer);
        portletRequest.setAttribute("view.jsp-title", assetEntry.getTitle(themeDisplay.getLocale()));
        portletRequest.setAttribute("view.jsp-show", new Boolean(false));
        portletRequest.setAttribute("view.jsp-print", new Boolean(false));
    } else if (path.equals(UserSegmentContentListPath.CONFIGURATION)) {
        List<KeyValuePair> typesLeftList = new ArrayList<KeyValuePair>();

        for (long classNameId : classNameIds) {
            String className = PortalUtil.getClassName(classNameId);

            typesLeftList.add(new KeyValuePair(String.valueOf(classNameId),
                    ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className)));
        }

        List<KeyValuePair> typesRightList = new ArrayList<KeyValuePair>();

        Arrays.sort(classNameIds);

        List<String> modelResources = new ArrayList<String>();

        for (long classNameId : availableClassNameIds) {
            ClassName className = ClassNameLocalServiceUtil.getClassName(classNameId);

            if (Arrays.binarySearch(classNameIds, classNameId) < 0) {
                typesRightList.add(new KeyValuePair(String.valueOf(classNameId),
                        ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue())));
            }

            modelResources
                    .add(ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue()));
        }

        typesRightList = ListUtil.sort(typesRightList, new KeyValuePairComparator(false, true));

        boolean anyAssetType = GetterUtil.getBoolean(portletPreferences.getValue("anyAssetType", null), true);

        template.put("anyAssetType", anyAssetType);
        template.put("availableClassNameIds", availableClassNameIds);
        template.put("classNameIds", classNameIds);
        template.put("modelResources", modelResources);
        template.put("typesLeftList", typesLeftList);
        template.put("typesRightList", typesRightList);
    }
}

From source file:com.liferay.document.library.web.internal.display.context.logic.DLPortletInstanceSettingsHelper.java

License:Open Source License

private void _populateDisplayViews() {
    DLPortletInstanceSettings dlPortletInstanceSettings = _dlRequestHelper.getDLPortletInstanceSettings();

    String[] displayViews = dlPortletInstanceSettings.getDisplayViews();

    _currentDisplayViews = new ArrayList<>();

    for (String displayView : displayViews) {
        _currentDisplayViews.add(//from w ww  .  ja  v  a 2  s.co  m
                new KeyValuePair(displayView, LanguageUtil.get(_dlRequestHelper.getLocale(), displayView)));
    }

    Arrays.sort(displayViews);

    _availableDisplayViews = new ArrayList<>();

    Set<String> allDisplayViews = SetUtil.fromArray(PropsValues.DL_DISPLAY_VIEWS);

    for (String displayView : allDisplayViews) {
        if (Arrays.binarySearch(displayViews, displayView) < 0) {
            _availableDisplayViews.add(
                    new KeyValuePair(displayView, LanguageUtil.get(_dlRequestHelper.getLocale(), displayView)));
        }
    }

    _availableDisplayViews = ListUtil.sort(_availableDisplayViews, new KeyValuePairComparator(false, true));
}

From source file:com.liferay.document.library.web.internal.display.context.logic.DLPortletInstanceSettingsHelper.java

License:Open Source License

private void _populateEntryColumns() {
    DLPortletInstanceSettings dlPortletInstanceSettings = _dlRequestHelper.getDLPortletInstanceSettings();

    String[] entryColumns = dlPortletInstanceSettings.getEntryColumns();

    _currentEntryColumns = new ArrayList<>();

    for (String entryColumn : entryColumns) {
        _currentEntryColumns.add(//from   ww w . j  av a  2  s. com
                new KeyValuePair(entryColumn, LanguageUtil.get(_dlRequestHelper.getLocale(), entryColumn)));
    }

    Arrays.sort(entryColumns);

    _availableEntryColumns = new ArrayList<>();

    Set<String> allEntryColumns = SetUtil.fromArray(_getAllEntryColumns());

    for (String entryColumn : allEntryColumns) {
        if (Arrays.binarySearch(entryColumns, entryColumn) < 0) {
            _availableEntryColumns.add(
                    new KeyValuePair(entryColumn, LanguageUtil.get(_dlRequestHelper.getLocale(), entryColumn)));
        }
    }

    _availableEntryColumns = ListUtil.sort(_availableEntryColumns, new KeyValuePairComparator(false, true));
}

From source file:com.liferay.document.library.web.internal.display.context.logic.DLPortletInstanceSettingsHelper.java

License:Open Source License

private void _populateFileEntryColumns() {
    DLPortletInstanceSettings dlPortletInstanceSettings = _dlRequestHelper.getDLPortletInstanceSettings();

    String[] fileEntryColumns = dlPortletInstanceSettings.getFileEntryColumns();

    _currentFileEntryColumns = new ArrayList<>();

    for (String fileEntryColumn : fileEntryColumns) {
        _currentFileEntryColumns.add(new KeyValuePair(fileEntryColumn,
                LanguageUtil.get(_dlRequestHelper.getLocale(), fileEntryColumn)));
    }//w w w  .  j a v  a 2  s.com

    _availableFileEntryColumns = new ArrayList<>();

    Arrays.sort(fileEntryColumns);

    Set<String> allFileEntryColumns = SetUtil.fromArray(_getAllFileEntryColumns());

    for (String fileEntryColumn : allFileEntryColumns) {
        if (Arrays.binarySearch(fileEntryColumns, fileEntryColumn) < 0) {
            _availableFileEntryColumns.add(new KeyValuePair(fileEntryColumn,
                    LanguageUtil.get(_dlRequestHelper.getLocale(), fileEntryColumn)));
        }
    }

    _availableFileEntryColumns = ListUtil.sort(_availableFileEntryColumns,
            new KeyValuePairComparator(false, true));
}