View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.apache.myfaces.tobago.event.TabChangeListener;
23  import org.apache.myfaces.tobago.example.demo.actionlistener.SimpleTabChangeListener;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.enterprise.context.SessionScoped;
28  import javax.inject.Named;
29  import java.io.Serializable;
30  import java.lang.invoke.MethodHandles;
31  
32  @SessionScoped
33  @Named
34  public class TabController implements Serializable {
35  
36    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
37  
38    private String open = "/image/feather-open.png";
39    private String close = "/image/feather-closed.png";
40    private int index;
41    private SimpleTabChangeListener tabChangeListener;
42  
43    public TabController() {
44      tabChangeListener = new SimpleTabChangeListener();
45    }
46  
47    public int getIndex() {
48      return index;
49    }
50  
51    public void setIndex(final int index) {
52      this.index = index;
53    }
54  
55    public String getTabOneImage() {
56      if (index != 0) {
57        return close;
58      } else {
59        return open;
60      }
61    }
62  
63    public String getTabTwoImage() {
64      if (index != 1) {
65        return close;
66      } else {
67        return open;
68      }
69    }
70  
71    public String getTabThreeImage() {
72      if (index != 2) {
73        return close;
74      } else {
75        return open;
76      }
77    }
78  
79    public TabChangeListener getTabChangeListener() {
80      return tabChangeListener;
81    }
82  
83    public void setTabChangeListener(final SimpleTabChangeListener tabChangeListener) {
84      this.tabChangeListener = tabChangeListener;
85    }
86  
87    public int getCount() {
88      return tabChangeListener.getCount();
89    }
90  
91    public int getNewTabIndex() {
92      return tabChangeListener.getNewTabIndex();
93    }
94  
95    public int getOldTabIndex() {
96      return tabChangeListener.getOldTabIndex();
97    }
98  
99    public String getClientId() {
100     return tabChangeListener.getClientId();
101   }
102 }