1 package org.vaadin.peter.contextmenu.client;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import com.vaadin.shared.AbstractComponentState;
8
9 public class ContextMenuState extends AbstractComponentState {
10 private static final long serialVersionUID = -247856391284942254L;
11
12 private List<ContextMenuItemState> rootItems;
13
14 private boolean openAutomatically;
15
16 public ContextMenuState() {
17 rootItems = new ArrayList<ContextMenuState.ContextMenuItemState>();
18 }
19
20 public ContextMenuItemState addChild(String caption, String id) {
21 ContextMenuItemState rootItem = new ContextMenuItemState();
22 rootItem.caption = caption;
23 rootItem.id = id;
24
25 rootItems.add(rootItem);
26
27 return rootItem;
28 }
29
30 public List<ContextMenuItemState> getRootItems() {
31 return rootItems;
32 }
33
34 public void setRootItems(List<ContextMenuItemState> rootItems) {
35 this.rootItems = rootItems;
36 }
37
38
39
40
41
42
43
44
45 public boolean isOpenAutomatically() {
46 return openAutomatically;
47 }
48
49
50
51
52
53
54
55
56
57 public void setOpenAutomatically(boolean openAutomatically) {
58 this.openAutomatically = openAutomatically;
59 }
60
61 public static class ContextMenuItemState implements Serializable {
62 private static final long serialVersionUID = 3836772122928080543L;
63
64 private List<ContextMenuItemState> children;
65
66 public String caption;
67
68 public String id;
69
70 public boolean separator;
71
72 public boolean enabled = true;
73
74 public ContextMenuItemState() {
75 children = new ArrayList<ContextMenuState.ContextMenuItemState>();
76 }
77
78 public ContextMenuItemState addChild(String caption, String id) {
79 ContextMenuItemState child = new ContextMenuItemState();
80 child.caption = caption;
81 child.id = id;
82
83 children.add(child);
84
85 return child;
86 }
87
88 public List<ContextMenuItemState> getChildren() {
89 return children;
90 }
91
92 public void setChildren(List<ContextMenuItemState> children) {
93 this.children = children;
94 }
95 }
96 }