1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.bar;
|
12
|
|
13
|
import java.util.Observable;
|
14
|
import java.util.Observer;
|
15
|
|
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;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.User;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
|
26
|
/**
|
27
|
* Shows the currently logged in user in status bar
|
28
|
*
|
29
|
* @author n.hoffmann
|
30
|
* @created 01.07.2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class AuthenticatedUserBar extends WorkbenchWindowControlContribution implements Observer{
|
34
|
|
35
|
private Label label_authenticatedUser;
|
36
|
|
37
|
/**
|
38
|
* <p>Constructor for AuthenticatedUserBar.</p>
|
39
|
*/
|
40
|
public AuthenticatedUserBar(){
|
41
|
CdmStore.getLoginManager().addObserver(this);
|
42
|
}
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
|
46
|
*/
|
47
|
/** {@inheritDoc} */
|
48
|
@Override
|
49
|
protected Control createControl(Composite parent) {
|
50
|
final Composite composite = new Composite(parent, SWT.NONE);
|
51
|
final GridLayout layout = new GridLayout();
|
52
|
composite.setLayout(layout);
|
53
|
|
54
|
label_authenticatedUser = new Label(composite, SWT.NULL);
|
55
|
|
56
|
update(null, null);
|
57
|
|
58
|
return composite;
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
|
63
|
*/
|
64
|
/** {@inheritDoc} */
|
65
|
public void update(Observable o, Object arg) {
|
66
|
User authenticatedUser = CdmStore.getLoginManager().getAuthenticatedUser();
|
67
|
// TODO find a method to recompute width for parental toolbar item
|
68
|
String text = authenticatedUser == null ? "Not logged in " :
|
69
|
"Logged in as: " + authenticatedUser.getUsername() + " ";
|
70
|
label_authenticatedUser.setText(text);
|
71
|
}
|
72
|
|
73
|
/* (non-Javadoc)
|
74
|
* @see org.eclipse.jface.action.ContributionItem#dispose()
|
75
|
*/
|
76
|
/** {@inheritDoc} */
|
77
|
@Override
|
78
|
public void dispose() {
|
79
|
super.dispose();
|
80
|
|
81
|
CdmStore.getLoginManager().deleteObserver(this);
|
82
|
}
|
83
|
|
84
|
|
85
|
}
|