2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.Groups.Images;
22 import gr.ebs.gss.client.commands.CopyCommand;
23 import gr.ebs.gss.client.commands.DeleteUserOrGroupCommand;
24 import gr.ebs.gss.client.commands.NewGroupCommand;
25 import gr.ebs.gss.client.commands.NewUserCommand;
26 import gr.ebs.gss.client.commands.PasteCommand;
27 import gr.ebs.gss.client.rest.resource.GroupResource;
28 import gr.ebs.gss.client.rest.resource.GroupUserResource;
30 import com.google.gwt.user.client.ui.AbstractImagePrototype;
31 import com.google.gwt.user.client.ui.MenuBar;
32 import com.google.gwt.user.client.ui.MenuItem;
33 import com.google.gwt.user.client.ui.PopupPanel;
34 import com.google.gwt.user.client.ui.TreeItem;
41 public class GroupContextMenu extends PopupPanel {
44 * The widget's images.
46 private final Images images;
47 private MenuItem copy;
48 private MenuItem paste;
51 public GroupContextMenu(final Images newImages) {
52 // The popup's constructor's argument is a boolean specifying that it
53 // auto-close itself when the user clicks outside of it.
56 setAnimationEnabled(true);
57 final MenuBar contextMenu = new MenuBar(true);
58 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " New Group</span>", true, new NewGroupCommand(this));
59 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " Add User</span>", true, new NewUserCommand(this));
60 copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy User</span>", true, new CopyCommand(this));
61 contextMenu.addItem(copy);
62 paste = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste User</span>", true, new PasteCommand(this));
63 contextMenu.addItem(paste);
64 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteUserOrGroupCommand(this,images));
70 * @see com.google.gwt.user.client.ui.PopupPanel#show()
74 TreeItem current = GSS.get().getGroups().getCurrent();
75 if(current !=null && current.getUserObject() instanceof GroupUserResource && GSS.get().getCurrentSelection() instanceof GroupUserResource)
76 copy.setVisible(true);
78 copy.setVisible(false);
79 if(current !=null && current.getUserObject() instanceof GroupResource && GSS.get().getCurrentSelection() instanceof GroupResource && GSS.get().getClipboard().hasUserItem())
80 paste.setVisible(true);
82 paste.setVisible(false);