Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FileVersionsDialog.java @ a2f617f8

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