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.Selectable;
23  
24  import javax.enterprise.context.SessionScoped;
25  import javax.inject.Named;
26  import javax.swing.tree.DefaultMutableTreeNode;
27  import java.io.Serializable;
28  
29  @SessionScoped
30  @Named
31  public class TreeSelectController implements Serializable {
32  
33    private static final Selectable[] TREE_SELECT_MODE_KEYS = {
34      Selectable.none,
35      Selectable.single,
36      Selectable.singleLeafOnly,
37      Selectable.multi,
38      Selectable.multiLeafOnly,
39      Selectable.multiCascade
40    };
41  
42    private DefaultMutableTreeNode sample;
43    private String selectable = "multi";
44  
45    public TreeSelectController() {
46      sample = CategoryTree.createSample();
47    }
48  
49    public Selectable[] getSelectModes() {
50      return TREE_SELECT_MODE_KEYS;
51    }
52  
53    public DefaultMutableTreeNode getSample() {
54      return sample;
55    }
56  
57    public String getSelectable() {
58      return selectable;
59    }
60  
61    public void setSelectable(final String selectable) {
62      this.selectable = selectable;
63      TreeUtils.resetSelection(sample);
64    }
65  
66    public String getSelectedNodes() {
67      return TreeUtils.getSelectedNodes(sample);
68    }
69  }