Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / EditMenu.java @ 4cef6f04

History | View | Annotate | Download (7.5 kB)

1 023f6f1e Panagiotis Astithas
/*
2 023f6f1e Panagiotis Astithas
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3 023f6f1e Panagiotis Astithas
 *
4 023f6f1e Panagiotis Astithas
 * This file is part of GSS.
5 023f6f1e Panagiotis Astithas
 *
6 023f6f1e Panagiotis Astithas
 * GSS is free software: you can redistribute it and/or modify
7 023f6f1e Panagiotis Astithas
 * it under the terms of the GNU General Public License as published by
8 023f6f1e Panagiotis Astithas
 * the Free Software Foundation, either version 3 of the License, or
9 023f6f1e Panagiotis Astithas
 * (at your option) any later version.
10 023f6f1e Panagiotis Astithas
 *
11 023f6f1e Panagiotis Astithas
 * GSS is distributed in the hope that it will be useful,
12 023f6f1e Panagiotis Astithas
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 023f6f1e Panagiotis Astithas
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 023f6f1e Panagiotis Astithas
 * GNU General Public License for more details.
15 023f6f1e Panagiotis Astithas
 *
16 023f6f1e Panagiotis Astithas
 * You should have received a copy of the GNU General Public License
17 023f6f1e Panagiotis Astithas
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 023f6f1e Panagiotis Astithas
 */
19 023f6f1e Panagiotis Astithas
package gr.ebs.gss.client;
20 023f6f1e Panagiotis Astithas
21 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.CopyCommand;
22 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.CutCommand;
23 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.DeleteCommand;
24 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.PasteCommand;
25 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.ToTrashCommand;
26 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.FileResource;
27 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.FolderResource;
28 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.rest.resource.GroupUserResource;
29 023f6f1e Panagiotis Astithas
30 023f6f1e Panagiotis Astithas
import java.util.List;
31 023f6f1e Panagiotis Astithas
32 023f6f1e Panagiotis Astithas
import com.google.gwt.event.dom.client.ClickEvent;
33 023f6f1e Panagiotis Astithas
import com.google.gwt.event.dom.client.ClickHandler;
34 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ClientBundle;
35 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ImageResource;
36 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.Command;
37 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.AbstractImagePrototype;
38 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.MenuBar;
39 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.PopupPanel;
40 023f6f1e Panagiotis Astithas
41 023f6f1e Panagiotis Astithas
/**
42 023f6f1e Panagiotis Astithas
 * The 'Edit' menu implementation.
43 023f6f1e Panagiotis Astithas
 */
44 023f6f1e Panagiotis Astithas
public class EditMenu extends PopupPanel implements ClickHandler {
45 023f6f1e Panagiotis Astithas
46 023f6f1e Panagiotis Astithas
        /**
47 023f6f1e Panagiotis Astithas
         * The widget's images.
48 023f6f1e Panagiotis Astithas
         */
49 023f6f1e Panagiotis Astithas
        private final Images images;
50 023f6f1e Panagiotis Astithas
51 023f6f1e Panagiotis Astithas
        private final MenuBar contextMenu  = new MenuBar(true);
52 023f6f1e Panagiotis Astithas
53 023f6f1e Panagiotis Astithas
        /**
54 023f6f1e Panagiotis Astithas
         * An image bundle for this widget's images.
55 023f6f1e Panagiotis Astithas
         */
56 023f6f1e Panagiotis Astithas
        public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
57 023f6f1e Panagiotis Astithas
58 023f6f1e Panagiotis Astithas
                /**
59 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'editcut.png' residing in the package
60 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
61 023f6f1e Panagiotis Astithas
                 *
62 023f6f1e Panagiotis Astithas
                 * @return the image prototype
63 023f6f1e Panagiotis Astithas
                 */
64 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/editcut.png")
65 023f6f1e Panagiotis Astithas
                ImageResource cut();
66 023f6f1e Panagiotis Astithas
67 023f6f1e Panagiotis Astithas
                /**
68 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'editcopy.png' residing in the package
69 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
70 023f6f1e Panagiotis Astithas
                 *
71 023f6f1e Panagiotis Astithas
                 * @return the image prototype
72 023f6f1e Panagiotis Astithas
                 */
73 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/editcopy.png")
74 023f6f1e Panagiotis Astithas
                ImageResource copy();
75 023f6f1e Panagiotis Astithas
76 023f6f1e Panagiotis Astithas
                /**
77 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'editpaste.png' residing in the package
78 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
79 023f6f1e Panagiotis Astithas
                 *
80 023f6f1e Panagiotis Astithas
                 * @return the image prototype
81 023f6f1e Panagiotis Astithas
                 */
82 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/editpaste.png")
83 023f6f1e Panagiotis Astithas
                ImageResource paste();
84 023f6f1e Panagiotis Astithas
85 023f6f1e Panagiotis Astithas
                /**
86 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'editdelete.png' residing in the package
87 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
88 023f6f1e Panagiotis Astithas
                 *
89 023f6f1e Panagiotis Astithas
                 * @return the image prototype
90 023f6f1e Panagiotis Astithas
                 */
91 023f6f1e Panagiotis Astithas
                @Override
92 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/editdelete.png")
93 023f6f1e Panagiotis Astithas
                ImageResource delete();
94 023f6f1e Panagiotis Astithas
95 023f6f1e Panagiotis Astithas
                /**
96 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'translate.png' residing in the package
97 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
98 023f6f1e Panagiotis Astithas
                 *
99 023f6f1e Panagiotis Astithas
                 * @return the image prototype
100 023f6f1e Panagiotis Astithas
                 */
101 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/translate.png")
102 023f6f1e Panagiotis Astithas
                ImageResource selectAll();
103 023f6f1e Panagiotis Astithas
104 023f6f1e Panagiotis Astithas
                /**
105 023f6f1e Panagiotis Astithas
                 * Will bundle the file 'border_remove.png' residing in the package
106 023f6f1e Panagiotis Astithas
                 * 'gr.ebs.gss.resources'.
107 023f6f1e Panagiotis Astithas
                 *
108 023f6f1e Panagiotis Astithas
                 * @return the image prototype
109 023f6f1e Panagiotis Astithas
                 */
110 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/border_remove.png")
111 023f6f1e Panagiotis Astithas
                ImageResource unselectAll();
112 023f6f1e Panagiotis Astithas
        }
