Example usage for com.liferay.portal.kernel.theme ThemeDisplay getLayout

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLayout

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getLayout.

Prototype

public Layout getLayout() 

Source Link

Document

Returns the site's page.

Usage

From source file:com.liferay.portlet.configuration.icon.maximize.internal.MaximizePortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!GetterUtil.getBoolean(themeDisplay.getThemeSetting("show-maximize-minimize-application-links"))) {

        return false;
    }/*from   w  w w .ja  v  a  2s  .com*/

    Layout layout = themeDisplay.getLayout();

    if (!layout.isTypePortlet()) {
        return false;
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    LayoutTypeController layoutTypeController = layoutTypePortlet.getLayoutTypeController();

    if (layoutTypeController.isFullPageDisplayable()) {
        return false;
    }

    Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);

    if (!portlet.hasWindowState(portletRequest.getResponseContentType(), WindowState.MAXIMIZED)) {

        return false;
    }

    Group group = themeDisplay.getScopeGroup();

    if (!themeDisplay.isSignedIn() || (group.hasStagingGroup() && !group.isStagingGroup())
            || !hasUpdateLayoutPermission(themeDisplay)) {

        if (!PropsValues.LAYOUT_GUEST_SHOW_MAX_ICON) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.portlet.configuration.icon.maximize.internal.MaximizePortletConfigurationIcon.java

License:Open Source License

protected boolean hasUpdateLayoutPermission(ThemeDisplay themeDisplay) {
    try {/*  w w  w.  jav a  2 s .com*/
        return LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
                ActionKeys.UPDATE);
    } catch (PortalException pe) {
        _log.error(pe, pe);

        return false;
    }
}

From source file:com.liferay.portlet.configuration.icon.minimize.internal.MinimizePortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!GetterUtil.getBoolean(themeDisplay.getThemeSetting("show-maximize-minimize-application-links"))) {

        return false;
    }//from  w w w.  j  av  a 2  s .  c om

    Layout layout = themeDisplay.getLayout();

    if (!layout.isTypePortlet()) {
        return false;
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    LayoutTypeController layoutTypeController = layoutTypePortlet.getLayoutTypeController();

    if (layoutTypeController.isFullPageDisplayable()) {
        return false;
    }

    Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);

    if (!portlet.hasWindowState(portletRequest.getResponseContentType(), WindowState.MINIMIZED)) {

        return false;
    }

    Group group = themeDisplay.getScopeGroup();

    if (!themeDisplay.isSignedIn() || (group.hasStagingGroup() && !group.isStagingGroup())
            || !hasUpdateLayoutPermission(themeDisplay)) {

        if (!PropsValues.LAYOUT_GUEST_SHOW_MIN_ICON) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.configuration.icon.ConfigurationTemplatesPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    try {/*from  ww  w.j a v  a2  s  .  c  om*/
        if (!GroupPermissionUtil.contains(permissionChecker, themeDisplay.getScopeGroupId(),
                ActionKeys.MANAGE_ARCHIVED_SETUPS)) {

            return false;
        }
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return false;
    }

    WindowState windowState = portletRequest.getWindowState();

    if (windowState.equals(LiferayWindowState.EXCLUSIVE)) {
        return false;
    }

    Layout layout = themeDisplay.getLayout();

    if (layout.isTypeControlPanel()) {
        return false;
    }

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    return portletDisplay.isShowConfigurationIcon();
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.configuration.icon.PermissionsPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String rootPortletId = portletDisplay.getRootPortletId();

    if (Validator.isNotNull(portletDisplay.getPortletResource())) {
        String portletResource = portletDisplay.getPortletResource();

        Portlet portlet = _portletLocalService.getPortletById(themeDisplay.getCompanyId(), portletResource);

        rootPortletId = portlet.getRootPortletId();
    }/*from  w  w  w .  jav  a2s . co  m*/

    boolean showPermissionsIcon = false;

    Layout layout = themeDisplay.getLayout();

    Group group = themeDisplay.getScopeGroup();

    if (!group.hasStagingGroup() || _STAGING_LIVE_GROUP_LOCKING_ENABLED) {
        try {
            if (PortletPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, rootPortletId,
                    ActionKeys.PERMISSIONS)) {

                showPermissionsIcon = true;
            }
        } catch (PortalException pe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }

            showPermissionsIcon = false;
        }
    }

    if (layout.isLayoutPrototypeLinkActive()) {
        showPermissionsIcon = false;
    }

    if (layout.isTypeControlPanel()) {
        showPermissionsIcon = false;
    }

    return showPermissionsIcon;
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

public void editConfiguration(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

    String settingsScope = ParamUtil.getString(actionRequest, "settingsScope");

    PortletPreferences portletPreferences = getPortletPreferences(themeDisplay, portlet.getPortletId(),
            settingsScope);/*from   w ww.  j a v a 2 s  . c om*/

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction == null) {
        return;
    }

    configurationAction.processAction(portletConfig, actionRequest, actionResponse);

    Layout layout = themeDisplay.getLayout();

    PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

    if (portletLayoutListener != null) {
        portletLayoutListener.onSetup(portlet.getPortletId(), layout.getPlid());
    }
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

public void restoreArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    Settings portletInstanceSettings = SettingsFactoryUtil
            .getSettings(new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings = portletInstanceSettings.getModifiableSettings();

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings = SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    portletInstanceModifiableSettings.reset();

    portletInstanceModifiableSettings.setValues(archivedSettings);

    portletInstanceModifiableSettings.store();

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(actionRequest,/*from   ww  w.  j  av  a 2s  .  c  o  m*/
            _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, portletResource);
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

public void updateArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings = SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    Settings portletInstanceSettings = SettingsFactoryUtil
            .getSettings(new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings = portletInstanceSettings.getModifiableSettings();

    archivedSettings.setValues(portletInstanceModifiableSettings);

    archivedSettings.store();//from w w  w.j av a 2  s . c  o m
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;/*from www  . ja v a 2s.  co m*/

    if (Validator.isNull(scopeType)) {
        scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
        scopeGroupId = themeDisplay.getCompanyGroupId();
        scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
        String scopeLayoutUuid = scopes[1];

        Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, layout.getGroupId(),
                layout.isPrivateLayout());

        if (!scopeLayout.hasScopeGroup()) {
            Map<Locale, String> nameMap = new HashMap<>();

            String name = String.valueOf(scopeLayout.getPlid());

            nameMap.put(LocaleUtil.getDefault(), name);

            _groupLocalService.addGroup(themeDisplay.getUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID,
                    Layout.class.getName(), scopeLayout.getPlid(), GroupConstants.DEFAULT_LIVE_GROUP_ID,
                    nameMap, null, 0, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false, true,
                    null);
        }

        scopeGroupId = scopeLayout.getGroupId();
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
        throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
        return null;
    }//from  w  w w.java 2  s .  com

    String scopeName = null;

    if (scopeType.equals("company")) {
        scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
        String scopeLayoutUuid = GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

        Layout scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                layout.getGroupId(), layout.isPrivateLayout());

        if (scopeLayout != null) {
            scopeName = scopeLayout.getName(themeDisplay.getLocale());
        }
    } else {
        throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
}