root / src / gr / grnet / pithos / web / client / FileVersionsDialog.java @ e6e9f6e6
History | View | Annotate | Download (6.2 kB)
1 | 9326b841 | Christos Stathis | /*
|
---|---|---|---|
2 | e6e9f6e6 | Christos KK Loverdos | * Copyright 2011-2013 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.FocusPanel; |
55 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
56 | 9326b841 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
57 | 9326b841 | Christos Stathis | |
58 | 9326b841 | Christos Stathis | /**
|
59 | 9326b841 | Christos Stathis | * The 'File properties' dialog box implementation.
|
60 | 9326b841 | Christos Stathis | *
|
61 | 9326b841 | Christos Stathis | */
|
62 | 9326b841 | Christos Stathis | public class FileVersionsDialog extends AbstractPropertiesDialog { |
63 | 9326b841 | Christos Stathis | |
64 | 9326b841 | Christos Stathis | /**
|
65 | 9326b841 | Christos Stathis | * An image bundle for this widgets images.
|
66 | 9326b841 | Christos Stathis | */
|
67 | 9326b841 | Christos Stathis | public interface Images extends MessagePanel.Images { |
68 | 9326b841 | Christos Stathis | |
69 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/edit_user.png") |
70 | 9326b841 | Christos Stathis | ImageResource permUser(); |
71 | 9326b841 | Christos Stathis | |
72 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
73 | 9326b841 | Christos Stathis | ImageResource permGroup(); |
74 | 9326b841 | Christos Stathis | |
75 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/editdelete.png") |
76 | 9326b841 | Christos Stathis | ImageResource delete(); |
77 | 9326b841 | Christos Stathis | |
78 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/db_update.png") |
79 | 9326b841 | Christos Stathis | ImageResource restore(); |
80 | 9326b841 | Christos Stathis | |
81 | 9326b841 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_inbox.png") |
82 | 9326b841 | Christos Stathis | ImageResource download(); |
83 | 9326b841 | Christos Stathis | } |
84 | 9326b841 | Christos Stathis | |
85 | 9326b841 | Christos Stathis | final File file; |
86 | 9326b841 | Christos Stathis | |
87 | 9326b841 | Christos Stathis | Images images = GWT.create(Images.class); |
88 | 9326b841 | Christos Stathis | |
89 | 9326b841 | Christos Stathis | /**
|
90 | 9326b841 | Christos Stathis | * The widget's constructor.
|
91 | 9326b841 | Christos Stathis | */
|
92 | 9326b841 | Christos Stathis | public FileVersionsDialog(Pithos _app, File _file) { |
93 | 9326b841 | Christos Stathis | super(_app);
|
94 | 9326b841 | Christos Stathis | file = _file; |
95 | 9326b841 | Christos Stathis | |
96 | 96705b13 | Christos Stathis | Anchor close = new Anchor("close"); |
97 | 9326b841 | Christos Stathis | close.addStyleName("close");
|
98 | 9326b841 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
99 | 9326b841 | Christos Stathis | |
100 | 9326b841 | Christos Stathis | @Override
|
101 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
102 | 9326b841 | Christos Stathis | hide(); |
103 | 9326b841 | Christos Stathis | } |
104 | 9326b841 | Christos Stathis | }); |
105 | 9326b841 | Christos Stathis | // Set the dialog's caption.
|
106 | 9326b841 | Christos Stathis | setText("File versions");
|
107 | 9326b841 | Christos Stathis | setGlassEnabled(true);
|
108 | 9326b841 | Christos Stathis | setStyleName("pithos-DialogBox");
|
109 | 9326b841 | Christos Stathis | |
110 | 9326b841 | Christos Stathis | // Outer contains inner and buttons.
|
111 | 9326b841 | Christos Stathis | final VerticalPanel outer = new VerticalPanel(); |
112 | 9326b841 | Christos Stathis | outer.add(close); |
113 | 9326b841 | Christos Stathis | final FocusPanel focusPanel = new FocusPanel(outer); |
114 | 9326b841 | Christos Stathis | // Inner contains generalPanel and permPanel.
|
115 | 9326b841 | Christos Stathis | inner = new VerticalPanel();
|
116 | 9326b841 | Christos Stathis | inner.addStyleName("inner");
|
117 | 9326b841 | Christos Stathis | |
118 | e9b8a745 | Christos Stathis | outer.add(inner); |
119 | 9326b841 | Christos Stathis | |
120 | 9326b841 | Christos Stathis | // Create the 'OK' button, along with a listener that hides the dialog
|
121 | 9326b841 | Christos Stathis | // when the button is clicked.
|
122 | 9326b841 | Christos Stathis | final Button ok = new Button("OK", new ClickHandler() { |
123 | 9326b841 | Christos Stathis | @Override
|
124 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
125 | 9326b841 | Christos Stathis | accept(); |
126 | 9326b841 | Christos Stathis | closeDialog(); |
127 | 9326b841 | Christos Stathis | } |
128 | 9326b841 | Christos Stathis | }); |
129 | 9326b841 | Christos Stathis | ok.addStyleName("button");
|
130 | 9326b841 | Christos Stathis | |
131 | 9326b841 | Christos Stathis | outer.add(ok); |
132 | 9326b841 | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
133 | 9326b841 | Christos Stathis | |
134 | 9326b841 | Christos Stathis | focusPanel.setFocus(true);
|
135 | 9326b841 | Christos Stathis | setWidget(outer); |
136 | 9326b841 | Christos Stathis | } |
137 | 9326b841 | Christos Stathis | |
138 | ae93aba1 | Christos Stathis | void doCenter() {
|
139 | e9b8a745 | Christos Stathis | super.center();
|
140 | e9b8a745 | Christos Stathis | } |
141 | e9b8a745 | Christos Stathis | |
142 | e9b8a745 | Christos Stathis | @Override
|
143 | e9b8a745 | Christos Stathis | public void center() { |
144 | e9b8a745 | Christos Stathis | fetchVersions(); |
145 | e9b8a745 | Christos Stathis | } |
146 | e9b8a745 | Christos Stathis | |
147 | 9326b841 | Christos Stathis | protected void fetchVersions() { |
148 | 9326b841 | Christos Stathis | String path = file.getUri() + "?format=json&version=list"; |
149 | dc8cc18a | Christos KK Loverdos | GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwnerID(), path) {
|
150 | 9326b841 | Christos Stathis | |
151 | 9326b841 | Christos Stathis | @Override
|
152 | 9326b841 | Christos Stathis | public void onSuccess(FileVersions _result) { |
153 | 9326b841 | Christos Stathis | inner.add(createVersionPanel(_result.getVersions())); |
154 | e9b8a745 | Christos Stathis | doCenter(); |
155 | 9326b841 | Christos Stathis | } |
156 | 9326b841 | Christos Stathis | |
157 | 9326b841 | Christos Stathis | @Override
|
158 | 9326b841 | Christos Stathis | public void onError(Throwable t) { |
159 | 9326b841 | Christos Stathis | GWT.log("", t);
|
160 | 9326b841 | Christos Stathis | app.setError(t); |
161 | 9326b841 | Christos Stathis | if (t instanceof RestException) { |
162 | 9326b841 | Christos Stathis | app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
|
163 | 9326b841 | Christos Stathis | } |
164 | 9326b841 | Christos Stathis | else
|
165 | 9326b841 | Christos Stathis | app.displayError("System error unable to fetch versions: "+t.getMessage());
|
166 | 9326b841 | Christos Stathis | } |
167 | 9326b841 | Christos Stathis | |
168 | 9326b841 | Christos Stathis | @Override
|
169 | ebead1b5 | Christos Stathis | protected void onUnauthorized(Response response) { |
170 | 9326b841 | Christos Stathis | app.sessionExpired(); |
171 | 9326b841 | Christos Stathis | } |
172 | 9326b841 | Christos Stathis | }; |
173 | cc0120ab | Christos KK Loverdos | getVersions.setHeader("X-Auth-Token", app.getUserToken());
|
174 | 9326b841 | Christos Stathis | Scheduler.get().scheduleDeferred(getVersions); |
175 | 9326b841 | Christos Stathis | } |
176 | 9326b841 | Christos Stathis | |
177 | 9326b841 | Christos Stathis | VerticalPanel createVersionPanel(List<Version> versions) {
|
178 | 9326b841 | Christos Stathis | VerticalPanel versionPanel = new VerticalPanel();
|
179 | 9326b841 | Christos Stathis | VersionsList verList = new VersionsList(app, this, images, file, versions); |
180 | 9326b841 | Christos Stathis | versionPanel.add(verList); |
181 | 9326b841 | Christos Stathis | return versionPanel;
|
182 | 9326b841 | Christos Stathis | } |
183 | 9326b841 | Christos Stathis | |
184 | 9326b841 | Christos Stathis | /**
|
185 | 9326b841 | Christos Stathis | * Accepts any change and updates the file
|
186 | 0099339a | Christos Stathis | * @return
|
187 | 9326b841 | Christos Stathis | *
|
188 | 9326b841 | Christos Stathis | */
|
189 | 9326b841 | Christos Stathis | @Override
|
190 | 0099339a | Christos Stathis | protected boolean accept() { |
191 | 9326b841 | Christos Stathis | app.updateFolder(file.getParent(), true, new Command() { |
192 | 9326b841 | Christos Stathis | |
193 | 9326b841 | Christos Stathis | @Override
|
194 | 9326b841 | Christos Stathis | public void execute() { |
195 | 71875b42 | Christos Stathis | if (file.isSharedOrPublished())
|
196 | 9326b841 | Christos Stathis | app.updateMySharedRoot(); |
197 | 9326b841 | Christos Stathis | } |
198 | 6acd4df3 | Christos Stathis | }, true);
|
199 | 0099339a | Christos Stathis | |
200 | 0099339a | Christos Stathis | return true; |
201 | ebead1b5 | Christos Stathis | } |
202 | 9326b841 | Christos Stathis | } |