X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fplugins%2Forg.argeo.security.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fui%2Fviews%2FUserProfile.java;h=817fbbc44387976b56aa52368fbe1f6c42227cec;hb=1d5afdce3e91054f07ddd3c98309c363b4cf1d46;hp=afa56948813f58aeded3bac18a2859c904699d74;hpb=041234a54c1b98bcba16e359c4c4905c4eed1768;p=lgpl%2Fargeo-commons.git diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UserProfile.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UserProfile.java index afa569488..817fbbc44 100644 --- a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UserProfile.java +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UserProfile.java @@ -1,22 +1,81 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.security.ui.views; +import java.util.TreeSet; + +import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.internal.CurrentUser; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; import org.eclipse.ui.part.ViewPart; +import org.springframework.security.Authentication; +/** Information about the currently logged in user */ public class UserProfile extends ViewPart { public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile"; + private TableViewer viewer; + @Override public void createPartControl(Composite parent) { - new Label(parent, SWT.NONE).setText(CurrentUser.getUsername()); + parent.setLayout(new GridLayout(2, false)); + + Authentication authentication = CurrentUser.getAuthentication(); + EclipseUiUtils.createGridLL(parent, "Name", authentication + .getPrincipal().toString()); + EclipseUiUtils.createGridLL(parent, "User ID", + CurrentUser.getUsername()); + + // roles table + Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + table.setLinesVisible(false); + table.setHeaderVisible(false); + viewer = new TableViewer(table); + viewer.setContentProvider(new RolesContentProvider()); + viewer.setLabelProvider(new LabelProvider()); + getViewSite().setSelectionProvider(viewer); + viewer.setInput(getViewSite()); } @Override public void setFocus() { + viewer.getTable(); + } + + private class RolesContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + return new TreeSet(CurrentUser.roles()).toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } }