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