Statistics
| Branch: | Tag: | Revision:

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

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.CheckBox;
55
import com.google.gwt.user.client.ui.FocusPanel;
56
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
57
import com.google.gwt.user.client.ui.VerticalPanel;
58

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

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

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

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

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

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

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

    
86
        final File file;
87

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

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

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

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

    
120
                outer.add(inner);
121

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

    
133
        outer.add(ok);
134
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
135

    
136
        focusPanel.setFocus(true);
137
        setWidget(outer);
138
        }
139

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

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

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

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

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

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

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