3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.user
;
13 import java
.util
.Observable
;
14 import java
.util
.Observer
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Label
;
21 import org
.eclipse
.ui
.menus
.WorkbenchWindowControlContribution
;
23 import eu
.etaxonomy
.cdm
.model
.common
.User
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 * Shows the currently logged in user in status bar
33 public class AuthenticatedUserBar
extends WorkbenchWindowControlContribution
implements Observer
{
35 private Label label_authenticatedUser
;
37 public AuthenticatedUserBar(){
38 CdmStore
.getLoginManager().addObserver(this);
42 * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
45 protected Control
createControl(Composite parent
) {
46 final Composite composite
= new Composite(parent
, SWT
.NONE
);
47 final GridLayout layout
= new GridLayout();
48 composite
.setLayout(layout
);
50 label_authenticatedUser
= new Label(composite
, SWT
.NULL
);
58 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
60 public void update(Observable o
, Object arg
) {
61 User authenticatedUser
= CdmStore
.getLoginManager().getAuthenticatedUser();
62 // TODO find a method to recompute width for parental toolbar item
63 String text
= authenticatedUser
== null ?
"Not logged in " :
64 "Logged in as: " + authenticatedUser
.getUsername() + " ";
65 label_authenticatedUser
.setText(text
);
69 * @see org.eclipse.jface.action.ContributionItem#dispose()
72 public void dispose() {
75 CdmStore
.getLoginManager().deleteObserver(this);