Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / Toolbar.java @ a5b2770f

History | View | Annotate | Download (8.6 kB)

1 7c02238e Christos Stathis
/*
2 7c02238e Christos Stathis
 * Copyright 2012 GRNET S.A. All rights reserved.
3 7c02238e Christos Stathis
 *
4 7c02238e Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 7c02238e Christos Stathis
 * without modification, are permitted provided that the following
6 7c02238e Christos Stathis
 * conditions are met:
7 7c02238e Christos Stathis
 *
8 7c02238e Christos Stathis
 *   1. Redistributions of source code must retain the above
9 7c02238e Christos Stathis
 *      copyright notice, this list of conditions and the following
10 7c02238e Christos Stathis
 *      disclaimer.
11 7c02238e Christos Stathis
 *
12 7c02238e Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 7c02238e Christos Stathis
 *      copyright notice, this list of conditions and the following
14 7c02238e Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 7c02238e Christos Stathis
 *      provided with the distribution.
16 7c02238e Christos Stathis
 *
17 7c02238e Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 7c02238e Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 7c02238e Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 7c02238e Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 7c02238e Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 7c02238e Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 7c02238e Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 7c02238e Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 7c02238e Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 7c02238e Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 7c02238e Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 7c02238e Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 7c02238e Christos Stathis
 *
30 7c02238e Christos Stathis
 * The views and conclusions contained in the software and
31 7c02238e Christos Stathis
 * documentation are those of the authors and should not be
32 7c02238e Christos Stathis
 * interpreted as representing official policies, either expressed
33 7c02238e Christos Stathis
 * or implied, of GRNET S.A.
34 7c02238e Christos Stathis
 */
