View Javadoc
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  	 * @return true if open automatically is on. If open automatically is on, it
40  	 *         means that context menu will always be opened when it's host
41  	 *         component is right clicked. If automatic opening is turned off,
42  	 *         context menu will only open when server side open(x, y) is
43  	 *         called.
44  	 */
45  	public boolean isOpenAutomatically() {
46  		return openAutomatically;
47  	}
48  
49  	/**
50  	 * Enables or disables open automatically feature. If open automatically is
51  	 * on, it means that context menu will always be opened when it's host
52  	 * component is right clicked. If automatic opening is turned off, context
53  	 * menu will only open when server side open(x, y) is called.
54  	 * 
55  	 * @param openAutomatically
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  }