// $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;
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
*/
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);
+ }
+
}