Updated copyright notice
[pithos] / web_client / src / gr / grnet / pithos / web / client / TopPanel.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.core.client.GWT;
7 import com.google.gwt.resources.client.ClientBundle;
8 import com.google.gwt.resources.client.ImageResource;
9 import com.google.gwt.user.client.Command;
10 import com.google.gwt.user.client.Window;
11 import com.google.gwt.user.client.ui.AbstractImagePrototype;
12 import com.google.gwt.user.client.ui.Composite;
13 import com.google.gwt.user.client.ui.HTML;
14 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
15 import com.google.gwt.user.client.ui.HasVerticalAlignment;
16 import com.google.gwt.user.client.ui.HorizontalPanel;
17 import com.google.gwt.user.client.ui.MenuBar;
18 import com.google.gwt.user.client.ui.MenuItem;
19
20 /**
21  * The top panel, which contains the menu bar icons and the user name.
22  */
23 public class TopPanel extends Composite {
24
25         /**
26          * A constant that denotes the completion of an IncrementalCommand.
27          */
28         public static final boolean DONE = false;
29
30         /**
31          * An image bundle for this widgets images.
32          */
33         public interface Images extends ClientBundle, FileMenu.Images, EditMenu.Images,
34                         SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images,
35                         HelpMenu.Images, LoadingIndicator.Images {
36
37                 @Source("gr/grnet/pithos/resources/exit.png")
38                 ImageResource exit();
39
40                 @Source("gr/grnet/pithos/resources/folder_blue.png")
41                 ImageResource folder();
42
43                 @Source("gr/grnet/pithos/resources/edit.png")
44                 ImageResource edit();
45
46                 @Source("gr/grnet/pithos/resources/edit_group.png")
47                 ImageResource group();
48
49                 @Source("gr/grnet/pithos/resources/configure.png")
50                 ImageResource configure();
51
52                 @Source("gr/grnet/pithos/resources/help.png")
53                 ImageResource help();
54
55                 @Source("gr/grnet/pithos/resources/pithos-logo.png")
56                 ImageResource gssLogo();
57
58                 @Source("gr/grnet/pithos/resources/grnet-logo.png")
59                 ImageResource grnetLogo();
60         }
61
62         /**
63          * The menu bar widget.
64          */
65         private MenuBar menu;
66
67         /**
68          * The file menu widget.
69          */
70         private FileMenu fileMenu;
71
72         /**
73          * The edit menu widget.
74          */
75         private EditMenu editMenu;
76
77         /**
78          * The group menu widget.
79          */
80         private GroupMenu groupMenu;
81
82         /**
83          * The settings menu widget.
84          */
85         private SettingsMenu settingsMenu;
86
87         /**
88          * The help menu widget.
89          */
90         private HelpMenu helpMenu;
91
92         /**
93          * A widget that displays a message indicating that communication with the
94          * server is underway.
95          */
96         private LoadingIndicator loading;
97
98         /**
99          * The constructor for the top panel.
100          *
101          * @param images the supplied images
102          */
103         public TopPanel(Images images) {
104                 fileMenu = new FileMenu(images);
105                 editMenu = new EditMenu(images);
106                 groupMenu = new GroupMenu(images);
107                 settingsMenu = new SettingsMenu(images);
108                 helpMenu = new HelpMenu(images);
109                 loading = new LoadingIndicator(images);
110                 HorizontalPanel outer = new HorizontalPanel();
111
112                 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
113
114                 menu = new MenuBar();
115                 menu.setWidth("100%");
116                 menu.setAutoOpen(false);
117                 menu.setAnimationEnabled(true);
118                 menu.setStyleName("toolbarmenu");
119
120                 Command quitCommand = new Command(){
121                         @Override
122                         public void execute() {
123                                 QuitDialog dlg = new QuitDialog();
124                                 dlg.center();
125                         }
126                 };
127                 MenuItem quitItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
128                                         AbstractImagePrototype.create(images.exit()).getHTML() + "</td><td>Quit</td></tr></table>", true, quitCommand);
129                 quitItem.getElement().setId("topMenu.quit");
130                 
131                 MenuItem fileItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
132                                         AbstractImagePrototype.create(images.folder()).getHTML() + "</td><td>File</td></tr></table>", true, new MenuBar(true)){
133                         @Override
134                         public MenuBar getSubMenu() {
135                                 return fileMenu.createMenu();
136                         }
137                 };
138                 fileItem.getElement().setId("topMenu.file");
139                 
140                 MenuItem editItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
141                                         AbstractImagePrototype.create(images.edit()).getHTML() + "</td><td>Edit</td></tr></table>", true, new MenuBar(true)){
142                         @Override
143                         public MenuBar getSubMenu() {
144                                 return editMenu.createMenu();
145                         }
146                 };
147                 editItem.getElement().setId("topMenu.edit");
148                 
149                 MenuItem groupItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
150                                         AbstractImagePrototype.create(images.group()).getHTML() + "</td><td>Group</td></tr></table>", true,
151                                         groupMenu.getContextMenu());
152                 groupItem.getElement().setId("topMenu.group");
153                 
154                 MenuItem configureItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
155                                         AbstractImagePrototype.create(images.configure()).getHTML() + "</td><td>Settings</td></tr></table>",
156                                         true,settingsMenu.getContextMenu());
157                 configureItem.getElement().setId("topMenu.settings");
158                 
159                 MenuItem helpItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
160                                         AbstractImagePrototype.create(images.help()).getHTML() + "</td><td>Help</td></tr></table>", true, new MenuBar(true)){
161                         @Override
162                         public MenuBar getSubMenu() {
163                                 return helpMenu.createMenu();
164                         }
165                 };
166                 helpItem.getElement().setId("topMenu.help");
167                 
168                 menu.addItem(quitItem);
169                 menu.addItem(fileItem);
170                 menu.addItem(editItem);
171                 menu.addItem(groupItem);
172                 menu.addItem(configureItem);
173                 menu.addItem(helpItem);
174
175                 outer.setSpacing(2);
176                 outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
177                 outer.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_MIDDLE);
178                 outer.add(menu);
179                 outer.setStyleName("toolbar");
180
181                 outer.add(loading);
182
183                 Configuration conf = (Configuration) GWT.create(Configuration.class);
184         String path = Window.Location.getPath();
185         String baseUrl = GWT.getModuleBaseURL();
186         String homeUrl = baseUrl.substring(0, baseUrl.indexOf(path));
187                 HTML logos = new HTML("<table><tr><td><a href='" + homeUrl +
188                                         "' target='pithos'>" +  AbstractImagePrototype.create(images.gssLogo()).getHTML() +
189                                         "</a><a href='http://www.grnet.gr/' " + "target='grnet'>" +
190                                         AbstractImagePrototype.create(images.grnetLogo()).getHTML()+"</a></td></tr></table>");
191                 outer.add(logos);
192
193                 outer.setCellHorizontalAlignment(logos, HasHorizontalAlignment.ALIGN_RIGHT);
194
195                 initWidget(outer);
196         }
197
198
199         /**
200          * Retrieve the loading.
201          *
202          * @return the loading
203          */
204         public LoadingIndicator getLoading() {
205                 return loading;
206         }
207
208         /**
209          * Retrieve the fileMenu.
210          *
211          * @return the fileMenu
212          */
213         FileMenu getFileMenu() {
214                 return fileMenu;
215         }
216
217         /**
218          * Retrieve the editMenu.
219          *
220          * @return the editMenu
221          */
222         EditMenu getEditMenu() {
223                 return editMenu;
224         }
225 }