Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.1 kB)

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 org.gss_project.gss.web.client;
20

    
21
import org.gss_project.gss.web.client.Groups.Images;
22
import org.gss_project.gss.web.client.commands.CopyCommand;
23
import org.gss_project.gss.web.client.commands.DeleteUserOrGroupCommand;
24
import org.gss_project.gss.web.client.commands.NewGroupCommand;
25
import org.gss_project.gss.web.client.commands.NewUserCommand;
26
import org.gss_project.gss.web.client.commands.PasteCommand;
27
import org.gss_project.gss.web.client.rest.resource.GroupResource;
28
import org.gss_project.gss.web.client.rest.resource.GroupUserResource;
29

    
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;
35

    
36

    
37
/**
38
 * @author kman
39
 *
40
 */
41
public class GroupContextMenu extends PopupPanel {
42

    
43
        /**
44
         * The widget's images.
45
         */
46
        private final Images images;
47
        private MenuItem copy;
48
        private MenuItem paste;
49
        private MenuItem newGroup;
50
        private MenuItem addUser;
51
        private MenuItem delete;
52
        public GroupContextMenu(final Images newImages) {
53
                // The popup's constructor's argument is a boolean specifying that it
54
                // auto-close itself when the user clicks outside of it.
55
                super(true);
56
                images=newImages;
57
                setAnimationEnabled(true);
58
                final MenuBar contextMenu = new MenuBar(true);
59
                newGroup = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));
60
                newGroup.getElement().setId("groupContextMenu.newGroup");
61
                contextMenu.addItem(newGroup);
62
                
63
                addUser = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;Add User</span>", true, new NewUserCommand(this));
64
                addUser.getElement().setId("groupContextMenu.addUser");
65
                contextMenu.addItem(addUser);
66
                                
67
                copy = new MenuItem("<span id=groupContextMenu.copyUser>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy User</span>", true, new CopyCommand(this));
68
                copy.getElement().setId("groupContextMenu.copyUser");
69
                contextMenu.addItem(copy);
70
                
71
                paste = new MenuItem("<span id=groupContextMenu.pasteUser>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste User</span>", true, new PasteCommand(this));
72
                paste.getElement().setId("groupContextMenu.pasteUser");
73
                contextMenu.addItem(paste);
74
                
75
                delete = new MenuItem("<span id=groupContextMenu.delete>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteUserOrGroupCommand(this,images));
76
                delete.getElement().setId("groupContextMenu.delete");
77
                contextMenu.addItem(delete);
78
                
79
                add(contextMenu);
80

    
81
        }
82

    
83
        /* (non-Javadoc)
84
         * @see com.google.gwt.user.client.ui.PopupPanel#show()
85
         */
86
        @Override
87
        public void show() {
88
                TreeItem current = GSS.get().getGroups().getCurrent();
89
                if(current==null){
90
                        copy.setVisible(false);
91
                        paste.setVisible(false);
92
                        addUser.setVisible(false);
93
                        delete.setVisible(false);
94
                }
95
                else{
96
                        newGroup.setVisible(false);
97
                        if(current.getUserObject() instanceof GroupUserResource && GSS.get().getCurrentSelection() instanceof GroupUserResource)
98
                                copy.setVisible(true);
99
                        else
100
                                copy.setVisible(false);
101
                        if(current.getUserObject() instanceof GroupResource && GSS.get().getCurrentSelection() instanceof GroupResource && GSS.get().getClipboard().hasUserItem())
102
                                paste.setVisible(true);
103
                        else
104
                                paste.setVisible(false);
105
                }
106
                super.show();
107
        }
108

    
109
}