Statistics
| Branch: | Tag: | Revision:

root / src / org / gss_project / gss / web / client / EditMenu.java @ 1206:292dec4eae08

History | View | Annotate | Download (8.4 kB)

1
/*
2
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package org.gss_project.gss.web.client;
20

    
21
import org.gss_project.gss.web.client.commands.CopyCommand;
22
import org.gss_project.gss.web.client.commands.CutCommand;
23
import org.gss_project.gss.web.client.commands.DeleteCommand;
24
import org.gss_project.gss.web.client.commands.PasteCommand;
25
import org.gss_project.gss.web.client.commands.ToTrashCommand;
26
import org.gss_project.gss.web.client.rest.resource.FileResource;
27

    
28
import org.gss_project.gss.web.client.rest.resource.GroupUserResource;
29
import org.gss_project.gss.web.client.rest.resource.RestResourceWrapper;
30

    
31
import java.util.List;
32

    
33
import com.google.gwt.event.dom.client.ClickEvent;
34
import com.google.gwt.event.dom.client.ClickHandler;
35
import com.google.gwt.resources.client.ClientBundle;
36
import com.google.gwt.resources.client.ImageResource;
37
import com.google.gwt.user.client.Command;
38
import com.google.gwt.user.client.ui.AbstractImagePrototype;
39
import com.google.gwt.user.client.ui.MenuBar;
40
import com.google.gwt.user.client.ui.MenuItem;
41
import com.google.gwt.user.client.ui.PopupPanel;
42

    
43
/**
44
 * The 'Edit' menu implementation.
45
 */
46
public class EditMenu extends PopupPanel implements ClickHandler {
47

    
48
        /**
49
         * The widget's images.
50
         */
51
        private final Images images;
52

    
53
        private final MenuBar contextMenu  = new MenuBar(true);
54

    
55
        /**
56
         * An image bundle for this widget's images.
57
         */
58
        public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
59

    
60
                /**
61
                 * Will bundle the file 'editcut.png' residing in the package
62
                 * 'org.gss_project.gss.web.resources'.
63
                 *
64
                 * @return the image prototype
65
                 */
66
                @Source("org/gss_project/gss/resources/editcut.png")
67
                ImageResource cut();
68

    
69
                /**
70
                 * Will bundle the file 'editcopy.png' residing in the package
71
                 * 'org.gss_project.gss.web.resources'.
72
                 *
73
                 * @return the image prototype
74
                 */
75
                @Source("org/gss_project/gss/resources/editcopy.png")
76
                ImageResource copy();
77

    
78
                /**
79
                 * Will bundle the file 'editpaste.png' residing in the package
80
                 * 'org.gss_project.gss.web.resources'.
81
                 *
82
                 * @return the image prototype
83
                 */
84
                @Source("org/gss_project/gss/resources/editpaste.png")
85
                ImageResource paste();
86

    
87
                /**
88
                 * Will bundle the file 'editdelete.png' residing in the package
89
                 * 'org.gss_project.gss.web.resources'.
90
                 *
91
                 * @return the image prototype
92
                 */
93
                @Override
94
                @Source("org/gss_project/gss/resources/editdelete.png")
95
                ImageResource delete();
96

    
97
                /**
98
                 * Will bundle the file 'translate.png' residing in the package
99
                 * 'org.gss_project.gss.web.resources'.
100
                 *
101
                 * @return the image prototype
102
                 */
103
                @Source("org/gss_project/gss/resources/translate.png")
104
                ImageResource selectAll();
105

    
106
                /**
107
                 * Will bundle the file 'border_remove.png' residing in the package
108
                 * 'org.gss_project.gss.web.resources'.
109
                 *
110
                 * @return the image prototype
111
                 */
112
                @Source("org/gss_project/gss/resources/border_remove.png")
113
                ImageResource unselectAll();
114
        }
115

    
116
        /**
117
         * The widget's constructor.
118
         *
119
         * @param newImages the image bundle passed on by the parent object
120
         */
