root / web_client / src / gr / grnet / pithos / web / client / GroupMenu.java @ 9e6e0572
History | View | Annotate | Download (2.2 kB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2011 Greek Research and Technology Network
|
3 |
*/
|
4 |
package gr.grnet.pithos.web.client; |
5 |
|
6 |
import gr.grnet.pithos.web.client.commands.NewGroupCommand; |
7 |
|
8 |
import com.google.gwt.event.dom.client.ClickEvent; |
9 |
import com.google.gwt.event.dom.client.ClickHandler; |
10 |
import com.google.gwt.resources.client.ClientBundle; |
11 |
import com.google.gwt.resources.client.ImageResource; |
12 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
13 |
import com.google.gwt.user.client.ui.MenuBar; |
14 |
import com.google.gwt.user.client.ui.MenuItem; |
15 |
import com.google.gwt.user.client.ui.PopupPanel; |
16 |
|
17 |
/**
|
18 |
* The 'Group' menu implementation.
|
19 |
*/
|
20 |
public class GroupMenu extends PopupPanel implements ClickHandler { |
21 |
/**
|
22 |
* The widget's images.
|
23 |
*/
|
24 |
private Images images;
|
25 |
private final MenuBar contextMenu; |
26 |
|
27 |
/**
|
28 |
* An image bundle for this widgets images.
|
29 |
*/
|
30 |
public interface Images extends ClientBundle { |
31 |
@Source("gr/grnet/pithos/resources/groupevent.png") |
32 |
ImageResource groupNew(); |
33 |
|
34 |
@Source("gr/grnet/pithos/resources/view_text.png") |
35 |
ImageResource viewText(); |
36 |
|
37 |
} |
38 |
|
39 |
/**
|
40 |
* The widget's constructor.
|
41 |
*
|
42 |
* @param newImages the image bundle passed on by the parent object
|
43 |
*/
|
44 |
public GroupMenu(final Images newImages) { |
45 |
// The popup's constructor's argument is a boolean specifying that it
|
46 |
// auto-close itself when the user clicks outside of it.
|
47 |
super(true); |
48 |
setAnimationEnabled(true);
|
49 |
images = newImages; |
50 |
|
51 |
contextMenu = new MenuBar(true); |
52 |
MenuItem newGroupItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " New Group</span>", true, new NewGroupCommand(this)); |
53 |
newGroupItem.getElement().setId("topMenu.group.newGroup");
|
54 |
contextMenu.addItem(newGroupItem); |
55 |
|
56 |
add(contextMenu); |
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void onClick(ClickEvent event) { |
61 |
GroupMenu menu = new GroupMenu(images);
|
62 |
int left = event.getRelativeElement().getAbsoluteLeft();
|
63 |
int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
|
64 |
menu.setPopupPosition(left, top); |
65 |
|
66 |
menu.show(); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Retrieve the contextMenu.
|
71 |
*
|
72 |
* @return the contextMenu
|
73 |
*/
|
74 |
public MenuBar getContextMenu() { |
75 |
contextMenu.setAutoOpen(false);
|
76 |
return contextMenu;
|
77 |
} |
78 |
|
79 |
} |