forked from ome/openmicroscopy
/
GroupSelectionAction.java
179 lines (157 loc) · 5.55 KB
/
GroupSelectionAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* org.openmicroscopy.shoola.agents.treeviewer.actions.GroupSelectionAction
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2010 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.treeviewer.actions;
//Java imports
import java.awt.event.ActionEvent;
import javax.swing.Action;
import javax.swing.Icon;
//Third-party libraries
//Application-internal dependencies
import org.openmicroscopy.shoola.agents.treeviewer.IconManager;
import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent;
import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser;
import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer;
import org.openmicroscopy.shoola.env.data.model.AdminObject;
import org.openmicroscopy.shoola.util.ui.UIUtilities;
import pojos.GroupData;
/**
* Selects the group the user is member of.
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* <small>
* (<b>Internal version:</b> $Revision: $Date: $)
* </small>
* @since 3.0-Beta4
*/
public class GroupSelectionAction
extends TreeViewerAction
{
/** The name of the action. */
public static final String NAME = "Switch Group";
/** The name of the action. */
public static final String NAME_ADD = "Add Group...";
/** The name of the action. */
public static final String DESCRIPTION = "Select the sole group to " +
"display in the tree.";
/** The name of the action. */
public static final String DESCRIPTION_ADD = "Select the group to " +
"add to the tree.";
/** The group the logged in user is member of. */
private GroupData group;
/** Flag indicating to add the group or to switch.*/
private boolean add;
/**
* Sets the icon and tool tip text according to the permissions of the
* group.
*/
private void setPermissions()
{
IconManager im = IconManager.getInstance();
Icon icon = im.getIcon(IconManager.PERSONAL);
int level =
TreeViewerAgent.getRegistry().getAdminService().getPermissionLevel(
group);
String desc = "";
switch (level) {
case AdminObject.PERMISSIONS_PRIVATE:
desc = AdminObject.PERMISSIONS_PRIVATE_TEXT;
icon = im.getIcon(IconManager.PRIVATE_GROUP);
break;
case AdminObject.PERMISSIONS_GROUP_READ:
desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT;
icon = im.getIcon(IconManager.READ_GROUP);
break;
case AdminObject.PERMISSIONS_GROUP_READ_LINK:
desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT;
icon = im.getIcon(IconManager.READ_LINK_GROUP);
break;
case AdminObject.PERMISSIONS_PUBLIC_READ:
desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT;
icon = im.getIcon(IconManager.PUBLIC_GROUP);
break;
case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE:
desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT;
icon = im.getIcon(IconManager.PUBLIC_GROUP);
}
putValue(Action.SMALL_ICON, icon);
putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(desc));
}
/**
* Enables the action if the browser is not ready.
* @see TreeViewerAction#onBrowserStateChange(Browser)
*/
protected void onBrowserStateChange(Browser browser)
{
if (browser == null) return;
setEnabled(browser.getState() == Browser.READY);
}
/**
* Creates a new instance.
*
* @param model Reference to the Model. Mustn't be <code>null</code>.
* @param group The group the logged in user is a member of.
* @param add Passes <code>true</code> to add the group, <code>false</code>
* to switch.
*/
public GroupSelectionAction(TreeViewer model, GroupData group, boolean add)
{
super(model);
if (group == null)
throw new IllegalArgumentException("No group specified.");
this.group = group;
this.add = add;
name = group.getName();
putValue(Action.NAME, name);
setPermissions();
}
/**
* Returns <code>true</code> if the passed id corresponds to the group
* hosted by this component, <code>false</code> otherwise.
*
* @param groupID The id to check.
* @return See above.
*/
public boolean isSameGroup(long groupID)
{
return group.getId() == groupID;
}
/**
* Returns the id of the group hosted by this component.
*
* @return See above.
*/
public long getGroupId() { return group.getId(); }
/**
* Sets the default group for the currently logged in user.
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public void actionPerformed(ActionEvent e)
{
model.retrieveUserGroups(null, group);
//model.setUserGroup(group, add);
}
}