Automated merge with https://gss.googlecode.com/hg/
[pithos] / src / gr / ebs / gss / client / TopPanel.java
1 /*
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
6  * GSS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 package gr.ebs.gss.client;
20
21 import com.google.gwt.core.client.GWT;
22 import com.google.gwt.resources.client.ClientBundle;
23 import com.google.gwt.resources.client.ImageResource;
24 import com.google.gwt.user.client.Command;
25 import com.google.gwt.user.client.ui.AbstractImagePrototype;
26 import com.google.gwt.user.client.ui.Composite;
27 import com.google.gwt.user.client.ui.HTML;
28 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
29 import com.google.gwt.user.client.ui.HasVerticalAlignment;
30 import com.google.gwt.user.client.ui.HorizontalPanel;
31 import com.google.gwt.user.client.ui.MenuBar;
32 import com.google.gwt.user.client.ui.MenuItem;
33
34 /**
35  * The top panel, which contains the menu bar icons and the user name.
36  */
37 public class TopPanel extends Composite {
38
39         /**
40          * A constant that denotes the completion of an IncrementalCommand.
41          */
42         public static final boolean DONE = false;
43
44         /**
45          * An image bundle for this widgets images.
46          */
47         public interface Images extends ClientBundle, FileMenu.Images, EditMenu.Images,
48                         SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images,
49                         HelpMenu.Images, LoadingIndicator.Images {
50
51                 @Source("gr/ebs/gss/resources/exit.png")
52                 ImageResource exit();
53
54                 @Source("gr/ebs/gss/resources/folder_blue.png")
55                 ImageResource folder();
56
57                 @Source("gr/ebs/gss/resources/edit.png")
58                 ImageResource edit();
59
60                 @Source("gr/ebs/gss/resources/edit_group.png")
61                 ImageResource group();
62
63                 @Source("gr/ebs/gss/resources/configure.png")
64                 ImageResource configure();
65
66                 @Source("gr/ebs/gss/resources/help.png")
67                 ImageResource help();
68
69                 @Source("gr/ebs/gss/resources/pithos-logo.png")
70                 ImageResource gssLogo();
71
72                 @Source("gr/ebs/gss/resources/grnet-logo.png")
73                 ImageResource grnetLogo();
74         }
75
76         /**
77          * The menu bar widget.
78          */
79         private MenuBar menu;
80
81         /**
82          * The file menu widget.
83          */
84         private FileMenu fileMenu;
85
86         /**
87          * The edit menu widget.
88          */
89         private EditMenu editMenu;
90
91         /**
92          * The group menu widget.
93          */
94         private GroupMenu groupMenu;
95
96         /**
97          * The settings menu widget.
98          */
99         private SettingsMenu settingsMenu;
100
101         /**
102          * The help menu widget.
103          */
104         private HelpMenu helpMenu;
105
106         /**
107          * A widget that displays a message indicating that communication with the
108          * server is underway.
109          */
110         private LoadingIndicator loading;
111
112         /**
113          * The constructor for the top panel.
114          *
115          * @param images the supplied images
116          */
117         public TopPanel(Images images) {
118                 fileMenu = new FileMenu(images);
119                 editMenu = new EditMenu(images);
120                 groupMenu = new GroupMenu(images);
121                 settingsMenu = new SettingsMenu(images);
122                 helpMenu = new HelpMenu(images);
123                 loading = new LoadingIndicator(images);
124                 HorizontalPanel outer = new HorizontalPanel();
125
126                 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
127
128                 menu = new MenuBar();
129                 menu.setWidth("100%");
130                 menu.setAutoOpen(false);
131                 menu.setAnimationEnabled(true);
132                 menu.setStyleName("toolbarmenu");
133
134                 Command quitCommand = new Command(){
135                         @Override
136                         public void execute() {
137                                 QuitDialog dlg = new QuitDialog();
138                                 dlg.center();
139                         }
140                 };
141                 MenuItem quitItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
142                                         AbstractImagePrototype.create(images.exit()).getHTML() + "</td><td>Quit</td></tr></table>", true, quitCommand);
143                 MenuItem fileItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
144                                         AbstractImagePrototype.create(images.folder()).getHTML() + "</td><td>File</td></tr></table>", true, new MenuBar(true)){
145                         @Override
146                         public MenuBar getSubMenu() {
147                                 return fileMenu.createMenu();
148                         }
149                 };
150                 MenuItem editItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
151                                         AbstractImagePrototype.create(images.edit()).getHTML() + "</td><td>Edit</td></tr></table>", true, new MenuBar(true)){
152                         @Override
153                         public MenuBar getSubMenu() {
154                                 return editMenu.createMenu();
155                         }
156                 };
157                 MenuItem groupItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
158                                         AbstractImagePrototype.create(images.group()).getHTML() + "</td><td>Group</td></tr></table>", true,
159                                         groupMenu.getContextMenu());
160                 MenuItem configureItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
161                                         AbstractImagePrototype.create(images.configure()).getHTML() + "</td><td>Settings</td></tr></table>",
162                                         true,settingsMenu.getContextMenu());
163                 MenuItem helpItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
164                                         AbstractImagePrototype.create(images.help()).getHTML() + "</td><td>Help</td></tr></table>", true, new MenuBar(true)){
165                         @Override
166                         public MenuBar getSubMenu() {
167                                 return helpMenu.createMenu();
168                         }
169                 };
170                 menu.addItem(quitItem);
171                 menu.addItem(fileItem);
172                 menu.addItem(editItem);
173                 menu.addItem(groupItem);
174                 menu.addItem(configureItem);
175                 menu.addItem(helpItem);
176
177                 outer.setSpacing(2);
178                 outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
179                 outer.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_MIDDLE);
180                 outer.add(menu);
181                 outer.setStyleName("toolbar");
182
183                 outer.add(loading);
184
185                 Configuration conf = (Configuration) GWT.create(Configuration.class);
186                 HTML logos = new HTML("<table><tr><td><a href='" + conf.serviceHome() +
187                                         "' target='gss'>" +     AbstractImagePrototype.create(images.gssLogo()).getHTML() +
188                                         "</a><a href='http://www.grnet.gr/' " + "target='grnet'>" +
189                                         AbstractImagePrototype.create(images.grnetLogo()).getHTML()+"</a></td></tr></table>");
190                 outer.add(logos);
191
192                 outer.setCellHorizontalAlignment(logos, HasHorizontalAlignment.ALIGN_RIGHT);
193
194                 initWidget(outer);
195         }
196
197
198         /**
199          * Retrieve the loading.
200          *
201          * @return the loading
202          */
203         public LoadingIndicator getLoading() {
204                 return loading;
205         }
206
207         /**
208          * Retrieve the fileMenu.
209          *
210          * @return the fileMenu
211          */
212         FileMenu getFileMenu() {
213                 return fileMenu;
214         }
215
216         /**
217          * Retrieve the editMenu.
218          *
219          * @return the editMenu
220          */
221         EditMenu getEditMenu() {
222                 return editMenu;
223         }
224 }