113 023f6f1e Panagiotis Astithas
114 023f6f1e Panagiotis Astithas
        /**
115 023f6f1e Panagiotis Astithas
         * The widget's constructor.
116 023f6f1e Panagiotis Astithas
         *
117 023f6f1e Panagiotis Astithas
         * @param newImages the image bundle passed on by the parent object
118 023f6f1e Panagiotis Astithas
         */
119 023f6f1e Panagiotis Astithas
        public EditMenu(final Images newImages) {
120 023f6f1e Panagiotis Astithas
                // The popup's constructor's argument is a boolean specifying that it
121 023f6f1e Panagiotis Astithas
                // auto-close itself when the user clicks outside of it.
122 023f6f1e Panagiotis Astithas
                super(true);
123 023f6f1e Panagiotis Astithas
                setAnimationEnabled(true);
124 023f6f1e Panagiotis Astithas
                images = newImages;
125 023f6f1e Panagiotis Astithas
                createMenu();
126 023f6f1e Panagiotis Astithas
                add(contextMenu);
127 023f6f1e Panagiotis Astithas
        }
128 023f6f1e Panagiotis Astithas
129 023f6f1e Panagiotis Astithas
        @Override
130 023f6f1e Panagiotis Astithas
        public void onClick(ClickEvent event) {
131 023f6f1e Panagiotis Astithas
                final EditMenu menu = new EditMenu(images);
132 023f6f1e Panagiotis Astithas
                final int left = event.getRelativeElement().getAbsoluteLeft();
133 023f6f1e Panagiotis Astithas
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
134 023f6f1e Panagiotis Astithas
                menu.setPopupPosition(left, top);
135 023f6f1e Panagiotis Astithas
                menu.show();
136 023f6f1e Panagiotis Astithas
        }
137 023f6f1e Panagiotis Astithas
138 023f6f1e Panagiotis Astithas
        public MenuBar createMenu() {
139 023f6f1e Panagiotis Astithas
                contextMenu.clearItems();
140 023f6f1e Panagiotis Astithas
                contextMenu.setAutoOpen(false);
141 023f6f1e Panagiotis Astithas
142 023f6f1e Panagiotis Astithas
                final Command selectAllCommand = new Command() {
143 023f6f1e Panagiotis Astithas
144 023f6f1e Panagiotis Astithas
                        @Override
145 023f6f1e Panagiotis Astithas
                        public void execute() {
146 023f6f1e Panagiotis Astithas
                                hide();
147 023f6f1e Panagiotis Astithas
                                if(GSS.get().isFileListShowing())
148 023f6f1e Panagiotis Astithas
                                        GSS.get().getFileList().selectAllRows();
149 023f6f1e Panagiotis Astithas
                                else if(GSS.get().isSearchResultsShowing())
150 023f6f1e Panagiotis Astithas
                                        GSS.get().getSearchResults().selectAllRows();
151 023f6f1e Panagiotis Astithas
                        }
152 023f6f1e Panagiotis Astithas
                };
153 023f6f1e Panagiotis Astithas
                final Command unselectAllCommand = new Command() {
154 023f6f1e Panagiotis Astithas
155 023f6f1e Panagiotis Astithas
                        @Override
156 023f6f1e Panagiotis Astithas
                        public void execute() {
157 023f6f1e Panagiotis Astithas
                                hide();
158 023f6f1e Panagiotis Astithas
                                if(GSS.get().isFileListShowing())
159 023f6f1e Panagiotis Astithas
                                        GSS.get().getFileList().clearSelectedRows();
160 023f6f1e Panagiotis Astithas
                                else if(GSS.get().isSearchResultsShowing())
161 023f6f1e Panagiotis Astithas
                                        GSS.get().getSearchResults().clearSelectedRows();
162 023f6f1e Panagiotis Astithas
                        }
163 023f6f1e Panagiotis Astithas
                };
164 023f6f1e Panagiotis Astithas
165 023f6f1e Panagiotis Astithas
                boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource
166 023f6f1e Panagiotis Astithas
                                        || GSS.get().getCurrentSelection() instanceof FileResource || GSS        .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);
