Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.2 kB)

1
/*
2
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.foldertree.File;
38
import gr.grnet.pithos.web.client.foldertree.FileVersions;
39
import gr.grnet.pithos.web.client.foldertree.Version;
40
import gr.grnet.pithos.web.client.rest.GetRequest;
41
import gr.grnet.pithos.web.client.rest.RestException;
42

    
43
import java.util.List;
44

    
45
import com.google.gwt.core.client.GWT;
46
import com.google.gwt.core.client.Scheduler;
47
import com.google.gwt.event.dom.client.ClickEvent;
48
import com.google.gwt.event.dom.client.ClickHandler;
49
import com.google.gwt.http.client.Response;
50
import com.google.gwt.resources.client.ImageResource;
51
import com.google.gwt.user.client.Command;
52
import com.google.gwt.user.client.ui.Anchor;
53
import com.google.gwt.user.client.ui.Button;
54
import com.google.gwt.user.client.ui.FocusPanel;
55
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
56
import com.google.gwt.user.client.ui.VerticalPanel;
57

    
58
/**
59
 * The 'File properties' dialog box implementation.
60
 *
61
 */
62
public class FileVersionsDialog extends AbstractPropertiesDialog {
63

    
64
        /**
65
         * An image bundle for this widgets images.
66
         */
67
        public interface Images extends MessagePanel.Images {
68

    
69
                @Source("gr/grnet/pithos/resources/edit_user.png")
70
                ImageResource permUser();
71

    
72
                @Source("gr/grnet/pithos/resources/groups22.png")
73
                ImageResource permGroup();
74

    
75
                @Source("gr/grnet/pithos/resources/editdelete.png")
76
                ImageResource delete();
77

    
78
                @Source("gr/grnet/pithos/resources/db_update.png")
79
                ImageResource restore();
80

    
81
                @Source("gr/grnet/pithos/resources/folder_inbox.png")
82
                ImageResource download();
83
        }
84

    
85
        final File file;
86

    
87
    Images images = GWT.create(Images.class);
88

    
89
        /**
90
         * The widget's constructor.
91
         */
92
        public FileVersionsDialog(Pithos _app, File _file) {
93
        super(_app);
94
        file = _file;
95

    
96
                Anchor close = new Anchor("close");
97
                close.addStyleName("close");
98
                close.addClickHandler(new ClickHandler() {
99
                        
100
                        @Override
101
                        public void onClick(ClickEvent event) {
102
                                hide();
103
                        }
104
                });
105
                // Set the dialog's caption.
106
                setText("File versions");
107
                setGlassEnabled(true);
108
                setStyleName("pithos-DialogBox");
109

    
110
                // Outer contains inner and buttons.
111
                final VerticalPanel outer = new VerticalPanel();
112
                outer.add(close);
113
                final FocusPanel focusPanel = new FocusPanel(outer);
114
                // Inner contains generalPanel and permPanel.
115
                inner = new VerticalPanel();
116
                inner.addStyleName("inner");
117

    
118
                outer.add(inner);
119

    
120
                // Create the 'OK' button, along with a listener that hides the dialog
121
                // when the button is clicked.
122
                final Button ok = new Button("OK", new ClickHandler() {
123
                        @Override
124
                        public void onClick(ClickEvent event) {
125
                                accept();
126
                                closeDialog();
127
                        }
128
                });
129
                ok.addStyleName("button");
130

    
131
        outer.add(ok);
132
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
133

    
134
        focusPanel.setFocus(true);
135
        setWidget(outer);
136
        }
137

    
138
        void doCenter() {
139
                super.center();
140
        }
141
        
142
        @Override
143
        public void center() {
144
                fetchVersions();
145
        }
146

    
147
    protected void fetchVersions() {
148
            String path = file.getUri() + "?format=json&version=list";
149
            GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {
150

    
151
                        @Override
152
                        public void onSuccess(FileVersions _result) {
153
                        inner.add(createVersionPanel(_result.getVersions()));
154
                                doCenter();
155
                        }
156

    
157
                        @Override
158
                        public void onError(Throwable t) {
159
                                GWT.log("", t);
160
                                app.setError(t);
161
                if (t instanceof RestException) {
162
                    app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
163
                }
164
                else
165
                    app.displayError("System error unable to fetch versions: "+t.getMessage());
166
                        }
167

    
168
                        @Override
169
                        protected void onUnauthorized(Response response) {
170
                                app.sessionExpired();
171
                        }
172
                };
173
                getVersions.setHeader("X-Auth-Token", app.getUserToken());
174
                Scheduler.get().scheduleDeferred(getVersions);
175
        }
176

    
177
    VerticalPanel createVersionPanel(List<Version> versions) {
178
        VerticalPanel versionPanel = new VerticalPanel();
179
        VersionsList verList = new VersionsList(app, this, images, file, versions);
180
        versionPanel.add(verList);
181
        return versionPanel;
182
    }
183

    
184
        /**
185
         * Accepts any change and updates the file
186
         * @return 
187
         *
188
         */
189
        @Override
190
        protected boolean accept() {
191
        app.updateFolder(file.getParent(), true, new Command() {
192
                        
193
                        @Override
194
                        public void execute() {
195
                                if (file.isSharedOrPublished())
196
                                        app.updateMySharedRoot();
197
                        }
198
                }, true);
199
        
200
        return true;
201
        }
202
}