35 7c02238e Christos Stathis
36 7c02238e Christos Stathis
package gr.grnet.pithos.web.client;
37 7c02238e Christos Stathis
38 a5b2770f Christos Stathis
import java.util.List;
39 a5b2770f Christos Stathis
40 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.commands.NewFolderCommand;
41 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 a5b2770f Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
43 a5b2770f Christos Stathis
import gr.grnet.pithos.web.client.foldertree.FileFolderResource;
44 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
45 7c02238e Christos Stathis
46 7c02238e Christos Stathis
import com.google.gwt.dom.client.Style.Display;
47 7c02238e Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
48 7c02238e Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
49 7c02238e Christos Stathis
import com.google.gwt.user.client.Command;
50 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
51 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.Composite;
52 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.FlowPanel;
53 7c02238e Christos Stathis
54 7c02238e Christos Stathis
public class Toolbar extends Composite {
55 7c02238e Christos Stathis
56 7c02238e Christos Stathis
        Pithos app;
57 7c02238e Christos Stathis
        
58 a2f617f8 Christos Stathis
        Anchor newFolderButton;
59 7c02238e Christos Stathis
        
60 a2f617f8 Christos Stathis
        Anchor shareFolderButton;
61 7c02238e Christos Stathis
        
62 a2f617f8 Christos Stathis
        Anchor refreshButton;
63 7c02238e Christos Stathis
        
64 7c02238e Christos Stathis
        private Anchor toolsButton;
65 7c02238e Christos Stathis
        
66 7c02238e Christos Stathis
        ToolsMenu menu;
67 7c02238e Christos Stathis
        
68 7c02238e Christos Stathis
        public Toolbar(final Pithos _app) {
69 7c02238e Christos Stathis
                app = _app;
70 7c02238e Christos Stathis
        FlowPanel toolbar = new FlowPanel();
71 7c02238e Christos Stathis
        toolbar.getElement().setId("toolbar");
72 7c02238e Christos Stathis
        toolbar.addStyleName("clearfix");
73 7c02238e Christos Stathis
        toolbar.getElement().getStyle().setDisplay(Display.BLOCK);
74 7c02238e Christos Stathis
75 7c02238e Christos Stathis
        newFolderButton = new Anchor("<span class='ico'></span><span class='title'>New folder</span>", true);
76 7c02238e Christos Stathis
        newFolderButton.getElement().setId("newfolder-button");
77 7c02238e Christos Stathis
        newFolderButton.addStyleName("pithos-toolbarItem");
78 7c02238e Christos Stathis
        newFolderButton.setVisible(false);
79 7c02238e Christos Stathis
        newFolderButton.addClickHandler(new ClickHandler() {
80 7c02238e Christos Stathis
                        
81 7c02238e Christos Stathis
                        @Override
82 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
83 7c02238e Christos Stathis
                                Folder folder = app.getSelectedTree().getSelection();
84 7c02238e Christos Stathis
                                if (folder != null) {
85 7c02238e Christos Stathis
                                Boolean[] permissions = folder.getPermissions().get(app.getUsername());
86 7c02238e Christos Stathis
                                    boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
87 7c02238e Christos Stathis
                                    
88 7c02238e Christos Stathis
                                    if (!folder.isInTrash() && canWrite)
89 7c02238e Christos Stathis
                                            new NewFolderCommand(app, null, folder).execute();
90 7c02238e Christos Stathis
                                }
91 7c02238e Christos Stathis
                        }
92 7c02238e Christos Stathis
                });
93 7c02238e Christos Stathis
        toolbar.add(newFolderButton);
94 7c02238e Christos Stathis
95 7c02238e Christos Stathis
        shareFolderButton = new Anchor("<span class='ico'></span><span class='title'>Share folder</span>", true);
96 7c02238e Christos Stathis
        shareFolderButton.getElement().setId("sharefolder-button");
97 7c02238e Christos Stathis
        shareFolderButton.addStyleName("pithos-toolbarItem");
98 7c02238e Christos Stathis
        shareFolderButton.setVisible(false);
99 7c02238e Christos Stathis
        shareFolderButton.addClickHandler(new ClickHandler() {
100 7c02238e Christos Stathis
                        
101 7c02238e Christos Stathis
                        @Override
102 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
103 7c02238e Christos Stathis
                                Folder folder = app.getSelectedTree().getSelection();
104 7c02238e Christos Stathis
                                if (folder != null) {
105 7c02238e Christos Stathis
                                Boolean[] permissions = folder.getPermissions().get(app.getUsername());
106 7c02238e Christos Stathis
                                    boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
107 7c02238e Christos Stathis
                                    boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
108 7c02238e Christos Stathis
                                    
109 7c02238e Christos Stathis
                                    if (!folder.isInTrash() && canWrite && isFolderTreeSelected && !folder.isContainer())
110 7c02238e Christos Stathis
                                            new PropertiesCommand(app, null, folder, PropertiesCommand.PERMISSIONS).execute();
111 7c02238e Christos Stathis
                                }
112 7c02238e Christos Stathis
                        }
113 7c02238e Christos Stathis
                });
114 7c02238e Christos Stathis
        toolbar.add(shareFolderButton);
115 7c02238e Christos Stathis
116 7c02238e Christos Stathis
        refreshButton = new Anchor("<span class='ico'></span><span class='title'>Refresh</span>", true);
117 7c02238e Christos Stathis
        refreshButton.getElement().setId("refresh-button");
118 7c02238e Christos Stathis
        refreshButton.addStyleName("pithos-toolbarItem");
119 7c02238e Christos Stathis
        refreshButton.setVisible(false);
