root / src / gr / grnet / pithos / web / client / FileVersionsDialog.java @ 39f6d7b0
History | View | Annotate | Download (6.2 kB)
1 | 9326b841 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | 9326b841 | Christos Stathis | *
|
4 | 9326b841 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 9326b841 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 9326b841 | Christos Stathis | * conditions are met:
|
7 | 9326b841 | Christos Stathis | *
|
8 | 9326b841 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 9326b841 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 9326b841 | Christos Stathis | * disclaimer.
|
11 | 9326b841 | Christos Stathis | *
|
12 | 9326b841 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 9326b841 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 9326b841 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 9326b841 | Christos Stathis | * provided with the distribution.
|
16 | 9326b841 | Christos Stathis | *
|
17 | 9326b841 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 9326b841 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 9326b841 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 9326b841 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 9326b841 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 9326b841 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 9326b841 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 9326b841 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 9326b841 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 9326b841 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 9326b841 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 9326b841 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 9326b841 | Christos Stathis | *
|
30 | 9326b841 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 9326b841 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 9326b841 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 9326b841 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 9326b841 | Christos Stathis | */
|
35 | 9326b841 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | 9326b841 | Christos Stathis | |
37 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
38 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FileVersions; |
39 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Version; |
40 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
41 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
42 | 9326b841 | Christos Stathis | |
43 | 9326b841 | Christos Stathis | import java.util.List; |
44 | 9326b841 | Christos Stathis | |
45 | 9326b841 | Christos Stathis | import com.google.gwt.core.client.GWT; |
46 | 9326b841 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
47 | 9326b841 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
48 | 9326b841 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
49 | 9326b841 | Christos Stathis | import com.google.gwt.http.client.Response; |
50 | 9326b841 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
51 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.Command; |
52 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
53 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
54 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.CheckBox; |
55 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.FocusPanel; |
56 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
57 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
58 | 9326b841 | Christos Stathis | |
59 | 9326b841 | Christos Stathis | /**
|
60 | 9326b841 | Christos Stathis | * The 'File properties' dialog box implementation.
|
61 | 9326b841 | Christos Stathis | *
|
62 | 9326b841 | Christos Stathis | */
|
63 | 9326b841 | Christos Stathis | public class FileVersionsDialog extends AbstractPropertiesDialog { |
64 | 9326b841 | Christos Stathis | |
65 | 9326b841 | Christos Stathis | /**
|
66 | 9326b841 | Christos Stathis | * An image bundle for this widgets images.
|
67 | 9326b841 | Christos Stathis | */
|
68 | 9326b841 | Christos Stathis | public interface Images extends MessagePanel.Images { |
69 | 9326b841 | Christos Stathis | |
70 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/edit_user.png") |
71 | 9326b841 | Christos Stathis | ImageResource permUser(); |
72 | 9326b841 | Christos Stathis | |
73 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
74 | 9326b841 | Christos Stathis | ImageResource permGroup(); |
75 | 9326b841 | Christos Stathis | |
76 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/editdelete.png") |
77 | 9326b841 | Christos Stathis | ImageResource delete(); |
78 | 9326b841 | Christos Stathis | |
79 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/db_update.png") |
80 | 9326b841 | Christos Stathis | ImageResource restore(); |
81 | 9326b841 | Christos Stathis | |
82 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_inbox.png") |
83 | 9326b841 | Christos Stathis | ImageResource download(); |
84 | 9326b841 | Christos Stathis | } |
85 | 9326b841 | Christos Stathis | |
86 | 9326b841 | Christos Stathis | final File file; |
87 | 9326b841 | Christos Stathis | |
88 | 9326b841 | Christos Stathis | Images images = GWT.create(Images.class); |
89 | 9326b841 | Christos Stathis | |
90 | 9326b841 | Christos Stathis | /**
|
91 | 9326b841 | Christos Stathis | * The widget's constructor.
|
92 | 9326b841 | Christos Stathis | */
|
93 | 9326b841 | Christos Stathis | public FileVersionsDialog(Pithos _app, File _file) { |
94 | 9326b841 | Christos Stathis | super(_app);
|
95 | 9326b841 | Christos Stathis | file = _file; |
96 | 9326b841 | Christos Stathis | |
97 | 9326b841 | Christos Stathis | Anchor close = new Anchor();
|
98 | 9326b841 | Christos Stathis | close.addStyleName("close");
|
99 | 9326b841 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
100 | 9326b841 | Christos Stathis | |
101 | 9326b841 | Christos Stathis | @Override
|
102 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
103 | 9326b841 | Christos Stathis | hide(); |
104 | 9326b841 | Christos Stathis | } |
105 | 9326b841 | Christos Stathis | }); |
106 | 9326b841 | Christos Stathis | // Set the dialog's caption.
|
107 | 9326b841 | Christos Stathis | setText("File versions");
|
108 | 9326b841 | Christos Stathis | setAnimationEnabled(true);
|
109 | 9326b841 | Christos Stathis | setGlassEnabled(true);
|
110 | 9326b841 | Christos Stathis | setStyleName("pithos-DialogBox");
|
111 | 9326b841 | Christos Stathis | |
112 | 9326b841 | Christos Stathis | // Outer contains inner and buttons.
|
113 | 9326b841 | Christos Stathis | final VerticalPanel outer = new VerticalPanel(); |
114 | 9326b841 | Christos Stathis | outer.add(close); |
115 | 9326b841 | Christos Stathis | final FocusPanel focusPanel = new FocusPanel(outer); |
116 | 9326b841 | Christos Stathis | // Inner contains generalPanel and permPanel.
|
117 | 9326b841 | Christos Stathis | inner = new VerticalPanel();
|
118 | 9326b841 | Christos Stathis | inner.addStyleName("inner");
|
119 | 9326b841 | Christos Stathis | |
120 | e9b8a745 | Christos Stathis | outer.add(inner); |
121 | 9326b841 | Christos Stathis | |
122 | 9326b841 | Christos Stathis | // Create the 'OK' button, along with a listener that hides the dialog
|
123 | 9326b841 | Christos Stathis | // when the button is clicked.
|
124 | 9326b841 | Christos Stathis | final Button ok = new Button("OK", new ClickHandler() { |
125 | 9326b841 | Christos Stathis | @Override
|
126 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
127 | 9326b841 | Christos Stathis | accept(); |
128 | 9326b841 | Christos Stathis | closeDialog(); |
129 | 9326b841 | Christos Stathis | } |
130 | 9326b841 | Christos Stathis | }); |
131 | 9326b841 | Christos Stathis | ok.addStyleName("button");
|
132 | 9326b841 | Christos Stathis | |
133 | 9326b841 | Christos Stathis | outer.add(ok); |
134 | 9326b841 | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
135 | 9326b841 | Christos Stathis | |
136 | 9326b841 | Christos Stathis | focusPanel.setFocus(true);
|
137 | 9326b841 | Christos Stathis | setWidget(outer); |
138 | 9326b841 | Christos Stathis | } |
139 | 9326b841 | Christos Stathis | |
140 | ae93aba1 | Christos Stathis | void doCenter() {
|
141 | e9b8a745 | Christos Stathis | super.center();
|
142 | e9b8a745 | Christos Stathis | } |
143 | e9b8a745 | Christos Stathis | |
144 | e9b8a745 | Christos Stathis | @Override
|
145 | e9b8a745 | Christos Stathis | public void center() { |
146 | e9b8a745 | Christos Stathis | fetchVersions(); |
147 | e9b8a745 | Christos Stathis | } |
148 | e9b8a745 | Christos Stathis | |
149 | 9326b841 | Christos Stathis | protected void fetchVersions() { |
150 | 9326b841 | Christos Stathis | String path = file.getUri() + "?format=json&version=list"; |
151 | 9326b841 | Christos Stathis | GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {
|
152 | 9326b841 | Christos Stathis | |
153 | 9326b841 | Christos Stathis | @Override
|
154 | 9326b841 | Christos Stathis | public void onSuccess(FileVersions _result) { |
155 | 9326b841 | Christos Stathis | inner.add(createVersionPanel(_result.getVersions())); |
156 | e9b8a745 | Christos Stathis | doCenter(); |
157 | 9326b841 | Christos Stathis | } |
158 | 9326b841 | Christos Stathis | |
159 | 9326b841 | Christos Stathis | @Override
|
160 | 9326b841 | Christos Stathis | public void onError(Throwable t) { |
161 | 9326b841 | Christos Stathis | GWT.log("", t);
|
162 | 9326b841 | Christos Stathis | app.setError(t); |
163 | 9326b841 | Christos Stathis | if (t instanceof RestException) { |
164 | 9326b841 | Christos Stathis | app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
|
165 | 9326b841 | Christos Stathis | } |
166 | 9326b841 | Christos Stathis | else
|
167 | 9326b841 | Christos Stathis | app.displayError("System error unable to fetch versions: "+t.getMessage());
|
168 | 9326b841 | Christos Stathis | } |
169 | 9326b841 | Christos Stathis | |
170 | 9326b841 | Christos Stathis | @Override
|
171 | ebead1b5 | Christos Stathis | protected void onUnauthorized(Response response) { |
172 | 9326b841 | Christos Stathis | app.sessionExpired(); |
173 | 9326b841 | Christos Stathis | } |
174 | 9326b841 | Christos Stathis | }; |
175 | 9326b841 | Christos Stathis | getVersions.setHeader("X-Auth-Token", app.getToken());
|
176 | 9326b841 | Christos Stathis | Scheduler.get().scheduleDeferred(getVersions); |
177 | 9326b841 | Christos Stathis | } |
178 | 9326b841 | Christos Stathis | |
179 | 9326b841 | Christos Stathis | VerticalPanel createVersionPanel(List<Version> versions) {
|
180 | 9326b841 | Christos Stathis | VerticalPanel versionPanel = new VerticalPanel();
|
181 | 9326b841 | Christos Stathis | VersionsList verList = new VersionsList(app, this, images, file, versions); |
182 | 9326b841 | Christos Stathis | versionPanel.add(verList); |
183 | 9326b841 | Christos Stathis | return versionPanel;
|
184 | 9326b841 | Christos Stathis | } |
185 | 9326b841 | Christos Stathis | |
186 | 9326b841 | Christos Stathis | /**
|
187 | 9326b841 | Christos Stathis | * Accepts any change and updates the file
|
188 | 9326b841 | Christos Stathis | *
|
189 | 9326b841 | Christos Stathis | */
|
190 | 9326b841 | Christos Stathis | @Override
|
191 | 9326b841 | Christos Stathis | protected void accept() { |
192 | 9326b841 | Christos Stathis | app.updateFolder(file.getParent(), true, new Command() { |
193 | 9326b841 | Christos Stathis | |
194 | 9326b841 | Christos Stathis | @Override
|
195 | 9326b841 | Christos Stathis | public void execute() { |
196 | 71875b42 | Christos Stathis | if (file.isSharedOrPublished())
|
197 | 9326b841 | Christos Stathis | app.updateMySharedRoot(); |
198 | 9326b841 | Christos Stathis | } |
199 | 6acd4df3 | Christos Stathis | }, true);
|
200 | ebead1b5 | Christos Stathis | } |
201 | 9326b841 | Christos Stathis | } |