Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FileList.java @ 10791b56

History | View | Annotate | Download (19.3 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 6dd67d1c Christos Stathis
36 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client;
37 ab1eb3f8 Christos Stathis
38 fbff60ff Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
39 fbff60ff Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
40 fbff60ff Christos Stathis
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
41 ab1eb3f8 Christos Stathis
42 ab1eb3f8 Christos Stathis
import java.util.ArrayList;
43 ab1eb3f8 Christos Stathis
import java.util.Collections;
44 ab1eb3f8 Christos Stathis
import java.util.Comparator;
45 ab1eb3f8 Christos Stathis
import java.util.Iterator;
46 ab1eb3f8 Christos Stathis
import java.util.List;
47 ab1eb3f8 Christos Stathis
48 ab1eb3f8 Christos Stathis
import com.google.gwt.cell.client.ImageResourceCell;
49 ab1eb3f8 Christos Stathis
import com.google.gwt.cell.client.SafeHtmlCell;
50 ab1eb3f8 Christos Stathis
import com.google.gwt.cell.client.TextCell;
51 ab1eb3f8 Christos Stathis
import com.google.gwt.cell.client.ValueUpdater;
52 ab1eb3f8 Christos Stathis
import com.google.gwt.core.client.GWT;
53 10791b56 Christos Stathis
import com.google.gwt.event.dom.client.ContextMenuEvent;
54 10791b56 Christos Stathis
import com.google.gwt.event.dom.client.ContextMenuHandler;
55 ab1eb3f8 Christos Stathis
import com.google.gwt.i18n.client.DateTimeFormat;
56 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
57 ab1eb3f8 Christos Stathis
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
58 ab1eb3f8 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtml;
59 ab1eb3f8 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
60 ab1eb3f8 Christos Stathis
import com.google.gwt.user.cellview.client.CellTable;
61 10791b56 Christos Stathis
import com.google.gwt.user.cellview.client.Column;
62 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.Event;
63 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
64 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
65 ab1eb3f8 Christos Stathis
import com.google.gwt.view.client.ListDataProvider;
66 ab1eb3f8 Christos Stathis
import com.google.gwt.view.client.MultiSelectionModel;
67 ab1eb3f8 Christos Stathis
import com.google.gwt.view.client.ProvidesKey;
68 ab1eb3f8 Christos Stathis
69 ab1eb3f8 Christos Stathis
/**
70 ab1eb3f8 Christos Stathis
 * A composite that displays the list of files in a particular folder.
71 ab1eb3f8 Christos Stathis
 */
72 ab1eb3f8 Christos Stathis
public class FileList extends Composite {
73 fbff60ff Christos Stathis
74 fbff60ff Christos Stathis
        ListDataProvider<File> provider = new ListDataProvider<File>();
75 fbff60ff Christos Stathis
76 fbff60ff Christos Stathis
    /**
77 fbff60ff Christos Stathis
       * The styles applied to the table.
78 fbff60ff Christos Stathis
       */
79 fbff60ff Christos Stathis
    interface TableStyle extends CellTable.Style {
80 fbff60ff Christos Stathis
    }
81 fbff60ff Christos Stathis
82 7ed6977e Christos Stathis
        interface TableResources extends CellTable.Resources {
83 10791b56 Christos Stathis
            @Override
84 10791b56 Christos Stathis
                @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
85 ab1eb3f8 Christos Stathis
            TableStyle cellTableStyle();
86 fbff60ff Christos Stathis
        }
87 ab1eb3f8 Christos Stathis
        
88 ab1eb3f8 Christos Stathis
        static interface Templates extends SafeHtmlTemplates {
89 ab1eb3f8 Christos Stathis
            Templates INSTANCE = GWT.create(Templates.class);
90 ab1eb3f8 Christos Stathis
91 ab1eb3f8 Christos Stathis
            @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
92 ab1eb3f8 Christos Stathis
            SafeHtml outerHelper();
93 ab1eb3f8 Christos Stathis
94 ab1eb3f8 Christos Stathis
        @Template("<span id='{0}'>{0}</span>")
95 ab1eb3f8 Christos Stathis
        public SafeHtml filenameSpan(String filename);
96 ab1eb3f8 Christos Stathis
97 ab1eb3f8 Christos Stathis
        @Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>")
98 ab1eb3f8 Christos Stathis
        public SafeHtml viewLink(String link, String title);
99 ab1eb3f8 Christos Stathis
100 ab1eb3f8 Christos Stathis
        @Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>")
101 ab1eb3f8 Christos Stathis
        public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize);
102 ab1eb3f8 Christos Stathis
103 ab1eb3f8 Christos Stathis
        @Template("<span id='{0}' class='{1}'>{2}</span>")
104 ab1eb3f8 Christos Stathis
        public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
105 fbff60ff Christos Stathis
        }
106 ab1eb3f8 Christos Stathis
107 10791b56 Christos Stathis
        protected final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
108 ab1eb3f8 Christos Stathis
109 ab1eb3f8 Christos Stathis
        /**
110 ab1eb3f8 Christos Stathis
         * Specifies that the images available for this composite will be the ones
111 ab1eb3f8 Christos Stathis
         * available in FileContextMenu.
112 ab1eb3f8 Christos Stathis
         */
113 10791b56 Christos Stathis
        public interface Images extends FolderTreeView.Images {
114 ab1eb3f8 Christos Stathis
115 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/blank.gif")
116 ab1eb3f8 Christos Stathis
                ImageResource blank();
117 ab1eb3f8 Christos Stathis
118 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/asc.png")
119 ab1eb3f8 Christos Stathis
                ImageResource asc();
120 ab1eb3f8 Christos Stathis
121 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/desc.png")
122 ab1eb3f8 Christos Stathis
                ImageResource desc();
123 ab1eb3f8 Christos Stathis
124 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
125 ab1eb3f8 Christos Stathis
                ImageResource documentShared();
126 ab1eb3f8 Christos Stathis
127 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
128 ab1eb3f8 Christos Stathis
                ImageResource wordprocessor();
129 ab1eb3f8 Christos Stathis
130 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/log.png")
131 ab1eb3f8 Christos Stathis
                ImageResource spreadsheet();
132 ab1eb3f8 Christos Stathis
133 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
134 ab1eb3f8 Christos Stathis
                ImageResource presentation();
135 ab1eb3f8 Christos Stathis
136 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
137 ab1eb3f8 Christos Stathis
                ImageResource pdf();
138 ab1eb3f8 Christos Stathis
139 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/image.png")
140 ab1eb3f8 Christos Stathis
                ImageResource image();
141 ab1eb3f8 Christos Stathis
142 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
143 ab1eb3f8 Christos Stathis
                ImageResource video();
144 ab1eb3f8 Christos Stathis
145 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
146 ab1eb3f8 Christos Stathis
                ImageResource audio();
147 ab1eb3f8 Christos Stathis
148 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/html.png")
149 ab1eb3f8 Christos Stathis
                ImageResource html();
150 ab1eb3f8 Christos Stathis
151 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
152 ab1eb3f8 Christos Stathis
                ImageResource txt();
153 ab1eb3f8 Christos Stathis
154 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
155 ab1eb3f8 Christos Stathis
                ImageResource zip();
156 ab1eb3f8 Christos Stathis
157 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
158 ab1eb3f8 Christos Stathis
                ImageResource wordprocessorShared();
159 ab1eb3f8 Christos Stathis
160 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
161 ab1eb3f8 Christos Stathis
                ImageResource spreadsheetShared();
162 ab1eb3f8 Christos Stathis
163 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
164 ab1eb3f8 Christos Stathis
                ImageResource presentationShared();
165 ab1eb3f8 Christos Stathis
166 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
167 ab1eb3f8 Christos Stathis
                ImageResource pdfShared();
168 ab1eb3f8 Christos Stathis
169 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
170 ab1eb3f8 Christos Stathis
                ImageResource imageShared();
171 ab1eb3f8 Christos Stathis
172 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
173 ab1eb3f8 Christos Stathis
                ImageResource videoShared();
174 ab1eb3f8 Christos Stathis
175 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
176 ab1eb3f8 Christos Stathis
                ImageResource audioShared();
177 ab1eb3f8 Christos Stathis
178 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
179 ab1eb3f8 Christos Stathis
                ImageResource htmlShared();
180 ab1eb3f8 Christos Stathis
181 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
182 ab1eb3f8 Christos Stathis
                ImageResource txtShared();
183 ab1eb3f8 Christos Stathis
184 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
185 ab1eb3f8 Christos Stathis
                ImageResource zipShared();
186 ab1eb3f8 Christos Stathis
187 ab1eb3f8 Christos Stathis
        }
188 ab1eb3f8 Christos Stathis
        
189 ab1eb3f8 Christos Stathis
        /**
190 ab1eb3f8 Christos Stathis
         * The number of files in this folder.
191 ab1eb3f8 Christos Stathis
         */
192 ab1eb3f8 Christos Stathis
        int folderFileCount;
193 ab1eb3f8 Christos Stathis
194 ab1eb3f8 Christos Stathis
        /**
195 ab1eb3f8 Christos Stathis
         * Total folder size
196 ab1eb3f8 Christos Stathis
         */
197 ab1eb3f8 Christos Stathis
        long folderTotalSize;
198 ab1eb3f8 Christos Stathis
199 ab1eb3f8 Christos Stathis
        /**
200 ab1eb3f8 Christos Stathis
         * A cache of the files in the list.
201 ab1eb3f8 Christos Stathis
         */
202 fbff60ff Christos Stathis
        private List<File> files;
203 ab1eb3f8 Christos Stathis
204 ab1eb3f8 Christos Stathis
        /**
205 ab1eb3f8 Christos Stathis
         * The widget's image bundle.
206 ab1eb3f8 Christos Stathis
         */
207 10791b56 Christos Stathis
        protected final Images images;
208 ab1eb3f8 Christos Stathis
        
209 10791b56 Christos Stathis
        protected CellTable<File> celltable;
210 fbff60ff Christos Stathis
211 fbff60ff Christos Stathis
        private final MultiSelectionModel<File> selectionModel;
212 fbff60ff Christos Stathis
213 10791b56 Christos Stathis
        protected final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
214 fbff60ff Christos Stathis
215 ab1eb3f8 Christos Stathis
        SortableHeader nameHeader;
216 fbff60ff Christos Stathis
217 fbff60ff Christos Stathis
    FolderTreeView treeView;
218 fbff60ff Christos Stathis
219 10791b56 Christos Stathis
    protected Pithos app;
220 e9c9f408 Christos Stathis
221 fbff60ff Christos Stathis
    /**
222 ab1eb3f8 Christos Stathis
         * Construct the file list widget. This entails setting up the widget
223 ab1eb3f8 Christos Stathis
         * layout, fetching the number of files in the current folder from the
224 ab1eb3f8 Christos Stathis
         * server and filling the local file cache of displayed files with data from
225 ab1eb3f8 Christos Stathis
         * the server, as well.
226 ab1eb3f8 Christos Stathis
         *
227 ab1eb3f8 Christos Stathis
         * @param _images
228 ab1eb3f8 Christos Stathis
         */
229 e9c9f408 Christos Stathis
        public FileList(final Pithos _app, Images _images, FolderTreeView _treeView) {
230 e9c9f408 Christos Stathis
        app = _app;
231 ab1eb3f8 Christos Stathis
                images = _images;
232 58777026 Christos Stathis
        this.treeView = _treeView;
233 fbff60ff Christos Stathis
234 7ed6977e Christos Stathis
        CellTable.Resources resources = GWT.create(TableResources.class);
235 fbff60ff Christos Stathis
236 fbff60ff Christos Stathis
        ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
237 ab1eb3f8 Christos Stathis
238 ab1eb3f8 Christos Stathis
                        @Override
239 fbff60ff Christos Stathis
                        public Object getKey(File item) {
240 ab1eb3f8 Christos Stathis
                                return item.getUri();
241 ab1eb3f8 Christos Stathis
                        }
242 ab1eb3f8 Christos Stathis
                };
243 fbff60ff Christos Stathis
244 3331e8d8 Christos Stathis
                celltable = new CellTable<File>(10, resources, keyProvider);
245 fbff60ff Christos Stathis
        celltable.setWidth("100%");
246 fbff60ff Christos Stathis
        celltable.setStyleName("pithos-List");
247 fbff60ff Christos Stathis
248 7ed6977e Christos Stathis
                Column<File, ImageResource> status = new Column<File, ImageResource>(new ImageResourceCell() {
249 fbff60ff Christos Stathis
                    @Override
250 fbff60ff Christos Stathis
                public boolean handlesSelection() {
251 fbff60ff Christos Stathis
                    return false;
252 fbff60ff Christos Stathis
                }
253 fbff60ff Christos Stathis
                })
254 fbff60ff Christos Stathis
        {
255 fbff60ff Christos Stathis
                 @Override
256 fbff60ff Christos Stathis
                 public ImageResource getValue(File entity) {
257 fbff60ff Christos Stathis
                     return getFileIcon(entity);
258 fbff60ff Christos Stathis
                 }
259 fbff60ff Christos Stathis
            };
260 ab1eb3f8 Christos Stathis
            celltable.addColumn(status,"");
261 fbff60ff Christos Stathis
262 7ed6977e Christos Stathis
        final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) {
263 ab1eb3f8 Christos Stathis
264 ab1eb3f8 Christos Stathis
                        @Override
265 fbff60ff Christos Stathis
                        public SafeHtml getValue(File object) {
266 ab1eb3f8 Christos Stathis
                                SafeHtmlBuilder sb = new SafeHtmlBuilder();
267 ab1eb3f8 Christos Stathis
                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
268 fbff60ff Christos Stathis
                                if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) {
269 fbff60ff Christos Stathis
                                sb.appendHtmlConstant("&nbsp;")
270 fbff60ff Christos Stathis
                      .append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName()));
271 ab1eb3f8 Christos Stathis
                                }
272 ab1eb3f8 Christos Stathis
                                
273 ab1eb3f8 Christos Stathis
                                return sb.toSafeHtml();
274 ab1eb3f8 Christos Stathis
                        }
275 ab1eb3f8 Christos Stathis
                        
276 ab1eb3f8 Christos Stathis
                };
277 fbff60ff Christos Stathis
        celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
278 ab1eb3f8 Christos Stathis
                allHeaders.add(nameHeader);
279 ab1eb3f8 Christos Stathis
                nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
280 fbff60ff Christos Stathis
281 ab1eb3f8 Christos Stathis
                celltable.redrawHeaders();
282 ab1eb3f8 Christos Stathis
                
283 0ae83d19 Christos Stathis
        Column<File,String> aColumn = new Column<File,String>(new TextCell()) {
284 ab1eb3f8 Christos Stathis
                        @Override
285 fbff60ff Christos Stathis
                        public String getValue(File object) {
286 ab1eb3f8 Christos Stathis
                                // TODO Auto-generated method stub
287 fbff60ff Christos Stathis
                                return object.getSizeAsString();
288 fbff60ff Christos Stathis
                        }
289 fbff60ff Christos Stathis
                };
290 0ae83d19 Christos Stathis
        SortableHeader aheader = new SortableHeader("Size");
