2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.ui
.views
;
18 import java
.util
.TreeSet
;
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 import org
.springframework
.security
.Authentication
;
35 /** Information about the currently logged in user */
36 public class UserProfile
extends ViewPart
{
37 public static String ID
= SecurityUiPlugin
.PLUGIN_ID
+ ".userProfile";
39 private TableViewer viewer
;
42 public void createPartControl(Composite parent
) {
43 parent
.setLayout(new GridLayout(2, false));
45 Authentication authentication
= CurrentUser
.getAuthentication();
46 EclipseUiUtils
.createGridLL(parent
, "Name", authentication
47 .getPrincipal().toString());
48 EclipseUiUtils
.createGridLL(parent
, "User ID",
49 CurrentUser
.getUsername());
52 Table table
= new Table(parent
, SWT
.V_SCROLL
| SWT
.BORDER
);
53 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
54 table
.setLinesVisible(false);
55 table
.setHeaderVisible(false);
56 viewer
= new TableViewer(table
);
57 viewer
.setContentProvider(new RolesContentProvider());
58 viewer
.setLabelProvider(new LabelProvider());
59 getViewSite().setSelectionProvider(viewer
);
60 viewer
.setInput(getViewSite());
64 public void setFocus() {
68 private class RolesContentProvider
implements IStructuredContentProvider
{
69 public Object
[] getElements(Object inputElement
) {
70 return new TreeSet
<String
>(CurrentUser
.roles()).toArray();
73 public void dispose() {
76 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {