All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.ui.dialogs.permissions.CmsPrincipalSelect Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.ui.dialogs.permissions;

import org.opencms.main.OpenCms;
import org.opencms.security.CmsRole;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.ui.A_CmsUI;
import org.opencms.ui.CmsVaadinUtils;
import org.opencms.ui.components.CmsBasicDialog;

import java.util.LinkedHashMap;
import java.util.Map;

import com.vaadin.data.Item;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;

/**
 * The principal select widget.

*/ public class CmsPrincipalSelect extends CustomComponent { /** * Handles the principal selection.

*/ public interface PrincipalSelectHandler { /** * Called to select a principal.

* * @param principalType the principal type * @param principalName the principal name */ void onPrincipalSelect(String principalType, String principalName); } /** The serial version id. */ private static final long serialVersionUID = 6944968889428174262L; /** The add button. */ private Button m_addPermissionSetButton; /** The principal name text field. */ private TextField m_principalName; /** The type select box. */ private ComboBox m_principalTypeSelect; /** The principal select handler. */ private PrincipalSelectHandler m_selectHandler; /** The open principal select dialog button. */ private Button m_selectPrincipalButton; /** The principal select dialog window. */ private Window m_window; /** * Constructor.

*/ @SuppressWarnings("unused") public CmsPrincipalSelect() { HorizontalLayout main = new HorizontalLayout(); main.setSpacing(true); main.setMargin(true); main.setWidth("100%"); setCompositionRoot(main); m_principalTypeSelect = new ComboBox(); m_principalTypeSelect.setWidth("150px"); Map principalTypes = new LinkedHashMap(); principalTypes.put( I_CmsPrincipal.PRINCIPAL_USER, CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_USER_0)); principalTypes.put( I_CmsPrincipal.PRINCIPAL_GROUP, CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_GROUP_0)); CmsVaadinUtils.prepareComboBox(m_principalTypeSelect, principalTypes); m_principalTypeSelect.setNewItemsAllowed(false); m_principalTypeSelect.setNullSelectionAllowed(false); m_principalTypeSelect.select(I_CmsPrincipal.PRINCIPAL_USER); main.addComponent(m_principalTypeSelect); m_principalName = new TextField(); m_principalName.setWidth("100%"); main.addComponent(m_principalName); main.setExpandRatio(m_principalName, 2); m_selectPrincipalButton = new Button(FontAwesome.USER); m_selectPrincipalButton.addStyleName("borderless"); m_selectPrincipalButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { openPrincipalSelect(); } }); main.addComponent(m_selectPrincipalButton); m_addPermissionSetButton = new Button(FontAwesome.PLUS); m_addPermissionSetButton.addStyleName("borderless"); m_addPermissionSetButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { onSelect(); } }); main.addComponent(m_addPermissionSetButton); new CmsPrincipalSelectExtension(this); } /** * Enables/disables selection of the 'Roles' prinipal type.

* * @param editRoles true if the user should be allowed to select roles */ public void setRoleSelectionAllowed(boolean editRoles) { m_principalTypeSelect.removeItem(CmsRole.PRINCIPAL_ROLE); if (editRoles) { Item item = m_principalTypeSelect.addItem(CmsRole.PRINCIPAL_ROLE); String roleText = CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_ROLE_0); item.getItemProperty(CmsVaadinUtils.PROPERTY_LABEL).setValue(roleText); } m_principalTypeSelect.setNewItemsAllowed(!editRoles); } /** * Sets the principal select handler.

* * @param selectHandler the principal select handler */ public void setSelectHandler(PrincipalSelectHandler selectHandler) { m_selectHandler = selectHandler; } /** * Closes the principal select dialog window if present.

*/ protected void closeWindow() { if (m_window != null) { m_window.close(); m_window = null; } } /** * Sets the principal type and name.

* * @param type the principal type * @param principalName the principal name */ @SuppressWarnings("incomplete-switch") protected void setPrincipal(int type, String principalName) { m_principalName.setValue(principalName); String typeName = null; switch (type) { case 0: typeName = I_CmsPrincipal.PRINCIPAL_GROUP; break; case 1: typeName = I_CmsPrincipal.PRINCIPAL_USER; break; } if (typeName != null) { m_principalTypeSelect.setValue(typeName); } } /** * Calls the principal select handler.

*/ void onSelect() { if (m_selectHandler != null) { String principalType = (String)m_principalTypeSelect.getValue(); if (CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_ROLE_0).equals( principalType)) { principalType = CmsRole.PRINCIPAL_ROLE; } m_selectHandler.onPrincipalSelect(principalType, m_principalName.getValue()); } } /** * Opens the principal select dialog window.

*/ void openPrincipalSelect() { String parameters = "?type=principalwidget&flags=null&action=listindependentaction&useparent=true&listaction="; if (I_CmsPrincipal.PRINCIPAL_GROUP.equals(m_principalTypeSelect.getValue())) { parameters += "iag"; } else { parameters += "iau"; } BrowserFrame selectFrame = new BrowserFrame( "Select principal", new ExternalResource( OpenCms.getLinkManager().substituteLinkForUnknownTarget( A_CmsUI.getCmsObject(), "/system/workplace/commons/principal_selection.jsp") + parameters)); selectFrame.setWidth("100%"); selectFrame.setHeight("500px"); CmsBasicDialog dialog = new CmsBasicDialog(); dialog.setContent(selectFrame); m_window = CmsBasicDialog.prepareWindow(); m_window.setCaption( CmsVaadinUtils.getMessageText( org.opencms.workplace.commons.Messages.GUI_PRINCIPALSELECTION_LIST_ACTION_SELECT_NAME_0)); m_window.setContent(dialog); A_CmsUI.get().addWindow(m_window); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy