Statistics
| Branch: | Tag: | Revision:

root / web_client / src / org / gss_project / gss / web / client / commands / UploadFileCommand.java @ f1ec19a9

History | View | Annotate | Download (3 kB)

1
/*
2
 * Copyright 2008, 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package org.gss_project.gss.web.client.commands;
20

    
21
import org.gss_project.gss.web.client.FileUploadDialog;
22
import org.gss_project.gss.web.client.GSS;
23
import org.gss_project.gss.web.client.rest.GetCommand;
24
import org.gss_project.gss.web.client.rest.resource.FileResource;
25
import org.gss_project.gss.web.client.rest.resource.FolderResource;
26
import org.gss_project.gss.web.client.rest.resource.RestResource;
27
import org.gss_project.gss.web.client.rest.resource.RestResourceWrapper;
28

    
29
import java.util.ArrayList;
30
import java.util.List;
31

    
32
import com.google.gwt.core.client.GWT;
33
import com.google.gwt.user.client.Command;
34
import com.google.gwt.user.client.DeferredCommand;
35
import com.google.gwt.user.client.IncrementalCommand;
36
import com.google.gwt.user.client.ui.PopupPanel;
37

    
38
/**
39
 * Upload a file command
40
 *
41
 * @author kman
42
 */
43
public class UploadFileCommand implements Command {
44

    
45
        private PopupPanel containerPanel;
46
        private List<FileResource> files;
47

    
48
        public UploadFileCommand(PopupPanel _containerPanel) {
49
                containerPanel = _containerPanel;
50
        }
51

    
52
        @Override
53
        public void execute() {
54
                if(containerPanel!=null)
55
                        containerPanel.hide();
56
                displayNewFile();
57
        }
58

    
59
        /**
60
         * Display the 'new file' dialog for uploading a new file to the system.
61
         */
62
        private void displayNewFile() {
63
                RestResource currentFolder = GSS.get().getTreeView().getSelection();
64
                if (currentFolder == null) {
65
                        GSS.get().displayError("You have to select the parent folder first");
66
                        return;
67
                }
68
                getFileList();
69
                DeferredCommand.addCommand(new IncrementalCommand() {
70

    
71
                        @Override
72
                        public boolean execute() {
73
                                boolean res = canContinue();
74
                                if (res) {
75
                                        FileUploadDialog dlg = GWT.create(FileUploadDialog.class);
76
                                        dlg.setFiles(files);
77
                                        dlg.center();
78
                                        return false;
79
                                }
80
                                return true;
81
                        }
82

    
83
                });
84
        }
85

    
86
        private boolean canContinue() {
87
                if (files != null )
88
                        return true;
89
                return false;
90
        }
91

    
92
        private void getFileList() {
93
                GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class,((RestResourceWrapper)GSS.get().getTreeView().getSelection()).getUri(), null){
94

    
95
                        @Override
96
                        public void onComplete() {
97
                                files = getResult().getFiles();
98
                        }
99

    
100
                        @Override
101
                        public void onError(Throwable t) {
102
                                files = new ArrayList<FileResource>();
103
                        }
104

    
105
                };
106
                DeferredCommand.addCommand(eg);
107
        }
108

    
109
}