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.TreePath;
23  import org.apache.myfaces.tobago.model.TreeState;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.enterprise.context.SessionScoped;
28  import javax.faces.context.FacesContext;
29  import javax.inject.Named;
30  import javax.swing.tree.DefaultMutableTreeNode;
31  import java.io.Serializable;
32  import java.lang.invoke.MethodHandles;
33  
34  @SessionScoped
35  @Named
36  public class TreeListboxController implements Serializable {
37  
38    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
39  
40    private DefaultMutableTreeNode sample;
41  
42    private TreeState state;
43  
44    public TreeListboxController() {
45      sample = CategoryTree.createSample();
46      state = new TreeState();
47      state.getSelectedState().select(new TreePath(2, 2)); // world music
48      state.getExpandedState().expandAll();
49    }
50  
51    public String submit() {
52      LOG.info("Selected: {}", state.getSelectedState());
53      return FacesContext.getCurrentInstance().getViewRoot().getViewId();
54    }
55  
56    public DefaultMutableTreeNode getSample() {
57      return sample;
58    }
59  
60    public TreeState getState() {
61      return state;
62    }
63  
64    public void setState(TreeState state) {
65      this.state = state;
66    }
67  }