001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/menu/CmsMirPrSameLockedActiveChangedAl.java,v $
003: * Date : $Date: 2008-02-27 12:05:22 $
004: * Version: $Revision: 1.6 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.explorer.menu;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.file.CmsResourceFilter;
036: import org.opencms.lock.CmsLock;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsPermissionSet;
040: import org.opencms.workplace.explorer.CmsResourceUtil;
041:
042: /**
043: * Defines a menu item rule that sets the visibility to active if the current resource is changed
044: * and locked by the current user or the autolock feature is enabled.<p>
045: *
046: * It sets the visibility to inactive for new resources and to invisible for deleted resources,
047: * for folders it sets the visibility to active for unchanged resources.<p>
048: *
049: * @author Andreas Zahner
050: *
051: * @version $Revision: 1.6 $
052: *
053: * @since 6.5.6
054: */
055: public class CmsMirPrSameLockedActiveChangedAl extends
056: A_CmsMenuItemRule {
057:
058: /**
059: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#getVisibility(org.opencms.file.CmsObject, CmsResourceUtil[])
060: */
061: public CmsMenuItemVisibilityMode getVisibility(CmsObject cms,
062: CmsResourceUtil[] resourceUtil) {
063:
064: if (resourceUtil[0].getResource().getState().isDeleted()) {
065: return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
066: } else if (resourceUtil[0].getResource().getState().isNew()
067: || (resourceUtil[0].getResource().isFile() && resourceUtil[0]
068: .getResource().getState().isUnchanged())) {
069: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
070: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_NEW_UNCHANGED_0);
071: }
072: try {
073: if (!resourceUtil[0].isEditable()
074: || !cms.hasPermissions(resourceUtil[0]
075: .getResource(),
076: CmsPermissionSet.ACCESS_WRITE, false,
077: CmsResourceFilter.ALL)) {
078: return CmsMenuItemVisibilityMode.VISIBILITY_INACTIVE
079: .addMessageKey(Messages.GUI_CONTEXTMENU_TITLE_INACTIVE_PERM_WRITE_0);
080: }
081: } catch (CmsException e) {
082: // error checking permissions, disable entry completely
083: return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
084: }
085: return CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE;
086: }
087:
088: /**
089: * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject, CmsResourceUtil[])
090: */
091: public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) {
092:
093: if (resourceUtil[0].isInsideProject()) {
094: CmsLock lock = resourceUtil[0].getLock();
095: boolean lockedForPublish = resourceUtil[0]
096: .getProjectState().isLockedForPublishing();
097: return (!lockedForPublish && !lock.isShared() && lock
098: .isOwnedInProjectBy(cms.getRequestContext()
099: .currentUser(), cms.getRequestContext()
100: .currentProject()))
101: || (!lockedForPublish && lock.isNullLock() && OpenCms
102: .getWorkplaceManager().autoLockResources());
103: }
104: // resource is not locked by the user in current project or not locked with enabled autolock, rule does not match
105: return false;
106: }
107:
108: }
|