291 fbff60ff Christos Stathis
        celltable.addColumn(aColumn, aheader);
292 ab1eb3f8 Christos Stathis
                allHeaders.add(aheader);
293 fbff60ff Christos Stathis
                aheader.setUpdater(new FileValueUpdater(aheader, "size"));
294 fbff60ff Christos Stathis
295 7ed6977e Christos Stathis
        aColumn = new Column<File,String>(new TextCell()) {
296 ab1eb3f8 Christos Stathis
                        @Override
297 fbff60ff Christos Stathis
                        public String getValue(File object) {
298 fbff60ff Christos Stathis
                                return formatter.format(object.getLastModified());
299 fbff60ff Christos Stathis
                        }
300 fbff60ff Christos Stathis
                };
301 fbff60ff Christos Stathis
        aheader = new SortableHeader("Last Modified");
302 fbff60ff Christos Stathis
                celltable.addColumn(aColumn, aheader);
303 ab1eb3f8 Christos Stathis
                allHeaders.add(aheader);
304 ab1eb3f8 Christos Stathis
                aheader.setUpdater(new FileValueUpdater(aheader, "date"));
305 ab1eb3f8 Christos Stathis
               
306 ab1eb3f8 Christos Stathis
                provider.addDataDisplay(celltable);
307 fbff60ff Christos Stathis
308 ab1eb3f8 Christos Stathis
                VerticalPanel vp = new VerticalPanel();
