Project

General

Profile

« Previous | Next » 

Revision ac23ea9b

Added by Cherian Mathew over 8 years ago

#5029 Add login info to application title bar

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationUtil.java
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;
12

  
13
import org.eclipse.core.runtime.Platform;
14
import org.osgi.framework.Bundle;
15

  
16
import eu.etaxonomy.taxeditor.model.AbstractUtility;
17

  
18
/**
19
 * <p>ApplicationUtil class.</p>
20
 *
21
 * @author n.hoffmann
22
 * @created Oct 13, 2010
23
 * @version 1.0
24
 */
25
public class ApplicationUtil extends AbstractUtility {
26

  
27

  
28
    /**
29
     * Prefix to declare the version as beta
30
     */
31
    private static final String BETA_PREFIX = "[REMOTING]";
32

  
33
    /**
34
     * @return
35
     */
36
    public static String getVersion() {
37
        Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.application");
38
        String version = bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
39
        // Checking if this is a beta (snapshot) version
40
        if(version ==null || version.isEmpty()) {
41
            return "";
42
        }
43
        String[] parts = version.split("\\.");
44
        if(parts.length <= 3) {
45
            // this is a stable version
46
            return version;
47
        } else {
48
            return BETA_PREFIX + " " + version + " UTC";
49
        }
50

  
51
    }
52

  
53
    /**
54
     * @return
55
     */
56
    public static boolean isStable() {
57
        return !getVersion().startsWith("[");
58
    }
59
	/**
60
	 * <p>getPluginId</p>
61
	 *
62
	 * @return a {@link java.lang.String} object.
63
	 */
64
	public static String getPluginId(){
65
		return TaxonomicEditorPlugin.PLUGIN_ID;
66
	}
67

  
68

  
69

  
70
}
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
12 12
import eu.etaxonomy.taxeditor.store.CdmStore;
13 13
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
14 14
import eu.etaxonomy.taxeditor.update.P2Util;
15
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
15 16

  
16 17
/**
17 18
 * <p>ApplicationWorkbenchWindowAdvisor class.</p>
......
47 48
		configurer.setShowCoolBar(true);
48 49
		configurer.setShowStatusLine(true);
49 50
		configurer.setShowPerspectiveBar(true);
50
		configurer.setTitle("EDIT Taxonomic Editor " + ApplicationUtil.getVersion());
51
		configurer.setTitle(ApplicationUtil.getTitle());
51 52
		configurer.setShowProgressIndicator(true);
52 53

  
53 54
		CdmDataSourceRepository.createDefaultH2DataSource();
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/P2Util.java
30 30
import org.osgi.framework.BundleContext;
31 31
import org.osgi.framework.ServiceReference;
32 32

  
33
import eu.etaxonomy.taxeditor.ApplicationUtil;
34 33
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
35 34
import eu.etaxonomy.taxeditor.model.MessagingUtils;
36 35
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
36
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
37 37

  
38 38
/**
39 39
 * This class is a utility class for updating the editor from a p2 update site,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/bar/AuthenticatedUserBar.java
1 1
// $Id$
2 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
*/
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 10

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

  
......
14 14
import java.util.Observer;
15 15

  
16 16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.layout.GridLayout;
18 17
import org.eclipse.swt.widgets.Composite;
19 18
import org.eclipse.swt.widgets.Control;
20 19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.ui.PlatformUI;
21 21
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
22 22

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

  
26 28
/**
27 29
 * Shows the currently logged in user in status bar
......
32 34
 */
33 35
public class AuthenticatedUserBar extends WorkbenchWindowControlContribution implements Observer{
34 36

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

  
84 93

  
85 94
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/util/ApplicationUtil.java
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.util;
12

  
13
import org.eclipse.core.runtime.Platform;
14
import org.osgi.framework.Bundle;
15

  
16
import eu.etaxonomy.taxeditor.model.AbstractUtility;
17

  
18
/**
19
 * <p>ApplicationUtil class.</p>
20
 *
21
 * @author n.hoffmann
22
 * @created Oct 13, 2010
23
 * @version 1.0
24
 */
25
public class ApplicationUtil extends AbstractUtility {
26

  
27

  
28
    /**
29
     * Prefix to declare the version as beta
30
     */
31
    private static final String BETA_PREFIX = "[REMOTING]";
32

  
33
    public static String getTitle() {
34
        return "EDIT Taxonomic Editor " + ApplicationUtil.getVersion();
35
    }
36
    /**
37
     * @return
38
     */
39
    public static String getVersion() {
40
        Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.application");
41
        String version = bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
42
        // Checking if this is a beta (snapshot) version
43
        if(version ==null || version.isEmpty()) {
44
            return "";
45
        }
46
        String[] parts = version.split("\\.");
47
        if(parts.length <= 3) {
48
            // this is a stable version
49
            return version;
50
        } else {
51
            return BETA_PREFIX + " " + version + " UTC";
52
        }
53

  
54
    }
55

  
56
    /**
57
     * @return
58
     */
59
    public static boolean isStable() {
60
        return !getVersion().startsWith("[");
61
    }
62

  
63

  
64
}

Also available in: Unified diff