]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java
Improve security UI
[lgpl/argeo-commons.git] / security / eclipse / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / SecurityUiPlugin.java
1 package org.argeo.security.ui;
2
3 import org.argeo.ArgeoException;
4 import org.argeo.security.ArgeoUser;
5 import org.argeo.security.UserNature;
6 import org.argeo.security.nature.SimpleUserNature;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.ui.plugin.AbstractUIPlugin;
9 import org.osgi.framework.BundleContext;
10
11 /**
12 * The activator class controls the plug-in life cycle
13 */
14 public class SecurityUiPlugin extends AbstractUIPlugin {
15
16 // The plug-in ID
17 public static final String PLUGIN_ID = "org.argeo.security.ui"; //$NON-NLS-1$
18
19 // The shared instance
20 private static SecurityUiPlugin plugin;
21
22 /**
23 * The constructor
24 */
25 public SecurityUiPlugin() {
26 }
27
28 /*
29 * (non-Javadoc)
30 *
31 * @see
32 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
33 * )
34 */
35 public void start(BundleContext context) throws Exception {
36 super.start(context);
37 plugin = this;
38 }
39
40 /*
41 * (non-Javadoc)
42 *
43 * @see
44 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
45 * )
46 */
47 public void stop(BundleContext context) throws Exception {
48 plugin = null;
49 super.stop(context);
50 }
51
52 /**
53 * Returns the shared instance
54 *
55 * @return the shared instance
56 */
57 public static SecurityUiPlugin getDefault() {
58 return plugin;
59 }
60
61 public static ImageDescriptor getImageDescriptor(String path) {
62 return imageDescriptorFromPlugin(PLUGIN_ID, path);
63 }
64
65 /*
66 * SECURITY UTILITIES
67 */
68 public final static SimpleUserNature findSimpleUserNature(ArgeoUser user,
69 String simpleNatureType) {
70 SimpleUserNature simpleNature = null;
71 if (simpleNatureType != null)
72 simpleNature = (SimpleUserNature) user.getUserNatures().get(
73 simpleNatureType);
74 else
75 for (UserNature userNature : user.getUserNatures().values())
76 if (userNature instanceof SimpleUserNature)
77 simpleNature = (SimpleUserNature) userNature;
78
79 if (simpleNature == null)
80 throw new ArgeoException("No simple user nature in user " + user);
81 return simpleNature;
82 }
83 }