2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.bar
;
11 import java
.util
.Observable
;
12 import java
.util
.Observer
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Label
;
18 import org
.eclipse
.ui
.PlatformUI
;
19 import org
.eclipse
.ui
.menus
.WorkbenchWindowControlContribution
;
21 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
22 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
23 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.util
.ApplicationUtil
;
28 * 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 public boolean isDynamic() {
47 protected Control
createControl(Composite parent
) {
48 parent
.getParent().setRedraw(true);
49 label_authenticatedUser
= new Label(parent
, SWT
.NULL
);
53 return label_authenticatedUser
;
57 public void update(Observable o
, Object arg
) {
58 User authenticatedUser
= CdmStore
.getLoginManager().getAuthenticatedUser();
59 // TODO find a method to recompute width for parental toolbar item
60 String text
= ""; //$NON-NLS-1$
61 if(authenticatedUser
== null) {
62 text
= Messages
.AuthenticatedUserBar_NOT_LOGGED_IN
;
64 ICdmRemoteSource source
= (ICdmRemoteSource
) CdmStore
.getActiveCdmSource();
65 String loginInfo
= String
.format("%s@%s:%s",authenticatedUser
.getUsername(), source
.getName(), source
.getContext()); //$NON-NLS-1$
66 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell().setText(ApplicationUtil
.getTitle() + " " + loginInfo
); //$NON-NLS-1$
68 text
= String
.format(Messages
.AuthenticatedUserBar_LOGGED_IN_AS
, authenticatedUser
.getUsername());
71 label_authenticatedUser
.setText(text
);
72 label_authenticatedUser
.setRedraw(true);
76 public void dispose() {
78 CdmStore
.getLoginManager().deleteObserver(this);