]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui/src/org/argeo/security/ui/views/UserProfile.java
Documentation
[lgpl/argeo-commons.git] / org.argeo.security.ui / src / org / argeo / security / ui / views / UserProfile.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.views;
17
18 import java.util.TreeSet;
19
20 import org.argeo.eclipse.ui.EclipseUiUtils;
21 import org.argeo.security.ui.SecurityUiPlugin;
22 import org.argeo.security.ui.internal.CurrentUser;
23 import org.eclipse.jface.viewers.IStructuredContentProvider;
24 import org.eclipse.jface.viewers.LabelProvider;
25 import org.eclipse.jface.viewers.TableViewer;
26 import org.eclipse.jface.viewers.Viewer;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Table;
32 import org.eclipse.ui.part.ViewPart;
33
34 /** Information about the currently logged in user */
35 public class UserProfile extends ViewPart {
36 public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile";
37
38 private TableViewer viewer;
39
40 @Override
41 public void createPartControl(Composite parent) {
42 parent.setLayout(new GridLayout(2, false));
43
44 // Authentication authentication = CurrentUser.getAuthentication();
45 // EclipseUiUtils.createGridLL(parent, "Name", authentication
46 // .getPrincipal().toString());
47 EclipseUiUtils.createGridLL(parent, "User ID",
48 CurrentUser.getUsername());
49
50 // roles table
51 Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
52 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
53 table.setLinesVisible(false);
54 table.setHeaderVisible(false);
55 viewer = new TableViewer(table);
56 viewer.setContentProvider(new RolesContentProvider());
57 viewer.setLabelProvider(new LabelProvider());
58 getViewSite().setSelectionProvider(viewer);
59 viewer.setInput(getViewSite());
60 }
61
62 @Override
63 public void setFocus() {
64 viewer.getTable();
65 }
66
67 private class RolesContentProvider implements IStructuredContentProvider {
68 private static final long serialVersionUID = -4576917440167866233L;
69
70 public Object[] getElements(Object inputElement) {
71 return new TreeSet<String>(CurrentUser.roles()).toArray();
72 }
73
74 public void dispose() {
75 }
76
77 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
78 }
79
80 }
81
82 }