309 ab1eb3f8 Christos Stathis
                vp.setWidth("100%");
310 fbff60ff Christos Stathis
311 fbff60ff Christos Stathis
        vp.add(celltable);
312 fbff60ff Christos Stathis
313 ab1eb3f8 Christos Stathis
                vp.setCellWidth(celltable, "100%");
314 58777026 Christos Stathis
        vp.addHandler(new ContextMenuHandler() {
315 58777026 Christos Stathis
            @Override
316 58777026 Christos Stathis
            public void onContextMenu(ContextMenuEvent event) {
317 c2b71ac3 Christos Stathis
                Folder selectedFolder = treeView.getSelection();
318 c2b71ac3 Christos Stathis
                if (!selectedFolder.isTrash()) {
319 e9c9f408 Christos Stathis
                    FileContextMenu contextMenu = new FileContextMenu(app, images, selectedFolder, getSelectedFiles(), false);
320 c2b71ac3 Christos Stathis
                    int x = event.getNativeEvent().getClientX();
321 c2b71ac3 Christos Stathis
                    int y = event.getNativeEvent().getClientY();
322 c2b71ac3 Christos Stathis
                    contextMenu.setPopupPosition(x, y);
323 c2b71ac3 Christos Stathis
                    contextMenu.show();
324 c2b71ac3 Christos Stathis
                }
325 58777026 Christos Stathis
            }
326 58777026 Christos Stathis
        }, ContextMenuEvent.getType());
327 ab1eb3f8 Christos Stathis
                initWidget(vp);
328 ab1eb3f8 Christos Stathis
329 fbff60ff Christos Stathis
                selectionModel = new MultiSelectionModel<File>(keyProvider);
