root / web_client / src / gr / grnet / pithos / web / client / TopPanel.java @ 63f9af58
History | View | Annotate | Download (6.2 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 58777026 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 58777026 | Christos Stathis | *
|
4 | 58777026 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 58777026 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 58777026 | Christos Stathis | * conditions are met:
|
7 | 58777026 | Christos Stathis | *
|
8 | 58777026 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 58777026 | Christos Stathis | * disclaimer.
|
11 | 58777026 | Christos Stathis | *
|
12 | 58777026 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 58777026 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 58777026 | Christos Stathis | * provided with the distribution.
|
16 | 58777026 | Christos Stathis | *
|
17 | 58777026 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 58777026 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 58777026 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 58777026 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 58777026 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 58777026 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 58777026 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 58777026 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 58777026 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 58777026 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 58777026 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 58777026 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 58777026 | Christos Stathis | *
|
30 | 58777026 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 58777026 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 58777026 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 58777026 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ab1eb3f8 | Christos Stathis | */
|
35 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | ab1eb3f8 | Christos Stathis | |
37 | 63f9af58 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
38 | 63f9af58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
39 | 63f9af58 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
40 | 63f9af58 | Christos Stathis | |
41 | 63f9af58 | Christos Stathis | import com.google.gwt.core.client.GWT; |
42 | 63f9af58 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
43 | 63f9af58 | Christos Stathis | import com.google.gwt.http.client.Response; |
44 | ab1eb3f8 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
45 | 466e52ea | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtml; |
46 | 466e52ea | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
47 | 466e52ea | Christos Stathis | import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
48 | 603e82ce | Christos Stathis | import com.google.gwt.user.client.Command; |
49 | 603e82ce | Christos Stathis | import com.google.gwt.user.client.Cookies; |
50 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
51 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
52 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
53 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
54 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HasVerticalAlignment; |
55 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
56 | 466e52ea | Christos Stathis | import com.google.gwt.user.client.ui.Image; |
57 | 0ae83d19 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
58 | 0ae83d19 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
59 | ab1eb3f8 | Christos Stathis | |
60 | ab1eb3f8 | Christos Stathis | /**
|
61 | ab1eb3f8 | Christos Stathis | * The top panel, which contains the menu bar icons and the user name.
|
62 | ab1eb3f8 | Christos Stathis | */
|
63 | ab1eb3f8 | Christos Stathis | public class TopPanel extends Composite { |
64 | ab1eb3f8 | Christos Stathis | |
65 | ab1eb3f8 | Christos Stathis | /**
|
66 | ab1eb3f8 | Christos Stathis | * A constant that denotes the completion of an IncrementalCommand.
|
67 | ab1eb3f8 | Christos Stathis | */
|
68 | ab1eb3f8 | Christos Stathis | public static final boolean DONE = false; |
69 | ab1eb3f8 | Christos Stathis | |
70 | 603e82ce | Christos Stathis | Pithos app; |
71 | e9c9f408 | Christos Stathis | |
72 | ab1eb3f8 | Christos Stathis | /**
|
73 | ab1eb3f8 | Christos Stathis | * An image bundle for this widgets images.
|
74 | ab1eb3f8 | Christos Stathis | */
|
75 | 10791b56 | Christos Stathis | public interface Images extends FilePropertiesDialog.Images { |
76 | ab1eb3f8 | Christos Stathis | |
77 | 7ed6977e | Christos Stathis | @Source("gr/grnet/pithos/resources/pithos2-logo.png") |
78 | 7ed6977e | Christos Stathis | ImageResource pithosLogo(); |
79 | 466e52ea | Christos Stathis | |
80 | 466e52ea | Christos Stathis | @Source("gr/grnet/pithos/resources/desc.png") |
81 | 466e52ea | Christos Stathis | ImageResource downArrow(); |
82 | ab1eb3f8 | Christos Stathis | } |
83 | ab1eb3f8 | Christos Stathis | |
84 | ab1eb3f8 | Christos Stathis | /**
|
85 | ab1eb3f8 | Christos Stathis | * The constructor for the top panel.
|
86 | ab1eb3f8 | Christos Stathis | *
|
87 | ab1eb3f8 | Christos Stathis | * @param images the supplied images
|
88 | ab1eb3f8 | Christos Stathis | */
|
89 | e9c9f408 | Christos Stathis | public TopPanel(Pithos _app, final Images images) { |
90 | e9c9f408 | Christos Stathis | this.app = _app;
|
91 | ab1eb3f8 | Christos Stathis | HorizontalPanel outer = new HorizontalPanel();
|
92 | ab1eb3f8 | Christos Stathis | outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
93 | ab1eb3f8 | Christos Stathis | |
94 | ab1eb3f8 | Christos Stathis | outer.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
95 | 0ae83d19 | Christos Stathis | outer.setStyleName("pithos-topPanel");
|
96 | ab1eb3f8 | Christos Stathis | |
97 | 60207db6 | Christos Stathis | HorizontalPanel inner = new HorizontalPanel();
|
98 | 60207db6 | Christos Stathis | inner.setWidth("75%");
|
99 | 60207db6 | Christos Stathis | inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); |
100 | 60207db6 | Christos Stathis | |
101 | 7ed6977e | Christos Stathis | HTML logos = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.pithosLogo()).getHTML() + "</td></tr></table>"); |
102 | 9d8eee31 | Christos Stathis | logos.addStyleName("pithos-logo");
|
103 | 60207db6 | Christos Stathis | inner.add(logos); |
104 | ab1eb3f8 | Christos Stathis | |
105 | 0ae83d19 | Christos Stathis | MenuBar username = new MenuBar(); |
106 | 0ae83d19 | Christos Stathis | username.setStyleName("pithos-usernameMenu");
|
107 | 466e52ea | Christos Stathis | |
108 | 603e82ce | Christos Stathis | MenuBar userItemMenu = new MenuBar(true); |
109 | fe452461 | Christos Stathis | userItemMenu.addStyleName("pithos-userItemMenu");
|
110 | 294d2ea9 | Christos Stathis | userItemMenu.addItem(new MenuItem("invite friends...", new Command() { |
111 | 294d2ea9 | Christos Stathis | |
112 | 294d2ea9 | Christos Stathis | @Override
|
113 | 294d2ea9 | Christos Stathis | public void execute() { |
114 | 63f9af58 | Christos Stathis | GetRequest<Invitations> getInvitations = new GetRequest<Invitations> (Invitations.class, "/im/", "", "invitations") { |
115 | 63f9af58 | Christos Stathis | |
116 | 63f9af58 | Christos Stathis | @Override
|
117 | 63f9af58 | Christos Stathis | public void onSuccess(Invitations _result) { |
118 | 63f9af58 | Christos Stathis | new InvitationsDialog(app, _result).center();
|
119 | 63f9af58 | Christos Stathis | } |
120 | 63f9af58 | Christos Stathis | |
121 | 63f9af58 | Christos Stathis | @Override
|
122 | 63f9af58 | Christos Stathis | public void onError(Throwable t) { |
123 | 63f9af58 | Christos Stathis | GWT.log("", t);
|
124 | 63f9af58 | Christos Stathis | if (t instanceof RestException) |
125 | 63f9af58 | Christos Stathis | app.displayError("Error getting invitations: " + ((RestException) t).getHttpStatusText());
|
126 | 63f9af58 | Christos Stathis | else
|
127 | 63f9af58 | Christos Stathis | app.displayError("System error getting invitations: " + t.getMessage());
|
128 | 63f9af58 | Christos Stathis | } |
129 | 63f9af58 | Christos Stathis | |
130 | 63f9af58 | Christos Stathis | @Override
|
131 | 63f9af58 | Christos Stathis | protected void onUnauthorized(Response response) { |
132 | 63f9af58 | Christos Stathis | app.sessionExpired(); |
133 | 63f9af58 | Christos Stathis | } |
134 | 63f9af58 | Christos Stathis | }; |
135 | 63f9af58 | Christos Stathis | getInvitations.setHeader("X-Auth-Token", app.getToken());
|
136 | 63f9af58 | Christos Stathis | Scheduler.get().scheduleDeferred(getInvitations); |
137 | 294d2ea9 | Christos Stathis | } |
138 | 294d2ea9 | Christos Stathis | })); |
139 | 294d2ea9 | Christos Stathis | userItemMenu.addItem(new MenuItem("send feedback...", new Command() { |
140 | 294d2ea9 | Christos Stathis | |
141 | 294d2ea9 | Christos Stathis | @Override
|
142 | 294d2ea9 | Christos Stathis | public void execute() { |
143 | 294d2ea9 | Christos Stathis | new FeedbackDialog().center();
|
144 | 294d2ea9 | Christos Stathis | } |
145 | 294d2ea9 | Christos Stathis | })); |
146 | 466e52ea | Christos Stathis | userItemMenu.addItem(new MenuItem("API token", new Command() { |
147 | 603e82ce | Christos Stathis | |
148 | 603e82ce | Christos Stathis | @Override
|
149 | 603e82ce | Christos Stathis | public void execute() { |
150 | 466e52ea | Christos Stathis | new CredentialsDialog(app, images).center();
|
151 | 603e82ce | Christos Stathis | } |
152 | 603e82ce | Christos Stathis | })); |
153 | 466e52ea | Christos Stathis | userItemMenu.addItem(new MenuItem("Log off", new Command() { |
154 | 69d74a2b | Christos Stathis | |
155 | 69d74a2b | Christos Stathis | @Override
|
156 | 69d74a2b | Christos Stathis | public void execute() { |
157 | 466e52ea | Christos Stathis | app.logoff(); |
158 | 69d74a2b | Christos Stathis | } |
159 | 69d74a2b | Christos Stathis | })); |
160 | 466e52ea | Christos Stathis | |
161 | 603e82ce | Christos Stathis | MenuItem userItem = new MenuItem(_app.getUsername(), userItemMenu); |
162 | af428752 | Christos Stathis | userItem.addStyleName("pithos-usernameMenuItem");
|
163 | 0ae83d19 | Christos Stathis | username.addItem(userItem); |
164 | af428752 | Christos Stathis | username.addSeparator(); |
165 | fe452461 | Christos Stathis | |
166 | fe452461 | Christos Stathis | MenuItem langItem = new MenuItem("en", (Command) null); |
167 | fe452461 | Christos Stathis | langItem.addStyleName("pithos-langMenuItem");
|
168 | fe452461 | Christos Stathis | username.addItem(langItem); |
169 | fe452461 | Christos Stathis | |
170 | 60207db6 | Christos Stathis | inner.add(username); |
171 | 60207db6 | Christos Stathis | inner.setCellHorizontalAlignment(username, HasHorizontalAlignment.ALIGN_RIGHT); |
172 | 60207db6 | Christos Stathis | |
173 | 60207db6 | Christos Stathis | outer.add(inner); |
174 | 60207db6 | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
175 | 60207db6 | Christos Stathis | outer.setCellVerticalAlignment(inner, HasVerticalAlignment.ALIGN_BOTTOM); |
176 | ab1eb3f8 | Christos Stathis | initWidget(outer); |
177 | ab1eb3f8 | Christos Stathis | } |
178 | ab1eb3f8 | Christos Stathis | } |