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