330 ab1eb3f8 Christos Stathis
331 fbff60ff Christos Stathis
                celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
332 3331e8d8 Christos Stathis
//                celltable.setPageSize(Pithos.VISIBLE_FILE_COUNT);
333 ab1eb3f8 Christos Stathis
                
334 ab1eb3f8 Christos Stathis
                sinkEvents(Event.ONCONTEXTMENU);
335 287c3d8d Christos Stathis
//                sinkEvents(Event.ONMOUSEUP);
336 287c3d8d Christos Stathis
//                sinkEvents(Event.ONMOUSEDOWN);
337 287c3d8d Christos Stathis
//                sinkEvents(Event.ONCLICK);
338 287c3d8d Christos Stathis
//                sinkEvents(Event.ONKEYDOWN);
339 287c3d8d Christos Stathis
//                sinkEvents(Event.ONDBLCLICK);
340 f55cf326 Christos Stathis
                Pithos.preventIESelection();
341 ab1eb3f8 Christos Stathis
        }
342 5cd18037 Christos Stathis
343 fbff60ff Christos Stathis
        public List<File> getSelectedFiles() {
344 fbff60ff Christos Stathis
        return new ArrayList<File>(selectionModel.getSelectedSet());
345 fbff60ff Christos Stathis
        }
346 ab1eb3f8 Christos Stathis
        
347 58777026 Christos Stathis
//        @Override
348 58777026 Christos Stathis
//        public void onBrowserEvent(Event event) {
349 58777026 Christos Stathis
//
350 58777026 Christos Stathis
//                if (files == null || files.size() == 0) {
351 58777026 Christos Stathis
//                        if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
352 58777026 Christos Stathis
//                                contextMenu = new FileContextMenu(images, false, true);
353 58777026 Christos Stathis
//                contextMenu.show();
354 58777026 Christos Stathis
//                                event.preventDefault();
355 58777026 Christos Stathis
//                                event.cancelBubble(true);
356 58777026 Christos Stathis
//                        }
357 58777026 Christos Stathis
//                        return;
358 58777026 Christos Stathis
//                }
359 58777026 Christos Stathis
//                if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
360 58777026 Christos Stathis
//                        GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
361 58777026 Christos Stathis
//                        contextMenu =  new FileContextMenu(images, false, false);
362 58777026 Christos Stathis
//                        contextMenu = contextMenu.onEvent(event);
363 58777026 Christos Stathis
//                        event.cancelBubble(true);
364 58777026 Christos Stathis
//                        event.preventDefault();
365 58777026 Christos Stathis
//                } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
366 58777026 Christos Stathis
//                        contextMenu = new FileContextMenu(images, false, true);
367 58777026 Christos Stathis
//                        contextMenu = contextMenu.onEmptyEvent(event);
368 58777026 Christos Stathis
//                        event.cancelBubble(true);
369 58777026 Christos Stathis
//                        event.preventDefault();
370 58777026 Christos Stathis
//                } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
371 58777026 Christos Stathis
//                        if (getSelectedFiles().size() == 1) {
372 e9c9f408 Christos Stathis
//                                Pithos app = app;
373 58777026 Christos Stathis
//                                File file = getSelectedFiles().get(0);
374 58777026 Christos Stathis
//                                Window.open(file.getUri(), "_blank", "");
375 58777026 Christos Stathis
//                                event.preventDefault();
376 58777026 Christos Stathis
//                                return;
377 58777026 Christos Stathis
//                        }
378 58777026 Christos Stathis
//                super.onBrowserEvent(event);
379 58777026 Christos Stathis
//        }
380 ab1eb3f8 Christos Stathis
381 ab1eb3f8 Christos Stathis
        /**
382 ab1eb3f8 Christos Stathis
         * Update the display of the file list.
383 ab1eb3f8 Christos Stathis
         */
384 10791b56 Christos Stathis
        void update(@SuppressWarnings("unused") boolean sort) {
385 ab1eb3f8 Christos Stathis
                showCellTable();
386 ab1eb3f8 Christos Stathis
        }
387 ab1eb3f8 Christos Stathis
388 ab1eb3f8 Christos Stathis
        /**
389 ab1eb3f8 Christos Stathis
         * Return the proper icon based on the MIME type of the file.
390 ab1eb3f8 Christos Stathis
         *
391 ab1eb3f8 Christos Stathis
         * @param file
392 ab1eb3f8 Christos Stathis
         * @return the icon
393 ab1eb3f8 Christos Stathis
         */