120 7c02238e Christos Stathis
        refreshButton.addClickHandler(new ClickHandler() {
121 7c02238e Christos Stathis
                        
122 7c02238e Christos Stathis
                        @Override
123 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
124 7c02238e Christos Stathis
                            boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
125 7c02238e Christos Stathis
                            boolean otherSharedTreeSelected = app.getSelectedTree().equals(app.getOtherSharedTreeView());
126 7c02238e Christos Stathis
                            Folder folder = app.getSelectedTree().getSelection();
127 7c02238e Christos Stathis
                            
128 5d18aa82 Christos Stathis
                            if (folder != null) {
129 5d18aa82 Christos Stathis
                                    if (!app.isMySharedSelected()) {
130 5d18aa82 Christos Stathis
                                            app.updateFolder(folder, true, new Command() {
131 5d18aa82 Christos Stathis
                                                    
132 5d18aa82 Christos Stathis
                                                    @Override
133 5d18aa82 Christos Stathis
                                                    public void execute() {
134 5d18aa82 Christos Stathis
                                                            app.updateStatistics();
135 5d18aa82 Christos Stathis
                                                    }
136 5d18aa82 Christos Stathis
                                            }, true);
137 5d18aa82 Christos Stathis
                                    }
138 5d18aa82 Christos Stathis
                                    else
139 5d18aa82 Christos Stathis
                                            app.updateSharedFolder(folder, true);
140 7c02238e Christos Stathis
                                            
141 5d18aa82 Christos Stathis
                            }
142 7c02238e Christos Stathis
                        }
143 5d18aa82 Christos Stathis
        });
144 7c02238e Christos Stathis
        toolbar.add(refreshButton);
145 7c02238e Christos Stathis
146 7c02238e Christos Stathis
        toolsButton = new Anchor("<span class='ico'></span><span class='title'>More...</span>", true);
147 7c02238e Christos Stathis
        toolsButton.getElement().setId("tools-button");
148 7c02238e Christos Stathis
        toolsButton.addStyleName("pithos-toolbarItem");
149 7c02238e Christos Stathis
        toolsButton.setVisible(false);
150 7c02238e Christos Stathis
        toolsButton.addClickHandler(new ClickHandler() {
151 7c02238e Christos Stathis
                        
152 7c02238e Christos Stathis
                        @Override
153 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
154 7c02238e Christos Stathis
                if (!menu.isEmpty()) {
155 7c02238e Christos Stathis
                            menu.setPopupPosition(event.getClientX(), event.getClientY());
156 7c02238e Christos Stathis
                            menu.show();
157 7c02238e Christos Stathis
                }
158 7c02238e Christos Stathis
                        }
159 7c02238e Christos Stathis
                });
160 7c02238e Christos Stathis
        toolbar.add(toolsButton);
161 7c02238e Christos Stathis
        
162 7c02238e Christos Stathis
        initWidget(toolbar);
163 7c02238e Christos Stathis
        }
164 7c02238e Christos Stathis
        
