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.model.SelectItem;
23  
24  public abstract class PlanetExample {
25  
26    private SelectItem[] planets;
27    private SelectItem[] earthMoons;
28    private SelectItem[] marsMoons;
29    private SelectItem[] jupiterMoons;
30    private int planet;
31  
32    public PlanetExample() {
33      planets = new SelectItem[]{
34          new SelectItem(0, "Earth"),
35          new SelectItem(1, "Mars"),
36          new SelectItem(2, "Jupiter")};
37      earthMoons = new SelectItem[]{
38          new SelectItem(0, "Moon")
39      };
40      marsMoons = new SelectItem[]{
41          new SelectItem(0, "Phobos"),
42          new SelectItem(1, "Deimos")
43      };
44      jupiterMoons = new SelectItem[]{
45          new SelectItem(0, "Europa"),
46          new SelectItem(1, "Ganymed"),
47          new SelectItem(2, "Io"),
48          new SelectItem(3, "Kallisto")
49      };
50    }
51  
52    public SelectItem[] getPlanets() {
53      return planets;
54    }
55  
56    public int getPlanet() {
57      return planet;
58    }
59  
60    public void setPlanet(final int planet) {
61      this.planet = planet;
62    }
63  
64    public SelectItem[] getMoons() {
65      switch (planet) {
66        case 0:
67          return earthMoons;
68        case 1:
69          return marsMoons;
70        case 2:
71          return jupiterMoons;
72        default:
73          return new SelectItem[0];
74      }
75    }
76  }