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.
10 package eu
.etaxonomy
.taxeditor
.ui
.bar
;
12 import java
.util
.Observable
;
13 import java
.util
.Observer
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.swt
.widgets
.Label
;
19 import org
.eclipse
.ui
.PlatformUI
;
20 import org
.eclipse
.ui
.menus
.WorkbenchWindowControlContribution
;
22 import eu
.etaxonomy
.cdm
.model
.common
.User
;
23 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.util
.ApplicationUtil
;
29 * Shows the currently logged in user in status bar
35 public class AuthenticatedUserBar
extends WorkbenchWindowControlContribution
implements Observer
{
37 private Label label_authenticatedUser
;
39 public AuthenticatedUserBar(){
40 CdmStore
.getLoginManager().addObserver(this);
45 protected Control
createControl(Composite parent
) {
47 label_authenticatedUser
= new Label(parent
, SWT
.NULL
);
51 return label_authenticatedUser
;
56 public void update(Observable o
, Object arg
) {
57 User authenticatedUser
= CdmStore
.getLoginManager().getAuthenticatedUser();
58 // TODO find a method to recompute width for parental toolbar item
59 String text
= ""; //$NON-NLS-1$
60 if(authenticatedUser
== null) {
61 text
= Messages
.AuthenticatedUserBar_NOT_LOGGED_IN
;
63 CdmRemoteSource source
= (CdmRemoteSource
) CdmStore
.getActiveCdmSource();
64 String loginInfo
= String
.format("%s@%s:%s",authenticatedUser
.getUsername(), source
.getName(), source
.getContextPath()); //$NON-NLS-1$
65 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell().setText(ApplicationUtil
.getTitle() + " " + loginInfo
); //$NON-NLS-1$
67 text
= String
.format(Messages
.AuthenticatedUserBar_LOGGED_IN_AS
, authenticatedUser
.getUsername());
70 label_authenticatedUser
.setText(text
);
75 public void dispose() {
77 CdmStore
.getLoginManager().deleteObserver(this);