1 package com.vaadin.v7.contextmenu;
2
3 import com.vaadin.contextmenu.ContextMenu;
4 import com.vaadin.event.ContextClickEvent;
5 import com.vaadin.event.ContextClickEvent.ContextClickNotifier;
6 import com.vaadin.shared.MouseEventDetails;
7 import com.vaadin.shared.MouseEventDetails.MouseButton;
8 import com.vaadin.v7.event.ItemClickEvent;
9 import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
10 import com.vaadin.v7.ui.Table;
11 import com.vaadin.v7.ui.TreeTable;
12
13
14
15
16
17
18
19
20 public class TableContextMenu extends ContextMenu {
21
22
23
24
25
26
27
28 public TableContextMenu(Table table) {
29 super(table, true);
30 }
31
32
33
34
35
36
37
38 public TableContextMenu(TreeTable treeTable) {
39 super(treeTable, true);
40 }
41
42
43
44
45
46
47
48
49 @Override
50 public void setAsContextMenuOf(ContextClickNotifier component) {
51
52
53
54
55 if (component instanceof Table) {
56 useTableSpecificContextClickListener((Table) component);
57
58
59 }
60 super.setAsContextMenuOf(component);
61 }
62
63 private void useTableSpecificContextClickListener(final Table table) {
64 table.addItemClickListener(new ItemClickListener() {
65
66 @Override
67 public void itemClick(ItemClickEvent event) {
68 if (event.getButton() == MouseButton.RIGHT) {
69 MouseEventDetails mouseEventDetails = new MouseEventDetails();
70 mouseEventDetails.setAltKey(event.isAltKey());
71 mouseEventDetails.setButton(event.getButton());
72 mouseEventDetails.setClientX(event.getClientX());
73 mouseEventDetails.setClientY(event.getClientY());
74 mouseEventDetails.setCtrlKey(event.isCtrlKey());
75 mouseEventDetails.setMetaKey(event.isMetaKey());
76 mouseEventDetails.setRelativeX(event.getRelativeX());
77 mouseEventDetails.setRelativeY(event.getRelativeY());
78 mouseEventDetails.setShiftKey(event.isShiftKey());
79 if (event.isDoubleClick()) {
80 mouseEventDetails.setType(0x00002);
81 } else {
82 mouseEventDetails.setType(0x00001);
83 }
84
85 getContextClickListener().contextClick(
86 new ContextClickEvent(table, mouseEventDetails));
87 }
88 }
89 });
90 }
91
92 }