001/* 002 * Copyright 2024 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.odf.program.properties; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020import org.apache.avalon.framework.service.Serviceable; 021 022import org.ametys.cms.model.properties.AbstractProperty; 023import org.ametys.cms.model.properties.Property; 024import org.ametys.cms.repository.Content; 025import org.ametys.odf.ODFHelper; 026import org.ametys.odf.ProgramItem; 027import org.ametys.runtime.model.type.ModelItemTypeConstants; 028 029/** 030 * {@link Property} which represents the shared status of a {@link ProgramItem}. 031 */ 032public class SharedProperty extends AbstractProperty<Boolean, Content> implements Serviceable 033{ 034 private ODFHelper _odfHelper; 035 036 public void service(ServiceManager manager) throws ServiceException 037 { 038 _odfHelper = (ODFHelper) manager.lookup(ODFHelper.ROLE); 039 } 040 041 @Override 042 public boolean isMultiple() 043 { 044 return false; 045 } 046 047 public Object getValue(Content content) 048 { 049 if (content instanceof ProgramItem programItem) 050 { 051 return _odfHelper.isShared(programItem); 052 } 053 054 return false; 055 } 056 057 @Override 058 protected String _getTypeId() 059 { 060 return ModelItemTypeConstants.BOOLEAN_TYPE_ID; 061 } 062 063}