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