Add Cut, Move to trash and Delete options to Other's shared context menu.
[pithos] / src / gr / ebs / gss / client / GroupContextMenu.java
1 /*
2  * Copyright 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 gr.ebs.gss.client;
20
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;
29
30 import com.google.gwt.user.client.ui.MenuBar;
31 import com.google.gwt.user.client.ui.MenuItem;
32 import com.google.gwt.user.client.ui.PopupPanel;
33 import com.google.gwt.user.client.ui.TreeItem;
34
35
36 /**
37  * @author kman
38  *
39  */
40 public class GroupContextMenu extends PopupPanel {
41
42         /**
43          * The widget's images.
44          */
45         private final Images images;
46         private MenuItem copy;
47         private MenuItem paste;
48
49
50         public GroupContextMenu(final Images newImages) {
51                 // The popup's constructor's argument is a boolean specifying that it
52                 // auto-close itself when the user clicks outside of it.
53                 super(true);
54                 images=newImages;
55                 setAnimationEnabled(true);
56                 final MenuBar contextMenu = new MenuBar(true);
57                 contextMenu.addItem("<span>" + newImages.groupNew().getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));
58                 contextMenu.addItem("<span>" + newImages.groupNew().getHTML() + "&nbsp;Add User</span>", true, new NewUserCommand(this));
59                 copy = new MenuItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy User</span>", true, new CopyCommand(this));
60                 contextMenu.addItem(copy);
61                 paste = new MenuItem("<span>" + newImages.paste().getHTML() + "&nbsp;Paste User</span>", true, new PasteCommand(this));
62                 contextMenu.addItem(paste);
63                 contextMenu.addItem("<span>" + newImages.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteUserOrGroupCommand(this,images));
64                 add(contextMenu);
65
66         }
67
68         /* (non-Javadoc)
69          * @see com.google.gwt.user.client.ui.PopupPanel#show()
70          */
71         @Override
72         public void show() {
73                 TreeItem current = GSS.get().getGroups().getCurrent();
74                 if(current !=null && current.getUserObject() instanceof GroupUserResource && GSS.get().getCurrentSelection() instanceof GroupUserResource)
75                         copy.setVisible(true);
76                 else
77                         copy.setVisible(false);
78                 if(current !=null && current.getUserObject() instanceof GroupResource && GSS.get().getCurrentSelection() instanceof GroupResource && GSS.get().getClipboard().hasUserItem())
79                         paste.setVisible(true);
80                 else
81                         paste.setVisible(false);
82                 super.show();
83         }
84
85 }