001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.picture.web; 023 024import static org.jboss.seam.ScopeType.CONVERSATION; 025 026import java.io.Serializable; 027import java.util.Collections; 028import java.util.List; 029 030import javax.faces.event.ActionEvent; 031 032import org.apache.commons.logging.Log; 033import org.apache.commons.logging.LogFactory; 034import org.jboss.seam.annotations.Create; 035import org.jboss.seam.annotations.Destroy; 036import org.jboss.seam.annotations.In; 037import org.jboss.seam.annotations.Name; 038import org.jboss.seam.annotations.Observer; 039import org.jboss.seam.annotations.Scope; 040import org.jboss.seam.annotations.intercept.BypassInterceptors; 041import org.nuxeo.ecm.core.api.CoreSession; 042import org.nuxeo.ecm.core.api.DocumentModel; 043import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 044import org.nuxeo.ecm.webapp.helpers.EventNames; 045 046/** 047 * @author <a href="mailto:ldoguin@nuxeo.com">Laurent Doguin</a> 048 * @deprecated since 6.0. See NXP-15370. 049 */ 050@Name("slideShowManager") 051@Scope(CONVERSATION) 052@Deprecated 053public class SlideShowManagerBean implements SlideShowManager, Serializable { 054 055 private static final long serialVersionUID = -3281363416111697725L; 056 057 private static final Log log = LogFactory.getLog(PictureBookManagerBean.class); 058 059 @In(create = true) 060 protected CoreSession documentManager; 061 062 @In(create = true) 063 protected transient NavigationContext navigationContext; 064 065 protected List<DocumentModel> children; 066 067 protected Integer childrenSize; 068 069 protected DocumentModel child; 070 071 protected Integer index; 072 073 protected Boolean stopped; 074 075 protected Boolean repeat; 076 077 @Create 078 public void initialize() { 079 log.debug("Initializing..."); 080 index = 1; 081 childrenSize = null; 082 stopped = false; 083 repeat = false; 084 } 085 086 @Override 087 public void firstPic() { 088 index = 1; 089 } 090 091 @Override 092 public void lastPic() { 093 index = getChildren().size(); 094 } 095 096 @Destroy 097 public void destroy() { 098 log.debug("Destroy"); 099 index = null; 100 child = null; 101 childrenSize = null; 102 stopped = null; 103 repeat = null; 104 } 105 106 @Override 107 public Integer getIndex() { 108 return index; 109 } 110 111 @Override 112 public void decIndex() { 113 index--; 114 } 115 116 @Override 117 public void incIndex() { 118 index++; 119 if ((index) > getChildrenSize()) { 120 if (repeat) { 121 index = 1; 122 } else { 123 index = childrenSize; 124 } 125 } 126 } 127 128 @Override 129 public void setIndex(Integer idx) { 130 index = idx; 131 } 132 133 @Override 134 @Observer({ EventNames.DOCUMENT_SELECTION_CHANGED, EventNames.DOCUMENT_CHILDREN_CHANGED }) 135 @BypassInterceptors 136 public void resetIndex() { 137 index = 1; 138 child = null; 139 children = null; 140 childrenSize = null; 141 stopped = false; 142 repeat = false; 143 } 144 145 @Override 146 public void inputValidation(ActionEvent arg0) { 147 if (getChildrenSize() < index) { 148 index = getChildrenSize(); 149 } 150 if (index <= 0) { 151 index = 1; 152 } 153 } 154 155 @Override 156 public Integer getChildrenSize() { 157 if (childrenSize == null) { 158 childrenSize = getChildren().size(); 159 } 160 return childrenSize; 161 } 162 163 @Override 164 public DocumentModel getChild() { 165 if (index > getChildrenSize()) { 166 index = childrenSize; 167 } 168 if (!getChildren().isEmpty()) { 169 return getChildren().get(index - 1); 170 } 171 return null; 172 } 173 174 protected List<DocumentModel> getChildren() { 175 if (children == null) { 176 DocumentModel currentDoc = navigationContext.getCurrentDocument(); 177 if (currentDoc != null) { 178 children = documentManager.getChildren(currentDoc.getRef()); 179 } else { 180 children = Collections.emptyList(); 181 } 182 } 183 return children; 184 } 185 186 @Override 187 public void setChild(DocumentModel child) { 188 this.child = child; 189 } 190 191 public void togglePause() { 192 stopped = true; 193 } 194 195 public void stop() { 196 index = 1; 197 stopped = true; 198 } 199 200 public void start() { 201 stopped = false; 202 } 203 204 public Boolean getStopped() { 205 return stopped; 206 } 207 208 public void toggleRepeat() { 209 repeat = !repeat; 210 } 211 212 public void setStopped(Boolean stopped) { 213 this.stopped = stopped; 214 } 215 216 public Boolean getRepeat() { 217 return repeat; 218 } 219 220 public void setRepeat(Boolean repeat) { 221 this.repeat = repeat; 222 } 223 224}