2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import gr.grnet.pithos.web.client.foldertree.Resource;
38 import gr.grnet.pithos.web.client.rest.GetRequest;
39 import gr.grnet.pithos.web.client.rest.RestException;
41 import com.google.gwt.core.client.GWT;
42 import com.google.gwt.core.client.Scheduler;
43 import com.google.gwt.http.client.Response;
44 import com.google.gwt.resources.client.ImageResource;
45 import com.google.gwt.safehtml.shared.SafeHtml;
46 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
47 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
48 import com.google.gwt.user.client.Command;
49 import com.google.gwt.user.client.Cookies;
50 import com.google.gwt.user.client.ui.AbstractImagePrototype;
51 import com.google.gwt.user.client.ui.Composite;
52 import com.google.gwt.user.client.ui.HTML;
53 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
54 import com.google.gwt.user.client.ui.HasVerticalAlignment;
55 import com.google.gwt.user.client.ui.HorizontalPanel;
56 import com.google.gwt.user.client.ui.Image;
57 import com.google.gwt.user.client.ui.MenuBar;
58 import com.google.gwt.user.client.ui.MenuItem;
61 * The top panel, which contains the menu bar icons and the user name.
63 public class TopPanel extends Composite {
66 * A constant that denotes the completion of an IncrementalCommand.
68 public static final boolean DONE = false;
73 * An image bundle for this widgets images.
75 public interface Images extends FilePropertiesDialog.Images {
77 @Source("gr/grnet/pithos/resources/pithos2-logo.png")
78 ImageResource pithosLogo();
80 @Source("gr/grnet/pithos/resources/desc.png")
81 ImageResource downArrow();
85 * The constructor for the top panel.
87 * @param images the supplied images
89 public TopPanel(Pithos _app, final Images images) {
91 HorizontalPanel outer = new HorizontalPanel();
92 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
94 outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
95 outer.setStyleName("pithos-topPanel");
97 HorizontalPanel inner = new HorizontalPanel();
98 inner.setWidth("75%");
99 inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
101 HTML logos = new HTML("<table><tr><td><a href='/'>" + AbstractImagePrototype.create(images.pithosLogo()).getHTML() + "</a></td></tr></table>");
102 logos.addStyleName("pithos-logo");
105 MenuBar username = new MenuBar();
106 username.setStyleName("pithos-usernameMenu");
108 MenuBar userItemMenu = new MenuBar(true);
109 userItemMenu.addStyleName("pithos-userItemMenu");
110 userItemMenu.addItem(new MenuItem("invite friends...", new Command() {
113 public void execute() {
114 GetRequest<Invitations> getInvitations = new GetRequest<Invitations> (Invitations.class, "/im/", "", "invite?format=json") {
117 public void onSuccess(Invitations _result) {
118 new InvitationsDialog(app, _result).center();
122 public void onError(Throwable t) {
124 if (t instanceof RestException)
125 app.displayError("Error getting invitations: " + ((RestException) t).getHttpStatusText());
127 app.displayError("System error getting invitations: " + t.getMessage());
131 protected void onUnauthorized(Response response) {
132 app.sessionExpired();
135 getInvitations.setHeader("X-Auth-Token", app.getToken());
136 Scheduler.get().scheduleDeferred(getInvitations);
139 userItemMenu.addItem(new MenuItem("send feedback...", new Command() {
142 public void execute() {
143 new FeedbackDialog(app).center();
146 userItemMenu.addItem(new MenuItem("API access", new Command() {
149 public void execute() {
150 new CredentialsDialog(app, images).center();
153 userItemMenu.addItem(new MenuItem("logout", new Command() {
156 public void execute() {
161 MenuItem userItem = new MenuItem(_app.getUsername(), userItemMenu);
162 userItem.addStyleName("pithos-usernameMenuItem");
163 username.addItem(userItem);
164 username.addSeparator();
166 MenuItem langItem = new MenuItem("en", (Command) null);
167 langItem.addStyleName("pithos-langMenuItem");
168 username.addItem(langItem);
171 inner.setCellHorizontalAlignment(username, HasHorizontalAlignment.ALIGN_RIGHT);
174 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
175 outer.setCellVerticalAlignment(inner, HasVerticalAlignment.ALIGN_BOTTOM);