165 7c02238e Christos Stathis
        public void showRelevantButtons() {
166 80a65a5f Christos Stathis
                TreeView selectedTree = app.getSelectedTree();
167 80a65a5f Christos Stathis
                if (selectedTree != null) {
168 80a65a5f Christos Stathis
                        final Folder folder = app.getSelectedTree().getSelection();
169 80a65a5f Christos Stathis
                        if (folder != null) {
170 80a65a5f Christos Stathis
                                app.scheduleFolderHeadCommand(folder, new Command() {
171 80a65a5f Christos Stathis
                                        
172 80a65a5f Christos Stathis
                                        @Override
173 80a65a5f Christos Stathis
                                        public void execute() {
174 80a65a5f Christos Stathis
                                        Boolean[] permissions = folder.getPermissions().get(app.getUsername());
175 80a65a5f Christos Stathis
                                            boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
176 80a65a5f Christos Stathis
                                            boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
177 80a65a5f Christos Stathis
                                            boolean otherSharedTreeSelected = app.getSelectedTree().equals(app.getOtherSharedTreeView());
178 80a65a5f Christos Stathis
                                            
179 5d18aa82 Christos Stathis
                                            refreshButton.setVisible(true);
180 80a65a5f Christos Stathis
                                            
181 80a65a5f Christos Stathis
                                            if (!folder.isInTrash() && canWrite) {
182 80a65a5f Christos Stathis
                                                    if (isFolderTreeSelected || otherSharedTreeSelected)
183 80a65a5f Christos Stathis
                                                            newFolderButton.setVisible(true);
184 c46c9e31 Christos Stathis
                                                    else
185 c46c9e31 Christos Stathis
                                                            newFolderButton.setVisible(false);
186 80a65a5f Christos Stathis
                                                    if (isFolderTreeSelected && !folder.isContainer())
187 80a65a5f Christos Stathis
                                                            shareFolderButton.setVisible(true);
188 80a65a5f Christos Stathis
                                                    else
189 80a65a5f Christos Stathis
                                                            shareFolderButton.setVisible(false);
190 80a65a5f Christos Stathis
                                            }
191 80a65a5f Christos Stathis
                                            else {
192 80a65a5f Christos Stathis
                                                    newFolderButton.setVisible(false);
193 80a65a5f Christos Stathis
                                                    shareFolderButton.setVisible(false);
194 80a65a5f Christos Stathis
                                            }
195 80a65a5f Christos Stathis
                                        }
196 80a65a5f Christos Stathis
                                });
197 80a65a5f Christos Stathis
                        }
198 80a65a5f Christos Stathis
                        else {
199 80a65a5f Christos Stathis
                                newFolderButton.setVisible(false);
200 80a65a5f Christos Stathis
                                shareFolderButton.setVisible(false);
201 80a65a5f Christos Stathis
                                refreshButton.setVisible(false);
202 80a65a5f Christos Stathis
                        }
203 7c02238e Christos Stathis
                }
204 7c02238e Christos Stathis
                else {
205 7c02238e Christos Stathis
                        newFolderButton.setVisible(false);
206 7c02238e Christos Stathis
                        shareFolderButton.setVisible(false);
207 7c02238e Christos Stathis
                        refreshButton.setVisible(false);
208 7c02238e Christos Stathis
                }
209 7c02238e Christos Stathis
210 80a65a5f Christos Stathis
                if (selectedTree != null) {
211 a5b2770f Christos Stathis
                        boolean ofSameType = true;
212 a5b2770f Christos Stathis
                        FileFolderResource previous = null;
213 a5b2770f Christos Stathis
                        List<FileFolderResource> selectedFiles = app.getFileList().getSelectedFiles();
214 a5b2770f Christos Stathis
                        for (FileFolderResource r : selectedFiles) {
215 a5b2770f Christos Stathis
                                if (previous != null && ((previous instanceof Folder && r instanceof File)) || (r instanceof Folder && previous instanceof File)) {
216 a5b2770f Christos Stathis
                                        ofSameType = false;
217 a5b2770f Christos Stathis
                                        break;
218 a5b2770f Christos Stathis
                                }
219 a5b2770f Christos Stathis
                                previous = r;
220 a5b2770f Christos Stathis
                        }
221 a5b2770f Christos Stathis
                        if (!ofSameType) {
222 a5b2770f Christos Stathis
                        toolsButton.setVisible(false);
223 a5b2770f Christos Stathis
                                return;
224 a5b2770f Christos Stathis
                        }
225 a5b2770f Christos Stathis
                        if (selectedFiles.get(0) instanceof Folder) {
226 a5b2770f Christos Stathis
                        toolsButton.setVisible(false);
227 a5b2770f Christos Stathis
                                return;
228 a5b2770f Christos Stathis
                        }
229 a5b2770f Christos Stathis
                        
230 80a65a5f Christos Stathis
                menu = new ToolsMenu(app, Pithos.images, selectedTree, selectedTree.getSelection(), app.getFileList().getSelectedFiles());
231 80a65a5f Christos Stathis
                if (!menu.isEmpty())
232 80a65a5f Christos Stathis
                        toolsButton.setVisible(true);
233 80a65a5f Christos Stathis
                else
234 80a65a5f Christos Stathis
                        toolsButton.setVisible(false);
235 80a65a5f Christos Stathis
                }
236 7c02238e Christos Stathis
    }
237 7c02238e Christos Stathis
}