1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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));
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 }