Added a new test class in order to test the 'Sharing' option for Folder. Also added...
[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                 quitItem.getElement().setId("topMenu.quit");
144                 
145                 MenuItem fileItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
146                                         AbstractImagePrototype.create(images.folder()).getHTML() + "</td><td>File</td></tr></table>", true, new MenuBar(true)){
147                         @Override
148                         public MenuBar getSubMenu() {
149                                 return fileMenu.createMenu();
150                         }
151                 };
152                 fileItem.getElement().setId("topMenu.file");
153                 
154                 MenuItem editItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
155                                         AbstractImagePrototype.create(images.edit()).getHTML() + "</td><td>Edit</td></tr></table>", true, new MenuBar(true)){
156                         @Override
157                         public MenuBar getSubMenu() {
158                                 return editMenu.createMenu();
159                         }
160                 };
161                 editItem.getElement().setId("topMenu.edit");
162                 
163                 MenuItem groupItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
164                                         AbstractImagePrototype.create(images.group()).getHTML() + "</td><td>Group</td></tr></table>", true,
165                                         groupMenu.getContextMenu());
166                 groupItem.getElement().setId("topMenu.group");
167                 
168                 MenuItem configureItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
169                                         AbstractImagePrototype.create(images.configure()).getHTML() + "</td><td>Settings</td></tr></table>",
170                                         true,settingsMenu.getContextMenu());
171                 configureItem.getElement().setId("topMenu.settings");
172                 
173                 MenuItem helpItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
174                                         AbstractImagePrototype.create(images.help()).getHTML() + "</td><td>Help</td></tr></table>", true, new MenuBar(true)){
175                         @Override
176                         public MenuBar getSubMenu() {
177                                 return helpMenu.createMenu();
178                         }
179                 };
180                 helpItem.getElement().setId("topMenu.help");
181                 
182                 menu.addItem(quitItem);
183                 menu.addItem(fileItem);
184                 menu.addItem(editItem);
185                 menu.addItem(groupItem);
186                 menu.addItem(configureItem);
187                 menu.addItem(helpItem);
188
189                 outer.setSpacing(2);
190                 outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
191                 outer.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_MIDDLE);
192                 outer.add(menu);
193                 outer.setStyleName("toolbar");
194
195                 outer.add(loading);
196
197                 Configuration conf = (Configuration) GWT.create(Configuration.class);
198                 HTML logos = new HTML("<table><tr><td><a href='" + conf.serviceHome() +
199                                         "' target='gss'>" +     AbstractImagePrototype.create(images.gssLogo()).getHTML() +
200                                         "</a><a href='http://www.grnet.gr/' " + "target='grnet'>" +
201                                         AbstractImagePrototype.create(images.grnetLogo()).getHTML()+"</a></td></tr></table>");
202                 outer.add(logos);
203
204                 outer.setCellHorizontalAlignment(logos, HasHorizontalAlignment.ALIGN_RIGHT);
205
206                 initWidget(outer);
207         }
208
209
210         /**
211          * Retrieve the loading.
212          *
213          * @return the loading
214          */
215         public LoadingIndicator getLoading() {
216                 return loading;
217         }
218
219         /**
220          * Retrieve the fileMenu.
221          *
222          * @return the fileMenu
223          */
224         FileMenu getFileMenu() {
225                 return fileMenu;
226         }
227
228         /**
229          * Retrieve the editMenu.
230          *
231          * @return the editMenu
232          */
233         EditMenu getEditMenu() {
234                 return editMenu;
235         }
236 }