Project

General

Profile

Download (2.52 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.ui.bar;
11

    
12
import java.util.Observable;
13
import java.util.Observer;
14

    
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;
21

    
22
import eu.etaxonomy.cdm.model.common.User;
23
import eu.etaxonomy.taxeditor.Messages;
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
    public AuthenticatedUserBar(){
40
        CdmStore.getLoginManager().addObserver(this);
41
    }
42

    
43
    /** {@inheritDoc} */
44
    @Override
45
    protected Control createControl(Composite parent) {
46

    
47
        label_authenticatedUser = new Label(parent,  SWT.NULL);
48

    
49
        update(null, null);
50

    
51
        return label_authenticatedUser;
52
    }
53

    
54
    /** {@inheritDoc} */
55
    @Override
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 ;
62
        } else {
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$
66

    
67
            text = String.format(Messages.AuthenticatedUserBar_LOGGED_IN_AS, authenticatedUser.getUsername());
68
        }
69

    
70
        label_authenticatedUser.setText(text);
71
    }
72

    
73
    /** {@inheritDoc} */
74
    @Override
75
    public void dispose() {
76
        super.dispose();
77
        CdmStore.getLoginManager().deleteObserver(this);
78
    }
79

    
80
}
    (1-1/1)