001    package org.apache.myfaces.tobago.event;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.slf4j.Logger;
021    import org.slf4j.LoggerFactory;
022    import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
023    import org.apache.myfaces.tobago.util.ComponentUtils;
024    
025    import javax.faces.component.StateHolder;
026    import javax.faces.context.FacesContext;
027    import javax.faces.event.ActionEvent;
028    
029    /*
030     * Date: Dec 23, 2006
031     * Time: 10:59:53 AM
032     */
033    public class PopupActionListener extends AbstractPopupActionListener implements StateHolder {
034    
035      private static final Logger LOG = LoggerFactory.getLogger(PopupActionListener.class);
036    
037      private String popupId;
038    
039      public PopupActionListener() {
040      }
041    
042      public PopupActionListener(String popupId) {
043        this.popupId = popupId;
044        if (LOG.isDebugEnabled()) {
045          LOG.debug("Add ActionListener: {}", popupId);
046        }
047      }
048    
049      @Override
050      protected AbstractUIPopup getPopup(ActionEvent actionEvent) {
051        FacesContext facesContext = FacesContext.getCurrentInstance();
052        AbstractUIPopup popup = (AbstractUIPopup) ComponentUtils.findComponent(actionEvent.getComponent(), popupId);
053        if (popup == null) {
054          LOG.error("Found no popup for \"{}\"! Search base componentId : {}"
055              + popupId, actionEvent.getComponent().getClientId(facesContext));
056        }
057        return popup;
058      }
059    
060      public boolean isTransient() {
061        return false;
062      }
063    
064      public void restoreState(FacesContext context, Object state) {
065        Object[] values = (Object[]) state;
066        popupId = (String) values[0];
067      }
068    
069      public Object saveState(FacesContext context) {
070        Object[] values = new Object[1];
071        values[0] = popupId;
072        return values;
073      }
074    
075      public void setTransient(boolean newTransientValue) {
076        // ignore
077      }
078    }