001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.contextmenu; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsLog; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.I_CmsDialogContext; 036import org.opencms.ui.Messages; 037import org.opencms.ui.components.CmsLockedResourcesList; 038import org.opencms.util.CmsUUID; 039 040import java.util.Collections; 041import java.util.List; 042 043import org.apache.commons.logging.Log; 044 045import com.google.common.collect.Lists; 046 047/** 048 * A wrapper context menu action which first checks whether the resources for which the action is executed have any children 049 * locked by different users.<p> 050 * 051 * If so, a dialog showing these resources will be displayed; otherwise the wrapped context menu action 052 * will be executed.<p> 053 */ 054public class CmsBlockingLockCheck implements I_CmsContextMenuAction { 055 056 /** Log instance for this class. */ 057 private static final Log LOG = CmsLog.getLog(CmsBlockingLockCheck.class); 058 059 /** Context menu to execute if we don't have blocking locked resources. */ 060 private I_CmsContextMenuAction m_nextAction; 061 062 /** 063 * Creates a new instance.<p> 064 * 065 * @param nextAction the action to execute if we don't have blocking locked resources 066 * 067 */ 068 public CmsBlockingLockCheck(I_CmsContextMenuAction nextAction) { 069 070 m_nextAction = nextAction; 071 } 072 073 /** 074 * @see org.opencms.ui.contextmenu.I_CmsContextMenuAction#executeAction(org.opencms.ui.I_CmsDialogContext) 075 */ 076 public void executeAction(final I_CmsDialogContext context) { 077 078 CmsObject cms = context.getCms(); 079 List<CmsResource> resources = context.getResources(); 080 List<CmsResource> blocked = Lists.newArrayList(); 081 for (CmsResource resource : resources) { 082 try { 083 blocked.addAll(cms.getBlockingLockedResources(resource)); 084 } catch (CmsException e) { 085 LOG.error(e.getLocalizedMessage(), e); 086 } 087 } 088 if (blocked.isEmpty()) { 089 m_nextAction.executeAction(context); 090 } else { 091 092 CmsLockedResourcesList dialog = new CmsLockedResourcesList( 093 cms, 094 blocked, 095 CmsVaadinUtils.getMessageText(Messages.GUI_CANT_PERFORM_OPERATION_BECAUSE_OF_LOCKED_RESOURCES_0), 096 new Runnable() { 097 098 public void run() { 099 100 List<CmsUUID> noStructureIds = Collections.emptyList(); 101 context.finish(noStructureIds); 102 } 103 104 }, 105 null); 106 107 context.start( 108 CmsVaadinUtils.getMessageText(org.opencms.workplace.explorer.Messages.GUI_EXPLORER_CONTEXT_LOCKS_0), 109 dialog); 110 } 111 } 112 113 /** 114 * @see java.lang.Object#toString() 115 */ 116 @Override 117 public String toString() { 118 119 return "CmsBlockingLockCheck[" + m_nextAction.toString() + "]"; 120 } 121}