Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.2 kB)

1
/*
2
 * Copyright 2011 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
    protected void fetchVersions() {
147
            String path = file.getUri() + "?format=json&version=list";
148
            GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {
149

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

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

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

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

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