Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.3 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
        protected PermissionsList permList;
66

    
67
        protected CheckBox readForAll;
68

    
69
        /**
70
         * An image bundle for this widgets images.
71
         */
72
        public interface Images extends MessagePanel.Images {
73

    
74
                @Source("gr/grnet/pithos/resources/edit_user.png")
75
                ImageResource permUser();
76

    
77
                @Source("gr/grnet/pithos/resources/groups22.png")
78
                ImageResource permGroup();
79

    
80
                @Source("gr/grnet/pithos/resources/editdelete.png")
81
                ImageResource delete();
82

    
83
                @Source("gr/grnet/pithos/resources/db_update.png")
84
                ImageResource restore();
85

    
86
                @Source("gr/grnet/pithos/resources/folder_inbox.png")
87
                ImageResource download();
88
        }
89

    
90
        final File file;
91

    
92
    Images images = GWT.create(Images.class);
93

    
94
        /**
95
         * The widget's constructor.
96
         */
97
        public FileVersionsDialog(Pithos _app, File _file) {
98
        super(_app);
99
        file = _file;
100

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

    
116
                // Outer contains inner and buttons.
117
                final VerticalPanel outer = new VerticalPanel();
118
                outer.add(close);
119
                final FocusPanel focusPanel = new FocusPanel(outer);
120
                // Inner contains generalPanel and permPanel.
121
                inner = new VerticalPanel();
122
                inner.addStyleName("inner");
123

    
124
                fetchVersions();
125

    
126
                outer.add(inner);
127

    
128
                // Create the 'OK' button, along with a listener that hides the dialog
129
                // when the button is clicked.
130
                final Button ok = new Button("OK", new ClickHandler() {
131
                        @Override
132
                        public void onClick(ClickEvent event) {
133
                                accept();
134
                                closeDialog();
135
                        }
136
                });
137
                ok.addStyleName("button");
138

    
139
        outer.add(ok);
140
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
141

    
142
        focusPanel.setFocus(true);
143
        setWidget(outer);
144
        }
145

    
146
        void doCenter() {
147
                super.center();
148
        }
149
        
150
        @Override
151
        public void center() {
152
                fetchVersions();
153
        }
154

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

    
159
                        @Override
160
                        public void onSuccess(FileVersions _result) {
161
                        inner.add(createVersionPanel(_result.getVersions()));
162
                                doCenter();
163
                        }
164

    
165
                        @Override
166
                        public void onError(Throwable t) {
167
                                GWT.log("", t);
168
                                app.setError(t);
169
                if (t instanceof RestException) {
170
                    app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
171
                }
172
                else
173
                    app.displayError("System error unable to fetch versions: "+t.getMessage());
174
                        }
175

    
176
                        @Override
177
                        protected void onUnauthorized(Response response) {
178
                                app.sessionExpired();
179
                        }
180
                };
181
                getVersions.setHeader("X-Auth-Token", app.getToken());
182
                Scheduler.get().scheduleDeferred(getVersions);
183
        }
184

    
185
    VerticalPanel createVersionPanel(List<Version> versions) {
186
        VerticalPanel versionPanel = new VerticalPanel();
187
        VersionsList verList = new VersionsList(app, this, images, file, versions);
188
        versionPanel.add(verList);
189
        return versionPanel;
190
    }
191

    
192
        /**
193
         * Accepts any change and updates the file
194
         *
195
         */
196
        @Override
197
        protected void accept() {
198
        app.updateFolder(file.getParent(), true, new Command() {
199
                        
200
                        @Override
201
                        public void execute() {
202
                                if (file.isShared())
203
                                        app.updateMySharedRoot();
204
                        }
205
                });
206
        }
207
}