Project

General

Profile

Download (2.88 KB) Statistics
| Branch: | Tag: | Revision:
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.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
22

    
23
import eu.etaxonomy.cdm.model.common.User;
24
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
27

    
28
/**
29
 * Shows the currently logged in user in status bar
30
 *
31
 * @author n.hoffmann
32
 * @created 01.07.2009
33
 * @version 1.0
34
 */
35
public class AuthenticatedUserBar extends WorkbenchWindowControlContribution implements Observer{
36

    
37
    private Label label_authenticatedUser;
38

    
39
    /**
40
     * <p>Constructor for AuthenticatedUserBar.</p>
41
     */
42
    public AuthenticatedUserBar(){
43
        CdmStore.getLoginManager().addObserver(this);
44
    }
45

    
46
    /* (non-Javadoc)
47
     * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
48
     */
49
    /** {@inheritDoc} */
50
    @Override
51
    protected Control createControl(Composite parent) {
52

    
53
        label_authenticatedUser = new Label(parent,  SWT.NULL);
54

    
55
        update(null, null);
56

    
57
        return label_authenticatedUser;
58
    }
59

    
60
    /* (non-Javadoc)
61
     * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
62
     */
63
    /** {@inheritDoc} */
64
    @Override
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 = "";
69
        if(authenticatedUser == null) {
70
            text = "Not logged in              " ;
71
        } else {
72
            if(CdmStore.getCurrentSessionManager().isRemoting()) {
73
                CdmRemoteSource source = (CdmRemoteSource) CdmStore.getActiveCdmSource();
74
                String loginInfo = authenticatedUser.getUsername() + "@" + source.getName() + ":" + source.getContextPath();
75
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText(ApplicationUtil.getTitle() + " " + loginInfo);
76
            }
77
            text = "Logged in as: " + authenticatedUser.getUsername() + "         ";
78
        }
79

    
80
        label_authenticatedUser.setText(text);
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see org.eclipse.jface.action.ContributionItem#dispose()
85
     */
86
    /** {@inheritDoc} */
87
    @Override
88
    public void dispose() {
89
        super.dispose();
90
        CdmStore.getLoginManager().deleteObserver(this);
91
    }
92

    
93

    
94
}
    (1-1/1)