394 10791b56 Christos Stathis
        protected ImageResource getFileIcon(File file) {
395 ab1eb3f8 Christos Stathis
                String mimetype = file.getContentType();
396 fbff60ff Christos Stathis
                boolean shared = file.isShared();
397 ab1eb3f8 Christos Stathis
                if (mimetype == null)
398 ab1eb3f8 Christos Stathis
                        return shared ? images.documentShared() : images.document();
399 ab1eb3f8 Christos Stathis
                mimetype = mimetype.toLowerCase();
400 ab1eb3f8 Christos Stathis
                if (mimetype.startsWith("application/pdf"))
401 ab1eb3f8 Christos Stathis
                        return shared ? images.pdfShared() : images.pdf();
402 ab1eb3f8 Christos Stathis
                else if (mimetype.endsWith("excel"))
403 ab1eb3f8 Christos Stathis
                        return shared ? images.spreadsheetShared() : images.spreadsheet();
404 ab1eb3f8 Christos Stathis
                else if (mimetype.endsWith("msword"))
405 ab1eb3f8 Christos Stathis
                        return shared ? images.wordprocessorShared() : images.wordprocessor();
406 ab1eb3f8 Christos Stathis
                else if (mimetype.endsWith("powerpoint"))
407 ab1eb3f8 Christos Stathis
                        return shared ? images.presentationShared() : images.presentation();
408 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("application/zip") ||
409 ab1eb3f8 Christos Stathis
                                        mimetype.startsWith("application/gzip") ||
410 ab1eb3f8 Christos Stathis
                                        mimetype.startsWith("application/x-gzip") ||
411 ab1eb3f8 Christos Stathis
                                        mimetype.startsWith("application/x-tar") ||
412 ab1eb3f8 Christos Stathis
                                        mimetype.startsWith("application/x-gtar"))
413 ab1eb3f8 Christos Stathis
                        return shared ? images.zipShared() : images.zip();
414 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("text/html"))
415 ab1eb3f8 Christos Stathis
                        return shared ? images.htmlShared() : images.html();
416 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("text/plain"))
417 ab1eb3f8 Christos Stathis
                        return shared ? images.txtShared() : images.txt();
418 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("image/"))
419 ab1eb3f8 Christos Stathis
                        return shared ? images.imageShared() : images.image();
420 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("video/"))
421 ab1eb3f8 Christos Stathis
                        return shared ? images.videoShared() : images.video();
422 ab1eb3f8 Christos Stathis
                else if (mimetype.startsWith("audio/"))
423 ab1eb3f8 Christos Stathis
                        return shared ? images.audioShared() : images.audio();
424 ab1eb3f8 Christos Stathis
                return shared ? images.documentShared() : images.document();
425 ab1eb3f8 Christos Stathis
        }
426 ab1eb3f8 Christos Stathis
427 ab1eb3f8 Christos Stathis
        /**
428 ab1eb3f8 Christos Stathis
         * Fill the file cache with data.
429 ab1eb3f8 Christos Stathis
         */
430 fbff60ff Christos Stathis
        public void setFiles(final List<File> _files) {
431 fbff60ff Christos Stathis
                files = new ArrayList<File>();
432 fbff60ff Christos Stathis
            for (File fres : _files)
433 fbff60ff Christos Stathis
                    if (!fres.isInTrash())
434 fbff60ff Christos Stathis
                                files.add(fres);
435 fbff60ff Christos Stathis
                Collections.sort(files, new Comparator<File>() {
436 ab1eb3f8 Christos Stathis
437 ab1eb3f8 Christos Stathis
                        @Override
438 fbff60ff Christos Stathis
                        public int compare(File arg0, File arg1) {
439 ab1eb3f8 Christos Stathis
                                return arg0.getName().compareTo(arg1.getName());
440 ab1eb3f8 Christos Stathis
                        }
441 ab1eb3f8 Christos Stathis
442 ab1eb3f8 Christos Stathis
                });
443 ab1eb3f8 Christos Stathis
                folderFileCount = files.size();
444 ab1eb3f8 Christos Stathis
                
445 ab1eb3f8 Christos Stathis
                nameHeader.setSorted(true);
446 ab1eb3f8 Christos Stathis
                nameHeader.toggleReverseSort();
447 ab1eb3f8 Christos Stathis
                for (SortableHeader otherHeader : allHeaders) {
448 fbff60ff Christos Stathis
                if (otherHeader != nameHeader) {
449 ab1eb3f8 Christos Stathis
                    otherHeader.setSorted(false);
450 ab1eb3f8 Christos Stathis
                    otherHeader.setReverseSort(true);
451 ab1eb3f8 Christos Stathis
                }
452 fbff60ff Christos Stathis
            }
453 ab1eb3f8 Christos Stathis
454 fbff60ff Christos Stathis
        provider.setList(files);
455 a39e5b47 Christos Stathis
        selectionModel.clear();
456 fbff60ff Christos Stathis
        }
