Updated copyright notice
[pithos] / web_client / src / gr / grnet / pithos / web / client / HelpMenu.java
1 /*
2  * Copyright (c) 2011 Greek Research and Technology Network
3  */
4 package gr.grnet.pithos.web.client;
5
6 import com.google.gwt.event.dom.client.ClickEvent;
7 import com.google.gwt.event.dom.client.ClickHandler;
8 import com.google.gwt.resources.client.ClientBundle;
9 import com.google.gwt.resources.client.ImageResource;
10 import com.google.gwt.user.client.Command;
11 import com.google.gwt.user.client.ui.AbstractImagePrototype;
12 import com.google.gwt.user.client.ui.MenuBar;
13 import com.google.gwt.user.client.ui.MenuItem;
14 import com.google.gwt.user.client.ui.PopupPanel;
15
16 /**
17  * The 'Help' menu implementation.
18  */
19 public class HelpMenu extends PopupPanel implements ClickHandler {
20
21         /**
22          * The widget's images.
23          */
24         private final Images images;
25
26         private MenuBar contextMenu  = new MenuBar(true);
27
28         /**
29          * An image bundle for this widget's images.
30          */
31         public interface Images extends ClientBundle{
32                 @Source("gr/grnet/pithos/resources/khelpcenter.png")
33                 ImageResource userGuide();
34
35                 @Source("gr/grnet/pithos/resources/linewidth.png")
36                 ImageResource terms();
37
38                 @Source("gr/grnet/pithos/resources/bell.png")
39                 ImageResource reportAbuse();
40
41                 @Source("gr/grnet/pithos/resources/bug.png")
42                 ImageResource reportBug();
43
44                 @Source("gr/grnet/pithos/resources/info.png")
45                 ImageResource about();
46
47                 @Source("gr/grnet/pithos/resources/edit_add.png")
48                 ImageResource upgradeQuota();
49         }
50
51         /**
52          * The widget's constructor.
53          *
54          * @param newImages the image bundle passed on by the parent object
55          */
56         public HelpMenu(final Images newImages) {
57                 // The popup's constructor's argument is a boolean specifying that it
58                 // auto-close itself when the user clicks outside of it.
59                 super(true);
60                 setAnimationEnabled(true);
61                 images = newImages;
62                 createMenu();
63                 add(contextMenu);
64         }
65
66         @Override
67         public void onClick(ClickEvent event) {
68                 HelpMenu menu = new HelpMenu(images);
69                 int left = event.getRelativeElement().getAbsoluteLeft();
70                 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
71                 menu.setPopupPosition(left, top);
72                 menu.show();
73         }
74
75         public MenuBar createMenu() {
76                 contextMenu.clearItems();
77                 contextMenu.setAutoOpen(false);
78                 Command hideCommand = new Command() {
79                         @Override
80                         public void execute() {
81                                 hide();
82                         }
83                 };
84                 Command aboutCommand = new Command(){
85                         @Override
86                         public void execute() {
87                                 AboutDialog dlg = new AboutDialog();
88                                 dlg.center();
89                         }
90                 };
91                 MenuItem userGuideItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.userGuide()).getHTML() + "&nbsp;<a class='hidden-link' " +
92                                         "href='/userguide/el' target='_blank'>User Guide</a></span>", true, hideCommand);
93                 contextMenu.addItem(userGuideItem);
94                 userGuideItem.getElement().setId("topMenu.help.userGuide");
95                 
96                 MenuItem termsItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.terms()).getHTML() + "&nbsp;<a class='hidden-link' " +
97                                         "href='/terms' target='_blank'>Terms &amp; Conditions</a></span>", true, hideCommand);
98                 termsItem.getElement().setId("topMenu.help.terms");
99                 contextMenu.addItem(termsItem);
100                 
101                 MenuItem reportAbuseItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.reportAbuse()).getHTML() + "&nbsp;<a class='hidden-link' " +
102                                         "href='/report-abuse' target='_blank'>Report abuse</a></span>", true, hideCommand);
103                 reportAbuseItem.getElement().setId("topMenu.help.reportAbuse");
104                 contextMenu.addItem(reportAbuseItem);
105                 
106                 MenuItem upgradeQuotaItem= new MenuItem("<span>" + AbstractImagePrototype.create(images.upgradeQuota()).getHTML() + "&nbsp;<a class='hidden-link' " +
107                                         "href='/pithos/coupon' target='_blank'>Upgrade quota</a></span>", true, hideCommand);
108                 upgradeQuotaItem.getElement().setId("topMenu.help.upgradeQuota");
109                 contextMenu.addItem(upgradeQuotaItem);
110                 
111                 MenuItem reportBugItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.reportBug()).getHTML() + "&nbsp;<a class='hidden-link' " +
112                                         "href='http://code.google.com/p/pithos/issues/list' target='_blank'>Report bug</a></span>", true, hideCommand);
113                 reportBugItem.getElement().setId("topMenu.help.reportBug");
114                 contextMenu.addItem(reportBugItem);
115                                 
116                 MenuItem aboutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.about()).getHTML() + "&nbsp;About</span>", true, aboutCommand);
117                 aboutItem.getElement().setId("topMenu.help.about");
118                 contextMenu.addItem(aboutItem);
119                 return contextMenu;
120         }
121
122 }