Merge branch 'hotfix/5.45.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / bar / AuthenticatedUserBar.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.ui.bar;
10
11 import java.util.Observable;
12 import java.util.Observer;
13
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;
20
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;
26
27 /**
28 * Shows the currently logged in user in status bar
29 *
30 * @author n.hoffmann
31 * @created 01.07.2009
32 */
33 public class AuthenticatedUserBar extends WorkbenchWindowControlContribution implements Observer{
34
35 private Label label_authenticatedUser;
36
37 public AuthenticatedUserBar(){
38 CdmStore.getLoginManager().addObserver(this);
39 }
40
41 @Override
42 public boolean isDynamic() {
43 return true;
44 }
45
46 @Override
47 protected Control createControl(Composite parent) {
48 parent.getParent().setRedraw(true);
49 label_authenticatedUser = new Label(parent, SWT.NULL);
50
51 update(null, null);
52
53 return label_authenticatedUser;
54 }
55
56 @Override
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 ;
63 } else {
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$
67
68 text = String.format(Messages.AuthenticatedUserBar_LOGGED_IN_AS, authenticatedUser.getUsername());
69 }
70
71 label_authenticatedUser.setText(text);
72 label_authenticatedUser.setRedraw(true);
73 }
74
75 @Override
76 public void dispose() {
77 super.dispose();
78 CdmStore.getLoginManager().deleteObserver(this);
79 }
80
81 }