001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.user; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsUser; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsLog; 034import org.opencms.main.OpenCms; 035import org.opencms.security.CmsOrganizationalUnit; 036import org.opencms.ui.A_CmsUI; 037import org.opencms.ui.CmsVaadinUtils; 038import org.opencms.ui.FontOpenCms; 039import org.opencms.ui.apps.Messages; 040import org.opencms.ui.components.CmsBasicDialog; 041 042import java.util.Collections; 043import java.util.List; 044 045import org.apache.commons.logging.Log; 046 047import com.vaadin.ui.Button; 048import com.vaadin.ui.Button.ClickEvent; 049import com.vaadin.ui.Button.ClickListener; 050import com.vaadin.ui.FormLayout; 051import com.vaadin.ui.Panel; 052import com.vaadin.ui.Window; 053import com.vaadin.v7.shared.ui.label.ContentMode; 054import com.vaadin.v7.ui.Label; 055 056/** 057 * Dialog for delete of principals and ous.<p> 058 */ 059public class CmsDeleteOUDialog extends CmsBasicDialog { 060 061 /**vaadin serial id. */ 062 private static final long serialVersionUID = -7191571070148172989L; 063 064 /** The log object for this class. */ 065 private static final Log LOG = CmsLog.getLog(CmsDeleteOUDialog.class); 066 067 /**vaadin component. */ 068 private Label m_label; 069 070 /**vaadin component. */ 071 private Label m_icon; 072 073 /**vaadin component. */ 074 private Button m_cancelButton; 075 076 /**vaadin component. */ 077 private Button m_okButton; 078 079 /**vaadin component. */ 080 private FormLayout m_principalSelectLayout; 081 082 /**CmsObject. */ 083 private CmsObject m_cms; 084 085 /**The name of the ou which should be deleted, may be null.*/ 086 private String m_ouName; 087 088 /**vaadin component. */ 089 private Panel m_dependencyPanel; 090 091 /** 092 * public constructor used for OUs.<p> 093 * 094 * @param cms CmsObject 095 * @param ouName name of ou to delete 096 * @param window window showing dialog 097 * @param app 098 */ 099 public CmsDeleteOUDialog(CmsObject cms, String ouName, Window window, CmsAccountsApp app) { 100 101 m_ouName = ouName; 102 init(cms, window, app); 103 m_dependencyPanel.setVisible(false); 104 m_principalSelectLayout.setVisible(false); 105 try { 106 List<CmsUser> userList = OpenCms.getOrgUnitManager().getUsers(m_cms, ouName, true); 107 List<CmsOrganizationalUnit> oUs = OpenCms.getOrgUnitManager().getOrganizationalUnits(m_cms, ouName, true); 108 109 if (userList.isEmpty() && oUs.isEmpty()) { 110 m_label.setValue( 111 CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_DELETE_OU_CONFIRM_1, ouName)); 112 } else { 113 m_label.setValue( 114 CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_DELETE_OU_NOT_POSSIBLE_1, ouName)); 115 m_okButton.setEnabled(false); 116 } 117 } catch (CmsException e) { 118 LOG.error("Unable to read OU", e); 119 } 120 } 121 122 /** 123 * Deletes the princiapl or OU.<p> 124 */ 125 void deletePrincipal() { 126 127 //Delete OU 128 try { 129 OpenCms.getOrgUnitManager().deleteOrganizationalUnit(m_cms, m_ouName); 130 } catch (CmsException e) { 131 LOG.error("Unable to delete OU"); 132 } 133 } 134 135 /** 136 * Initialized the dialog.<p> 137 * 138 * @param cms CmsObject 139 * @param window window 140 * @param app 141 */ 142 private void init(CmsObject cms, final Window window, final CmsAccountsApp app) { 143 144 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 145 try { 146 displayResourceInfoDirectly( 147 Collections.singletonList( 148 CmsAccountsApp.getOUInfo( 149 OpenCms.getOrgUnitManager().readOrganizationalUnit(A_CmsUI.getCmsObject(), m_ouName)))); 150 } catch (CmsException e) { 151 LOG.error("Unable to read OU", e); 152 } 153 m_icon.setContentMode(ContentMode.HTML); 154 m_icon.setValue(FontOpenCms.WARNING.getHtml()); 155 m_cms = cms; 156 m_okButton.addClickListener(new ClickListener() { 157 158 private static final long serialVersionUID = -7845894751587879028L; 159 160 public void buttonClick(ClickEvent event) { 161 162 deletePrincipal(); 163 window.close(); 164 app.reload(); 165 166 } 167 168 }); 169 170 m_cancelButton.addClickListener(new ClickListener() { 171 172 private static final long serialVersionUID = 6649262870116199591L; 173 174 public void buttonClick(ClickEvent event) { 175 176 window.close(); 177 178 } 179 180 }); 181 } 182 183}