457 ab1eb3f8 Christos Stathis
458 ab1eb3f8 Christos Stathis
        /**
459 ab1eb3f8 Christos Stathis
         * Does the list contains the requested filename
460 ab1eb3f8 Christos Stathis
         *
461 ab1eb3f8 Christos Stathis
         * @param fileName
462 ab1eb3f8 Christos Stathis
         * @return true/false
463 ab1eb3f8 Christos Stathis
         */
464 ab1eb3f8 Christos Stathis
        public boolean contains(String fileName) {
465 ab1eb3f8 Christos Stathis
                for (int i = 0; i < files.size(); i++)
466 ab1eb3f8 Christos Stathis
                        if (files.get(i).getName().equals(fileName))
467 ab1eb3f8 Christos Stathis
                                return true;
468 ab1eb3f8 Christos Stathis
                return false;
469 ab1eb3f8 Christos Stathis
        }
470 ab1eb3f8 Christos Stathis
471 ab1eb3f8 Christos Stathis
        public void clearSelectedRows() {
472 fbff60ff Christos Stathis
                Iterator<File> it = selectionModel.getSelectedSet().iterator();
473 ab1eb3f8 Christos Stathis
                while(it.hasNext()){
474 ab1eb3f8 Christos Stathis
                        selectionModel.setSelected(it.next(),false);
475 ab1eb3f8 Christos Stathis
                }
476 ab1eb3f8 Christos Stathis
        }
477 ab1eb3f8 Christos Stathis
        
478 ab1eb3f8 Christos Stathis
        /**
479 ab1eb3f8 Christos Stathis
         *
480 ab1eb3f8 Christos Stathis
         */
481 ab1eb3f8 Christos Stathis
        public void selectAllRows() {
482 fbff60ff Christos Stathis
                Iterator<File> it = provider.getList().iterator();
483 ab1eb3f8 Christos Stathis
                while(it.hasNext()){
484 ab1eb3f8 Christos Stathis
                        selectionModel.setSelected(it.next(),true);
485 ab1eb3f8 Christos Stathis
                }
486 ab1eb3f8 Christos Stathis
        }
487 ab1eb3f8 Christos Stathis
488 10791b56 Christos Stathis
        protected void sortFiles(final String sortingProperty, final boolean sortingType){
489 fbff60ff Christos Stathis
                Collections.sort(files, new Comparator<File>() {
490 ab1eb3f8 Christos Stathis
491 ab1eb3f8 Christos Stathis
            @Override
492 fbff60ff Christos Stathis
            public int compare(File arg0, File arg1) {
493 ab1eb3f8 Christos Stathis
                    if (sortingType){
494 ab1eb3f8 Christos Stathis
                            if (sortingProperty.equals("version")) {
495 fbff60ff Christos Stathis
                                    return arg0.getVersion() - arg1.getVersion();
496 ab1eb3f8 Christos Stathis
                            } else if (sortingProperty.equals("owner")) {
497 ab1eb3f8 Christos Stathis
                                    return arg0.getOwner().compareTo(arg1.getOwner());
498 ab1eb3f8 Christos Stathis
                            } else if (sortingProperty.equals("date")) {
499 fbff60ff Christos Stathis
                                    return arg0.getLastModified().compareTo(arg1.getLastModified());
500 ab1eb3f8 Christos Stathis
                            } else if (sortingProperty.equals("size")) {
501 fbff60ff Christos Stathis
                                    return (int) (arg0.getBytes() - arg1.getBytes());
502 ab1eb3f8 Christos Stathis
                            } else if (sortingProperty.equals("name")) {
503 ab1eb3f8 Christos Stathis
                                    return arg0.getName().compareTo(arg1.getName());
504 ab1eb3f8 Christos Stathis
                            } else if (sortingProperty.equals("path")) {
505 ab1eb3f8 Christos Stathis
                                    return arg0.getUri().compareTo(arg1.getUri());
506 ab1eb3f8 Christos Stathis
                            } else {
507 ab1eb3f8 Christos Stathis
                                    return arg0.getName().compareTo(arg1.getName());
508 ab1eb3f8 Christos Stathis
                            }
509 ab1eb3f8 Christos Stathis
                    }
510 ab1eb3f8 Christos Stathis
                    else if (sortingProperty.equals("version")) {
511 ab1eb3f8 Christos Stathis
                            
512 fbff60ff Christos Stathis
                            return arg1.getVersion() - arg0.getVersion();
513 ab1eb3f8 Christos Stathis
                    } else if (sortingProperty.equals("owner")) {
514 ab1eb3f8 Christos Stathis
                            
515 ab1eb3f8 Christos Stathis
                            return arg1.getOwner().compareTo(arg0.getOwner());
516 ab1eb3f8 Christos Stathis
                    } else if (sortingProperty.equals("date")) {
517 ab1eb3f8 Christos Stathis
                            
518 fbff60ff Christos Stathis
                            return arg1.getLastModified().compareTo(arg0.getLastModified());
519 ab1eb3f8 Christos Stathis
                    } else if (sortingProperty.equals("size")) {
520 fbff60ff Christos Stathis
                            return (int) (arg1.getBytes() - arg0.getBytes());
521 ab1eb3f8 Christos Stathis
                    } else if (sortingProperty.equals("name")) {
522 ab1eb3f8 Christos Stathis
                            
523 ab1eb3f8 Christos Stathis
                            return arg1.getName().compareTo(arg0.getName());
524 ab1eb3f8 Christos Stathis
                    } else if (sortingProperty.equals("path")) {
525 ab1eb3f8 Christos Stathis
                            
526 ab1eb3f8 Christos Stathis
                            return arg1.getUri().compareTo(arg0.getUri());
527 ab1eb3f8 Christos Stathis
                    } else {
528 ab1eb3f8 Christos Stathis
                            
529 ab1eb3f8 Christos Stathis
                            return arg1.getName().compareTo(arg0.getName());
530 ab1eb3f8 Christos Stathis
                    }
531 ab1eb3f8 Christos Stathis
            }
532 ab1eb3f8 Christos Stathis
533 ab1eb3f8 Christos Stathis
                });
534 ab1eb3f8 Christos Stathis
        }
