1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.track.operation;
26
27 import java.util.ArrayList;
28
29 import org.utgenome.gwt.utgb.client.track.lib.old.Utilities;
30
31 import com.google.gwt.user.client.ui.DockPanel;
32 import com.google.gwt.user.client.ui.Label;
33 import com.google.gwt.user.client.ui.PopupPanel;
34 import com.google.gwt.user.client.ui.ScrollPanel;
35 import com.google.gwt.user.client.ui.VerticalPanel;
36 import com.google.gwt.user.client.ui.Widget;
37 import com.google.gwt.xml.client.Node;
38
39
40
41
42
43 public class MenuOperation implements Operation {
44 final String title;
45 final ArrayList<MenuOperationItem> menuItems = new ArrayList<MenuOperationItem>();
46
47 public MenuOperation(final Node menuOperationNode) {
48 this(Utilities.getAttributeValue(menuOperationNode, "title"));
49 }
50
51 public MenuOperation(final String title) {
52 this.title = title;
53 }
54
55 class MenuPopupWindow extends PopupPanel {
56 public MenuPopupWindow(final String title, final boolean autoHide, final ArrayList<MenuOperationItem> _menuItems) {
57 super(autoHide);
58
59 setTitle(title);
60
61 final DockPanel _panel = new DockPanel();
62 _panel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
63 _panel.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
64 _panel.setStyleName("menu-popup");
65
66
67 final Label titleLabel = new Label(title);
68 titleLabel.setStyleName("menu-popup-title");
69 _panel.add(titleLabel, DockPanel.NORTH);
70
71 final VerticalPanel verticalPanel = new VerticalPanel();
72 verticalPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
73 verticalPanel.setVerticalAlignment(VerticalPanel.ALIGN_TOP);
74 verticalPanel.setWidth("100%");
75
76 {
77 final int itemNum = menuItems.size();
78 for (int i = 0; i < itemNum; i++) {
79 final MenuOperationItem menuItem = (MenuOperationItem) (menuItems.get(i));
80
81 final Widget menuWidget = menuItem.getWidget(this);
82 menuWidget.setWidth("100%");
83 verticalPanel.add(menuWidget);
84 }
85 }
86
87 final ScrollPanel scrollPanel = new ScrollPanel(verticalPanel);
88 scrollPanel.setAlwaysShowScrollBars(false);
89 _panel.add(scrollPanel, DockPanel.CENTER);
90 scrollPanel.setWidth("100%");
91 scrollPanel.setHeight("150px");
92 setWidget(_panel);
93
94
95 }
96 }
97
98 public void execute(Widget sender, int x, int y) {
99 final MenuPopupWindow menuWindow = new MenuPopupWindow(title, true, menuItems);
100
101 {
102 final int offsetX = sender.getAbsoluteLeft();
103 final int offsetY = sender.getAbsoluteTop();
104
105 menuWindow.setPopupPosition(offsetX + x, offsetY + y);
106 }
107
108 menuWindow.show();
109 }
110
111 public void addMenuItem(final MenuOperationItem menuItem) {
112 menuItems.add(menuItem);
113 }
114
115 }