Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / commands / UploadFileCommand.java @ 623:66f69a7348ed

History | View | Annotate | Download (2.8 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 gr.ebs.gss.client.commands;
20

    
21
import gr.ebs.gss.client.FileUploadDialog;
22
import gr.ebs.gss.client.GSS;
23
import gr.ebs.gss.client.rest.GetCommand;
24
import gr.ebs.gss.client.rest.resource.FileResource;
25
import gr.ebs.gss.client.rest.resource.FolderResource;
26

    
27
import java.util.ArrayList;
28
import java.util.List;
29

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

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

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

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

    
51
        @Override
52
        public void execute() {
53
                containerPanel.hide();
54
                displayNewFile();
55
        }
56

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

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

    
81
                });
82
        }
83

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

    
90
        private void getFileList() {
91
                GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class,((FolderResource)GSS.get().getFolders().getCurrent().getUserObject()).getUri(), null){
92

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

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

    
103
                };
104
                DeferredCommand.addCommand(eg);
105
        }
106

    
107
}