535 ab1eb3f8 Christos Stathis
        
536 ab1eb3f8 Christos Stathis
        final class FileValueUpdater implements ValueUpdater<String>{
537 ab1eb3f8 Christos Stathis
                private String property;
538 ab1eb3f8 Christos Stathis
                private SortableHeader header;
539 ab1eb3f8 Christos Stathis
                /**
540 ab1eb3f8 Christos Stathis
                 * 
541 ab1eb3f8 Christos Stathis
                 */
542 ab1eb3f8 Christos Stathis
                public FileValueUpdater(SortableHeader header,String property) {
543 ab1eb3f8 Christos Stathis
                        this.property=property;
544 ab1eb3f8 Christos Stathis
                        this.header=header;
545 ab1eb3f8 Christos Stathis
                }
546 ab1eb3f8 Christos Stathis
                @Override
547 10791b56 Christos Stathis
                public void update(@SuppressWarnings("unused") String value) {
548 ab1eb3f8 Christos Stathis
                        header.setSorted(true);
549 ab1eb3f8 Christos Stathis
                        header.toggleReverseSort();
550 ab1eb3f8 Christos Stathis
551 ab1eb3f8 Christos Stathis
                for (SortableHeader otherHeader : allHeaders) {
552 ab1eb3f8 Christos Stathis
                  if (otherHeader != header) {
553 ab1eb3f8 Christos Stathis
                    otherHeader.setSorted(false);
554 ab1eb3f8 Christos Stathis
                    otherHeader.setReverseSort(true);
555 ab1eb3f8 Christos Stathis
                  }
556 ab1eb3f8 Christos Stathis
                }
557 ab1eb3f8 Christos Stathis
                celltable.redrawHeaders();
558 ab1eb3f8 Christos Stathis
                sortFiles(property, header.getReverseSort());
559 ab1eb3f8 Christos Stathis
                FileList.this.update(true);                        
560 ab1eb3f8 Christos Stathis
                }
561 ab1eb3f8 Christos Stathis
                
562 ab1eb3f8 Christos Stathis
        }
563 ab1eb3f8 Christos Stathis
564 ab1eb3f8 Christos Stathis
        /**
565 ab1eb3f8 Christos Stathis
         * Shows the files in the cellTable 
566 fbff60ff Christos Stathis
     */
567 ab1eb3f8 Christos Stathis
        private void showCellTable(){
568 ab1eb3f8 Christos Stathis
                provider.setList(files);
569 ab1eb3f8 Christos Stathis
                
570 ab1eb3f8 Christos Stathis
                provider.refresh();
571 ab1eb3f8 Christos Stathis
                
572 ab1eb3f8 Christos Stathis
                //celltable.redraw();
573 ab1eb3f8 Christos Stathis
                celltable.redrawHeaders();                
574 ab1eb3f8 Christos Stathis
        }
575 ab1eb3f8 Christos Stathis
}