2 * Copyright 2011 GRNET S.A. All rights reserved.
\r
4 * Redistribution and use in source and binary forms, with or
\r
5 * without modification, are permitted provided that the following
\r
6 * conditions are met:
\r
8 * 1. Redistributions of source code must retain the above
\r
9 * copyright notice, this list of conditions and the following
\r
12 * 2. Redistributions in binary form must reproduce the above
\r
13 * copyright notice, this list of conditions and the following
\r
14 * disclaimer in the documentation and/or other materials
\r
15 * provided with the distribution.
\r
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
28 * POSSIBILITY OF SUCH DAMAGE.
\r
30 * The views and conclusions contained in the software and
\r
31 * documentation are those of the authors and should not be
\r
32 * interpreted as representing official policies, either expressed
\r
33 * or implied, of GRNET S.A.
\r
35 package gr.grnet.pithos.web.client;
\r
37 import gr.grnet.pithos.web.client.foldertree.File;
\r
38 import gr.grnet.pithos.web.client.foldertree.FileVersions;
\r
39 import gr.grnet.pithos.web.client.foldertree.Resource;
\r
40 import gr.grnet.pithos.web.client.foldertree.Version;
\r
41 import gr.grnet.pithos.web.client.rest.GetRequest;
\r
42 import gr.grnet.pithos.web.client.rest.PostRequest;
\r
43 import gr.grnet.pithos.web.client.rest.PutRequest;
\r
44 import gr.grnet.pithos.web.client.rest.RestException;
\r
46 import java.util.HashMap;
\r
47 import java.util.List;
\r
48 import java.util.Map;
\r
50 import com.google.gwt.core.client.GWT;
\r
51 import com.google.gwt.core.client.Scheduler;
\r
52 import com.google.gwt.event.dom.client.ClickEvent;
\r
53 import com.google.gwt.event.dom.client.ClickHandler;
\r
54 import com.google.gwt.http.client.Response;
\r
55 import com.google.gwt.http.client.URL;
\r
56 import com.google.gwt.resources.client.ImageResource;
\r
57 import com.google.gwt.user.client.Command;
\r
58 import com.google.gwt.user.client.ui.Anchor;
\r
59 import com.google.gwt.user.client.ui.Button;
\r
60 import com.google.gwt.user.client.ui.CheckBox;
\r
61 import com.google.gwt.user.client.ui.DecoratedTabPanel;
\r
62 import com.google.gwt.user.client.ui.FocusPanel;
\r
63 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
64 import com.google.gwt.user.client.ui.TextBox;
\r
65 import com.google.gwt.user.client.ui.VerticalPanel;
\r
68 * The 'File properties' dialog box implementation.
\r
71 public class FileVersionsDialog extends AbstractPropertiesDialog {
\r
73 protected PermissionsList permList;
\r
75 protected CheckBox readForAll;
\r
78 * An image bundle for this widgets images.
\r
80 public interface Images extends MessagePanel.Images {
\r
82 @Source("gr/grnet/pithos/resources/edit_user.png")
\r
83 ImageResource permUser();
\r
85 @Source("gr/grnet/pithos/resources/groups22.png")
\r
86 ImageResource permGroup();
\r
88 @Source("gr/grnet/pithos/resources/editdelete.png")
\r
89 ImageResource delete();
\r
91 @Source("gr/grnet/pithos/resources/db_update.png")
\r
92 ImageResource restore();
\r
94 @Source("gr/grnet/pithos/resources/folder_inbox.png")
\r
95 ImageResource download();
\r
100 Images images = GWT.create(Images.class);
\r
103 * The widget's constructor.
\r
105 public FileVersionsDialog(Pithos _app, File _file) {
\r
109 Anchor close = new Anchor();
\r
110 close.addStyleName("close");
\r
111 close.addClickHandler(new ClickHandler() {
\r
114 public void onClick(@SuppressWarnings("unused") ClickEvent event) {
\r
118 // Set the dialog's caption.
\r
119 setText("File versions");
\r
120 setAnimationEnabled(true);
\r
121 setGlassEnabled(true);
\r
122 setStyleName("pithos-DialogBox");
\r
124 // Outer contains inner and buttons.
\r
125 final VerticalPanel outer = new VerticalPanel();
\r
127 final FocusPanel focusPanel = new FocusPanel(outer);
\r
128 // Inner contains generalPanel and permPanel.
\r
129 inner = new VerticalPanel();
\r
130 inner.addStyleName("inner");
\r
136 // Create the 'OK' button, along with a listener that hides the dialog
\r
137 // when the button is clicked.
\r
138 final Button ok = new Button("OK", new ClickHandler() {
\r
140 public void onClick(@SuppressWarnings("unused") ClickEvent event) {
\r
145 ok.addStyleName("button");
\r
148 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
\r
150 focusPanel.setFocus(true);
\r
154 protected void fetchVersions() {
\r
155 String path = file.getUri() + "?format=json&version=list";
\r
156 GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {
\r
159 public void onSuccess(FileVersions _result) {
\r
160 inner.add(createVersionPanel(_result.getVersions()));
\r
164 public void onError(Throwable t) {
\r
167 if (t instanceof RestException) {
\r
168 app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
\r
171 app.displayError("System error unable to fetch versions: "+t.getMessage());
\r
175 protected void onUnauthorized(@SuppressWarnings("unused") Response response) {
\r
176 app.sessionExpired();
\r
179 getVersions.setHeader("X-Auth-Token", app.getToken());
\r
180 Scheduler.get().scheduleDeferred(getVersions);
\r
183 VerticalPanel createVersionPanel(List<Version> versions) {
\r
184 VerticalPanel versionPanel = new VerticalPanel();
\r
185 VersionsList verList = new VersionsList(app, this, images, file, versions);
\r
186 versionPanel.add(verList);
\r
187 return versionPanel;
\r
191 * Accepts any change and updates the file
\r
195 protected void accept() {
\r
196 updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=");
\r
199 protected void updateMetaData(String api, String owner, String path) {
\r
200 app.updateFolder(file.getParent(), true, new Command() {
\r
203 public void execute() {
\r
204 if (file.isShared())
\r
205 app.updateMySharedRoot();
\r