root / src / gr / grnet / pithos / web / client / FileVersionsDialog.java @ 28267d27
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("close"); |
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 |
setGlassEnabled(true);
|
109 |
setStyleName("pithos-DialogBox");
|
110 |
|
111 |
// Outer contains inner and buttons.
|
112 |
final VerticalPanel outer = new VerticalPanel(); |
113 |
outer.add(close); |
114 |
final FocusPanel focusPanel = new FocusPanel(outer); |
115 |
// Inner contains generalPanel and permPanel.
|
116 |
inner = new VerticalPanel();
|
117 |
inner.addStyleName("inner");
|
118 |
|
119 |
outer.add(inner); |
120 |
|
121 |
// Create the 'OK' button, along with a listener that hides the dialog
|
122 |
// when the button is clicked.
|
123 |
final Button ok = new Button("OK", new ClickHandler() { |
124 |
@Override
|
125 |
public void onClick(ClickEvent event) { |
126 |
accept(); |
127 |
closeDialog(); |
128 |
} |
129 |
}); |
130 |
ok.addStyleName("button");
|
131 |
|
132 |
outer.add(ok); |
133 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
134 |
|
135 |
focusPanel.setFocus(true);
|
136 |
setWidget(outer); |
137 |
} |
138 |
|
139 |
void doCenter() {
|
140 |
super.center();
|
141 |
} |
142 |
|
143 |
@Override
|
144 |
public void center() { |
145 |
fetchVersions(); |
146 |
} |
147 |
|
148 |
protected void fetchVersions() { |
149 |
String path = file.getUri() + "?format=json&version=list"; |
150 |
GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {
|
151 |
|
152 |
@Override
|
153 |
public void onSuccess(FileVersions _result) { |
154 |
inner.add(createVersionPanel(_result.getVersions())); |
155 |
doCenter(); |
156 |
} |
157 |
|
158 |
@Override
|
159 |
public void onError(Throwable t) { |
160 |
GWT.log("", t);
|
161 |
app.setError(t); |
162 |
if (t instanceof RestException) { |
163 |
app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());
|
164 |
} |
165 |
else
|
166 |
app.displayError("System error unable to fetch versions: "+t.getMessage());
|
167 |
} |
168 |
|
169 |
@Override
|
170 |
protected void onUnauthorized(Response response) { |
171 |
app.sessionExpired(); |
172 |
} |
173 |
}; |
174 |
getVersions.setHeader("X-Auth-Token", app.getToken());
|
175 |
Scheduler.get().scheduleDeferred(getVersions); |
176 |
} |
177 |
|
178 |
VerticalPanel createVersionPanel(List<Version> versions) {
|
179 |
VerticalPanel versionPanel = new VerticalPanel();
|
180 |
VersionsList verList = new VersionsList(app, this, images, file, versions); |
181 |
versionPanel.add(verList); |
182 |
return versionPanel;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Accepts any change and updates the file
|
187 |
* @return
|
188 |
*
|
189 |
*/
|
190 |
@Override
|
191 |
protected boolean accept() { |
192 |
app.updateFolder(file.getParent(), true, new Command() { |
193 |
|
194 |
@Override
|
195 |
public void execute() { |
196 |
if (file.isSharedOrPublished())
|
197 |
app.updateMySharedRoot(); |
198 |
} |
199 |
}, true);
|
200 |
|
201 |
return true; |
202 |
} |
203 |
} |