root / src / gr / grnet / pithos / web / client / Toolbar.java @ 5f91f72d
History | View | Annotate | Download (7.4 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 | 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 | 7c02238e | Christos Stathis | private Anchor newFolderButton;
|
55 | 7c02238e | Christos Stathis | |
56 | 7c02238e | Christos Stathis | private Anchor shareFolderButton;
|
57 | 7c02238e | Christos Stathis | |
58 | 7c02238e | Christos Stathis | private 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 | 7c02238e | Christos Stathis | Boolean[] permissions = folder.getPermissions().get(app.getUsername()); |
82 | 7c02238e | Christos Stathis | boolean canWrite = folder.getOwner().equals(app.getUsername()) || (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 | 7c02238e | Christos Stathis | Boolean[] permissions = folder.getPermissions().get(app.getUsername()); |
102 | 7c02238e | Christos Stathis | boolean canWrite = folder.getOwner().equals(app.getUsername()) || (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 | 7c02238e | Christos Stathis | if (folder != null && (isFolderTreeSelected || otherSharedTreeSelected)) |
125 | 7c02238e | Christos Stathis | app.updateFolder(folder, true, new Command() { |
126 | 7c02238e | Christos Stathis | |
127 | 7c02238e | Christos Stathis | @Override
|
128 | 7c02238e | Christos Stathis | public void execute() { |
129 | 7c02238e | Christos Stathis | app.updateStatistics(); |
130 | 7c02238e | Christos Stathis | } |
131 | 7c02238e | Christos Stathis | }); |
132 | 7c02238e | Christos Stathis | } |
133 | 7c02238e | Christos Stathis | }); |
134 | 7c02238e | Christos Stathis | toolbar.add(refreshButton); |
135 | 7c02238e | Christos Stathis | |
136 | 7c02238e | Christos Stathis | toolsButton = new Anchor("<span class='ico'></span><span class='title'>More...</span>", true); |
137 | 7c02238e | Christos Stathis | toolsButton.getElement().setId("tools-button");
|
138 | 7c02238e | Christos Stathis | toolsButton.addStyleName("pithos-toolbarItem");
|
139 | 7c02238e | Christos Stathis | toolsButton.setVisible(false);
|
140 | 7c02238e | Christos Stathis | toolsButton.addClickHandler(new ClickHandler() {
|
141 | 7c02238e | Christos Stathis | |
142 | 7c02238e | Christos Stathis | @Override
|
143 | 7c02238e | Christos Stathis | public void onClick(ClickEvent event) { |
144 | 7c02238e | Christos Stathis | if (!menu.isEmpty()) {
|
145 | 7c02238e | Christos Stathis | menu.setPopupPosition(event.getClientX(), event.getClientY()); |
146 | 7c02238e | Christos Stathis | menu.show(); |
147 | 7c02238e | Christos Stathis | } |
148 | 7c02238e | Christos Stathis | } |
149 | 7c02238e | Christos Stathis | }); |
150 | 7c02238e | Christos Stathis | toolbar.add(toolsButton); |
151 | 7c02238e | Christos Stathis | |
152 | 7c02238e | Christos Stathis | initWidget(toolbar); |
153 | 7c02238e | Christos Stathis | } |
154 | 7c02238e | Christos Stathis | |
155 | 7c02238e | Christos Stathis | public void showRelevantButtons() { |
156 | 7c02238e | Christos Stathis | Folder folder = app.getSelectedTree().getSelection(); |
157 | 7c02238e | Christos Stathis | if (folder != null) { |
158 | 7c02238e | Christos Stathis | Boolean[] permissions = folder.getPermissions().get(app.getUsername()); |
159 | 7c02238e | Christos Stathis | boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]); |
160 | 7c02238e | Christos Stathis | boolean isFolderTreeSelected = app.getSelectedTree().equals(app.getFolderTreeView());
|
161 | 7c02238e | Christos Stathis | boolean otherSharedTreeSelected = app.getSelectedTree().equals(app.getOtherSharedTreeView());
|
162 | 7c02238e | Christos Stathis | |
163 | 7c02238e | Christos Stathis | if (isFolderTreeSelected || otherSharedTreeSelected)
|
164 | 7c02238e | Christos Stathis | refreshButton.setVisible(true);
|
165 | 7c02238e | Christos Stathis | else
|
166 | 7c02238e | Christos Stathis | refreshButton.setVisible(true);
|
167 | 7c02238e | Christos Stathis | |
168 | 7c02238e | Christos Stathis | if (!folder.isInTrash() && canWrite) {
|
169 | 7c02238e | Christos Stathis | if (isFolderTreeSelected || otherSharedTreeSelected)
|
170 | 7c02238e | Christos Stathis | newFolderButton.setVisible(true);
|
171 | 7c02238e | Christos Stathis | if (isFolderTreeSelected && !folder.isContainer())
|
172 | 7c02238e | Christos Stathis | shareFolderButton.setVisible(true);
|
173 | 7c02238e | Christos Stathis | else
|
174 | 7c02238e | Christos Stathis | shareFolderButton.setVisible(false);
|
175 | 7c02238e | Christos Stathis | } |
176 | 7c02238e | Christos Stathis | else {
|
177 | 7c02238e | Christos Stathis | newFolderButton.setVisible(false);
|
178 | 7c02238e | Christos Stathis | shareFolderButton.setVisible(false);
|
179 | 7c02238e | Christos Stathis | } |
180 | 7c02238e | Christos Stathis | } |
181 | 7c02238e | Christos Stathis | else {
|
182 | 7c02238e | Christos Stathis | newFolderButton.setVisible(false);
|
183 | 7c02238e | Christos Stathis | shareFolderButton.setVisible(false);
|
184 | 7c02238e | Christos Stathis | refreshButton.setVisible(false);
|
185 | 7c02238e | Christos Stathis | } |
186 | 7c02238e | Christos Stathis | |
187 | 7c02238e | Christos Stathis | menu = new ToolsMenu(app, Pithos.images, app.getSelectedTree(), app.getSelectedTree().getSelection(), app.getFileList().getSelectedFiles());
|
188 | 7c02238e | Christos Stathis | if (!menu.isEmpty())
|
189 | 7c02238e | Christos Stathis | toolsButton.setVisible(true);
|
190 | 7c02238e | Christos Stathis | else
|
191 | 7c02238e | Christos Stathis | toolsButton.setVisible(false);
|
192 | 7c02238e | Christos Stathis | } |
193 | 7c02238e | Christos Stathis | } |