167 023f6f1e Panagiotis Astithas
                String cutLabel = "Cut";
168 023f6f1e Panagiotis Astithas
                String copyLabel ="Copy";
169 023f6f1e Panagiotis Astithas
                String pasteLabel = "Paste";
170 023f6f1e Panagiotis Astithas
                if(GSS.get().getCurrentSelection() != null)
171 023f6f1e Panagiotis Astithas
                        if(GSS.get().getCurrentSelection() instanceof FolderResource){
172 023f6f1e Panagiotis Astithas
                                cutLabel = "Cut Folder";
173 023f6f1e Panagiotis Astithas
                                copyLabel = "Copy Folder";
174 023f6f1e Panagiotis Astithas
                        }
175 023f6f1e Panagiotis Astithas
                        else if(GSS.get().getCurrentSelection() instanceof FileResource){
176 023f6f1e Panagiotis Astithas
                                cutLabel = "Cut File";
177 023f6f1e Panagiotis Astithas
                                copyLabel = "Copy File";
178 023f6f1e Panagiotis Astithas
                        }
179 023f6f1e Panagiotis Astithas
                        else if(GSS.get().getCurrentSelection() instanceof List){
180 023f6f1e Panagiotis Astithas
                                cutLabel = "Cut Files";
181 023f6f1e Panagiotis Astithas
                                copyLabel = "Copy Files";
182 023f6f1e Panagiotis Astithas
                        }
183 023f6f1e Panagiotis Astithas
                if(GSS.get().getClipboard().getItem() != null)
184 023f6f1e Panagiotis Astithas
                        if(GSS.get().getClipboard().getItem().getFile() != null)
185 023f6f1e Panagiotis Astithas
                                pasteLabel = "Paste File";
186 023f6f1e Panagiotis Astithas
                        else if(GSS.get().getClipboard().getItem().getFiles() != null)
187 023f6f1e Panagiotis Astithas
                                pasteLabel = "Paste Files";
188 023f6f1e Panagiotis Astithas
                        else if(GSS.get().getClipboard().getItem().getFolderResource() != null)
189 023f6f1e Panagiotis Astithas
                                pasteLabel = "Paste Folder";
190 023f6f1e Panagiotis Astithas
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(this)).setVisible(cutcopyVisible);
191 023f6f1e Panagiotis Astithas
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(this)).setVisible(cutcopyVisible);
192 023f6f1e Panagiotis Astithas
                if (GSS.get().getClipboard().getItem() != null)
193 023f6f1e Panagiotis Astithas
                        if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null)
194 023f6f1e Panagiotis Astithas
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));
195 023f6f1e Panagiotis Astithas
                        else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
196 023f6f1e Panagiotis Astithas
                                //do not show paste
197 023f6f1e Panagiotis Astithas
                        }
198 023f6f1e Panagiotis Astithas
                        else if (GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
199 023f6f1e Panagiotis Astithas
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));
200 023f6f1e Panagiotis Astithas
                contextMenu        .addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this))
201 023f6f1e Panagiotis Astithas
                                        .setVisible(cutcopyVisible);
202 023f6f1e Panagiotis Astithas
                contextMenu        .addItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images))
203 023f6f1e Panagiotis Astithas
                                        .setVisible(cutcopyVisible);
204 023f6f1e Panagiotis Astithas
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
205 023f6f1e Panagiotis Astithas
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
206 023f6f1e Panagiotis Astithas
                return contextMenu;
207 023f6f1e Panagiotis Astithas
        }
208 023f6f1e Panagiotis Astithas
209 023f6f1e Panagiotis Astithas
210 023f6f1e Panagiotis Astithas
211 023f6f1e Panagiotis Astithas
}