121
        public EditMenu(final Images newImages) {
122
                // The popup's constructor's argument is a boolean specifying that it
123
                // auto-close itself when the user clicks outside of it.
124
                super(true);
125
                setAnimationEnabled(true);
126
                images = newImages;
127
                createMenu();
128
                add(contextMenu);
129
        }
130

    
131
        @Override
132
        public void onClick(ClickEvent event) {
133
                final EditMenu menu = new EditMenu(images);
134
                final int left = event.getRelativeElement().getAbsoluteLeft();
135
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
136
                menu.setPopupPosition(left, top);
137
                menu.show();
138
        }
139

    
140
        public MenuBar createMenu() {
141
                contextMenu.clearItems();
142
                contextMenu.setAutoOpen(false);
143

    
144
                final Command selectAllCommand = new Command() {
145

    
146
                        @Override
147
                        public void execute() {
148
                                hide();
149
                                if(GSS.get().isFileListShowing())
150
                                        GSS.get().getFileList().selectAllRows();
151
                                else if(GSS.get().isSearchResultsShowing())
152
                                        GSS.get().getSearchResults().selectAllRows();
153
                        }
154
                };
155
                final Command unselectAllCommand = new Command() {
156

    
157
                        @Override
158
                        public void execute() {
159
                                hide();
160
                                if(GSS.get().isFileListShowing())
161
                                        GSS.get().getFileList().clearSelectedRows();
162
                                else if(GSS.get().isSearchResultsShowing())
163
                                        GSS.get().getSearchResults().clearSelectedRows();
164
                        }
165
                };
166

    
167
                boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
168
                                        || GSS.get().getCurrentSelection() instanceof FileResource || GSS        .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);
169
                String cutLabel = "Cut";
170
                String copyLabel ="Copy";
171
                String pasteLabel = "Paste";
172
                if(GSS.get().getCurrentSelection() != null)
173
                        if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
174
                                cutLabel = "Cut Folder";
175
                                copyLabel = "Copy Folder";
176
                        }
177
                        else if(GSS.get().getCurrentSelection() instanceof FileResource){
178
                                cutLabel = "Cut File";
179
                                copyLabel = "Copy File";
180
                        }
181
                        else if(GSS.get().getCurrentSelection() instanceof List){
182
                                cutLabel = "Cut Files";
183
                                copyLabel = "Copy Files";
184
                        }
185
                if(GSS.get().getClipboard().getItem() != null)
186
                        if(GSS.get().getClipboard().getItem().getFile() != null)
187
                                pasteLabel = "Paste File";
188
                        else if(GSS.get().getClipboard().getItem().getFiles() != null)
189
                                pasteLabel = "Paste Files";
190
                        else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null)
191
                                pasteLabel = "Paste Folder";
192
                MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(this));
193
                cutItem.getElement().setId("topMenu.edit.cut");
194
                contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
195
                
196
                MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(this));
197
                copyItem.getElement().setId("topMenu.edit.copy");
198
                contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
199

    
200
                MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));                                
201
                pasteItem.getElement().setId("topMenu.edit.paste");
202
                if (GSS.get().getClipboard().getItem() != null)
203
                        if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){
204
                                contextMenu.addItem(pasteItem);
205
                        }
206
                        else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
207
                                //do not show paste
208
                        }
209
                        else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){
210
                                contextMenu.addItem(pasteItem);
211
                        }
212
                MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
213
                moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
214
                contextMenu        .addItem(moveToTrashItem)
215
                                        .setVisible(cutcopyVisible);
216
                
217
                MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
218
                deleteItem.getElement().setId("topMenu.edit.delete");
219
                contextMenu        .addItem(deleteItem)
220
                                        .setVisible(cutcopyVisible);
221
                
222
                MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
223
                selectAllItem.getElement().setId("topMenu.edit.selectAll");
224
                contextMenu.addItem(selectAllItem);
225
                
226
                MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
227
                unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
228
                contextMenu.addItem(unSelectAllItem);
229
                return contextMenu;
230
        }
231

    
232

    
233

    
234
}