]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UserProfile.java
f28ab57339cacb2337d7498a47889ecb606232d8
[lgpl/argeo-commons.git] / UserProfile.java
1 package org.argeo.security.ui.views;
2
3 import java.util.TreeSet;
4
5 import org.argeo.eclipse.ui.EclipseUiUtils;
6 import org.argeo.security.ui.SecurityUiPlugin;
7 import org.argeo.security.ui.internal.CurrentUser;
8 import org.eclipse.jface.viewers.IStructuredContentProvider;
9 import org.eclipse.jface.viewers.LabelProvider;
10 import org.eclipse.jface.viewers.TableViewer;
11 import org.eclipse.jface.viewers.Viewer;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Table;
17 import org.eclipse.swt.widgets.Text;
18 import org.eclipse.ui.part.ViewPart;
19 import org.springframework.security.Authentication;
20
21 /** Information about the currently logged in user */
22 public class UserProfile extends ViewPart {
23 public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile";
24
25 private TableViewer viewer;
26
27 @Override
28 public void createPartControl(Composite parent) {
29 parent.setLayout(new GridLayout(2, false));
30
31 Authentication authentication = CurrentUser.getAuthentication();
32 EclipseUiUtils.createGridLL(parent, "Name", authentication
33 .getPrincipal().toString());
34 EclipseUiUtils.createGridLL(parent, "User ID",
35 CurrentUser.getUsername());
36
37 // roles table
38 Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
39 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
40 table.setLinesVisible(false);
41 table.setHeaderVisible(false);
42 viewer = new TableViewer(table);
43 viewer.setContentProvider(new RolesContentProvider());
44 viewer.setLabelProvider(new LabelProvider());
45 getViewSite().setSelectionProvider(viewer);
46 viewer.setInput(getViewSite());
47 }
48
49 @Override
50 public void setFocus() {
51 viewer.getTable();
52 }
53
54 private class RolesContentProvider implements IStructuredContentProvider {
55 public Object[] getElements(Object inputElement) {
56 return new TreeSet<String>(CurrentUser.roles()).toArray();
57 }
58
59 public void dispose() {
60 }
61
62 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
63 }
64
65 }
66
67 }