Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FileMenu.java @ f55cf326

History | View | Annotate | Download (5.7 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.commands.NewFolderCommand;
38
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
39
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
40
import gr.grnet.pithos.web.client.foldertree.File;
41
import gr.grnet.pithos.web.client.foldertree.Folder;
42

    
43
import java.util.List;
44

    
45
import com.google.gwt.resources.client.ClientBundle;
46
import com.google.gwt.resources.client.ImageResource;
47
import com.google.gwt.user.client.Command;
48
import com.google.gwt.user.client.ui.AbstractImagePrototype;
49
import com.google.gwt.user.client.ui.MenuBar;
50
import com.google.gwt.user.client.ui.MenuItem;
51

    
52
/**
53
 * The 'File' menu implementation.
54
 */
55
public class FileMenu extends MenuBar {
56

    
57
        /**
58
         * The widget's images.
59
         */
60
        private final Images images;
61

    
62
        /**
63
         * An image bundle for this widgets images.
64
         */
65
        public interface Images extends ClientBundle,FilePropertiesDialog.Images {
66

    
67
                @Source("gr/grnet/pithos/resources/folder_new.png")
68
                ImageResource folderNew();
69

    
70
                @Source("gr/grnet/pithos/resources/folder_outbox.png")
71
                ImageResource fileUpdate();
72

    
73
                @Source("gr/grnet/pithos/resources/view_text.png")
74
                ImageResource viewText();
75

    
76
                @Override
77
                @Source("gr/grnet/pithos/resources/folder_inbox.png")
78
                ImageResource download();
79

    
80
                @Source("gr/grnet/pithos/resources/trashcan_empty.png")
81
                ImageResource emptyTrash();
82

    
83
                @Source("gr/grnet/pithos/resources/internet.png")
84
                ImageResource sharing();
85

    
86
                @Source("gr/grnet/pithos/resources/refresh.png")
87
                ImageResource refresh();
88

    
89
        @Source("gr/grnet/pithos/resources/")
90
        ImageResource unselectAll();
91
    }
92

    
93
        /**
94
         * The widget's constructor.
95
         *
96
         * @param _images the image bundle passed on by the parent object
97
         */
98
        public FileMenu(Pithos _app, final Images _images) {
99
        super(true);
100
                setAnimationEnabled(true);
101
                images = _images;
102

    
103
        Folder selectedFolder = _app.getFolderTreeView().getSelection();
104
        List<File> selectedFiles = _app.getFileList().getSelectedFiles();
105
        if (selectedFolder != null) {
106
                    MenuItem newFolderItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(null, selectedFolder, images));
107
                    addItem(newFolderItem);
108

    
109
            MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(null, selectedFolder));
110
            addItem(uploadItem);
111
        }
112
        if (selectedFiles.size() == 1) {
113
            addItem(new MenuItem("<span><a class='hidden-link' href='" + Pithos.get().getApiPath() + Pithos.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + Pithos.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(images.download()).getHTML() + " Download</a></span>", true, (Command) null));
114
        }
115

    
116
//        MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
117
//        emptyTrashItem.getElement().setId("topMenu.file.emptyTrash");
118
//        contextMenu.addItem(emptyTrashItem);
119

    
120
//        MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
121
//        refreshItem.getElement().setId("topMenu.file.refresh");
122
//        contextMenu.addItem(refreshItem);
123

    
124
//        MenuItem sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
125
//        sharingItem.getElement().setId("topMenu.file.sharing");
126
//        contextMenu.addItem(sharingItem)
127
//                       .setVisible(propertiesVisible);
128
//
129
        if (selectedFiles.size() > 0 || selectedFolder != null) {
130
            MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(Pithos.get(), null, selectedFiles.size() > 0 ? selectedFiles : selectedFolder, images, 0));
131
            addItem(propertiesItem);
132
        }
133
        }
134
}