#5029 Add login info to application title bar
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 30 Jul 2015 10:47:29 +0000 (12:47 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 30 Jul 2015 10:47:29 +0000 (12:47 +0200)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/P2Util.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/bar/AuthenticatedUserBar.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/util/ApplicationUtil.java [moved from eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationUtil.java with 87% similarity]

index a4d2e6816dc5452ab1f36ae1b54eeadeb5d4852f..bb5b360a311cca20625d70ad041ed5e78a56ccd2 100644 (file)
@@ -12,6 +12,7 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
 import eu.etaxonomy.taxeditor.update.P2Util;
+import eu.etaxonomy.taxeditor.util.ApplicationUtil;
 
 /**
  * <p>ApplicationWorkbenchWindowAdvisor class.</p>
@@ -47,7 +48,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
                configurer.setShowCoolBar(true);
                configurer.setShowStatusLine(true);
                configurer.setShowPerspectiveBar(true);
-               configurer.setTitle("EDIT Taxonomic Editor " + ApplicationUtil.getVersion());
+               configurer.setTitle(ApplicationUtil.getTitle());
                configurer.setShowProgressIndicator(true);
 
                CdmDataSourceRepository.createDefaultH2DataSource();
index 0a6fb6395ee0530208f6a66839ed79d4f627685d..a286718ff9854c4a23dc879cd655b6fdecd62087 100644 (file)
@@ -30,10 +30,10 @@ import org.eclipse.ui.PlatformUI;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
-import eu.etaxonomy.taxeditor.ApplicationUtil;
 import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.util.ApplicationUtil;
 
 /**
  * This class is a utility class for updating the editor from a p2 update site,
index dea82de48dabc61da01391b69959dad169b16287..38ae7193bb78ca5a632f2c114595fbd2d8e132e2 100644 (file)
@@ -1,12 +1,12 @@
 // $Id$
 /**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 
 package eu.etaxonomy.taxeditor.ui.bar;
 
@@ -14,14 +14,16 @@ import java.util.Observable;
 import java.util.Observer;
 
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
 
 import eu.etaxonomy.cdm.model.common.User;
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.util.ApplicationUtil;
 
 /**
  * Shows the currently logged in user in status bar
@@ -32,54 +34,61 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 public class AuthenticatedUserBar extends WorkbenchWindowControlContribution implements Observer{
 
-       private Label label_authenticatedUser;
-
-       /**
-        * <p>Constructor for AuthenticatedUserBar.</p>
-        */
-       public AuthenticatedUserBar(){
-               CdmStore.getLoginManager().addObserver(this);
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
-        */
-       /** {@inheritDoc} */
-       @Override
-       protected Control createControl(Composite parent) {
-               final Composite composite = new Composite(parent, SWT.NONE);
-               final GridLayout layout = new GridLayout();
-               composite.setLayout(layout);
-               
-               label_authenticatedUser = new Label(composite, SWT.NULL);
-
-               update(null, null);
-                       
-               return composite;
-       }
-
-       /* (non-Javadoc)
-        * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
-        */
-       /** {@inheritDoc} */
-       public void update(Observable o, Object arg) {
-               User authenticatedUser = CdmStore.getLoginManager().getAuthenticatedUser();
-               // TODO find a method to recompute width for parental toolbar item
-               String text = authenticatedUser == null ? "Not logged in              " : 
-                                                                                                 "Logged in as: " + authenticatedUser.getUsername() + "         ";     
-               label_authenticatedUser.setText(text);
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.action.ContributionItem#dispose()
-        */
-       /** {@inheritDoc} */
-       @Override
-       public void dispose() {
-               super.dispose();
-               
-               CdmStore.getLoginManager().deleteObserver(this);
-       }
-       
+    private Label label_authenticatedUser;
+
+    /**
+     * <p>Constructor for AuthenticatedUserBar.</p>
+     */
+    public AuthenticatedUserBar(){
+        CdmStore.getLoginManager().addObserver(this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    /** {@inheritDoc} */
+    @Override
+    protected Control createControl(Composite parent) {
+
+        label_authenticatedUser = new Label(parent,  SWT.NULL);
+
+        update(null, null);
+
+        return label_authenticatedUser;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void update(Observable o, Object arg) {
+        User authenticatedUser = CdmStore.getLoginManager().getAuthenticatedUser();
+        // TODO find a method to recompute width for parental toolbar item
+        String text = "";
+        if(authenticatedUser == null) {
+            text = "Not logged in              " ;
+        } else {
+            if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                CdmRemoteSource source = (CdmRemoteSource) CdmStore.getActiveCdmSource();
+                String loginInfo = authenticatedUser.getUsername() + "@" + source.getName() + ":" + source.getContextPath();
+                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText(ApplicationUtil.getTitle() + " " + loginInfo);
+            }
+            text = "Logged in as: " + authenticatedUser.getUsername() + "         ";
+        }
+
+        label_authenticatedUser.setText(text);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.action.ContributionItem#dispose()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void dispose() {
+        super.dispose();
+        CdmStore.getLoginManager().deleteObserver(this);
+    }
+
 
 }
similarity index 87%
rename from eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationUtil.java
rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/util/ApplicationUtil.java
index eb8f82986f5f5c573f611b153018b411dacec79a..8f3025067dabff93477c171c39023a49be7bf67f 100644 (file)
@@ -8,7 +8,7 @@
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 
-package eu.etaxonomy.taxeditor;
+package eu.etaxonomy.taxeditor.util;
 
 import org.eclipse.core.runtime.Platform;
 import org.osgi.framework.Bundle;
@@ -30,6 +30,9 @@ public class ApplicationUtil extends AbstractUtility {
      */
     private static final String BETA_PREFIX = "[REMOTING]";
 
+    public static String getTitle() {
+        return "EDIT Taxonomic Editor " + ApplicationUtil.getVersion();
+    }
     /**
      * @return
      */
@@ -56,15 +59,6 @@ public class ApplicationUtil extends AbstractUtility {
     public static boolean isStable() {
         return !getVersion().startsWith("[");
     }
-       /**
-        * <p>getPluginId</p>
-        *
-        * @return a {@link java.lang.String} object.
-        */
-       public static String getPluginId(){
-               return TaxonomicEditorPlugin.PLUGIN_ID;
-       }
-
 
 
 }