Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.9 kB)

1 7c02238e Christos Stathis
/*
2 e6e9f6e6 Christos KK Loverdos
 * Copyright 2012-2013 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 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.commands.NewFolderCommand;
39 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
40 7c02238e Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
41 7c02238e Christos Stathis
42 7c02238e Christos Stathis
import com.google.gwt.dom.client.Style.Display;
43 7c02238e Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
44 7c02238e Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
45 7c02238e Christos Stathis
import com.google.gwt.user.client.Command;
46 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
47 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.Composite;
48 7c02238e Christos Stathis
import com.google.gwt.user.client.ui.FlowPanel;
49 7c02238e Christos Stathis
50 7c02238e Christos Stathis
public class Toolbar extends Composite {
51 7c02238e Christos Stathis
52 7c02238e Christos Stathis
        Pithos app;
53 7c02238e Christos Stathis
        
54 a2f617f8 Christos Stathis
        Anchor newFolderButton;
55 7c02238e Christos Stathis
        
56 a2f617f8 Christos Stathis
        Anchor shareFolderButton;
57 7c02238e Christos Stathis
        
58 a2f617f8 Christos Stathis
        Anchor refreshButton;
59 7c02238e Christos Stathis
        
60 7c02238e Christos Stathis
        private Anchor toolsButton;
61 7c02238e Christos Stathis
        
62 7c02238e Christos Stathis
        ToolsMenu menu;
63 7c02238e Christos Stathis
        
64 7c02238e Christos Stathis
        public Toolbar(final Pithos _app) {
65 7c02238e Christos Stathis
                app = _app;
66 7c02238e Christos Stathis
        FlowPanel toolbar = new FlowPanel();
67 7c02238e Christos Stathis
        toolbar.getElement().setId("toolbar");
68 7c02238e Christos Stathis
        toolbar.addStyleName("clearfix");
69 7c02238e Christos Stathis
        toolbar.getElement().getStyle().setDisplay(Display.BLOCK);
70 7c02238e Christos Stathis
71 7c02238e Christos Stathis
        newFolderButton = new Anchor("<span class='ico'></span><span class='title'>New folder</span>", true);
72 7c02238e Christos Stathis
        newFolderButton.getElement().setId("newfolder-button");
73 7c02238e Christos Stathis
        newFolderButton.addStyleName("pithos-toolbarItem");
74 7c02238e Christos Stathis
        newFolderButton.setVisible(false);
75 7c02238e Christos Stathis
        newFolderButton.addClickHandler(new ClickHandler() {
76 7c02238e Christos Stathis
                        
77 7c02238e Christos Stathis
                        @Override
78 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
79 7c02238e Christos Stathis
                                Folder folder = app.getSelectedTree().getSelection();
80 7c02238e Christos Stathis
                                if (folder != null) {
81 cc0120ab Christos KK Loverdos
                                Boolean[] permissions = folder.getPermissions().get(app.getUserID());
82 4eaecbac Christos KK Loverdos
                                    boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
83 7c02238e Christos Stathis
                                    
84 7c02238e Christos Stathis
                                    if (!folder.isInTrash() && canWrite)
85 7c02238e Christos Stathis
                                            new NewFolderCommand(app, null, folder).execute();
86 7c02238e Christos Stathis
                                }
87 7c02238e Christos Stathis
                        }
88 7c02238e Christos Stathis
                });
89 7c02238e Christos Stathis
        toolbar.add(newFolderButton);
90 7c02238e Christos Stathis
91 7c02238e Christos Stathis
        shareFolderButton = new Anchor("<span class='ico'></span><span class='title'>Share folder</span>", true);
92 7c02238e Christos Stathis
        shareFolderButton.getElement().setId("sharefolder-button");
93 7c02238e Christos Stathis
        shareFolderButton.addStyleName("pithos-toolbarItem");
94 7c02238e Christos Stathis
        shareFolderButton.setVisible(false);
95 7c02238e Christos Stathis
        shareFolderButton.addClickHandler(new ClickHandler() {
96 7c02238e Christos Stathis
                        
97 7c02238e Christos Stathis
                        @Override
98 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
99 7c02238e Christos Stathis
                                Folder folder = app.getSelectedTree().getSelection();
100 7c02238e Christos Stathis
                                if (folder != null) {
101 cc0120ab Christos KK Loverdos
                                Boolean[] permissions = folder.getPermissions().get(app.getUserID());
102 4eaecbac Christos KK Loverdos
                                    boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
103 7c02238e Christos Stathis
                                    boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
104 7c02238e Christos Stathis
                                    
105 7c02238e Christos Stathis
                                    if (!folder.isInTrash() && canWrite && isFolderTreeSelected && !folder.isContainer())
106 7c02238e Christos Stathis
                                            new PropertiesCommand(app, null, folder, PropertiesCommand.PERMISSIONS).execute();
107 7c02238e Christos Stathis
                                }
108 7c02238e Christos Stathis
                        }
109 7c02238e Christos Stathis
                });
110 7c02238e Christos Stathis
        toolbar.add(shareFolderButton);
111 7c02238e Christos Stathis
112 7c02238e Christos Stathis
        refreshButton = new Anchor("<span class='ico'></span><span class='title'>Refresh</span>", true);
113 7c02238e Christos Stathis
        refreshButton.getElement().setId("refresh-button");
114 7c02238e Christos Stathis
        refreshButton.addStyleName("pithos-toolbarItem");
115 7c02238e Christos Stathis
        refreshButton.setVisible(false);
116 7c02238e Christos Stathis
        refreshButton.addClickHandler(new ClickHandler() {
117 7c02238e Christos Stathis
                        
118 7c02238e Christos Stathis
                        @Override
119 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
120 7c02238e Christos Stathis
                            boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
121 7c02238e Christos Stathis
                            boolean otherSharedTreeSelected = app.getSelectedTree().equals(app.getOtherSharedTreeView());
122 7c02238e Christos Stathis
                            Folder folder = app.getSelectedTree().getSelection();
123 7c02238e Christos Stathis
                            
124 5d18aa82 Christos Stathis
                            if (folder != null) {
125 5d18aa82 Christos Stathis
                                    if (!app.isMySharedSelected()) {
126 5d18aa82 Christos Stathis
                                            app.updateFolder(folder, true, new Command() {
127 5d18aa82 Christos Stathis
                                                    
128 5d18aa82 Christos Stathis
                                                    @Override
129 5d18aa82 Christos Stathis
                                                    public void execute() {
130 5d18aa82 Christos Stathis
                                                            app.updateStatistics();
131 5d18aa82 Christos Stathis
                                                    }
132 5d18aa82 Christos Stathis
                                            }, true);
133 5d18aa82 Christos Stathis
                                    }
134 5d18aa82 Christos Stathis
                                    else
135 5d18aa82 Christos Stathis
                                            app.updateSharedFolder(folder, true);
136 7c02238e Christos Stathis
                                            
137 5d18aa82 Christos Stathis
                            }
138 7c02238e Christos Stathis
                        }
139 5d18aa82 Christos Stathis
        });
140 7c02238e Christos Stathis
        toolbar.add(refreshButton);
141 7c02238e Christos Stathis
142 7c02238e Christos Stathis
        toolsButton = new Anchor("<span class='ico'></span><span class='title'>More...</span>", true);
143 7c02238e Christos Stathis
        toolsButton.getElement().setId("tools-button");
144 7c02238e Christos Stathis
        toolsButton.addStyleName("pithos-toolbarItem");
145 7c02238e Christos Stathis
        toolsButton.setVisible(false);
146 7c02238e Christos Stathis
        toolsButton.addClickHandler(new ClickHandler() {
147 7c02238e Christos Stathis
                        
148 7c02238e Christos Stathis
                        @Override
149 7c02238e Christos Stathis
                        public void onClick(ClickEvent event) {
150 7c02238e Christos Stathis
                if (!menu.isEmpty()) {
151 7c02238e Christos Stathis
                            menu.setPopupPosition(event.getClientX(), event.getClientY());
152 7c02238e Christos Stathis
                            menu.show();
153 7c02238e Christos Stathis
                }
154 7c02238e Christos Stathis
                        }
155 7c02238e Christos Stathis
                });
156 7c02238e Christos Stathis
        toolbar.add(toolsButton);
157 7c02238e Christos Stathis
        
158 7c02238e Christos Stathis
        initWidget(toolbar);
159 7c02238e Christos Stathis
        }
160 7c02238e Christos Stathis
        
161 7c02238e Christos Stathis
        public void showRelevantButtons() {
162 80a65a5f Christos Stathis
                TreeView selectedTree = app.getSelectedTree();
163 80a65a5f Christos Stathis
                if (selectedTree != null) {
164 80a65a5f Christos Stathis
                        final Folder folder = app.getSelectedTree().getSelection();
165 80a65a5f Christos Stathis
                        if (folder != null) {
166 80a65a5f Christos Stathis
                                app.scheduleFolderHeadCommand(folder, new Command() {
167 80a65a5f Christos Stathis
                                        
168 80a65a5f Christos Stathis
                                        @Override
169 80a65a5f Christos Stathis
                                        public void execute() {
170 cc0120ab Christos KK Loverdos
                                        Boolean[] permissions = folder.getPermissions().get(app.getUserID());
171 4eaecbac Christos KK Loverdos
                                            boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
172 80a65a5f Christos Stathis
                                            boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
173 80a65a5f Christos Stathis
                                            boolean otherSharedTreeSelected = app.getSelectedTree().equals(app.getOtherSharedTreeView());
174 80a65a5f Christos Stathis
                                            
175 5d18aa82 Christos Stathis
                                            refreshButton.setVisible(true);
176 80a65a5f Christos Stathis
                                            
177 80a65a5f Christos Stathis
                                            if (!folder.isInTrash() && canWrite) {
178 80a65a5f Christos Stathis
                                                    if (isFolderTreeSelected || otherSharedTreeSelected)
179 80a65a5f Christos Stathis
                                                            newFolderButton.setVisible(true);
180 c46c9e31 Christos Stathis
                                                    else
181 c46c9e31 Christos Stathis
                                                            newFolderButton.setVisible(false);
182 80a65a5f Christos Stathis
                                                    if (isFolderTreeSelected && !folder.isContainer())
183 80a65a5f Christos Stathis
                                                            shareFolderButton.setVisible(true);
184 80a65a5f Christos Stathis
                                                    else
185 80a65a5f Christos Stathis
                                                            shareFolderButton.setVisible(false);
186 80a65a5f Christos Stathis
                                            }
187 80a65a5f Christos Stathis
                                            else {
188 80a65a5f Christos Stathis
                                                    newFolderButton.setVisible(false);
189 80a65a5f Christos Stathis
                                                    shareFolderButton.setVisible(false);
190 80a65a5f Christos Stathis
                                            }
191 80a65a5f Christos Stathis
                                        }
192 80a65a5f Christos Stathis
                                });
193 80a65a5f Christos Stathis
                        }
194 80a65a5f Christos Stathis
                        else {
195 80a65a5f Christos Stathis
                                newFolderButton.setVisible(false);
196 80a65a5f Christos Stathis
                                shareFolderButton.setVisible(false);
197 80a65a5f Christos Stathis
                                refreshButton.setVisible(false);
198 80a65a5f Christos Stathis
                        }
199 7c02238e Christos Stathis
                }
200 7c02238e Christos Stathis
                else {
201 7c02238e Christos Stathis
                        newFolderButton.setVisible(false);
202 7c02238e Christos Stathis
                        shareFolderButton.setVisible(false);
203 7c02238e Christos Stathis
                        refreshButton.setVisible(false);
204 7c02238e Christos Stathis
                }
205 7c02238e Christos Stathis
206 80a65a5f Christos Stathis
                if (selectedTree != null) {
207 80a65a5f Christos Stathis
                menu = new ToolsMenu(app, Pithos.images, selectedTree, selectedTree.getSelection(), app.getFileList().getSelectedFiles());
208 80a65a5f Christos Stathis
                if (!menu.isEmpty())
209 80a65a5f Christos Stathis
                        toolsButton.setVisible(true);
210 80a65a5f Christos Stathis
                else
211 80a65a5f Christos Stathis
                        toolsButton.setVisible(false);
212 80a65a5f Christos Stathis
                }
213 7c02238e Christos Stathis
    }
214 7c02238e Christos Stathis
}