CSS and aesthetic changes
[pithos-web-client] / src / gr / grnet / pithos / web / client / TopPanel.java
index 06a8d15..2e8a776 100644 (file)
@@ -1,34 +1,52 @@
 /*
- * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
+ * Copyright 2011 GRNET S.A. All rights reserved.
  *
- * This file is part of GSS.
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
  *
- * GSS is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
  *
- * GSS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
  *
- * You should have received a copy of the GNU General Public License
- * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
  */
 package gr.grnet.pithos.web.client;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.resources.client.ClientBundle;
 import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.Cookies;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
 import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
 import com.google.gwt.user.client.ui.MenuBar;
 import com.google.gwt.user.client.ui.MenuItem;
 
@@ -42,199 +60,66 @@ public class TopPanel extends Composite {
         */
        public static final boolean DONE = false;
 
+    Pithos app;
+
        /**
         * An image bundle for this widgets images.
         */
-       public interface Images extends ClientBundle, FileMenu.Images, EditMenu.Images,
-                       SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images,
-                       HelpMenu.Images, LoadingIndicator.Images {
-
-               @Source("gr/grnet/pithos/resources/exit.png")
-               ImageResource exit();
-
-               @Source("gr/grnet/pithos/resources/folder_blue.png")
-               ImageResource folder();
-
-               @Source("gr/grnet/pithos/resources/edit.png")
-               ImageResource edit();
-
-               @Source("gr/grnet/pithos/resources/edit_group.png")
-               ImageResource group();
-
-               @Source("gr/grnet/pithos/resources/configure.png")
-               ImageResource configure();
-
-               @Source("gr/grnet/pithos/resources/help.png")
-               ImageResource help();
-
-               @Source("gr/grnet/pithos/resources/pithos-logo.png")
-               ImageResource gssLogo();
+       public interface Images extends FilePropertiesDialog.Images {
 
-               @Source("gr/grnet/pithos/resources/grnet-logo.png")
-               ImageResource grnetLogo();
+               @Source("gr/grnet/pithos/resources/pithos2-logo.png")
+               ImageResource pithosLogo();
+               
+               @Source("gr/grnet/pithos/resources/desc.png")
+               ImageResource downArrow();
        }
 
        /**
-        * The menu bar widget.
-        */
-       private MenuBar menu;
-
-       /**
-        * The file menu widget.
-        */
-       private FileMenu fileMenu;
-
-       /**
-        * The edit menu widget.
-        */
-       private EditMenu editMenu;
-
-       /**
-        * The group menu widget.
-        */
-       private GroupMenu groupMenu;
-
-       /**
-        * The settings menu widget.
-        */
-       private SettingsMenu settingsMenu;
-
-       /**
-        * The help menu widget.
-        */
-       private HelpMenu helpMenu;
-
-       /**
-        * A widget that displays a message indicating that communication with the
-        * server is underway.
-        */
-       private LoadingIndicator loading;
-
-       /**
         * The constructor for the top panel.
         *
         * @param images the supplied images
         */
-       public TopPanel(Images images) {
-               fileMenu = new FileMenu(images);
-               editMenu = new EditMenu(images);
-               groupMenu = new GroupMenu(images);
-               settingsMenu = new SettingsMenu(images);
-               helpMenu = new HelpMenu(images);
-               loading = new LoadingIndicator(images);
+       public TopPanel(Pithos _app, final Images images) {
+        this.app = _app;
                HorizontalPanel outer = new HorizontalPanel();
-
                outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
 
-               menu = new MenuBar();
-               menu.setWidth("100%");
-               menu.setAutoOpen(false);
-               menu.setAnimationEnabled(true);
-               menu.setStyleName("toolbarmenu");
+               outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
+               outer.setStyleName("pithos-topPanel");
+
+               HTML logos = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.pithosLogo()).getHTML() + "</td></tr></table>");
+               outer.add(logos);
 
-               Command quitCommand = new Command(){
+        MenuBar username = new MenuBar();
+        username.setStyleName("pithos-usernameMenu");
+        username.setAutoOpen(true);
+        
+        MenuBar userItemMenu = new MenuBar(true);
+        userItemMenu.addItem(new MenuItem("API token", new Command() {
+                       
                        @Override
                        public void execute() {
-                               QuitDialog dlg = new QuitDialog();
-                               dlg.center();
+                               new CredentialsDialog(app, images).center();
                        }
-               };
-               MenuItem quitItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.exit()).getHTML() + "</td><td>Quit</td></tr></table>", true, quitCommand);
-               quitItem.getElement().setId("topMenu.quit");
-               
-               MenuItem fileItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.folder()).getHTML() + "</td><td>File</td></tr></table>", true, new MenuBar(true)){
-                       @Override
-                       public MenuBar getSubMenu() {
-                               return fileMenu.createMenu();
-                       }
-               };
-               fileItem.getElement().setId("topMenu.file");
-               
-               MenuItem editItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.edit()).getHTML() + "</td><td>Edit</td></tr></table>", true, new MenuBar(true)){
-                       @Override
-                       public MenuBar getSubMenu() {
-                               return editMenu.createMenu();
-                       }
-               };
-               editItem.getElement().setId("topMenu.edit");
-               
-               MenuItem groupItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.group()).getHTML() + "</td><td>Group</td></tr></table>", true,
-                                       groupMenu.getContextMenu());
-               groupItem.getElement().setId("topMenu.group");
-               
-               MenuItem configureItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.configure()).getHTML() + "</td><td>Settings</td></tr></table>",
-                                       true,settingsMenu.getContextMenu());
-               configureItem.getElement().setId("topMenu.settings");
-               
-               MenuItem helpItem = new MenuItem("<table style='font-size: 100%'><tr><td>" +
-                                       AbstractImagePrototype.create(images.help()).getHTML() + "</td><td>Help</td></tr></table>", true, new MenuBar(true)){
+               }));
+        userItemMenu.addItem(new MenuItem("Log off", new Command() {
+                       
                        @Override
-                       public MenuBar getSubMenu() {
-                               return helpMenu.createMenu();
+                       public void execute() {
+                               app.logoff();
                        }
-               };
-               helpItem.getElement().setId("topMenu.help");
-               
-               menu.addItem(quitItem);
-               menu.addItem(fileItem);
-               menu.addItem(editItem);
-               menu.addItem(groupItem);
-               menu.addItem(configureItem);
-               menu.addItem(helpItem);
-
-               outer.setSpacing(2);
-               outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
-               outer.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_MIDDLE);
-               outer.add(menu);
-               outer.setStyleName("toolbar");
-
-               outer.add(loading);
-
-               Configuration conf = (Configuration) GWT.create(Configuration.class);
-        String path = Window.Location.getPath();
-        String baseUrl = GWT.getModuleBaseURL();
-        String homeUrl = baseUrl.substring(0, baseUrl.indexOf(path));
-               HTML logos = new HTML("<table><tr><td><a href='" + homeUrl +
-                                       "' target='pithos'>" +  AbstractImagePrototype.create(images.gssLogo()).getHTML() +
-                                       "</a><a href='http://www.grnet.gr/' " + "target='grnet'>" +
-                                       AbstractImagePrototype.create(images.grnetLogo()).getHTML()+"</a></td></tr></table>");
-               outer.add(logos);
-
-               outer.setCellHorizontalAlignment(logos, HasHorizontalAlignment.ALIGN_RIGHT);
-
+               }));
+
+        SafeHtmlBuilder sb = new SafeHtmlBuilder();
+        sb.append(SafeHtmlUtils.fromSafeConstant(_app.getUsername()));
+        sb.appendHtmlConstant(AbstractImagePrototype.create(images.downArrow()).getHTML());
+        MenuItem userItem = new MenuItem(_app.getUsername(), userItemMenu);
+        username.addItem(userItem);
+        outer.add(username);
+               outer.setCellHorizontalAlignment(username, HasHorizontalAlignment.ALIGN_RIGHT);
+               Image downArrow = AbstractImagePrototype.create(images.downArrow()).createImage();
+               outer.add(downArrow);
+               outer.setCellHorizontalAlignment(downArrow, HasHorizontalAlignment.ALIGN_LEFT);
                initWidget(outer);
        }
-
-
-       /**
-        * Retrieve the loading.
-        *
-        * @return the loading
-        */
-       public LoadingIndicator getLoading() {
-               return loading;
-       }
-
-       /**
-        * Retrieve the fileMenu.
-        *
-        * @return the fileMenu
-        */
-       FileMenu getFileMenu() {
-               return fileMenu;
-       }
-
-       /**
-        * Retrieve the editMenu.
-        *
-        * @return the editMenu
-        */
-       EditMenu getEditMenu() {
-               return editMenu;
-       }
 }